Title: [234957] trunk
Revision
234957
Author
[email protected]
Date
2018-08-16 14:18:02 -0700 (Thu, 16 Aug 2018)

Log 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):

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (234956 => 234957)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2018-08-16 21:10:57 UTC (rev 234956)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2018-08-16 21:18:02 UTC (rev 234957)
@@ -1,5 +1,17 @@
 2018-08-16  Ryosuke Niwa  <[email protected]>
 
+        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.
+
+        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:
+
+2018-08-16  Ryosuke Niwa  <[email protected]>
+
         Custom element doesn't invalidate its style when :defined rule starts to apply
         https://bugs.webkit.org/show_bug.cgi?id=188637
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/custom-elements/htmlconstructor/newtarget-expected.txt (234956 => 234957)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/custom-elements/htmlconstructor/newtarget-expected.txt	2018-08-16 21:10:57 UTC (rev 234956)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/custom-elements/htmlconstructor/newtarget-expected.txt	2018-08-16 21:18:02 UTC (rev 234957)
@@ -1,10 +1,10 @@
 
 PASS Use NewTarget's prototype, not the one stored at definition time 
 PASS Rethrow any exceptions thrown while getting the prototype 
-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]"
-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]"
-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]"
-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]"
+PASS If prototype is not object (null), derives the fallback from NewTarget's realm (autonomous custom elements) 
+PASS If prototype is not object (undefined), derives the fallback from NewTarget's realm (autonomous custom elements) 
+PASS If prototype is not object (5), derives the fallback from NewTarget's realm (autonomous custom elements) 
+PASS If prototype is not object (string), derives the fallback from NewTarget's realm (autonomous custom elements) 
 FAIL 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"
 FAIL 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"
 FAIL If prototype is not object (5), 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"

Modified: trunk/Source/WebCore/ChangeLog (234956 => 234957)


--- trunk/Source/WebCore/ChangeLog	2018-08-16 21:10:57 UTC (rev 234956)
+++ trunk/Source/WebCore/ChangeLog	2018-08-16 21:18:02 UTC (rev 234957)
@@ -1,3 +1,26 @@
+2018-08-16  Ryosuke Niwa  <[email protected]>
+
+        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.
+
+        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): 
+
 2018-08-16  Aditya Keerthi  <[email protected]>
 
         Unreviewed, fix the watchOS build after r188464.

Modified: trunk/Source/WebCore/bindings/js/JSHTMLElementCustom.cpp (234956 => 234957)


--- trunk/Source/WebCore/bindings/js/JSHTMLElementCustom.cpp	2018-08-16 21:10:57 UTC (rev 234956)
+++ trunk/Source/WebCore/bindings/js/JSHTMLElementCustom.cpp	2018-08-16 21:18:02 UTC (rev 234957)
@@ -55,7 +55,8 @@
     ASSERT(context->isDocument());
 
     JSValue newTargetValue = exec.thisValue();
-    auto* globalObject = jsConstructor->globalObject();
+    auto* newTarget = newTargetValue.getObject();
+    auto* globalObject = jsCast<JSDOMGlobalObject*>(newTarget->globalObject(vm));
     JSValue htmlElementConstructorValue = JSHTMLElement::getConstructor(vm, globalObject);
     if (newTargetValue == htmlElementConstructorValue)
         return throwVMTypeError(&exec, scope, "new.target is not a valid custom element constructor"_s);
@@ -70,7 +71,6 @@
     if (!registry)
         return throwVMTypeError(&exec, scope, "new.target is not a valid custom element constructor"_s);
 
-    JSObject* newTarget = newTargetValue.getObject();
     auto* elementInterface = registry->findInterface(newTarget);
     if (!elementInterface)
         return throwVMTypeError(&exec, scope, "new.target does not define a custom element"_s);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to