fix IE null ref exception

This commit is contained in:
Leo Horie 2014-10-03 13:31:02 -04:00
parent 35d328f416
commit 50173f0e74
4 changed files with 15 additions and 8 deletions

View file

@ -439,7 +439,8 @@ Mithril = m = new function app(window, undefined) {
} }
m.prop = function (store) { m.prop = function (store) {
if ((isObj(store) || isFn(store)) && store !== null && isFn(store.then)) { //note: using non-strict equality check here because we're checking if store is null OR undefined
if ((isObj(store) || isFn(store)) && store != null && isFn(store.then)) {
return propify(store) return propify(store)
} }

View file

@ -1,4 +1,5 @@
<!doctype html> <!doctype html>
<script src="http://polyfill.io"></script>
<script src="../mithril.js"></script> <script src="../mithril.js"></script>
<script src="test.js"></script> <script src="test.js"></script>
<script src="mock.js"></script> <script src="mock.js"></script>

View file

@ -26,7 +26,7 @@ function testMithril(mock) {
test(function() {return m("div", [{foo: "bar"}])}) //as long as it doesn't throw errors, it's fine test(function() {return m("div", [{foo: "bar"}])}) //as long as it doesn't throw errors, it's fine
test(function() {return m("svg", [m("g")])}) test(function() {return m("svg", [m("g")])})
test(function() {return m("svg", [m("a[href='http://google.com']")])}) test(function() {return m("svg", [m("a[href='http://google.com']")])})
test(function() {return m(".foo", {class: "bar"}).attrs.class == "foo bar"}) test(function() {return m(".foo", {"class": "bar"}).attrs["class"] == "foo bar"})
test(function() {return m(".foo", {className: "bar"}).attrs.className == "foo bar"}) test(function() {return m(".foo", {className: "bar"}).attrs.className == "foo bar"})
//m.module //m.module
@ -70,9 +70,9 @@ function testMithril(mock) {
}) })
test(function() { test(function() {
var root = mock.document.createElement("div") var root = mock.document.createElement("div")
m.render(root, m("div", {class: "a"})) m.render(root, m("div", {"class": "a"}))
var elementBefore = root.childNodes[0] var elementBefore = root.childNodes[0]
m.render(root, m("div", {class: "b"})) m.render(root, m("div", {"class": "b"}))
var elementAfter = root.childNodes[0] var elementAfter = root.childNodes[0]
return elementBefore === elementAfter return elementBefore === elementAfter
}) })
@ -701,8 +701,8 @@ function testMithril(mock) {
test(function() { test(function() {
//https://github.com/lhorie/mithril.js/issues/157 //https://github.com/lhorie/mithril.js/issues/157
var root = mock.document.createElement("div") var root = mock.document.createElement("div")
m.render(root, m("br", {class: "a"})) m.render(root, m("br", {"class": "a"}))
m.render(root, m("br", {class: "aa"})) m.render(root, m("br", {"class": "aa"}))
return root.childNodes[0].childNodes.length == 0 return root.childNodes[0].childNodes.length == 0
}) })
test(function() { test(function() {

View file

@ -1,10 +1,15 @@
if (!this.console) {
var log = function(value) {document.write("<pre>" + value + "</pre>")}
this.console = {log: log, error: log}
}
function test(condition) { function test(condition) {
var duration = 0 var duration = 0
var start = 0 var start = 0
var result = true var result = true
test.total++ test.total++
if (typeof performance != "undefined") { if (this.performance != null && performance.now) {
start = performance.now() start = performance.now()
} }
try { try {
@ -15,7 +20,7 @@ function test(condition) {
console.error(e) console.error(e)
test.failures.push(condition) test.failures.push(condition)
} }
if (typeof performance != "undefined") { if (this.performance != null && performance.now) {
duration = performance.now() - start duration = performance.now() - start
} }