Skip to content
Permalink
Browse files
[Shadow Realms] Add feature flag to enable Exposed=* web APIs in Shad…
…owRealms

https://bugs.webkit.org/show_bug.cgi?id=241448

Reviewed by Yusuke Suzuki.

No longer expose Web APIs to ShadowRealm by default. Instead, we
enable this with a new setting WebAPIsInShadowRealmEnabled.

Because the HTML integration aspect of the specification is still in the
air, it's prudent to disable it by default, while still providing a
feature flag for web-platform-tests.

* Source/WTF/Scripts/Preferences/WebPreferencesExperimental.yaml:
* Source/WebCore/bindings/js/WebCoreBuiltinNames.h:
* Source/WebCore/bindings/scripts/preprocess-idls.pl:
(GenerateConstructorAttributes):
* Source/WebCore/bindings/scripts/test/JS/JSShadowRealmGlobalScope.cpp:
(WebCore::JSShadowRealmGlobalScope::finishCreation):
* Source/WebCore/bindings/scripts/test/ShadowRealmGlobalScopeConstructors.idl:

Canonical link: https://commits.webkit.org/251465@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@295459 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
caitp committed Jun 10, 2022
1 parent 5eed7e9 commit b0668c973126fb6f0b9f51eca04a6c1176f6d27f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 8 deletions.
@@ -1564,6 +1564,18 @@ VorbisDecoderEnabled:
WebKit:
default: true

WebAPIsInShadowRealmEnabled:
type: bool
humanReadableName: "Web APIs in ShadowRealm"
humanReadableDescription: "Enable Web APIs to be exposed in ShadowRealm"
defaultValue:
WebKitLegacy:
default: false
WebKit:
default: false
WebCore:
default: false

WebAnimationsCompositeOperationsEnabled:
type: bool
humanReadableName: "Web Animations composite operations"
@@ -39,6 +39,25 @@ namespace WebCore {
#define WEBCORE_ADDITIONAL_PRIVATE_IDENTIFIERS(macro)
#endif

#if !defined(WEBCORE_COMMON_PRIVATE_IDENTIFIERS_FOR_SHADOWREALM_EACH_PROPERTY_NAME)
// Dom APIs exposed to ShadowRealm are temporarily enabled via the WebAPIsInShadowRealmEnabled
// experimental feature. When this is resolved, these can be deleted.
#define WEBCORE_COMMON_PRIVATE_IDENTIFIERS_FOR_SHADOWREALM_EACH_PROPERTY_NAME(macro) \
macro(AbortController) \
macro(ByteLengthQueuingStrategy) \
macro(CountQueuingStrategy) \
macro(CustomEvent) \
macro(ErrorEvent) \
macro(Event) \
macro(EventTarget) \
macro(Performance) \
macro(PromiseRejectionEvent) \
macro(TextDecoder) \
macro(TextEncoder) \
macro(URL) \
macro(URLSearchParams)
#endif

#define WEBCORE_COMMON_PRIVATE_IDENTIFIERS_EACH_PROPERTY_NAME(macro) \
macro(AbortSignal) \
macro(AbstractRange) \
@@ -608,6 +627,7 @@ namespace WebCore {
macro(pendingAbortRequest) \
macro(writeRequests) \
WEBCORE_ADDITIONAL_PRIVATE_IDENTIFIERS(macro) \
WEBCORE_COMMON_PRIVATE_IDENTIFIERS_FOR_SHADOWREALM_EACH_PROPERTY_NAME(macro) \

class WebCoreBuiltinNames {
public:
@@ -501,6 +501,15 @@ sub GenerateConstructorAttributes
$extendedAttributes->{"Conditional"} = $existingConditional;
}

if ($globalContext eq "ShadowRealm" && $extendedAttributes->{"Exposed"} eq "*") {
my $enabledBySetting = "WebAPIsInShadowRealmEnabled";
my $existingEnabledBySetting = $extendedAttributes->{"EnabledBySetting"};
if ($existingEnabledBySetting) {
$enabledBySetting .= "&" . $existingEnabledBySetting;
}
$extendedAttributes->{"EnabledBySetting"} = $enabledBySetting;
}

my $code = " ";
my @extendedAttributesList;
foreach my $attributeName (sort keys %{$extendedAttributes}) {
@@ -59,22 +59,18 @@ using JSShadowRealmGlobalScopeDOMConstructor = JSDOMConstructorNotConstructable<

/* Hash table */

static const struct CompactHashIndex JSShadowRealmGlobalScopeTableIndex[5] = {
static const struct CompactHashIndex JSShadowRealmGlobalScopeTableIndex[2] = {
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 0, 4 },
{ 1, -1 },
{ 0, -1 },
};


static const HashTableValue JSShadowRealmGlobalScopeTableValues[] =
{
{ "ExposedStar"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsShadowRealmGlobalScope_ExposedStarConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
{ "ShadowRealmGlobalScope"_s, static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsShadowRealmGlobalScope_ShadowRealmGlobalScopeConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
};

static const HashTable JSShadowRealmGlobalScopeTable = { 2, 3, true, JSShadowRealmGlobalScope::info(), JSShadowRealmGlobalScopeTableValues, JSShadowRealmGlobalScopeTableIndex };
static const HashTable JSShadowRealmGlobalScopeTable = { 1, 1, true, JSShadowRealmGlobalScope::info(), JSShadowRealmGlobalScopeTableValues, JSShadowRealmGlobalScopeTableIndex };
template<> const ClassInfo JSShadowRealmGlobalScopeDOMConstructor::s_info = { "ShadowRealmGlobalScope"_s, &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSShadowRealmGlobalScopeDOMConstructor) };

template<> JSValue JSShadowRealmGlobalScopeDOMConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
@@ -105,6 +101,8 @@ void JSShadowRealmGlobalScope::finishCreation(VM& vm, JSProxy* proxy)

static_assert(!std::is_base_of<ActiveDOMObject, ShadowRealmGlobalScope>::value, "Interface is not marked as [ActiveDOMObject] even though implementation class subclasses ActiveDOMObject.");

if (jsCast<JSDOMGlobalObject*>(globalObject())->scriptExecutionContext()->settingsValues().webAPIsInShadowRealmEnabled)
putDirectCustomAccessor(vm, builtinNames(vm).ExposedStarPublicName(), CustomGetterSetter::create(vm, jsShadowRealmGlobalScope_ExposedStarConstructor, nullptr), attributesForStructure(static_cast<unsigned>(JSC::PropertyAttribute::DontEnum)));
}

JSValue JSShadowRealmGlobalScope::getConstructor(VM& vm, const JSGlobalObject* globalObject)
@@ -1,4 +1,4 @@
partial interface ShadowRealmGlobalScope {
attribute ExposedStarConstructor ExposedStar;
[EnabledBySetting=WebAPIsInShadowRealmEnabled] attribute ExposedStarConstructor ExposedStar;
attribute ShadowRealmGlobalScopeConstructor ShadowRealmGlobalScope;
};

0 comments on commit b0668c9

Please sign in to comment.