Commit 10a777ee authored by legendecas's avatar legendecas Committed by V8 LUCI CQ

[ShadowRealm] Part 1 - Skeleton

1. Expose all the functions to empty builtins.
2. Wire up the basic structure of ShadowRealm and internal slots.

Bug: v8:11989
Change-Id: If7545fe18a74b2bd4b70a1a25776e41f03aaff89
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3195532Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Commit-Queue: Chengzhong Wu <legendecas@gmail.com>
Cr-Commit-Position: refs/heads/main@{#78757}
parent c1d39129
......@@ -857,6 +857,7 @@ filegroup(
"src/objects/js-proxy.tq",
"src/objects/js-regexp-string-iterator.tq",
"src/objects/js-regexp.tq",
"src/objects/js-shadow-realms.tq",
"src/objects/js-temporal-objects.tq",
"src/objects/js-weak-refs.tq",
"src/objects/literal-objects.tq",
......@@ -1051,6 +1052,7 @@ filegroup(
"src/builtins/builtins-promise.h",
"src/builtins/builtins-reflect.cc",
"src/builtins/builtins-regexp.cc",
"src/builtins/builtins-shadow-realms.cc",
"src/builtins/builtins-sharedarraybuffer.cc",
"src/builtins/builtins-string.cc",
"src/builtins/builtins-symbol.cc",
......@@ -1638,6 +1640,8 @@ filegroup(
"src/objects/js-regexp-string-iterator.h",
"src/objects/js-regexp.cc",
"src/objects/js-regexp.h",
"src/objects/js-shadow-realms.h",
"src/objects/js-shadow-realms-inl.h",
"src/objects/js-temporal-objects.h",
"src/objects/js-temporal-objects-inl.h",
"src/objects/js-temporal-objects.cc",
......
......@@ -1759,6 +1759,7 @@ torque_files = [
"src/objects/js-proxy.tq",
"src/objects/js-regexp-string-iterator.tq",
"src/objects/js-regexp.tq",
"src/objects/js-shadow-realms.tq",
"src/objects/js-temporal-objects.tq",
"src/objects/js-weak-refs.tq",
"src/objects/literal-objects.tq",
......@@ -3162,6 +3163,8 @@ v8_header_set("v8_internal_headers") {
"src/objects/js-regexp.h",
"src/objects/js-segments-inl.h",
"src/objects/js-segments.h",
"src/objects/js-shadow-realms-inl.h",
"src/objects/js-shadow-realms.h",
"src/objects/js-temporal-objects-inl.h",
"src/objects/js-temporal-objects.h",
"src/objects/js-weak-refs-inl.h",
......@@ -4029,6 +4032,7 @@ v8_source_set("v8_base_without_compiler") {
"src/builtins/builtins-object.cc",
"src/builtins/builtins-reflect.cc",
"src/builtins/builtins-regexp.cc",
"src/builtins/builtins-shadow-realms.cc",
"src/builtins/builtins-sharedarraybuffer.cc",
"src/builtins/builtins-string.cc",
"src/builtins/builtins-symbol.cc",
......
......@@ -367,6 +367,20 @@ using HostInitializeImportMetaObjectCallback = void (*)(Local<Context> context,
Local<Module> module,
Local<Object> meta);
/**
* HostCreateShadowRealmContextCallback is called each time a ShadowRealm is
* being constructed in the initiator_context.
*
* The method combines Context creation and implementation defined abstract
* operation HostInitializeShadowRealm into one.
*
* The embedder should use v8::Context::New or v8::Context:NewFromSnapshot to
* create a new context. If the creation fails, the embedder must propagate
* that exception by returning an empty MaybeLocal.
*/
using HostCreateShadowRealmContextCallback =
MaybeLocal<Context> (*)(Local<Context> initiator_context);
/**
* PrepareStackTraceCallback is called when the stack property of an error is
* first accessed. The return value will be used as the stack value. If this
......
......@@ -641,6 +641,13 @@ class V8_EXPORT Isolate {
void SetHostInitializeImportMetaObjectCallback(
HostInitializeImportMetaObjectCallback callback);
/**
* This specifies the callback called by the upcoming ShadowRealm
* construction language feature to retrieve host created globals.
*/
void SetHostCreateShadowRealmContextCallback(
HostCreateShadowRealmContextCallback callback);
/**
* This specifies the callback called when the stack property of Error
* is accessed.
......
......@@ -8816,6 +8816,12 @@ void Isolate::SetHostInitializeImportMetaObjectCallback(
isolate->SetHostInitializeImportMetaObjectCallback(callback);
}
void Isolate::SetHostCreateShadowRealmContextCallback(
HostCreateShadowRealmContextCallback callback) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
isolate->SetHostCreateShadowRealmContextCallback(callback);
}
void Isolate::SetPrepareStackTraceCallback(PrepareStackTraceCallback callback) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
isolate->SetPrepareStackTraceCallback(callback);
......
......@@ -16,6 +16,7 @@
#include 'src/objects/js-generator.h'
#include 'src/objects/js-promise.h'
#include 'src/objects/js-regexp-string-iterator.h'
#include 'src/objects/js-shadow-realms.h'
#include 'src/objects/js-weak-refs.h'
#include 'src/objects/objects.h'
#include 'src/objects/source-text-module.h'
......
......@@ -867,6 +867,11 @@ namespace internal {
TFJ(SetIteratorPrototypeNext, kJSArgcReceiverSlots, kReceiver) \
TFS(SetOrSetIteratorToList, kSource) \
\
/* ShadowRealm */ \
CPP(ShadowRealmConstructor) \
CPP(ShadowRealmPrototypeEvaluate) \
CPP(ShadowRealmPrototypeImportValue) \
\
/* SharedArrayBuffer */ \
CPP(SharedArrayBufferPrototypeGetByteLength) \
CPP(SharedArrayBufferPrototypeSlice) \
......
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/builtins/builtins-utils-inl.h"
#include "src/logging/counters.h"
#include "src/objects/js-shadow-realms-inl.h"
namespace v8 {
namespace internal {
// https://tc39.es/proposal-shadowrealm/#sec-shadowrealm-constructor
BUILTIN(ShadowRealmConstructor) {
HandleScope scope(isolate);
// 1. If NewTarget is undefined, throw a TypeError exception.
if (args.new_target()->IsUndefined(isolate)) { // [[Call]]
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewTypeError(MessageTemplate::kConstructorNotFunction,
isolate->factory()->ShadowRealm_string()));
}
// [[Construct]]
Handle<JSFunction> target = args.target();
Handle<JSReceiver> new_target = Handle<JSReceiver>::cast(args.new_target());
// 3. Let realmRec be CreateRealm().
// 5. Let context be a new execution context.
// 6. Set the Function of context to null.
// 7. Set the Realm of context to realmRec.
// 8. Set the ScriptOrModule of context to null.
// 10. Perform ? SetRealmGlobalObject(realmRec, undefined, undefined).
// 11. Perform ? SetDefaultGlobalBindings(O.[[ShadowRealm]]).
// 12. Perform ? HostInitializeShadowRealm(O.[[ShadowRealm]]).
// These steps are combined in
// Isolate::RunHostCreateShadowRealmContextCallback and Context::New.
// The host operation is hoisted for not creating a half-initialized
// ShadowRealm object, which can fail the heap verification.
Handle<NativeContext> native_context;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, native_context,
isolate->RunHostCreateShadowRealmContextCallback());
// 2. Let O be ? OrdinaryCreateFromConstructor(NewTarget,
// "%ShadowRealm.prototype%", « [[ShadowRealm]], [[ExecutionContext]] »).
Handle<JSObject> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, result,
JSObject::New(target, new_target, Handle<AllocationSite>::null()));
Handle<JSShadowRealm> O = Handle<JSShadowRealm>::cast(result);
// 4. Set O.[[ShadowRealm]] to realmRec.
// 9. Set O.[[ExecutionContext]] to context.
O->set_native_context(*native_context);
// 13. Return O.
return *O;
}
// https://tc39.es/proposal-shadowrealm/#sec-shadowrealm.prototype.evaluate
BUILTIN(ShadowRealmPrototypeEvaluate) {
HandleScope scope(isolate);
return ReadOnlyRoots(isolate).undefined_value();
}
// https://tc39.es/proposal-shadowrealm/#sec-shadowrealm.prototype.importvalue
BUILTIN(ShadowRealmPrototypeImportValue) {
HandleScope scope(isolate);
return ReadOnlyRoots(isolate).undefined_value();
}
} // namespace internal
} // namespace v8
......@@ -257,6 +257,7 @@ Type::bitset BitsetType::Lub(const MapRefLike& map) {
case JS_WEAK_REF_TYPE:
case JS_WEAK_SET_TYPE:
case JS_PROMISE_TYPE:
case JS_SHADOW_REALM_TYPE:
case JS_TEMPORAL_CALENDAR_TYPE:
case JS_TEMPORAL_DURATION_TYPE:
case JS_TEMPORAL_INSTANT_TYPE:
......
......@@ -1265,6 +1265,11 @@ void Shell::HostInitializeImportMetaObject(Local<Context> context,
meta->CreateDataProperty(context, url_key, url).ToChecked();
}
MaybeLocal<Context> Shell::HostCreateShadowRealmContext(
Local<Context> initiator_context) {
return v8::Context::New(initiator_context->GetIsolate());
}
void Shell::DoHostImportModuleDynamically(void* import_data) {
DynamicImportData* import_data_ =
static_cast<DynamicImportData*>(import_data);
......@@ -3190,6 +3195,8 @@ void Shell::Initialize(Isolate* isolate, D8Console* console,
Shell::HostImportModuleDynamically);
isolate->SetHostInitializeImportMetaObjectCallback(
Shell::HostInitializeImportMetaObject);
isolate->SetHostCreateShadowRealmContextCallback(
Shell::HostCreateShadowRealmContext);
#ifdef V8_FUZZILLI
// Let the parent process (Fuzzilli) know we are ready.
......
......@@ -636,6 +636,8 @@ class Shell : public i::AllStatic {
static void HostInitializeImportMetaObject(Local<Context> context,
Local<Module> module,
Local<Object> meta);
static MaybeLocal<Context> HostCreateShadowRealmContext(
Local<Context> initiator_context);
#ifdef V8_FUZZILLI
static void Fuzzilli(const v8::FunctionCallbackInfo<v8::Value>& args);
......
......@@ -54,6 +54,7 @@
#endif // V8_INTL_SUPPORT
#include "src/objects/js-regexp-inl.h"
#include "src/objects/js-regexp-string-iterator-inl.h"
#include "src/objects/js-shadow-realms-inl.h"
#ifdef V8_INTL_SUPPORT
#include "src/objects/js-relative-time-format-inl.h"
#include "src/objects/js-segment-iterator-inl.h"
......@@ -1134,6 +1135,8 @@ void JSMapIterator::JSMapIteratorVerify(Isolate* isolate) {
CHECK(index().IsSmi());
}
USE_TORQUE_VERIFIER(JSShadowRealm)
void WeakCell::WeakCellVerify(Isolate* isolate) {
CHECK(IsWeakCell());
......
......@@ -1399,6 +1399,12 @@ void JSWeakRef::JSWeakRefPrint(std::ostream& os) {
JSObjectPrintBody(os, *this);
}
void JSShadowRealm::JSShadowRealmPrint(std::ostream& os) {
JSObjectPrintHeader(os, *this, "JSShadowRealm");
os << "\n - native_context: " << Brief(native_context());
JSObjectPrintBody(os, *this);
}
void JSFinalizationRegistry::JSFinalizationRegistryPrint(std::ostream& os) {
JSObjectPrintHeader(os, *this, "JSFinalizationRegistry");
os << "\n - native_context: " << Brief(native_context());
......
......@@ -4771,6 +4771,32 @@ void Isolate::SetHostInitializeImportMetaObjectCallback(
host_initialize_import_meta_object_callback_ = callback;
}
void Isolate::SetHostCreateShadowRealmContextCallback(
HostCreateShadowRealmContextCallback callback) {
host_create_shadow_realm_context_callback_ = callback;
}
MaybeHandle<NativeContext> Isolate::RunHostCreateShadowRealmContextCallback() {
if (host_create_shadow_realm_context_callback_ == nullptr) {
Handle<Object> exception =
factory()->NewError(error_function(), MessageTemplate::kUnsupported);
Throw(*exception);
return kNullMaybeHandle;
}
v8::Local<v8::Context> api_context =
v8::Utils::ToLocal(Handle<Context>(native_context()));
v8::Local<v8::Context> shadow_realm_context;
ASSIGN_RETURN_ON_SCHEDULED_EXCEPTION_VALUE(
this, shadow_realm_context,
host_create_shadow_realm_context_callback_(api_context),
MaybeHandle<NativeContext>());
Handle<Context> shadow_realm_context_handle =
v8::Utils::OpenHandle(*shadow_realm_context);
DCHECK(shadow_realm_context_handle->IsNativeContext());
return Handle<NativeContext>::cast(shadow_realm_context_handle);
}
MaybeHandle<Object> Isolate::RunPrepareStackTraceCallback(
Handle<Context> context, Handle<JSObject> error, Handle<JSArray> sites) {
v8::Local<v8::Context> api_context = Utils::ToLocal(context);
......
......@@ -1753,6 +1753,10 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
MaybeHandle<JSObject> RunHostInitializeImportMetaObjectCallback(
Handle<SourceTextModule> module);
void SetHostCreateShadowRealmContextCallback(
HostCreateShadowRealmContextCallback callback);
MaybeHandle<NativeContext> RunHostCreateShadowRealmContextCallback();
void RegisterEmbeddedFileWriter(EmbeddedFileWriterInterface* writer) {
embedded_file_writer_ = writer;
}
......@@ -2137,6 +2141,9 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
HostInitializeImportMetaObjectCallback
host_initialize_import_meta_object_callback_ = nullptr;
HostCreateShadowRealmContextCallback
host_create_shadow_realm_context_callback_ = nullptr;
base::Mutex rail_mutex_;
double load_start_time_ms_ = 0;
......
......@@ -306,7 +306,8 @@ DEFINE_BOOL(harmony_shipping, true, "enable all shipped harmony features")
V(harmony_import_assertions, "harmony import assertions") \
V(harmony_rab_gsab, \
"harmony ResizableArrayBuffer / GrowableSharedArrayBuffer") \
V(harmony_temporal, "Temporal")
V(harmony_temporal, "Temporal") \
V(harmony_shadow_realm, "harmony ShadowRealm")
#ifdef V8_INTL_SUPPORT
#define HARMONY_INPROGRESS(V) HARMONY_INPROGRESS_BASE(V)
......
......@@ -52,6 +52,7 @@
#endif // V8_INTL_SUPPORT
#include "src/objects/js-regexp-string-iterator.h"
#include "src/objects/js-regexp.h"
#include "src/objects/js-shadow-realms.h"
#ifdef V8_INTL_SUPPORT
#include "src/objects/js-relative-time-format.h"
#include "src/objects/js-segment-iterator.h"
......@@ -4407,6 +4408,30 @@ EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_intl_best_fit_matcher)
#undef EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE
void Genesis::InitializeGlobal_harmony_shadow_realm() {
if (!FLAG_harmony_shadow_realm) return;
// -- S h a d o w R e a l m
// #sec-shadowrealm-objects
Handle<JSGlobalObject> global(native_context()->global_object(), isolate());
Handle<JSFunction> shadow_realm_fun = InstallFunction(
isolate_, global, "ShadowRealm", JS_SHADOW_REALM_TYPE,
JSShadowRealm::kHeaderSize, 0, factory()->the_hole_value(),
Builtin::kShadowRealmConstructor);
shadow_realm_fun->shared().set_length(0);
shadow_realm_fun->shared().DontAdaptArguments();
// Setup %ShadowRealmPrototype%.
Handle<JSObject> prototype(
JSObject::cast(shadow_realm_fun->instance_prototype()), isolate());
InstallToStringTag(isolate_, prototype, factory()->ShadowRealm_string());
SimpleInstallFunction(isolate_, prototype, "evaluate",
Builtin::kShadowRealmPrototypeEvaluate, 1, true);
SimpleInstallFunction(isolate_, prototype, "importValue",
Builtin::kShadowRealmPrototypeImportValue, 2, true);
}
void Genesis::InitializeGlobal_harmony_array_find_last() {
if (!FLAG_harmony_array_find_last) return;
......
......@@ -367,6 +367,7 @@
V(_, set_string, "set") \
V(_, SetIterator_string, "Set Iterator") \
V(_, setPrototypeOf_string, "setPrototypeOf") \
V(_, ShadowRealm_string, "ShadowRealm") \
V(_, SharedArrayBuffer_string, "SharedArrayBuffer") \
V(_, sign_string, "sign") \
V(_, smallestUnit_string, "smallestUnit") \
......
......@@ -47,6 +47,7 @@
#include "src/objects/js-proxy-inl.h"
#include "src/objects/js-regexp-inl.h"
#include "src/objects/js-regexp-string-iterator-inl.h"
#include "src/objects/js-shadow-realms-inl.h"
#include "src/objects/js-temporal-objects-inl.h"
#include "src/objects/js-weak-refs-inl.h"
#include "src/objects/literal-objects-inl.h"
......
......@@ -570,6 +570,7 @@ bool CanSubclassHaveInobjectProperties(InstanceType instance_type) {
case JS_PROMISE_TYPE:
case JS_REG_EXP_TYPE:
case JS_SET_TYPE:
case JS_SHADOW_REALM_TYPE:
case JS_SPECIAL_API_OBJECT_TYPE:
case JS_TYPED_ARRAY_TYPE:
case JS_PRIMITIVE_WRAPPER_TYPE:
......
......@@ -52,6 +52,7 @@
#include "src/objects/js-promise.h"
#include "src/objects/js-regexp-inl.h"
#include "src/objects/js-regexp-string-iterator.h"
#include "src/objects/js-shadow-realms.h"
#ifdef V8_INTL_SUPPORT
#include "src/objects/js-relative-time-format.h"
#include "src/objects/js-segment-iterator.h"
......@@ -2334,6 +2335,8 @@ int JSObject::GetHeaderSize(InstanceType type,
return JSObject::kHeaderSize;
case JS_ERROR_TYPE:
return JSObject::kHeaderSize;
case JS_SHADOW_REALM_TYPE:
return JSShadowRealm::kHeaderSize;
case JS_STRING_ITERATOR_TYPE:
return JSStringIterator::kHeaderSize;
case JS_MODULE_NAMESPACE_TYPE:
......
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_OBJECTS_JS_SHADOW_REALMS_INL_H_
#define V8_OBJECTS_JS_SHADOW_REALMS_INL_H_
#include "src/api/api-inl.h"
#include "src/heap/heap-write-barrier-inl.h"
#include "src/objects/js-shadow-realms.h"
#include "src/objects/smi-inl.h"
// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"
namespace v8 {
namespace internal {
#include "torque-generated/src/objects/js-shadow-realms-tq-inl.inc"
TQ_OBJECT_CONSTRUCTORS_IMPL(JSShadowRealm)
} // namespace internal
} // namespace v8
#include "src/objects/object-macros-undef.h"
#endif // V8_OBJECTS_JS_SHADOW_REALMS_INL_H_
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_OBJECTS_JS_SHADOW_REALMS_H_
#define V8_OBJECTS_JS_SHADOW_REALMS_H_
#include "src/objects/js-objects.h"
#include "torque-generated/bit-fields.h"
// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"
namespace v8 {
namespace internal {
class NativeContext;
#include "torque-generated/src/objects/js-shadow-realms-tq.inc"
// ShadowRealm object from the JS ShadowRealm spec proposal:
// https://github.com/tc39/proposal-shadowrealm
class JSShadowRealm
: public TorqueGeneratedJSShadowRealm<JSShadowRealm, JSObject> {
public:
DECL_PRINTER(JSShadowRealm)
EXPORT_DECL_VERIFIER(JSShadowRealm)
class BodyDescriptor;
TQ_OBJECT_CONSTRUCTORS(JSShadowRealm)
};
} // namespace internal
} // namespace v8
#include "src/objects/object-macros-undef.h"
#endif // V8_OBJECTS_JS_SHADOW_REALMS_H_
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
extern class JSShadowRealm extends JSObject { native_context: NativeContext; }
......@@ -272,6 +272,7 @@ VisitorId Map::GetVisitorId(Map map) {
case JS_SET_PROTOTYPE_TYPE:
case JS_SET_TYPE:
case JS_SET_VALUE_ITERATOR_TYPE:
case JS_SHADOW_REALM_TYPE:
case JS_STRING_ITERATOR_PROTOTYPE_TYPE:
case JS_STRING_ITERATOR_TYPE:
case JS_TEMPORAL_CALENDAR_TYPE:
......
......@@ -158,6 +158,7 @@ class ZoneForwardList;
V(JSRegExpStringIterator) \
V(JSSet) \
V(JSSetIterator) \
V(JSShadowRealm) \
V(JSSpecialObject) \
V(JSStringIterator) \
V(JSTemporalCalendar) \
......
......@@ -1153,6 +1153,7 @@ auto BodyDescriptorApply(InstanceType type, Args&&... args) {
case JS_SET_TYPE:
case JS_SET_VALUE_ITERATOR_TYPE:
case JS_SPECIAL_API_OBJECT_TYPE:
case JS_SHADOW_REALM_TYPE:
case JS_STRING_ITERATOR_PROTOTYPE_TYPE:
case JS_STRING_ITERATOR_TYPE:
case JS_TEMPORAL_CALENDAR_TYPE:
......
......@@ -64,6 +64,7 @@
// - JSMessageObject
// - JSRegExp
// - JSSetIterator
// - JSShadowRealm
// - JSStringIterator
// - JSTemporalCalendar
// - JSTemporalDuration
......
......@@ -26600,6 +26600,90 @@ TEST(ImportMetaThrowHandled) {
CHECK(!try_catch.HasCaught());
}
v8::MaybeLocal<v8::Context> HostCreateShadowRealmContextCallbackStatic(
v8::Local<v8::Context> initiator_context) {
CHECK(!initiator_context.IsEmpty());
return v8::Context::New(initiator_context->GetIsolate());
}
TEST(CreateShadowRealmContextHostNotSupported) {
i::FLAG_harmony_shadow_realm = true;
LocalContext context;
v8::Isolate* isolate = context->GetIsolate();
v8::HandleScope scope(isolate);
Local<String> url = v8_str("www.google.com");
Local<String> source_text = v8_str("new ShadowRealm()");
v8::ScriptOrigin origin(isolate, url, 0, 0, false, -1, Local<v8::Value>(),
false, false, false);
v8::ScriptCompiler::Source source(source_text, origin);
Local<Script> script =
v8::ScriptCompiler::Compile(context.local(), &source).ToLocalChecked();
v8::TryCatch try_catch(isolate);
v8::MaybeLocal<v8::Value> result = script->Run(context.local());
CHECK(try_catch.HasCaught());
CHECK(result.IsEmpty());
CHECK(v8_str("Error: Not supported")
->Equals(isolate->GetCurrentContext(),
try_catch.Exception()
->ToString(isolate->GetCurrentContext())
.ToLocalChecked())
.FromJust());
}
TEST(CreateShadowRealmContext) {
i::FLAG_harmony_shadow_realm = true;
LocalContext context;
v8::Isolate* isolate = context->GetIsolate();
v8::HandleScope scope(isolate);
isolate->SetHostCreateShadowRealmContextCallback(
HostCreateShadowRealmContextCallbackStatic);
Local<String> url = v8_str("www.google.com");
Local<String> source_text = v8_str("new ShadowRealm()");
v8::ScriptOrigin origin(isolate, url, 0, 0, false, -1, Local<v8::Value>(),
false, false, false);
v8::ScriptCompiler::Source source(source_text, origin);
Local<Script> script =
v8::ScriptCompiler::Compile(context.local(), &source).ToLocalChecked();
Local<Value> result = script->Run(context.local()).ToLocalChecked();
CHECK(result->IsObject());
i::Handle<i::Object> object = v8::Utils::OpenHandle(*result);
CHECK(object->IsJSShadowRealm());
}
v8::MaybeLocal<v8::Context> HostCreateShadowRealmContextCallbackThrow(
v8::Local<v8::Context> initiator_context) {
CcTest::isolate()->ThrowException(v8_num(42));
return v8::MaybeLocal<v8::Context>();
}
TEST(CreateShadowRealmContextThrow) {
i::FLAG_harmony_shadow_realm = true;
LocalContext context;
v8::Isolate* isolate = context->GetIsolate();
v8::HandleScope scope(isolate);
isolate->SetHostCreateShadowRealmContextCallback(
HostCreateShadowRealmContextCallbackThrow);
Local<String> url = v8_str("www.google.com");
Local<String> source_text = v8_str("new ShadowRealm()");
v8::ScriptOrigin origin(isolate, url, 0, 0, false, -1, Local<v8::Value>(),
false, false, false);
v8::ScriptCompiler::Source source(source_text, origin);
Local<Script> script =
v8::ScriptCompiler::Compile(context.local(), &source).ToLocalChecked();
v8::TryCatch try_catch(isolate);
CHECK(script->Run(context.local()).IsEmpty());
CHECK(try_catch.HasCaught());
CHECK(try_catch.Exception()->StrictEquals(v8_num(42)));
}
TEST(GetModuleNamespace) {
LocalContext context;
v8::Isolate* isolate = context->GetIsolate();
......@@ -2673,24 +2673,12 @@
# https://bugs.chromium.org/p/v8/issues/detail?id=11989
'built-ins/ShadowRealm/constructor': [FAIL],
'built-ins/ShadowRealm/descriptor': [FAIL],
'built-ins/ShadowRealm/extensibility': [FAIL],
'built-ins/ShadowRealm/instance': [FAIL],
'built-ins/ShadowRealm/instance-extensibility': [FAIL],
'built-ins/ShadowRealm/length': [FAIL],
'built-ins/ShadowRealm/name': [FAIL],
'built-ins/ShadowRealm/proto': [FAIL],
'built-ins/ShadowRealm/prototype/evaluate/descriptor': [FAIL],
'built-ins/ShadowRealm/prototype/evaluate/errors-from-the-other-realm-is-wrapped-into-a-typeerror': [FAIL],
'built-ins/ShadowRealm/prototype/evaluate/globalthis-available-properties': [FAIL],
'built-ins/ShadowRealm/prototype/evaluate/globalthis-config-only-properties': [FAIL],
'built-ins/ShadowRealm/prototype/evaluate/globalthis-orginary-object': [FAIL],
'built-ins/ShadowRealm/prototype/evaluate/length': [FAIL],
'built-ins/ShadowRealm/prototype/evaluate/name': [FAIL],
'built-ins/ShadowRealm/prototype/evaluate/no-conditional-strict-mode': [FAIL],
'built-ins/ShadowRealm/prototype/evaluate/not-constructor': [FAIL],
'built-ins/ShadowRealm/prototype/evaluate/proto': [FAIL],
'built-ins/ShadowRealm/prototype/evaluate/returns-primitive-values': [FAIL],
'built-ins/ShadowRealm/prototype/evaluate/returns-proxy-callable-object': [FAIL],
'built-ins/ShadowRealm/prototype/evaluate/returns-symbol-values': [FAIL],
......@@ -2717,20 +2705,13 @@
'built-ins/ShadowRealm/prototype/evaluate/wrapped-function-throws-typeerror-on-non-primitive-arguments': [FAIL],
'built-ins/ShadowRealm/prototype/evaluate/wrapped-function-throws-typeerror-on-non-primitive-returns': [FAIL],
'built-ins/ShadowRealm/prototype/evaluate/nested-realms': [FAIL],
'built-ins/ShadowRealm/prototype/importValue/descriptor': [FAIL],
'built-ins/ShadowRealm/prototype/importValue/exportName-tostring': [FAIL],
'built-ins/ShadowRealm/prototype/importValue/import-value': [FAIL],
'built-ins/ShadowRealm/prototype/importValue/length': [FAIL],
'built-ins/ShadowRealm/prototype/importValue/name': [FAIL],
'built-ins/ShadowRealm/prototype/importValue/not-constructor': [FAIL],
'built-ins/ShadowRealm/prototype/importValue/proto': [FAIL],
'built-ins/ShadowRealm/prototype/importValue/specifier-tostring': [FAIL],
'built-ins/ShadowRealm/prototype/importValue/throws-if-import-value-does-not-exist': [FAIL],
'built-ins/ShadowRealm/prototype/importValue/throws-typeerror-import-syntax-error': [FAIL],
'built-ins/ShadowRealm/prototype/importValue/throws-typeerror-import-throws': [FAIL],
'built-ins/ShadowRealm/prototype/importValue/validates-realm-object': [FAIL],
'built-ins/ShadowRealm/prototype/proto': [FAIL],
'built-ins/ShadowRealm/prototype/Symbol.toStringTag': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=12085
'language/statements/class/subclass/derived-class-return-override-catch-finally': [FAIL],
......
......@@ -61,6 +61,7 @@ FEATURE_FLAGS = {
'resizable-arraybuffer': '--harmony-rab-gsab',
'Temporal': '--harmony-temporal',
'array-find-from-last': '--harmony_array_find_last',
'ShadowRealm': '--harmony-shadow-realm',
}
SKIPPED_FEATURES = set([])
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment