From feef1883d19c80072c411b332cf97e3e99c11941 Mon Sep 17 00:00:00 2001 From: Bouke van der Bijl Date: Wed, 19 Nov 2014 16:18:50 -0500 Subject: [PATCH 01/32] Fix bug in IE10 with MutationObserver There is a difference in behavior between MutationObserver and this shim in IE10, causing the target for a MutationRecord to be different from the expect value. This happens because when you append a node with children in IE10 it'll call the DOMNodeInserted for the node and its children seperately. The test has an if statement because the behavior is different between IE10 and chrome, making both outcomes valid. --- src/MutationObserver/MutationObserver.js | 5 ++--- tests/MutationObservers/childList.js | 21 +++++++++++++++++++++ tests/MutationObservers/runner.html | 1 + 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/MutationObserver/MutationObserver.js b/src/MutationObserver/MutationObserver.js index f3b5695..44936ca 100644 --- a/src/MutationObserver/MutationObserver.js +++ b/src/MutationObserver/MutationObserver.js @@ -524,7 +524,6 @@ // Fall through. case 'DOMNodeInserted': // http://dom.spec.whatwg.org/#concept-mo-queue-childlist - var target = e.relatedNode; var changedNode = e.target; var addedNodes, removedNodes; if (e.type === 'DOMNodeInserted') { @@ -539,13 +538,13 @@ var nextSibling = changedNode.nextSibling; // 1. - var record = getRecord('childList', target); + var record = getRecord('childList', e.target.parentNode); record.addedNodes = addedNodes; record.removedNodes = removedNodes; record.previousSibling = previousSibling; record.nextSibling = nextSibling; - forEachAncestorAndObserverEnqueueRecord(target, function(options) { + forEachAncestorAndObserverEnqueueRecord(e.relatedNode, function(options) { // 2.1, 3.2 if (!options.childList) return; diff --git a/tests/MutationObservers/childList.js b/tests/MutationObservers/childList.js index a54f915..ab24c37 100644 --- a/tests/MutationObservers/childList.js +++ b/tests/MutationObservers/childList.js @@ -378,4 +378,25 @@ suite('JsMutationObserver childList', function() { }); }); + test('Append child in child', function() { + var div = testDiv.appendChild(document.createElement('div')); + + var observer = new JsMutationObserver(function() {}); + observer.observe(div, { + childList: true, + subtree: true + }); + var div2 = document.createElement('div') + var div3 = div2.appendChild(document.createElement('div')); + div.appendChild(div2); + var records = observer.takeRecords(); + + if(records.length == 1) { + assert.strictEqual(records[0].target, div); + assert.strictEqual(records[0].addedNodes[0].firstChild, div3); + } else { + assert.strictEqual(records[0].target, div); + assert.strictEqual(records[1].target, div2); + } + }); }); diff --git a/tests/MutationObservers/runner.html b/tests/MutationObservers/runner.html index ea8c3bc..d5b0406 100644 --- a/tests/MutationObservers/runner.html +++ b/tests/MutationObservers/runner.html @@ -17,6 +17,7 @@ + + + + + + + + + diff --git a/tests/HTMLImports/html/dynamic-errors-detail.html b/tests/HTMLImports/html/dynamic-errors-detail.html new file mode 100644 index 0000000..c10ce16 --- /dev/null +++ b/tests/HTMLImports/html/dynamic-errors-detail.html @@ -0,0 +1,50 @@ + + + + + HTML Imports Dynamic + + + + + + + + + diff --git a/tests/HTMLImports/html/dynamic-loaded-detail.html b/tests/HTMLImports/html/dynamic-loaded-detail.html new file mode 100644 index 0000000..6d963aa --- /dev/null +++ b/tests/HTMLImports/html/dynamic-loaded-detail.html @@ -0,0 +1,50 @@ + + + + + HTML Imports Dynamic + + + + + + + + + diff --git a/tests/HTMLImports/tests.js b/tests/HTMLImports/tests.js index 83f0879..ee82f91 100644 --- a/tests/HTMLImports/tests.js +++ b/tests/HTMLImports/tests.js @@ -21,6 +21,9 @@ htmlSuite('HTMLImports', function() { htmlTest('html/currentScript.html'); htmlTest('html/dedupe.html'); htmlTest('html/dynamic.html'); + htmlTest('html/dynamic-all-imports-detail.html'); + htmlTest('html/dynamic-errors-detail.html'); + htmlTest('html/dynamic-loaded-detail.html'); htmlTest('html/csp.html'); htmlTest('html/customevent-detail.html'); htmlTest('html/encoding.html');