Changeset 234957 in webkit


Ignore:
Timestamp:
Aug 16, 2018 2:18:02 PM (6 years ago)
Author:
rniwa@webkit.org
Message:

Custom element constructor doesn't use HTMLElement in new.target's realm
https://bugs.webkit.org/show_bug.cgi?id=188634

Reviewed by Keith Miller.

LayoutTests/imported/w3c:

Rebaselined the test now that all relevant test cases pass. All remaining test failures are
for customized builtin, which we do not and shall not implement.

  • web-platform-tests/custom-elements/htmlconstructor/newtarget-expected.txt:

Source/WebCore:

Fixed the bug that HTMLElement's constructor was constructing an element of its own realm
instead of the realm of new.target. This results in the JS wrapper created for the element
belonging to the global object of the HTMLElement constructor which was invoked instead of
the global object of new.target as specified in:
https://html.spec.whatwg.org/multipage/dom.html#html-element-constructors

In particular, step 9.2. specifies that we "perform element.SetPrototypeOf?(prototype)."
where prototype is the result of Get(NewTarget, "prototype") in step 7.

WebKit's new behavior matches that of Chrome and Firefox.

Test: imported/w3c/web-platform-tests/custom-elements/htmlconstructor/newtarget.html

  • bindings/js/JSHTMLElementCustom.cpp:

(WebCore::constructJSHTMLElement):

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r234953 r234957  
     12018-08-16  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Custom element constructor doesn't use HTMLElement in new.target's realm
     4        https://bugs.webkit.org/show_bug.cgi?id=188634
     5
     6        Reviewed by Keith Miller.
     7
     8        Rebaselined the test now that all relevant test cases pass. All remaining test failures are
     9        for customized builtin, which we do not and shall not implement.
     10
     11        * web-platform-tests/custom-elements/htmlconstructor/newtarget-expected.txt:
     12
    1132018-08-16  Ryosuke Niwa  <rniwa@webkit.org>
    214
  • trunk/LayoutTests/imported/w3c/web-platform-tests/custom-elements/htmlconstructor/newtarget-expected.txt

    r234039 r234957  
    22PASS Use NewTarget's prototype, not the one stored at definition time
    33PASS Rethrow any exceptions thrown while getting the prototype
    4 FAIL If prototype is not object (null), derives the fallback from NewTarget's realm (autonomous custom elements) assert_equals: Must use the HTMLElement from the realm of NewTarget expected object "[object HTMLElementPrototype]" but got object "[object HTMLElementPrototype]"
    5 FAIL If prototype is not object (undefined), derives the fallback from NewTarget's realm (autonomous custom elements) assert_equals: Must use the HTMLElement from the realm of NewTarget expected object "[object HTMLElementPrototype]" but got object "[object HTMLElementPrototype]"
    6 FAIL If prototype is not object (5), derives the fallback from NewTarget's realm (autonomous custom elements) assert_equals: Must use the HTMLElement from the realm of NewTarget expected object "[object HTMLElementPrototype]" but got object "[object HTMLElementPrototype]"
    7 FAIL If prototype is not object (string), derives the fallback from NewTarget's realm (autonomous custom elements) assert_equals: Must use the HTMLElement from the realm of NewTarget expected object "[object HTMLElementPrototype]" but got object "[object HTMLElementPrototype]"
     4PASS If prototype is not object (null), derives the fallback from NewTarget's realm (autonomous custom elements)
     5PASS If prototype is not object (undefined), derives the fallback from NewTarget's realm (autonomous custom elements)
     6PASS If prototype is not object (5), derives the fallback from NewTarget's realm (autonomous custom elements)
     7PASS If prototype is not object (string), derives the fallback from NewTarget's realm (autonomous custom elements)
    88FAIL If prototype is not object (null), derives the fallback from NewTarget's realm (customized built-in elements) promise_test: Unhandled rejection with value: object "TypeError: Reflect.construct requires the first argument be a constructor"
    99FAIL If prototype is not object (undefined), derives the fallback from NewTarget's realm (customized built-in elements) promise_test: Unhandled rejection with value: object "TypeError: Reflect.construct requires the first argument be a constructor"
  • trunk/Source/WebCore/ChangeLog

    r234956 r234957  
     12018-08-16  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Custom element constructor doesn't use HTMLElement in new.target's realm
     4        https://bugs.webkit.org/show_bug.cgi?id=188634
     5
     6        Reviewed by Keith Miller.
     7
     8        Fixed the bug that HTMLElement's constructor was constructing an element of its own realm
     9        instead of the realm of new.target. This results in the JS wrapper created for the element
     10        belonging to the global object of the HTMLElement constructor which was invoked instead of
     11        the global object of new.target as specified in:
     12        https://html.spec.whatwg.org/multipage/dom.html#html-element-constructors
     13
     14        In particular, step 9.2. specifies that we "perform element.[[SetPrototypeOf]](prototype)."
     15        where prototype is the result of Get(NewTarget, "prototype") in step 7.
     16
     17        WebKit's new behavior matches that of Chrome and Firefox.
     18
     19        Test: imported/w3c/web-platform-tests/custom-elements/htmlconstructor/newtarget.html
     20
     21        * bindings/js/JSHTMLElementCustom.cpp:
     22        (WebCore::constructJSHTMLElement):
     23
    1242018-08-16  Aditya Keerthi  <akeerthi@apple.com>
    225
  • trunk/Source/WebCore/bindings/js/JSHTMLElementCustom.cpp

    r233122 r234957  
    5656
    5757    JSValue newTargetValue = exec.thisValue();
    58     auto* globalObject = jsConstructor->globalObject();
     58    auto* newTarget = newTargetValue.getObject();
     59    auto* globalObject = jsCast<JSDOMGlobalObject*>(newTarget->globalObject(vm));
    5960    JSValue htmlElementConstructorValue = JSHTMLElement::getConstructor(vm, globalObject);
    6061    if (newTargetValue == htmlElementConstructorValue)
     
    7172        return throwVMTypeError(&exec, scope, "new.target is not a valid custom element constructor"_s);
    7273
    73     JSObject* newTarget = newTargetValue.getObject();
    7474    auto* elementInterface = registry->findInterface(newTarget);
    7575    if (!elementInterface)
Note: See TracChangeset for help on using the changeset viewer.