diff --git a/mithril.js b/mithril.js index 1949e13e..b2b5c30d 100644 --- a/mithril.js +++ b/mithril.js @@ -22,15 +22,14 @@ Mithril = m = new function app(window, undefined) { * */ function m() { - var arrSlice = Array.prototype.slice; - var args = arrSlice.call(arguments, 0) + var args = [].slice.call(arguments) 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" var cell = {tag: "div", attrs: {}} var match, classes = [] while (match = parser.exec(args[0])) { - if (match[1] == "") cell.tag = match[2] + if (match[1] == "" && match[2]) cell.tag = match[2] else if (match[1] == "#") cell.attrs.id = match[2] else if (match[1] == ".") classes.push(match[2]) else if (match[3][0] == "[") { @@ -42,8 +41,8 @@ Mithril = m = new function app(window, undefined) { var children = hasAttrs ? args[2] : args[1] - if (isArr(children) || type(children) == "[object Arguments]") { - cell.children = arrSlice.call(children, 0) + if (isArr(children)) { + cell.children = children } else { cell.children = hasAttrs ? args.slice(2) : args.slice(1) diff --git a/tests/index.html b/tests/index.html index 6e6064ea..340feec3 100644 --- a/tests/index.html +++ b/tests/index.html @@ -1,8 +1,8 @@ - +
Open the console to see the test report
\ No newline at end of file diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index 00e17dd7..75443038 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -775,15 +775,6 @@ function testMithril(mock) { m.render(root, new Field()) return root.childNodes.length == 1 }) - 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 @@ -1705,7 +1696,7 @@ function testMithril(mock) { var scriptTag = [].slice.call(mock.document.getElementsByTagName("script")).filter(function(script){ return script.src.indexOf(callbackKey) > -1 }).pop(); - mock[callbackKey]({foo: "bar1"}) + mock[callbackKey]({foo: "bar1"})//fixme ie mock.document.removeChild(body); return scriptTag.src.indexOf("/test?jsonpCallback=mithril_callback") > -1 && data.foo == "bar1"; }) @@ -1857,7 +1848,7 @@ function testMithril(mock) { deferred.resolve("test") } catch (e) {value3 = e} - return value1 === undefined && value2 === undefined && value3 instanceof ReferenceError + return value1 === undefined && value2 === undefined && (value3 instanceof ReferenceError || value3 instanceof TypeError) }) test(function() { var deferred1 = m.deferred() @@ -2026,11 +2017,6 @@ function testMithril(mock) { return root.childNodes[0].nodeValue === "foo" }) - //console.log presence - test(function() { - return m.deps.factory.toString().indexOf("console") < 0 - }) - // config context test(function() { var root = mock.document.createElement("div") @@ -2060,16 +2046,13 @@ function testMithril(mock) { return success; }) -} - -//test reporting for saucelabs -if (typeof window != "undefined") { - window.global_test_results = { - tests: [], - duration: 0, - passed: 0, - failed: 0 - }; + //console.log presence + test(function() { + return m.deps.factory.toString().indexOf("console") < 0 + }) + test(function() { + return m.deps.factory.toString().indexOf("document.write") < 0 + }) } //mock diff --git a/tests/mock.js b/tests/mock.js index 10999206..7adbceeb 100644 --- a/tests/mock.js +++ b/tests/mock.js @@ -1,3 +1,37 @@ +if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function(item) { + for (var i = 0; i < this.length; i++) { + if (this[i] === item) return i + } + return -1 + } +} +if (!Array.prototype.map) { + Array.prototype.map = function(callback) { + var results = [] + for (var i = 0; i < this.length; i++) { + results[i] = callback(this[i], i, this) + } + return results + } +} +if (!Array.prototype.filter) { + Array.prototype.filter = function(callback) { + var results = [] + for (var i = 0; i < this.length; i++) { + if (callback(this[i], i, this)) results.push(this[i]) + } + return results + } +} +if (!Object.keys) { + Object.keys = function() { + var keys = [] + for (var i in this) keys.push(i) + return keys + } +} + var mock = {} mock.window = new function() { var window = {} @@ -77,7 +111,7 @@ mock.window = new function() { var traverse = function(node){ if(node.childNodes && node.childNodes.length > 0){ - node.childNodes.forEach(function(curr){ + node.childNodes.map(function(curr){ if(curr.nodeName.toLowerCase() === name) out.push(curr); traverse(curr); diff --git a/tests/test.js b/tests/test.js index 0eab457f..1a4b68da 100644 --- a/tests/test.js +++ b/tests/test.js @@ -1,3 +1,13 @@ +//test reporting for saucelabs +if (typeof window != "undefined") { + window.global_test_results = { + tests: [], + duration: 0, + passed: 0, + failed: 0 + }; +} + if (!this.console) { var log = function(value) {document.write("" + value + "")} this.console = {log: log, error: log} @@ -13,7 +23,7 @@ function test(condition) { start = performance.now() } try { - if (!condition()) throw new Error() + if (!condition()) throw new Error("failed") } catch (e) { result = false