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

Commit

Permalink
Add the host property to the ShadowRoot interface
Browse files Browse the repository at this point in the history
  • Loading branch information
arv committed Oct 30, 2013
1 parent 589410b commit 4a2f593
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
3 changes: 1 addition & 2 deletions src/ShadowRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
var Node = scope.wrappers.Node;
var ShadowRoot = scope.wrappers.ShadowRoot;
var assert = scope.assert;
var getHostForShadowRoot = scope.getHostForShadowRoot;
var mixin = scope.mixin;
var muteMutationEvents = scope.muteMutationEvents;
var oneOf = scope.oneOf;
Expand Down Expand Up @@ -253,7 +252,7 @@
}

function getRendererForShadowRoot(shadowRoot) {
return getRendererForHost(getHostForShadowRoot(shadowRoot));
return getRendererForHost(shadowRoot.host);
}

var spliceDiff = new ArraySplice();
Expand Down
7 changes: 4 additions & 3 deletions src/wrappers/ShadowRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
return nextOlderShadowTreeTable.get(this) || null;
},

get host() {
return shadowHostTable.get(this) || null;
},

invalidateShadowRenderer: function() {
return shadowHostTable.get(this).invalidateShadowRenderer();
},
Expand All @@ -57,7 +61,4 @@
});

scope.wrappers.ShadowRoot = ShadowRoot;
scope.getHostForShadowRoot = function(node) {
return shadowHostTable.get(node);
};
})(this.ShadowDOMPolyfill);
12 changes: 5 additions & 7 deletions src/wrappers/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

// 1.
if (isShadowRoot(node))
return getInsertionParent(node) || scope.getHostForShadowRoot(node);
return getInsertionParent(node) || node.host;

// 2.
var eventParents = scope.eventParentsTable.get(node);
Expand Down Expand Up @@ -145,7 +145,7 @@
ancestor = calculateParents(ancestor, context, ancestors); // 3.4.7.
}
if (isShadowRoot(target)) // 3.5.
target = scope.getHostForShadowRoot(target);
target = target.host;
else
target = target.parentNode; // 3.6.
}
Expand Down Expand Up @@ -174,10 +174,8 @@
function enclosedBy(a, b) {
if (a === b)
return true;
if (a instanceof wrappers.ShadowRoot) {
var host = scope.getHostForShadowRoot(a);
return enclosedBy(rootOfNode(host), b);
}
if (a instanceof wrappers.ShadowRoot)
return enclosedBy(rootOfNode(a.host), b);
return false;
}

Expand Down Expand Up @@ -599,7 +597,7 @@

function getTargetToListenAt(wrapper) {
if (wrapper instanceof wrappers.ShadowRoot)
wrapper = scope.getHostForShadowRoot(wrapper);
wrapper = wrapper.host;
return unwrap(wrapper);
}

Expand Down
9 changes: 9 additions & 0 deletions test/js/ShadowRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,13 @@ suite('ShadowRoot', function() {
assert.equal(sr2.olderShadowRoot, sr);
});

test('host', function() {
var host = document.createElement('div');
var sr = host.createShadowRoot();
assert.equal(host, sr.host);

var sr2 = host.createShadowRoot();
assert.equal(host, sr2.host);
});

});

0 comments on commit 4a2f593

Please sign in to comment.