WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
160731
Move document.defineElement to customElements.define
https://bugs.webkit.org/show_bug.cgi?id=160731
Summary
Move document.defineElement to customElements.define
Ryosuke Niwa
Reported
2016-08-09 23:10:19 PDT
The latest custom elements specification (now merged into HTML spec) moved document.defineElement to window.customElements.define. Update our implementation to match this change.
Attachments
Updates the implementation
(93.72 KB, patch)
2016-08-09 23:39 PDT
,
Ryosuke Niwa
no flags
Details
Formatted Diff
Diff
Fix GTK+/EFL builds
(94.61 KB, patch)
2016-08-09 23:53 PDT
,
Ryosuke Niwa
no flags
Details
Formatted Diff
Diff
Archive of layout-test-results from ews103 for mac-yosemite
(864.61 KB, application/zip)
2016-08-10 00:50 PDT
,
Build Bot
no flags
Details
Archive of layout-test-results from ews105 for mac-yosemite-wk2
(1009.80 KB, application/zip)
2016-08-10 00:56 PDT
,
Build Bot
no flags
Details
Archive of layout-test-results from ews117 for mac-yosemite
(1.49 MB, application/zip)
2016-08-10 01:00 PDT
,
Build Bot
no flags
Details
Fixed builds and addressed review comments
(101.93 KB, patch)
2016-08-10 14:40 PDT
,
Ryosuke Niwa
no flags
Details
Formatted Diff
Diff
Updated for TOT
(103.09 KB, patch)
2016-08-10 14:47 PDT
,
Ryosuke Niwa
no flags
Details
Formatted Diff
Diff
Another build fix
(103.13 KB, patch)
2016-08-10 15:18 PDT
,
Ryosuke Niwa
no flags
Details
Formatted Diff
Diff
Show Obsolete
(7)
View All
Add attachment
proposed patch, testcase, etc.
Ryosuke Niwa
Comment 1
2016-08-09 23:39:29 PDT
Created
attachment 285716
[details]
Updates the implementation
Ryosuke Niwa
Comment 2
2016-08-09 23:53:56 PDT
Created
attachment 285717
[details]
Fix GTK+/EFL builds
Build Bot
Comment 3
2016-08-10 00:49:58 PDT
Comment on
attachment 285717
[details]
Fix GTK+/EFL builds
Attachment 285717
[details]
did not pass mac-ews (mac): Output:
http://webkit-queues.webkit.org/results/1844564
New failing tests: js/dom/global-constructors-attributes.html
Build Bot
Comment 4
2016-08-10 00:50:03 PDT
Created
attachment 285720
[details]
Archive of layout-test-results from ews103 for mac-yosemite The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: ews103 Port: mac-yosemite Platform: Mac OS X 10.10.5
Build Bot
Comment 5
2016-08-10 00:56:13 PDT
Comment on
attachment 285717
[details]
Fix GTK+/EFL builds
Attachment 285717
[details]
did not pass mac-wk2-ews (mac-wk2): Output:
http://webkit-queues.webkit.org/results/1844574
New failing tests: js/dom/global-constructors-attributes.html
Build Bot
Comment 6
2016-08-10 00:56:17 PDT
Created
attachment 285722
[details]
Archive of layout-test-results from ews105 for mac-yosemite-wk2 The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews. Bot: ews105 Port: mac-yosemite-wk2 Platform: Mac OS X 10.10.5
Build Bot
Comment 7
2016-08-10 01:00:03 PDT
Comment on
attachment 285717
[details]
Fix GTK+/EFL builds
Attachment 285717
[details]
did not pass mac-debug-ews (mac): Output:
http://webkit-queues.webkit.org/results/1844572
New failing tests: js/dom/global-constructors-attributes.html
Build Bot
Comment 8
2016-08-10 01:00:08 PDT
Created
attachment 285723
[details]
Archive of layout-test-results from ews117 for mac-yosemite The attached test failures were seen while running run-webkit-tests on the mac-debug-ews. Bot: ews117 Port: mac-yosemite Platform: Mac OS X 10.10.5
Chris Dumez
Comment 9
2016-08-10 09:56:58 PDT
Comment on
attachment 285717
[details]
Fix GTK+/EFL builds View in context:
https://bugs.webkit.org/attachment.cgi?id=285717&action=review
Looks like there is a test failure and that it still does build on EFL / GTK/Win.
> Source/WebCore/bindings/js/JSCustomElementsRegistryCustom.cpp:42 > +{
This function should throw if given less than 2 parameters: if (UNLIKELY(state.argumentCount() < 2)) return state.vm().throwException(&state, createNotEnoughArgumentsError(&state)); You can then use uncheckedArgument() below instead of argument().
> Source/WebCore/bindings/js/JSCustomElementsRegistryCustom.cpp:43 > + AtomicString tagName(state.argument(0).toString(&state)->toAtomicString(&state));
Isn't this a local name rather than a qualified name ? If so, I would suggest naming this variable localName or simply name as in the spec. tagName is a bit confusing to me because I think of a qualified name (
https://dom.spec.whatwg.org/#dom-element-tagname
).
> Source/WebCore/bindings/js/JSCustomElementsRegistryCustom.cpp:47 > + JSObject* object = state.argument(1).getObject();
How about we call this 'constructor' rather than 'object' ?
> Source/WebCore/bindings/js/JSCustomElementsRegistryCustom.cpp:49 > + if (!object || object->methodTable()->getConstructData(object, callData) == ConstructType::None)
Instead of all this, I think we should be able to use JSValue::isFunction(). We should probably pass a JSFunction* to the implementation instead of a JSObject* for clarity.
> Source/WebCore/bindings/js/JSCustomElementsRegistryCustom.cpp:51 > +
It looks like we may be missing step 2 in the spec? "If constructor is either an interface object or named constructor, whose corresponding interface either is HTMLElement or has HTMLElement in its set of inherited interfaces, throw a TypeError and abort these steps." We should at least add a FIXME. I am not sure how easy it is to detect our interface objects at the moment so we can look into it separately.
> Source/WebCore/bindings/js/JSCustomElementsRegistryCustom.cpp:56 > + return throwSyntaxError(&state, "Custom element name cannot be same as one of the builtin elements");
ASCIILiteral()?
> Source/WebCore/bindings/js/JSCustomElementsRegistryCustom.cpp:58 > + return throwSyntaxError(&state, "Custom element name must contain a hyphen");
ASCIILiteral()?
> Source/WebCore/bindings/js/JSCustomElementsRegistryCustom.cpp:60 > + return throwSyntaxError(&state, "Custom element name cannot contain an upper case letter");
ASCIILiteral()?
> Source/WebCore/bindings/js/JSCustomElementsRegistryCustom.cpp:65 > + throwNotSupportedError(state, "Cannot define multiple custom elements with the same tag name");
ASCIILiteral()?
> Source/WebCore/bindings/js/JSCustomElementsRegistryCustom.cpp:70 > + throwNotSupportedError(state, "Cannot define multiple custom elements with the same class");
ASCIILiteral()?
> Source/WebCore/bindings/js/JSCustomElementsRegistryCustom.cpp:83 > + QualifiedName name(nullAtom, tagName, HTMLNames::xhtmlNamespaceURI);
This seems to confirm tagName is a localName, not a qualifiedName.
> Source/WebCore/bindings/js/JSHTMLElementCustom.cpp:54 > + return throwVMTypeError(&exec, "new.target is not a valid custom element constructor");
ASCIILiteral()?
> Source/WebCore/dom/CustomElementsRegistry.cpp:2 > + * Copyright (C) 2015 Apple Inc. All rights reserved.
2015 on purpose? is it just moved code?
> Source/WebCore/dom/CustomElementsRegistry.h:31 > +#pragma once
I believe this usually comes before the includes.
> Source/WebCore/dom/CustomElementsRegistry.h:33 > +#if ENABLE(CUSTOM_ELEMENTS)
Ditto.
> Source/WebCore/dom/CustomElementsRegistry.h:48 > + WTF_MAKE_FAST_ALLOCATED;
Redundant since this subclasses RefCounted.
> Source/WebCore/dom/CustomElementsRegistry.h:53 > + RefPtr<Element> constructElement(const AtomicString&);
I cannot find the implementation for this method? In particular, I was curious why this returned a RefPtr<> and not a Ref<>.
> Source/WebCore/dom/CustomElementsRegistry.h:66 > + HashMap<AtomicString, Vector<RefPtr<Element>>> m_upgradeCandidatesMap;
Could this be a Vector of Ref<Element> ?
> Source/WebCore/dom/CustomElementsRegistry.h:67 > + HashMap<AtomicString, RefPtr<JSCustomElementInterface>> m_nameMap;
Could this be a Ref<> ? I believe Sam added support for Ref<> values in HashMap a while back.
> Source/WebCore/dom/CustomElementsRegistry.idl:28 > + JSGenerateToNativeObject,
I don't think we need this one. This is the default since the interface does not have a parent.
> Source/WebCore/dom/CustomElementsRegistry.idl:32 > + [InvokesCustomElementLifecycleCallbacks, Custom] void define(DOMString name, Function constructor);
nit: I would omit the extra blank lines surrounding this.
> Source/WebCore/dom/Document.cpp:883 > +static ALWAYS_INLINE RefPtr<HTMLElement> createUpgradeCandidateElement(Document& document, DOMWindow* window, const QualifiedName& name)
Why ALWAYS_INLINE?
> Source/WebCore/dom/Document.cpp:891 > + Ref<HTMLElement> element = HTMLElement::create(name, document);
auto
> Source/WebCore/dom/Document.cpp:897 > static RefPtr<Element> createHTMLElementWithNameValidation(Document& document, const AtomicString& localName, ExceptionCode& ec)
Can this return a RefPtr<HTMLElement> ?
> Source/WebCore/dom/Document.cpp:923 > return WTFMove(element);
No need for the WTFMove() if the function is updated to return a RefPtr<HTMLElement>.
> Source/WebCore/dom/Document.cpp:1092 > + Ref<HTMLElement> element = HTMLElement::create(name, document);
auto
> Source/WebCore/dom/Document.cpp:1101 > + return *element;
return element.releaseNonNull();
> Source/WebCore/page/DOMWindow.h:426 > + mutable RefPtr<CustomElementsRegistry> m_customElementsRegistry;
Does not look like you need the mutable since your methods are non-const?
Ryosuke Niwa
Comment 10
2016-08-10 14:39:32 PDT
Comment on
attachment 285717
[details]
Fix GTK+/EFL builds View in context:
https://bugs.webkit.org/attachment.cgi?id=285717&action=review
>> Source/WebCore/bindings/js/JSCustomElementsRegistryCustom.cpp:42 >> +{ > > This function should throw if given less than 2 parameters: > if (UNLIKELY(state.argumentCount() < 2)) > return state.vm().throwException(&state, createNotEnoughArgumentsError(&state)); > > You can then use uncheckedArgument() below instead of argument().
Done.
>> Source/WebCore/bindings/js/JSCustomElementsRegistryCustom.cpp:43 >> + AtomicString tagName(state.argument(0).toString(&state)->toAtomicString(&state)); > > Isn't this a local name rather than a qualified name ? If so, I would suggest naming this variable localName or simply name as in the spec. tagName is a bit confusing to me because I think of a qualified name (
https://dom.spec.whatwg.org/#dom-element-tagname
).
Fixed.
>> Source/WebCore/bindings/js/JSCustomElementsRegistryCustom.cpp:47 >> + JSObject* object = state.argument(1).getObject(); > > How about we call this 'constructor' rather than 'object' ?
Sure.
>> Source/WebCore/bindings/js/JSCustomElementsRegistryCustom.cpp:49 >> + if (!object || object->methodTable()->getConstructData(object, callData) == ConstructType::None) > > Instead of all this, I think we should be able to use JSValue::isFunction(). We should probably pass a JSFunction* to the implementation instead of a JSObject* for clarity.
object being a function isn't sufficient. We need to use JSValue::isConstructor instead. I'm going to keep JSObject* for now since changing this would require adding a lot more code.
>> Source/WebCore/bindings/js/JSCustomElementsRegistryCustom.cpp:51 >> + > > It looks like we may be missing step 2 in the spec? > "If constructor is either an interface object or named constructor, whose corresponding interface either is HTMLElement or has HTMLElement in its set of inherited interfaces, throw a TypeError and abort these steps." > > We should at least add a FIXME. I am not sure how easy it is to detect our interface objects at the moment so we can look into it separately.
Added a FIXME. In general, I'm keeping the original behavior we had instead of updating this function to the spec since that would require a lot of code changes.
>> Source/WebCore/dom/CustomElementsRegistry.h:48 >> + WTF_MAKE_FAST_ALLOCATED; > > Redundant since this subclasses RefCounted.
Removed.
>> Source/WebCore/dom/CustomElementsRegistry.h:53 >> + RefPtr<Element> constructElement(const AtomicString&); > > I cannot find the implementation for this method? In particular, I was curious why this returned a RefPtr<> and not a Ref<>.
Oops, I forgot to remove this. Done.
>> Source/WebCore/dom/CustomElementsRegistry.h:66 >> + HashMap<AtomicString, Vector<RefPtr<Element>>> m_upgradeCandidatesMap; > > Could this be a Vector of Ref<Element> ?
No, Vector doesn't support Ref in them.
>> Source/WebCore/dom/Document.cpp:883 >> +static ALWAYS_INLINE RefPtr<HTMLElement> createUpgradeCandidateElement(Document& document, DOMWindow* window, const QualifiedName& name) > > Why ALWAYS_INLINE?
This is needed for performance.
>> Source/WebCore/dom/Document.cpp:897 >> static RefPtr<Element> createHTMLElementWithNameValidation(Document& document, const AtomicString& localName, ExceptionCode& ec) > > Can this return a RefPtr<HTMLElement> ?
This requires constructElement returning HTMLElement so I'm gonna do that in a separate patch.
>> Source/WebCore/page/DOMWindow.h:426 >> + mutable RefPtr<CustomElementsRegistry> m_customElementsRegistry; > > Does not look like you need the mutable since your methods are non-const?
Fixed.
Ryosuke Niwa
Comment 11
2016-08-10 14:40:16 PDT
Created
attachment 285762
[details]
Fixed builds and addressed review comments
Ryosuke Niwa
Comment 12
2016-08-10 14:47:32 PDT
Created
attachment 285765
[details]
Updated for TOT
Ryosuke Niwa
Comment 13
2016-08-10 15:18:27 PDT
Created
attachment 285769
[details]
Another build fix
Chris Dumez
Comment 14
2016-08-10 18:41:32 PDT
Comment on
attachment 285769
[details]
Another build fix View in context:
https://bugs.webkit.org/attachment.cgi?id=285769&action=review
r=me
> Source/WebCore/dom/CustomElementsRegistry.idl:28 > + JSGenerateToNativeObject,
I think you missed my previous review comment about this being redundant since this interface has no parent.
Ryosuke Niwa
Comment 15
2016-08-10 18:43:59 PDT
(In reply to
comment #14
)
> Comment on
attachment 285769
[details]
> Another build fix > > View in context: >
https://bugs.webkit.org/attachment.cgi?id=285769&action=review
> > r=me > > > Source/WebCore/dom/CustomElementsRegistry.idl:28 > > + JSGenerateToNativeObject, > > I think you missed my previous review comment about this being redundant > since this interface has no parent.
The thing doesn't build without this.
Chris Dumez
Comment 16
2016-08-10 18:48:11 PDT
Comment on
attachment 285769
[details]
Another build fix View in context:
https://bugs.webkit.org/attachment.cgi?id=285769&action=review
>>> Source/WebCore/dom/CustomElementsRegistry.idl:28 >>> + JSGenerateToNativeObject, >> >> I think you missed my previous review comment about this being redundant since this interface has no parent. > > The thing doesn't build without this.
Very weird... Ok then.
WebKit Commit Bot
Comment 17
2016-08-10 19:09:48 PDT
Comment on
attachment 285769
[details]
Another build fix Clearing flags on attachment: 285769 Committed
r204367
: <
http://trac.webkit.org/changeset/204367
>
WebKit Commit Bot
Comment 18
2016-08-10 19:09:57 PDT
All reviewed patches have been landed. Closing bug.
Ryosuke Niwa
Comment 19
2016-09-01 16:16:07 PDT
<
rdar://problem/28090367
>
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug