Title: [293021] trunk
Revision
293021
Author
[email protected]
Date
2022-04-19 10:24:58 -0700 (Tue, 19 Apr 2022)

Log Message

Fix runtime expose scope check for shadow realms
https://bugs.webkit.org/show_bug.cgi?id=238381

LayoutTests/imported/w3c:

Reviewed Darin Adler.

Updated idlharness expectations to reflect the fix for
`AbortController.timeout` visibility

Patch by Joseph Griego <[email protected]> on 2022-04-19

* web-platform-tests/dom/idlharness-shadowrealm.window-expected.txt:

Source/WebCore:

Patch by Joseph Griego <[email protected]> on 2022-04-19
Reviewed by Darin Adler.

Because shadow realms re-use their incubating realm's execution context
it doesn't make sense to check the `is${expose_scope}GlobalScope`
methods on `ScriptExecutionContext` anymore--instead, we'll use the type
information on the `JSGlobalScope` wrapper

This is at least justified in part by the fact that
`JSDOMGlobalObject#scriptExecutionContext` already does this internally
today to actually fetch the execution context, so, we can at least be
assured that this behaves the same way.

Some global scopes (notably, here, `AudioWorklet`) do not have distinct
wrapper types so we need to add a side condition to the generated code,
which we do after the type check.

Also removes `ScriptExecutionContext::isShadowRealmGlobalScope` as it's
now dead code and was never overridden anyways (a mistake left over
from the initial integration)

Tests: idlharness tests, including fixed visibility of
`AbortController.timeout`

* bindings/scripts/CodeGeneratorJS.pm:
(GenerateRuntimeEnableConditionalStringForExposeScope):
* bindings/scripts/test/JS/JSExposedStar.cpp:
(WebCore::JSExposedStarPrototype::finishCreation):
* bindings/scripts/test/JS/JSTestDefaultToJSONFilteredByExposed.cpp:
(WebCore::JSTestDefaultToJSONFilteredByExposedPrototype::finishCreation):
(WebCore::jsTestDefaultToJSONFilteredByExposedPrototypeFunction_toJSONBody):
* bindings/scripts/test/JS/JSTestObj.cpp:
(WebCore::JSTestObjPrototype::finishCreation):
* dom/ScriptExecutionContext.h:
(WebCore::ScriptExecutionContext::isServiceWorkerGlobalScope const):
(WebCore::ScriptExecutionContext::isShadowRealmGlobalScope const): Deleted.

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (293020 => 293021)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2022-04-19 17:19:43 UTC (rev 293020)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2022-04-19 17:24:58 UTC (rev 293021)
@@ -1,3 +1,15 @@
+2022-04-19  Joseph Griego  <[email protected]>
+
+        Fix runtime expose scope check for shadow realms
+        https://bugs.webkit.org/show_bug.cgi?id=238381
+
+        Reviewed Darin Adler.
+
+        Updated idlharness expectations to reflect the fix for
+        `AbortController.timeout` visibility
+
+        * web-platform-tests/dom/idlharness-shadowrealm.window-expected.txt:
+
 2022-04-18  Alex Christensen  <[email protected]>
 
         Implement CSSTransformValue.is2D

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/idlharness-shadowrealm.window-expected.txt (293020 => 293021)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/idlharness-shadowrealm.window-expected.txt	2022-04-19 17:19:43 UTC (rev 293020)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/idlharness-shadowrealm.window-expected.txt	2022-04-19 17:24:58 UTC (rev 293021)
@@ -95,7 +95,7 @@
 PASS AbortSignal interface: existence and properties of interface prototype object's "constructor" property
 PASS AbortSignal interface: existence and properties of interface prototype object's @@unscopables property
 PASS AbortSignal interface: operation abort(optional any)
-FAIL AbortSignal interface: member timeout assert_false: The interface object must not have a property "timeout" expected false got true
+PASS AbortSignal interface: member timeout
 PASS AbortSignal interface: attribute aborted
 PASS AbortSignal interface: attribute reason
 PASS AbortSignal interface: operation throwIfAborted()

Modified: trunk/Source/WebCore/ChangeLog (293020 => 293021)


--- trunk/Source/WebCore/ChangeLog	2022-04-19 17:19:43 UTC (rev 293020)
+++ trunk/Source/WebCore/ChangeLog	2022-04-19 17:24:58 UTC (rev 293021)
@@ -1,3 +1,44 @@
+2022-04-19  Joseph Griego  <[email protected]>
+
+        Fix runtime expose scope check for shadow realms
+        https://bugs.webkit.org/show_bug.cgi?id=238381
+
+        Reviewed by Darin Adler.
+
+        Because shadow realms re-use their incubating realm's execution context
+        it doesn't make sense to check the `is${expose_scope}GlobalScope`
+        methods on `ScriptExecutionContext` anymore--instead, we'll use the type
+        information on the `JSGlobalScope` wrapper
+
+        This is at least justified in part by the fact that
+        `JSDOMGlobalObject#scriptExecutionContext` already does this internally
+        today to actually fetch the execution context, so, we can at least be
+        assured that this behaves the same way.
+
+        Some global scopes (notably, here, `AudioWorklet`) do not have distinct
+        wrapper types so we need to add a side condition to the generated code,
+        which we do after the type check.
+
+        Also removes `ScriptExecutionContext::isShadowRealmGlobalScope` as it's
+        now dead code and was never overridden anyways (a mistake left over
+        from the initial integration)
+
+        Tests: idlharness tests, including fixed visibility of
+        `AbortController.timeout`
+
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GenerateRuntimeEnableConditionalStringForExposeScope):
+        * bindings/scripts/test/JS/JSExposedStar.cpp:
+        (WebCore::JSExposedStarPrototype::finishCreation):
+        * bindings/scripts/test/JS/JSTestDefaultToJSONFilteredByExposed.cpp:
+        (WebCore::JSTestDefaultToJSONFilteredByExposedPrototype::finishCreation):
+        (WebCore::jsTestDefaultToJSONFilteredByExposedPrototypeFunction_toJSONBody):
+        * bindings/scripts/test/JS/JSTestObj.cpp:
+        (WebCore::JSTestObjPrototype::finishCreation):
+        * dom/ScriptExecutionContext.h:
+        (WebCore::ScriptExecutionContext::isServiceWorkerGlobalScope const):
+        (WebCore::ScriptExecutionContext::isShadowRealmGlobalScope const): Deleted.
+
 2022-04-16  Philippe Normand  <[email protected]>
 
         [GStreamer][WebRTC] Minor cleanup in IncomingSourceGStreamer

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (293020 => 293021)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2022-04-19 17:19:43 UTC (rev 293020)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2022-04-19 17:24:58 UTC (rev 293021)
@@ -3991,19 +3991,31 @@
 {
     my ($exposed, $context, $globalObjectPtr) = @_;
 
+    my $wrapperType;
+    my $sideCondition;
+
     if ($exposed eq "Window") {
-      return "jsCast<JSDOMGlobalObject*>(" . $globalObjectPtr . ")->scriptExecutionContext()->isDocument()";
+      $wrapperType = "JSDOMWindowBase";
     } elsif ($exposed eq "Worker") {
-      return "jsCast<JSDOMGlobalObject*>(" . $globalObjectPtr . ")->scriptExecutionContext()->isWorkerGlobalScope()";
+      $wrapperType = "JSWorkerGlobalScopeBase";
     } elsif ($exposed eq "ShadowRealm") {
-      return "jsCast<JSDOMGlobalObject*>(" . $globalObjectPtr . ")->scriptExecutionContext()->isShadowRealmGlobalScope()";
+      $wrapperType = "JSShadowRealmGlobalScopeBase";
     } elsif ($exposed eq "Worklet") {
-      return "jsCast<JSDOMGlobalObject*>(" . $globalObjectPtr . ")->scriptExecutionContext()->isWorkletGlobalScope()";
+      $wrapperType = "JSWorkletGlobalScopeBase";
     } elsif ($exposed eq "AudioWorklet") {
-      return "is<AudioWorkletGlobalScope>(jsCast<JSDOMGlobalObject*>(" . $globalObjectPtr . ")->scriptExecutionContext())";
+      $wrapperType = "JSWorkletGlobalScopeBase";
+      $sideCondition = "global->scriptExecutionContext()->isAudioWorkletGlobalScope()";
     } else {
       assert("Unrecognized value '" . Dumper($context->extendedAttributes->{Exposed}) . "' for the Exposed extended attribute on '" . ref($context) . "'.");
     }
+
+    AddToImplIncludes("$wrapperType.h", 0);
+
+    if (defined $sideCondition) {
+      return "([&] { auto* global = jsDynamicCast<$wrapperType>($globalObjectPtr); return global && $sideCondition; })()";
+    } else {
+      return "($globalObjectPtr)->inherits<$wrapperType>()"
+    }
 }
 
 sub GenerateRuntimeEnableConditionalStringForExposed

Modified: trunk/Source/WebCore/bindings/scripts/test/JS/JSExposedStar.cpp (293020 => 293021)


--- trunk/Source/WebCore/bindings/scripts/test/JS/JSExposedStar.cpp	2022-04-19 17:19:43 UTC (rev 293020)
+++ trunk/Source/WebCore/bindings/scripts/test/JS/JSExposedStar.cpp	2022-04-19 17:24:58 UTC (rev 293021)
@@ -31,7 +31,9 @@
 #include "JSDOMExceptionHandling.h"
 #include "JSDOMGlobalObjectInlines.h"
 #include "JSDOMOperation.h"
+#include "JSDOMWindowBase.h"
 #include "JSDOMWrapperCache.h"
+#include "JSWorkerGlobalScopeBase.h"
 #include "ScriptExecutionContext.h"
 #include "WebCoreJSClientData.h"
 #include <_javascript_Core/HeapAnalyzer.h>
@@ -124,7 +126,7 @@
     Base::finishCreation(vm);
     reifyStaticProperties(vm, JSExposedStar::info(), JSExposedStarPrototypeTableValues, *this);
     bool hasDisabledRuntimeProperties = false;
-    if (!jsCast<JSDOMGlobalObject*>(globalObject())->scriptExecutionContext()->isDocument()) {
+    if (!(globalObject())->inherits<JSDOMWindowBase>()) {
         hasDisabledRuntimeProperties = true;
         auto propertyName = Identifier::fromString(vm, "operationJustForWindowContexts"_s);
         VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
@@ -131,7 +133,7 @@
         DeletePropertySlot slot;
         JSObject::deleteProperty(this, globalObject(), propertyName, slot);
     }
-    if (!jsCast<JSDOMGlobalObject*>(globalObject())->scriptExecutionContext()->isWorkerGlobalScope()) {
+    if (!(globalObject())->inherits<JSWorkerGlobalScopeBase>()) {
         hasDisabledRuntimeProperties = true;
         auto propertyName = Identifier::fromString(vm, "operationJustForWorkerContexts"_s);
         VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);

Modified: trunk/Source/WebCore/bindings/scripts/test/JS/JSTestDefaultToJSONFilteredByExposed.cpp (293020 => 293021)


--- trunk/Source/WebCore/bindings/scripts/test/JS/JSTestDefaultToJSONFilteredByExposed.cpp	2022-04-19 17:19:43 UTC (rev 293020)
+++ trunk/Source/WebCore/bindings/scripts/test/JS/JSTestDefaultToJSONFilteredByExposed.cpp	2022-04-19 17:24:58 UTC (rev 293021)
@@ -32,7 +32,9 @@
 #include "JSDOMExceptionHandling.h"
 #include "JSDOMGlobalObjectInlines.h"
 #include "JSDOMOperation.h"
+#include "JSDOMWindowBase.h"
 #include "JSDOMWrapperCache.h"
+#include "JSWorkerGlobalScopeBase.h"
 #include "ScriptExecutionContext.h"
 #include "WebCoreJSClientData.h"
 #include <_javascript_Core/FunctionPrototype.h>
@@ -130,7 +132,7 @@
     Base::finishCreation(vm);
     reifyStaticProperties(vm, JSTestDefaultToJSONFilteredByExposed::info(), JSTestDefaultToJSONFilteredByExposedPrototypeTableValues, *this);
     bool hasDisabledRuntimeProperties = false;
-    if (!jsCast<JSDOMGlobalObject*>(globalObject())->scriptExecutionContext()->isDocument()) {
+    if (!(globalObject())->inherits<JSDOMWindowBase>()) {
         hasDisabledRuntimeProperties = true;
         auto propertyName = Identifier::fromString(vm, "filteredByExposedWindowAttribute"_s);
         VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
@@ -137,7 +139,7 @@
         DeletePropertySlot slot;
         JSObject::deleteProperty(this, globalObject(), propertyName, slot);
     }
-    if (!jsCast<JSDOMGlobalObject*>(globalObject())->scriptExecutionContext()->isWorkerGlobalScope()) {
+    if (!(globalObject())->inherits<JSWorkerGlobalScopeBase>()) {
         hasDisabledRuntimeProperties = true;
         auto propertyName = Identifier::fromString(vm, "filteredByExposedWorkerAttribute"_s);
         VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
@@ -245,12 +247,12 @@
     auto normalAttributeValue = toJS<IDLLong>(*lexicalGlobalObject, throwScope, impl.normalAttribute());
     RETURN_IF_EXCEPTION(throwScope, { });
     result->putDirect(vm, Identifier::fromString(vm, "normalAttribute"_s), normalAttributeValue);
-    if (jsCast<JSDOMGlobalObject*>(castedThis->globalObject())->scriptExecutionContext()->isDocument()) {
+    if ((castedThis->globalObject())->inherits<JSDOMWindowBase>()) {
         auto filteredByExposedWindowAttributeValue = toJS<IDLDouble>(*lexicalGlobalObject, throwScope, impl.filteredByExposedWindowAttribute());
         RETURN_IF_EXCEPTION(throwScope, { });
         result->putDirect(vm, Identifier::fromString(vm, "filteredByExposedWindowAttribute"_s), filteredByExposedWindowAttributeValue);
     }
-    if (jsCast<JSDOMGlobalObject*>(castedThis->globalObject())->scriptExecutionContext()->isWorkerGlobalScope()) {
+    if ((castedThis->globalObject())->inherits<JSWorkerGlobalScopeBase>()) {
         auto filteredByExposedWorkerAttributeValue = toJS<IDLDOMString>(*lexicalGlobalObject, throwScope, impl.filteredByExposedWorkerAttribute());
         RETURN_IF_EXCEPTION(throwScope, { });
         result->putDirect(vm, Identifier::fromString(vm, "filteredByExposedWorkerAttribute"_s), filteredByExposedWorkerAttributeValue);

Modified: trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp (293020 => 293021)


--- trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp	2022-04-19 17:19:43 UTC (rev 293020)
+++ trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp	2022-04-19 17:24:58 UTC (rev 293021)
@@ -81,6 +81,7 @@
 #include "JSTestSubObj.h"
 #include "JSVoidCallback.h"
 #include "JSWindowProxy.h"
+#include "JSWorkerGlobalScopeBase.h"
 #include "JSXPathNSResolver.h"
 #include "RuntimeEnabledFeatures.h"
 #include "ScriptExecutionContext.h"
@@ -2482,7 +2483,7 @@
         JSObject::deleteProperty(this, globalObject(), propertyName, slot);
     }
 #endif
-    if (!jsCast<JSDOMGlobalObject*>(globalObject())->scriptExecutionContext()->isDocument()) {
+    if (!(globalObject())->inherits<JSDOMWindowBase>()) {
         hasDisabledRuntimeProperties = true;
         auto propertyName = Identifier::fromString(vm, "conditionallyExposedToWindowFunction"_s);
         VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
@@ -2489,7 +2490,7 @@
         DeletePropertySlot slot;
         JSObject::deleteProperty(this, globalObject(), propertyName, slot);
     }
-    if (!jsCast<JSDOMGlobalObject*>(globalObject())->scriptExecutionContext()->isWorkerGlobalScope()) {
+    if (!(globalObject())->inherits<JSWorkerGlobalScopeBase>()) {
         hasDisabledRuntimeProperties = true;
         auto propertyName = Identifier::fromString(vm, "conditionallyExposedToWorkerFunction"_s);
         VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
@@ -2512,7 +2513,7 @@
         JSObject::deleteProperty(this, globalObject(), propertyName, slot);
     }
 #endif
-    if (!jsCast<JSDOMGlobalObject*>(globalObject())->scriptExecutionContext()->isDocument()) {
+    if (!(globalObject())->inherits<JSDOMWindowBase>()) {
         hasDisabledRuntimeProperties = true;
         auto propertyName = Identifier::fromString(vm, "conditionallyExposedToWindowAttribute"_s);
         VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
@@ -2519,7 +2520,7 @@
         DeletePropertySlot slot;
         JSObject::deleteProperty(this, globalObject(), propertyName, slot);
     }
-    if (!jsCast<JSDOMGlobalObject*>(globalObject())->scriptExecutionContext()->isWorkerGlobalScope()) {
+    if (!(globalObject())->inherits<JSWorkerGlobalScopeBase>()) {
         hasDisabledRuntimeProperties = true;
         auto propertyName = Identifier::fromString(vm, "conditionallyExposedToWorkerAttribute"_s);
         VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);

Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.h (293020 => 293021)


--- trunk/Source/WebCore/dom/ScriptExecutionContext.h	2022-04-19 17:19:43 UTC (rev 293020)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.h	2022-04-19 17:24:58 UTC (rev 293021)
@@ -102,7 +102,6 @@
     virtual bool isDocument() const { return false; }
     virtual bool isWorkerGlobalScope() const { return false; }
     virtual bool isServiceWorkerGlobalScope() const { return false; }
-    virtual bool isShadowRealmGlobalScope() const { return false; }
     virtual bool isWorkletGlobalScope() const { return false; }
 
     virtual bool isContextThread() const { return true; }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to