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-18
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):
Source/JavaScriptCore:
shadow realms implementation
https://bugs.webkit.org/show_bug.cgi?id=230602
Patch by Phillip Mates <Phillip Mates> on 2021-10-18
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):
(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):
(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: