Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

allow createShadowRoot on body #496

Merged
merged 1 commit into from
Sep 5, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
allow createShadowRoot on body, fixes Polymer/polymer#421
  • Loading branch information
John Messerly committed Aug 27, 2014

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit d5640d29d1885ea71807faee43c6402d4a89cf59
4 changes: 2 additions & 2 deletions src/ShadowRenderer.js
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@
refChildWrapper.previousSibling_ = refChildWrapper.previousSibling;
}

parentNode.insertBefore(newChild, refChild);
scope.originalInsertBefore.call(parentNode, newChild, refChild);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: the call through scope here is to support the "minimal DOM changes" test.

}

function remove(nodeWrapper) {
@@ -95,7 +95,7 @@
if (parentNodeWrapper.firstChild === nodeWrapper)
parentNodeWrapper.firstChild_ = nodeWrapper;

parentNode.removeChild(node);
scope.originalRemoveChild.call(parentNode, node);
}

var distributedNodesTable = new WeakMap();
2 changes: 2 additions & 0 deletions src/wrappers/Node.js
Original file line number Diff line number Diff line change
@@ -730,6 +730,8 @@
scope.nodeWasRemoved = nodeWasRemoved;
scope.nodesWereAdded = nodesWereAdded;
scope.nodesWereRemoved = nodesWereRemoved;
scope.originalInsertBefore = originalInsertBefore;
scope.originalRemoveChild = originalRemoveChild;
scope.snapshotNodeList = snapshotNodeList;
scope.wrappers.Node = Node;

33 changes: 33 additions & 0 deletions test/html/document-body-shadow-root.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<script src="../../../tools/test/chai/chai.js"></script>
<script src="../../../tools/test/htmltest.js"></script>
<script src="../../shadowdom.js"></script>
<script>

var assert = chai.assert;
var wrap = ShadowDOMPolyfill.wrap;
var doc = wrap(document);

doc.addEventListener('DOMContentLoaded', function(e) {

doc.body.innerHTML = 'You should NOT see this.';

var sr = doc.body.createShadowRoot();
var firstStr = 'You should see this';
var secondStr = '... and you should also see this';
sr.innerHTML = firstStr + '<content>';

doc.body.offsetHeight;

doc.body.innerHTML = secondStr;

doc.body.offsetHeight;

assert.equal(doc.body.innerHTML, secondStr);
assert.equal(sr.firstChild.textContent, firstStr);
assert.equal(document.body.textContent, firstStr + secondStr);

done();
});

</script>
2 changes: 2 additions & 0 deletions test/js/HTMLBodyElement.js
Original file line number Diff line number Diff line change
@@ -122,4 +122,6 @@ htmlSuite('HTMLBodyElement', function() {
});

htmlTest('html/document-body-inner-html.html');

htmlTest('html/document-body-shadow-root.html');
});
28 changes: 12 additions & 16 deletions test/js/rerender.js
Original file line number Diff line number Diff line change
@@ -540,28 +540,24 @@ suite('Shadow DOM rerender', function() {

test('minimal dom changes', function() {
var div = document.createElement('div');
var OriginalNodePrototype =
// Node.prototype
Object.getPrototypeOf(
// Element.prototype
Object.getPrototypeOf(
// HTMLElement.prototype
Object.getPrototypeOf(
// HTMLDivElement.prototype
Object.getPrototypeOf(unwrap(div)))));

var originalInsertBefore = OriginalNodePrototype.insertBefore;
var originalRemoveChild = OriginalNodePrototype.removeChild;

// TODO(jmesserly): ideally we would intercept all of the visual DOM
// operations, but that isn't possible because they are captured in the code
// as originalInsertBefore/originalRemoveChild, so we only see the calls
// inside ShadowRenderer.

var originalInsertBefore = ShadowDOMPolyfill.originalInsertBefore;
var originalRemoveChild = ShadowDOMPolyfill.originalRemoveChild;

var insertBeforeCount = 0;
var removeChildCount = 0;

OriginalNodePrototype.insertBefore = function(newChild, refChild) {
ShadowDOMPolyfill.originalInsertBefore = function(newChild, refChild) {
insertBeforeCount++;
return originalInsertBefore.call(this, newChild, refChild);
};

OriginalNodePrototype.removeChild = function(child) {
ShadowDOMPolyfill.originalRemoveChild = function(child) {
removeChildCount++;
return originalRemoveChild.call(this, child);
};
@@ -642,8 +638,8 @@ suite('Shadow DOM rerender', function() {


} finally {
OriginalNodePrototype.insertBefore = originalInsertBefore;
OriginalNodePrototype.removeChild = originalRemoveChild;
ShadowDOMPolyfill.originalInsertBefore = originalInsertBefore;
ShadowDOMPolyfill.originalRemoveChild = originalRemoveChild;
}
});
});