Ignore:
Timestamp:
Oct 14, 2021, 3:22:09 AM (4 years ago)
Author:
[email protected]
Message:

JSTests:
Test coverage for JSC shadow realms implementation
https://bugs.webkit.org/show_bug.cgi?id=230602

Patch by Phillip Mates <Phillip Mates> on 2021-10-14
Reviewed by Yusuke Suzuki.

  • modules/import-meta-syntax.js:

(shouldThrow):

  • stress/eval-indirect.js: Added.

(shouldBe):
(shouldThrow):

  • stress/import-syntax.js:
  • stress/resources/shadow-realm-example-module.js: Added.

(putInGlobal):
(getFromGlobal):
(getAnObject):
(getCallCount):

  • stress/shadow-realm-evaluate.js: Added.

(shouldBe):
(shouldThrow):
(assertionFn):
(shouldBe.String):
(shouldBe.globalObjectFor.doEval):
(shouldBe.globalObjectFor):

  • stress/shadow-realm-import-value.js: Added.

(shouldBe):
(shouldThrow):
(async shouldThrowAsync):
(async const):
(doImport):

  • stress/shadow-realm.js: Added.

(shouldBe):
(throw.new.Error):

  • test262/config.yaml:

Source/JavaScriptCore:
shadow realms implementation
https://bugs.webkit.org/show_bug.cgi?id=230602

Patch by Phillip Mates <Phillip Mates> on 2021-10-14
Reviewed by Yusuke Suzuki.

Implementation of the Shadow Realms proposal (stage 3 in TC39) [1]

Main APIs added are

  • new ShadowRealm() creates an object that has its own global object and module graph.
  • ShadowRealm.prototype.evaluate(sourceText) this allows for evaluating code in the context of the realm, which has its own module graph and global object.
  • ShadowRealm.prototype.importValue(specifier, exportName) this allows importing module exports in the the context of the realm, which has its own module graph and global object.

The main detail of the Shadow Realm implementation is that values
passed between realms must be either primitives or wrapped callables.
Wrapped callables themselves are callables that check that their
arguments and return values are also either primitives or wrapped
callables. This detail is implemented via JS builtins + a few new
intrinsics.

Can be enabled using --useShadowRealm=true

[1]: https://github.com/tc39/proposal-shadowrealm

  • CMakeLists.txt:
  • DerivedSources-input.xcfilelist:
  • DerivedSources-output.xcfilelist:
  • DerivedSources.make:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • Sources.txt:
  • builtins/BuiltinNames.h:
  • builtins/ShadowRealmPrototype.js: Added.

(globalPrivate.wrap.wrapped):
(globalPrivate.wrap):
(evaluate):
(importValue):

  • bytecode/BytecodeIntrinsicRegistry.h:
  • bytecode/LinkTimeConstant.h:
  • bytecompiler/BytecodeGenerator.h:

(JSC::BytecodeGenerator::emitIsShadowRealm):

  • bytecompiler/NodesCodegen.cpp:
  • jsc.cpp:

(JSC_DEFINE_HOST_FUNCTION):

  • parser/Parser.cpp:

(JSC::Parser<LexerType>::parseMemberExpression):

  • runtime/CommonIdentifiers.h:
  • runtime/IndirectEvalExecutable.cpp:

(JSC::IndirectEvalExecutable::createImpl):
(JSC::IndirectEvalExecutable::create):
(JSC::IndirectEvalExecutable::tryCreate):

  • runtime/IndirectEvalExecutable.h:
  • runtime/JSGlobalObject.cpp:

(JSC::JSGlobalObject::init):
(JSC::JSGlobalObject::visitChildrenImpl):
(JSC::JSGlobalObject::createWithCustomMethodTable):

  • runtime/JSGlobalObject.h:

(JSC::JSGlobalObject::shadowRealmPrototype const):
(JSC::JSGlobalObject::shadowRealmStructure const):

  • runtime/JSGlobalObjectFunctions.cpp:

(JSC::JSC_DEFINE_HOST_FUNCTION):

  • runtime/JSType.cpp:

(WTF::printInternal):

  • runtime/JSType.h:
  • runtime/OptionsList.h:
  • runtime/ShadowRealmConstructor.cpp: Added.

(JSC::ShadowRealmConstructor::ShadowRealmConstructor):
(JSC::ShadowRealmConstructor::finishCreation):
(JSC::JSC_DEFINE_HOST_FUNCTION):

  • runtime/ShadowRealmConstructor.h: Added.
  • runtime/ShadowRealmObject.cpp: Added.

(JSC::ShadowRealmObject::ShadowRealmObject):
(JSC::ShadowRealmObject::visitChildrenImpl):
(JSC::ShadowRealmObject::create):
(JSC::ShadowRealmObject::finishCreation):

  • runtime/ShadowRealmObject.h: Added.
  • runtime/ShadowRealmPrototype.cpp: Added.

(JSC::ShadowRealmPrototype::ShadowRealmPrototype):
(JSC::ShadowRealmPrototype::finishCreation):
(JSC::JSC_DEFINE_HOST_FUNCTION):

  • runtime/ShadowRealmPrototype.h: Added.
  • runtime/VM.cpp:
  • runtime/VM.h:
Location:
trunk/Source/JavaScriptCore/bytecompiler
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h

    r283168 r284151  
    886886        RegisterID* emitIsMap(RegisterID* dst, RegisterID* src) { return emitIsCellWithType(dst, src, JSMapType); }
    887887        RegisterID* emitIsSet(RegisterID* dst, RegisterID* src) { return emitIsCellWithType(dst, src, JSSetType); }
     888        RegisterID* emitIsShadowRealm(RegisterID* dst, RegisterID* src) { return emitIsCellWithType(dst, src, ShadowRealmType); }
    888889        RegisterID* emitIsStringIterator(RegisterID* dst, RegisterID* src) { return emitIsCellWithType(dst, src, JSStringIteratorType); }
    889890        RegisterID* emitIsArrayIterator(RegisterID* dst, RegisterID* src) { return emitIsCellWithType(dst, src, JSArrayIteratorType); }
  • trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp

    r283101 r284151  
    18951895CREATE_INTRINSIC_FOR_BRAND_CHECK(isMap, IsMap)
    18961896CREATE_INTRINSIC_FOR_BRAND_CHECK(isSet, IsSet)
     1897CREATE_INTRINSIC_FOR_BRAND_CHECK(isShadowRealm, IsShadowRealm)
    18971898CREATE_INTRINSIC_FOR_BRAND_CHECK(isStringIterator, IsStringIterator)
    18981899CREATE_INTRINSIC_FOR_BRAND_CHECK(isArrayIterator, IsArrayIterator)
Note: See TracChangeset for help on using the changeset viewer.