Changeset 292895 in webkit


Ignore:
Timestamp:
Apr 14, 2022 4:39:06 PM (3 months ago)
Author:
caitp@igalia.com
Message:

[JSC] ShadowRealm global object has a mutable prototype
https://bugs.webkit.org/show_bug.cgi?id=239332

Reviewed by Yusuke Suzuki.

JSTests:

  • stress/shadow-realm-globalThis-mutable-prototype.js: Added.

Source/JavaScriptCore:

This patch circumvents the ASSERT(toThis() == this) in JSObject::setPrototypeWithCycleCheck()
when this is a GlobalObject. Ordinarily, GlobalObjects have the IsImmutablePrototypeExoticObject
bit set and miss this pathway, however this is not the case for ShadowRealm Global Objects.

In addition, the JSC internal version is also modified to have a mutable prototype in the same way
as in WebCore.

  • runtime/JSGlobalObject.h:

(JSC::JSGlobalObject::deriveShadowRealmGlobalObject):
(JSC::JSGlobalObject::createStructureForShadowRealm):

  • runtime/JSObject.cpp:

(JSC::JSObject::setPrototypeWithCycleCheck):

Source/WebCore:

Hack: The IDL code generator now special cases ShadowRealmGlobalObject to remove the
ImmutablePrototypeExoticObject bit from the inherited JSGlobalObject structure flags.

As a result, this enables the assignment of a ShadowRealm's globalThis.proto, or
overwriting the prototype with [Object / Reflect].setPrototypeOf().

Test: js/ShadowRealm-globalThis.html

  • bindings/scripts/CodeGeneratorJS.pm:

(GenerateHeader):

  • bindings/scripts/test/JS/JSShadowRealmGlobalScope.h:

LayoutTests:

Add a new layout test to verify changes to verify that ShadowRealmGlobalObject has a properly
mutable prototype.

  • js/ShadowRealm-globalThis-expected.txt: Added.
  • js/ShadowRealm-globalThis.html: Added.
Location:
trunk
Files:
3 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r292883 r292895  
     12022-04-14  Caitlin Potter  <caitp@igalia.com>
     2
     3        [JSC] ShadowRealm global object has a mutable prototype
     4        https://bugs.webkit.org/show_bug.cgi?id=239332
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * stress/shadow-realm-globalThis-mutable-prototype.js: Added.
     9
    1102022-04-14  Alexey Shvayka  <ashvayka@apple.com>
    211
  • trunk/LayoutTests/ChangeLog

    r292893 r292895  
     12022-04-14  Caitlin Potter  <caitp@igalia.com>
     2
     3        [JSC] ShadowRealm global object has a mutable prototype
     4        https://bugs.webkit.org/show_bug.cgi?id=239332
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        Add a new layout test to verify changes to verify that ShadowRealmGlobalObject has a properly
     9        mutable prototype.
     10
     11        * js/ShadowRealm-globalThis-expected.txt: Added.
     12        * js/ShadowRealm-globalThis.html: Added.
     13
    1142022-04-14  Nikolaos Mouchtaris  <nmouchtaris@apple.com>
    215
  • trunk/Source/JavaScriptCore/ChangeLog

    r292891 r292895  
     12022-04-14  Caitlin Potter  <caitp@igalia.com>
     2
     3        [JSC] ShadowRealm global object has a mutable prototype
     4        https://bugs.webkit.org/show_bug.cgi?id=239332
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        This patch circumvents the `ASSERT(toThis() == this)` in JSObject::setPrototypeWithCycleCheck()
     9        when `this` is a GlobalObject. Ordinarily, GlobalObjects have the IsImmutablePrototypeExoticObject
     10        bit set and miss this pathway, however this is not the case for ShadowRealm Global Objects.
     11
     12        In addition, the JSC internal version is also modified to have a mutable prototype in the same way
     13        as in WebCore.
     14
     15        * runtime/JSGlobalObject.h:
     16        (JSC::JSGlobalObject::deriveShadowRealmGlobalObject):
     17        (JSC::JSGlobalObject::createStructureForShadowRealm):
     18        * runtime/JSObject.cpp:
     19        (JSC::JSObject::setPrototypeWithCycleCheck):
     20
    1212022-04-14  Yusuke Suzuki  <ysuzuki@apple.com>
    222
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h

    r292830 r292895  
    11001100    {
    11011101        auto& vm = globalObject->vm();
    1102         return JSGlobalObject::createWithCustomMethodTable(vm, JSGlobalObject::createStructure(vm, jsNull()), globalObject->globalObjectMethodTable());
     1102        JSGlobalObject* result = JSGlobalObject::createWithCustomMethodTable(vm, JSGlobalObject::createStructureForShadowRealm(vm, jsNull()), globalObject->globalObjectMethodTable());
     1103        return result;
    11031104    }
    11041105
     
    11411142    {
    11421143        Structure* result = Structure::create(vm, nullptr, prototype, TypeInfo(GlobalObjectType, StructureFlags), info());
     1144        result->setTransitionWatchpointIsLikelyToBeFired(true);
     1145        return result;
     1146    }
     1147    static Structure* createStructureForShadowRealm(VM& vm, JSValue prototype)
     1148    {
     1149        Structure* result = Structure::create(vm, nullptr, prototype, TypeInfo(GlobalObjectType, StructureFlags & ~IsImmutablePrototypeExoticObject), info());
    11431150        result->setTransitionWatchpointIsLikelyToBeFired(true);
    11441151        return result;
  • trunk/Source/JavaScriptCore/runtime/JSObject.cpp

    r292810 r292895  
    19161916    }
    19171917
    1918     ASSERT(methodTable(vm)->toThis(this, globalObject, ECMAMode::sloppy()) == this);
     1918    // Default realm global objects should have mutable prototypes despite having
     1919    // a Proxy globalThis.
     1920    ASSERT(this->isGlobalObject() || methodTable(vm)->toThis(this, globalObject, ECMAMode::sloppy()) == this);
    19191921
    19201922    if (this->getPrototypeDirect(vm) == prototype)
  • trunk/Source/WebCore/ChangeLog

    r292893 r292895  
     12022-04-14  Caitlin Potter  <caitp@igalia.com>
     2
     3        [JSC] ShadowRealm global object has a mutable prototype
     4        https://bugs.webkit.org/show_bug.cgi?id=239332
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        Hack: The IDL code generator now special cases ShadowRealmGlobalObject to remove the
     9        ImmutablePrototypeExoticObject bit from the inherited JSGlobalObject structure flags.
     10
     11        As a result, this enables the assignment of a ShadowRealm's globalThis.__proto__, or
     12        overwriting the prototype with [Object / Reflect].setPrototypeOf().
     13
     14        Test: js/ShadowRealm-globalThis.html
     15
     16        * bindings/scripts/CodeGeneratorJS.pm:
     17        (GenerateHeader):
     18        * bindings/scripts/test/JS/JSShadowRealmGlobalScope.h:
     19
    1202022-04-14  Nikolaos Mouchtaris  <nmouchtaris@apple.com>
    221
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r292641 r292895  
    32063206    if (%structureFlags) {
    32073207        push(@headerContent, "public:\n");
    3208         push(@headerContent, "    static constexpr unsigned StructureFlags = Base::StructureFlags");
     3208        if ($interfaceName eq "ShadowRealmGlobalScope") {
     3209            # Hack to make ShadowRealmGlobalScope a default realm global object (not an ImmutablePrototypeExoticObject)
     3210            push(@headerContent, "    static constexpr unsigned StructureFlags = (Base::StructureFlags & ~JSC::IsImmutablePrototypeExoticObject)");
     3211        } else {
     3212            push(@headerContent, "    static constexpr unsigned StructureFlags = Base::StructureFlags");
     3213        }
    32093214        foreach my $structureFlag (sort (keys %structureFlags)) {
    32103215            push(@headerContent, " | " . $structureFlag);
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSShadowRealmGlobalScope.h

    r290129 r292895  
    5858    static void analyzeHeap(JSCell*, JSC::HeapAnalyzer&);
    5959public:
    60     static constexpr unsigned StructureFlags = Base::StructureFlags | JSC::HasStaticPropertyTable;
     60    static constexpr unsigned StructureFlags = (Base::StructureFlags & ~JSC::IsImmutablePrototypeExoticObject) | JSC::HasStaticPropertyTable;
    6161protected:
    6262    JSShadowRealmGlobalScope(JSC::VM&, JSC::Structure*, Ref<ShadowRealmGlobalScope>&&);
Note: See TracChangeset for help on using the changeset viewer.