-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add polyfills for ChildNode APIs. #390
Conversation
Window: [WindowPatches] | ||
Window: [WindowPatches], | ||
CharacterData: [ChildNodePatches], | ||
DocumentType: [ChildNodePatches], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it isn't worth trying to make this work on DocumentType
. Testing it is pretty awkward and the restrictions on where a DocumentType
can go in a document (only first child of a document, maybe?) and what can go around one (almost nothing except comments and a single following <html>
?) makes most ChildNode
APIs on DocumentType
pretty useless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, let's remove that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, removed.
replaceWith(...args) { | ||
const parentNode = this[utils.SHADY_PREFIX + 'parentNode']; | ||
if (parentNode === null) { | ||
return; | ||
} | ||
for (const arg of args) { | ||
const newChild = typeof arg === 'string' ? document.createTextNode(arg) : arg; | ||
parentNode[utils.SHADY_PREFIX + 'insertBefore'](newChild, this); | ||
} | ||
parentNode[utils.SHADY_PREFIX + 'removeChild'](this); | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to check the order here since this probably feeds into MutationObserver
s. Likely, this should be remove first, then insert new children.
Window: [WindowPatches] | ||
Window: [WindowPatches], | ||
CharacterData: [ChildNodePatches], | ||
DocumentType: [ChildNodePatches], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, let's remove that.
DocumentType.prototype, | ||
Element.prototype, | ||
]) { | ||
delete item.after; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you have to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Answered this same question in the ParentNode PR: https://github.com/webcomponents/polyfills/pull/389/files/4c539009f045723cee214f5212a5e42b2601f5f6#r503487077 )
</head> | ||
<body> | ||
<script> | ||
const testBefore = (createChildNode) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testAfter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's simpler not to have the suite separated from the tests. You can just make the createChildNode
function inside the suite, can't you? (same for other test files).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, these are inlined now.
DocumentType.prototype, | ||
Element.prototype, | ||
]) { | ||
delete item.before; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, why is this here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Answered this same question in the ParentNode PR: https://github.com/webcomponents/polyfills/pull/389/files/4c539009f045723cee214f5212a5e42b2601f5f6#r503487077 )
DocumentType.prototype, | ||
Element.prototype, | ||
]) { | ||
delete item.remove; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, why is this here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Answered this same question in the ParentNode PR: https://github.com/webcomponents/polyfills/pull/389/files/4c539009f045723cee214f5212a5e42b2601f5f6#r503487077 )
DocumentType.prototype, | ||
Element.prototype, | ||
]) { | ||
delete item.replaceWith; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, why is this here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Answered this same question in the ParentNode PR: https://github.com/webcomponents/polyfills/pull/389/files/4c539009f045723cee214f5212a5e42b2601f5f6#r503487077 )
</head> | ||
<body> | ||
<script> | ||
const testBefore = (createChildNode) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testReplaceWith?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Removed based on another review comment.)
@@ -0,0 +1,56 @@ | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why it's important to polyfill these APIs in platform rather than just doing it in shadydom?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Answered this same question in the ParentNode PR: https://github.com/webcomponents/polyfills/pull/389/files/4c539009f045723cee214f5212a5e42b2601f5f6#r503492782 )
Adds polyfills for
ChildNode
'safter
,before
,remove
, andreplaceWith
functions and wrappers to support these in Shady DOM.