From c56f75a4c373a039e4ea10555a9007f0e93826bf Mon Sep 17 00:00:00 2001 From: Richard Eames Date: Thu, 18 Sep 2014 12:37:22 -0600 Subject: [PATCH] Check for arguments object edge case, and remove `instanceof` --- mithril.js | 7 ++++--- tests/mithril-tests.js | 9 +++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/mithril.js b/mithril.js index e20ef884..bb277ee2 100644 --- a/mithril.js +++ b/mithril.js @@ -22,7 +22,8 @@ Mithril = m = new function app(window, undefined) { * */ function m() { - var args = Array.prototype.slice.call(arguments, 0) + var arrSlice = Array.prototype.slice; + var args = arrSlice.call(arguments, 0) var hasAttrs = args[1] != null && isObj(args[1]) && !("tag" in args[1]) && !("subtree" in args[1]) var attrs = hasAttrs ? args[1] : {} var classAttrName = "class" in attrs ? "class" : "className" @@ -41,8 +42,8 @@ Mithril = m = new function app(window, undefined) { var children = hasAttrs ? args[2] : args[1] - if (children instanceof Array) { - cell.children = children + if (isArr(children) || type(children) == "[object Arguments]") { + cell.children = arrSlice.call(children, 0) } else { cell.children = hasAttrs ? args.slice(2) : args.slice(1) diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index 9a8cf482..339cba1f 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -784,6 +784,15 @@ function testMithril(mock) { m.render(root, [m("div.green", [m("div")]), m("div.blue")]) return root.childNodes.length == 2 }) + test(function() { + var root = mock.document.createElement("div") + m.render(root, m("ul", [m("li")])) + var change = function() { + m.render(root, m("ul", arguments)) + } + change(m("b")); + return root.childNodes[0].childNodes[0].nodeName == "B" + }) //end m.render //m.redraw