From a7a9447cd606e22ce2cee193f3acdf25759d8269 Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Thu, 20 Mar 2014 15:36:52 -0400 Subject: [PATCH] fixing null reference when passing undefined to virtual dom tree --- archive/v0.1.1/mithril-tests.js | 10 +++++++++- archive/v0.1.1/mithril.html | 4 ++-- archive/v0.1.1/mithril.min.js | 2 +- archive/v0.1.1/mithril.min.map | 2 +- archive/v0.1.1/mithril.min.zip | Bin 19774 -> 19837 bytes archive/v0.1.1/mithril.route.html | 2 +- mithril.js | 3 ++- tests/mithril-tests.js | 7 +++++++ 8 files changed, 23 insertions(+), 7 deletions(-) diff --git a/archive/v0.1.1/mithril-tests.js b/archive/v0.1.1/mithril-tests.js index bb34ed35..7badfa99 100644 --- a/archive/v0.1.1/mithril-tests.js +++ b/archive/v0.1.1/mithril-tests.js @@ -46,11 +46,12 @@ new function(window) { var nodes = [], intact = cached.length === data.length for (var i = 0; i < data.length; i++) { var item = build(parent, data[i], cached[i]) + if (item === undefined) continue if (!item.nodes.intact) intact = false cached[i] = item } if (!intact) { - for (var i = 0; i < data.length; i++) nodes = nodes.concat(cached[i].nodes) + for (var i = 0; i < data.length; i++) if (cached[i] !== undefined) nodes = nodes.concat(cached[i].nodes) for (var i = nodes.length, node; node = cached.nodes[i]; i++) if (node.parentNode !== null) node.parentNode.removeChild(node) for (var i = cached.nodes.length, node; node = nodes[i]; i++) if (node.parentNode === null) parent.appendChild(node) cached.length = data.length @@ -522,6 +523,8 @@ function testMithril(mock) { test(function() {return m("div", ["a", "b"]).children.length === 2}) test(function() {return m("div", [m("div")]).children[0].tag === "div"}) test(function() {return m("div", m("div")).attrs.tag === "div"}) //yes, this is expected behavior: see method signature + test(function() {return m("div", [undefined]).tag === "div"}) + test(function() {return m("div", [{foo: "bar"}])}) //as long as it doesn't throw errors, it's fine //m.module test(function() { @@ -601,6 +604,11 @@ function testMithril(mock) { var elementAfter = root.childNodes[0] return elementBefore !== elementAfter }) + test(function() { + var root = mock.document.createElement("div") + m.render(root, m("div", [undefined])) + return root.childNodes[0].childNodes.length === 0 + }) //m.redraw test(function() { diff --git a/archive/v0.1.1/mithril.html b/archive/v0.1.1/mithril.html index bb84ea23..86f4ab7b 100644 --- a/archive/v0.1.1/mithril.html +++ b/archive/v0.1.1/mithril.html @@ -182,7 +182,7 @@ m("a[href='/dashboard']", {config: m.route}, "Dashboard&q where: VirtualElement :: Object { String tag, Attributes attributes, Children children } - Attributes :: Object<any | void config(DOMElement element, Boolean isNew)> + Attributes :: Object<any | void config(DOMElement element, Boolean isInitialized)> Children :: String text | Array<String text | VirtualElement virtualElement | Children children>