forked from WebKit/WebKit-http
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
defineElement should upgrade existing unresolved custom elements
https://bugs.webkit.org/show_bug.cgi?id=155107 Reviewed by Darin Adler. Source/WebCore: Added the support for upgrading existing unresolved custom elements when defineElement is called. The current implementation upgrades elements in the order they were created and has the issue that it keeps accumulating all elements with a hyphen in its name until defineElement is called as documented in WICG/webcomponents#419 This patch re-purposes IsEditingTextFlag to indicate that the node is an unresolved custom element. Since isEditingText() is only called in textRendererIsNeeded only on Text nodes, it's mutually exclusive with isUnresolvedCustomElement(). The list of unresolved custom elements is kept in m_upgradeCandidatesMap, a hash map of element names to the list of unresolved elements with that name. In addition, added the logic to use HTMLElement as the interface for unresolved custom element instead of HTMLUnknownElement. Test: fast/custom-elements/upgrading/upgrading-parser-created-element.html * bindings/js/JSCustomElementInterface.cpp: (WebCore::JSCustomElementInterface::upgradeElement): Clear the flag. * bindings/js/JSDocumentCustom.cpp: (WebCore::JSDocument::defineElement): Set the unique private name to keep the interface alive before calling addElementDefinition as the call can now invoke author scripts. * dom/CustomElementDefinitions.cpp: (WebCore::CustomElementDefinitions::addElementDefinition): Upgrade existing unresolved elements kept in m_upgradeCandidatesMap. (WebCore::CustomElementDefinitions::addUpgradeCandidate): Added. * dom/CustomElementDefinitions.h: * dom/Document.cpp: (WebCore::createHTMLElementWithNameValidation): Added the code to add the unresolved custom elements to the upgrade candidates map. Also instantiate it as HTMLElement instead of HTMLUnknownElement. (WebCore::createFallbackHTMLElement): Ditto. * dom/Node.h: (WebCore::Node::setIsCustomElement): (WebCore::Node::isUnresolvedCustomElement): Added. (WebCore::Node::setIsUnresolvedCustomElement): Added. (WebCore::Node::setCustomElementIsResolved): Added. Clears IsEditingTextOrUnresolvedCustomElementFlag and sets IsCustomElement. (WebCore::Node::isEditingText): Check both IsEditingTextOrUnresolvedCustomElementFlag and IsTextFlag for safety even though it's currently only used in textRendererIsNeeded which takes Text&. * dom/make_names.pl: (defaultParametersHash): Added customElementInterfaceName as a parameter. (printWrapperFactoryCppFile): Generate the code to use customElementInterfaceName when the element for which the wrapper is created has isUnresolvedCustomElement flag set. * html/HTMLTagNames.in: Use HTMLElement for unresolved custom elements. * html/parser/HTMLConstructionSite.cpp: (WebCore::HTMLConstructionSite::createHTMLElementOrFindCustomElementInterface): Added the code to add the unresolved custom elements to the upgrade candidates map. Also instantiate it as HTMLElement instead of HTMLUnknownElement. LayoutTests: Added W3C style testharness.js tests for asynchronously defining custom elements. * fast/custom-elements/upgrading/Node-cloneNode.html: * fast/custom-elements/upgrading/upgrading-parser-created-element-expected.txt: Added. * fast/custom-elements/upgrading/upgrading-parser-created-element.html: Added. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@197917 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
rniwa@webkit.org
committed
Mar 10, 2016
1 parent
67fa249
commit 7df594e
Showing
14 changed files
with
274 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
LayoutTests/fast/custom-elements/upgrading/upgrading-parser-created-element-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
PASS Element.prototype.createElement must add an unresolved custom element to the upgrade candidates map | ||
PASS HTMLElement constructor must throw an InvalidStateError when the top of the construction stack is marked AlreadyConstructed due to a custom element constructor constructing itself after super() call | ||
PASS HTMLElement constructor must throw an InvalidStateError when the top of the construction stack is marked AlreadyConstructed due to a custom element constructor constructing itself before super() call | ||
PASS Upgrading a custom element must throw an InvalidStateError when the returned element is not SameValue as the upgraded element | ||
|
93 changes: 93 additions & 0 deletions
93
LayoutTests/fast/custom-elements/upgrading/upgrading-parser-created-element.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Custom Elements: Upgrading unresolved elements</title> | ||
<meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org"> | ||
<meta name="assert" content="HTML parser must add an unresolved custom element to the upgrade candidates map"> | ||
<link rel="help" href="https://w3c.github.io/webcomponents/spec/custom/#upgrading"> | ||
<script src="../../../resources/testharness.js"></script> | ||
<script src="../../../resources/testharnessreport.js"></script> | ||
<link rel='stylesheet' href='../../../resources/testharness.css'> | ||
</head> | ||
<body> | ||
<div id="log"></div> | ||
<my-custom-element></my-custom-element> | ||
<instantiates-itself-after-super></instantiates-itself-after-super> | ||
<instantiates-itself-before-super></instantiates-itself-before-super> | ||
<my-other-element id="instance"></my-other-element> | ||
<my-other-element id="otherInstance"></my-other-element> | ||
<script> | ||
|
||
test(function () { | ||
class MyCustomElement extends HTMLElement { } | ||
|
||
var instance = document.querySelector('my-custom-element'); | ||
assert_true(instance instanceof HTMLElement); | ||
assert_false(instance instanceof HTMLUnknownElement, | ||
'an unresolved custom element should not be an instance of HTMLUnknownElement'); | ||
assert_false(instance instanceof MyCustomElement); | ||
|
||
document.defineElement('my-custom-element', MyCustomElement); | ||
|
||
assert_true(instance instanceof HTMLElement); | ||
assert_true(instance instanceof MyCustomElement, | ||
'Calling defineElement must upgrade existing custom elements'); | ||
|
||
}, 'Element.prototype.createElement must add an unresolved custom element to the upgrade candidates map'); | ||
|
||
|
||
test(function () { | ||
class InstantiatesItselfAfterSuper extends HTMLElement { | ||
constructor(doNotCreateItself) { | ||
super(); | ||
if (!doNotCreateItself) | ||
new InstantiatesItselfAfterSuper(true); | ||
} | ||
} | ||
|
||
assert_throws({'name': 'InvalidStateError'}, function () { | ||
document.defineElement('instantiates-itself-after-super', InstantiatesItselfAfterSuper); | ||
}); | ||
}, 'HTMLElement constructor must throw an InvalidStateError when the top of the construction stack is marked AlreadyConstructed' | ||
+ ' due to a custom element constructor constructing itself after super() call'); | ||
|
||
test(function () { | ||
class InstantiatesItselfBeforeSuper extends HTMLElement { | ||
constructor(doNotCreateItself) { | ||
if (!doNotCreateItself) | ||
new InstantiatesItselfBeforeSuper(true); | ||
super(); | ||
} | ||
} | ||
|
||
assert_throws({'name': 'InvalidStateError'}, function () { | ||
document.defineElement('instantiates-itself-before-super', InstantiatesItselfBeforeSuper); | ||
}); | ||
}, 'HTMLElement constructor must throw an InvalidStateError when the top of the construction stack is marked AlreadyConstructed' | ||
+ ' due to a custom element constructor constructing itself before super() call'); | ||
|
||
test(function () { | ||
class MyOtherElement extends HTMLElement { | ||
constructor() { | ||
super(); | ||
if (this == instance) | ||
return otherInstance; | ||
} | ||
} | ||
var instance = document.getElementById('instance'); | ||
var otherInstance = document.getElementById('otherInstance'); | ||
|
||
assert_false(instance instanceof MyOtherElement); | ||
assert_false(otherInstance instanceof MyOtherElement); | ||
|
||
assert_throws({'name': 'InvalidStateError'}, function () { | ||
document.defineElement('my-other-element', MyOtherElement); | ||
}); | ||
|
||
assert_true(document.createElement('my-other-element') instanceof MyOtherElement, | ||
'Upgrading of custom elements must happen after the definition was added to the registry.'); | ||
}, 'Upgrading a custom element must throw an InvalidStateError when the returned element is not SameValue as the upgraded element'); | ||
|
||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.