Commit 03b99259 authored by Shu-yu Guo's avatar Shu-yu Guo Committed by V8 LUCI CQ

[shared-struct] Support shared objects in v8::Object::GetConstructorName

Bug: v8:12547
Change-Id: I6e48ac252361b3f3b495d2feaa5ad4e708e78eb9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3888379
Auto-Submit: Shu-yu Guo <syg@chromium.org>
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Commit-Queue: Adam Klein <adamk@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83118}
parent b11bfc21
...@@ -4736,11 +4736,16 @@ MaybeLocal<String> v8::Object::ObjectProtoToString(Local<Context> context) { ...@@ -4736,11 +4736,16 @@ MaybeLocal<String> v8::Object::ObjectProtoToString(Local<Context> context) {
} }
Local<String> v8::Object::GetConstructorName() { Local<String> v8::Object::GetConstructorName() {
// TODO(v8:12547): Consider adding GetConstructorName(Local<Context>).
auto self = Utils::OpenHandle(this); auto self = Utils::OpenHandle(this);
// TODO(v8:12547): Support shared objects. i::Isolate* i_isolate;
DCHECK(!self->InSharedHeap()); if (self->InSharedWritableHeap()) {
i_isolate = i::Isolate::Current();
} else {
i_isolate = self->GetIsolate();
}
i::Handle<i::String> name = i::Handle<i::String> name =
i::JSReceiver::GetConstructorName(self->GetIsolate(), self); i::JSReceiver::GetConstructorName(i_isolate, self);
return Utils::ToLocal(name); return Utils::ToLocal(name);
} }
......
...@@ -157,6 +157,8 @@ ...@@ -157,6 +157,8 @@
V(_, as_string, "as") \ V(_, as_string, "as") \
V(_, assert_string, "assert") \ V(_, assert_string, "assert") \
V(_, async_string, "async") \ V(_, async_string, "async") \
V(_, AtomicsCondition_string, "Atomics.Condition") \
V(_, AtomicsMutex_string, "Atomics.Mutex") \
V(_, auto_string, "auto") \ V(_, auto_string, "auto") \
V(_, await_string, "await") \ V(_, await_string, "await") \
V(_, BigInt_string, "BigInt") \ V(_, BigInt_string, "BigInt") \
...@@ -384,7 +386,9 @@ ...@@ -384,7 +386,9 @@
V(_, SetIterator_string, "Set Iterator") \ V(_, SetIterator_string, "Set Iterator") \
V(_, setPrototypeOf_string, "setPrototypeOf") \ V(_, setPrototypeOf_string, "setPrototypeOf") \
V(_, ShadowRealm_string, "ShadowRealm") \ V(_, ShadowRealm_string, "ShadowRealm") \
V(_, SharedArray_string, "SharedArray") \
V(_, SharedArrayBuffer_string, "SharedArrayBuffer") \ V(_, SharedArrayBuffer_string, "SharedArrayBuffer") \
V(_, SharedStruct_string, "SharedStruct") \
V(_, sign_string, "sign") \ V(_, sign_string, "sign") \
V(_, smallestUnit_string, "smallestUnit") \ V(_, smallestUnit_string, "smallestUnit") \
V(_, source_string, "source") \ V(_, source_string, "source") \
......
...@@ -544,6 +544,14 @@ String JSReceiver::class_name() { ...@@ -544,6 +544,14 @@ String JSReceiver::class_name() {
if (IsJSWeakMap()) return roots.WeakMap_string(); if (IsJSWeakMap()) return roots.WeakMap_string();
if (IsJSWeakSet()) return roots.WeakSet_string(); if (IsJSWeakSet()) return roots.WeakSet_string();
if (IsJSGlobalProxy()) return roots.global_string(); if (IsJSGlobalProxy()) return roots.global_string();
if (IsShared()) {
if (IsJSSharedStruct()) return roots.SharedStruct_string();
if (IsJSSharedArray()) return roots.SharedArray_string();
if (IsJSAtomicsMutex()) return roots.AtomicsMutex_string();
if (IsJSAtomicsCondition()) return roots.AtomicsCondition_string();
// Other shared values are primitives.
UNREACHABLE();
}
return roots.Object_string(); return roots.Object_string();
} }
......
...@@ -12879,6 +12879,22 @@ TEST(ObjectProtoToStringES6) { ...@@ -12879,6 +12879,22 @@ TEST(ObjectProtoToStringES6) {
} }
} }
namespace {
void CheckGetConstructorNameOfVar(LocalContext& context, const char* var_name,
const char* constructor_name) {
Local<v8::Value> var = context->Global()
->Get(context.local(), v8_str(var_name))
.ToLocalChecked();
CHECK(var->IsObject() &&
var->ToObject(context.local())
.ToLocalChecked()
->GetConstructorName()
->Equals(context.local(), v8_str(constructor_name))
.FromJust());
}
} // namespace
THREADED_TEST(ObjectGetConstructorName) { THREADED_TEST(ObjectGetConstructorName) {
v8::Isolate* isolate = CcTest::isolate(); v8::Isolate* isolate = CcTest::isolate();
...@@ -12897,41 +12913,10 @@ THREADED_TEST(ObjectGetConstructorName) { ...@@ -12897,41 +12913,10 @@ THREADED_TEST(ObjectGetConstructorName) {
->Run(context.local()) ->Run(context.local())
.ToLocalChecked(); .ToLocalChecked();
Local<v8::Value> p = CheckGetConstructorNameOfVar(context, "p", "Parent");
context->Global()->Get(context.local(), v8_str("p")).ToLocalChecked(); CheckGetConstructorNameOfVar(context, "c", "Child");
CHECK(p->IsObject() && CheckGetConstructorNameOfVar(context, "x", "outer.inner");
p->ToObject(context.local()) CheckGetConstructorNameOfVar(context, "proto", "Parent");
.ToLocalChecked()
->GetConstructorName()
->Equals(context.local(), v8_str("Parent"))
.FromJust());
Local<v8::Value> c =
context->Global()->Get(context.local(), v8_str("c")).ToLocalChecked();
CHECK(c->IsObject() &&
c->ToObject(context.local())
.ToLocalChecked()
->GetConstructorName()
->Equals(context.local(), v8_str("Child"))
.FromJust());
Local<v8::Value> x =
context->Global()->Get(context.local(), v8_str("x")).ToLocalChecked();
CHECK(x->IsObject() &&
x->ToObject(context.local())
.ToLocalChecked()
->GetConstructorName()
->Equals(context.local(), v8_str("outer.inner"))
.FromJust());
Local<v8::Value> child_prototype =
context->Global()->Get(context.local(), v8_str("proto")).ToLocalChecked();
CHECK(child_prototype->IsObject() &&
child_prototype->ToObject(context.local())
.ToLocalChecked()
->GetConstructorName()
->Equals(context.local(), v8_str("Parent"))
.FromJust());
} }
...@@ -12948,25 +12933,37 @@ THREADED_TEST(SubclassGetConstructorName) { ...@@ -12948,25 +12933,37 @@ THREADED_TEST(SubclassGetConstructorName) {
->Run(context.local()) ->Run(context.local())
.ToLocalChecked(); .ToLocalChecked();
Local<v8::Value> p = CheckGetConstructorNameOfVar(context, "p", "Parent");
context->Global()->Get(context.local(), v8_str("p")).ToLocalChecked(); CheckGetConstructorNameOfVar(context, "c", "Child");
CHECK(p->IsObject() &&
p->ToObject(context.local())
.ToLocalChecked()
->GetConstructorName()
->Equals(context.local(), v8_str("Parent"))
.FromJust());
Local<v8::Value> c =
context->Global()->Get(context.local(), v8_str("c")).ToLocalChecked();
CHECK(c->IsObject() &&
c->ToObject(context.local())
.ToLocalChecked()
->GetConstructorName()
->Equals(context.local(), v8_str("Child"))
.FromJust());
} }
UNINITIALIZED_TEST(SharedObjectGetConstructorName) {
i::FLAG_shared_string_table = true;
i::FLAG_harmony_struct = true;
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
v8::Isolate* isolate = v8::Isolate::New(create_params);
{
v8::Isolate::Scope i_scope(isolate);
v8::HandleScope scope(isolate);
LocalContext context(isolate);
v8_compile(
"var s = new (new SharedStructType(['foo']));"
"var a = new SharedArray(1);"
"var m = new Atomics.Mutex;"
"var c = new Atomics.Condition;")
->Run(context.local())
.ToLocalChecked();
CheckGetConstructorNameOfVar(context, "s", "SharedStruct");
CheckGetConstructorNameOfVar(context, "a", "SharedArray");
CheckGetConstructorNameOfVar(context, "m", "Atomics.Mutex");
CheckGetConstructorNameOfVar(context, "c", "Atomics.Condition");
}
isolate->Dispose();
}
bool ApiTestFuzzer::fuzzing_ = false; bool ApiTestFuzzer::fuzzing_ = false;
v8::base::Semaphore ApiTestFuzzer::all_tests_done_(0); v8::base::Semaphore ApiTestFuzzer::all_tests_done_(0);
...@@ -393,76 +393,76 @@ KNOWN_MAPS = { ...@@ -393,76 +393,76 @@ KNOWN_MAPS = {
("read_only_space", 0x03491): (131, "BasicBlockCountersMarkerMap"), ("read_only_space", 0x03491): (131, "BasicBlockCountersMarkerMap"),
("read_only_space", 0x034d5): (146, "ArrayBoilerplateDescriptionMap"), ("read_only_space", 0x034d5): (146, "ArrayBoilerplateDescriptionMap"),
("read_only_space", 0x035d5): (159, "InterceptorInfoMap"), ("read_only_space", 0x035d5): (159, "InterceptorInfoMap"),
("read_only_space", 0x073e9): (132, "PromiseFulfillReactionJobTaskMap"), ("read_only_space", 0x07455): (132, "PromiseFulfillReactionJobTaskMap"),
("read_only_space", 0x07411): (133, "PromiseRejectReactionJobTaskMap"), ("read_only_space", 0x0747d): (133, "PromiseRejectReactionJobTaskMap"),
("read_only_space", 0x07439): (134, "CallableTaskMap"), ("read_only_space", 0x074a5): (134, "CallableTaskMap"),
("read_only_space", 0x07461): (135, "CallbackTaskMap"), ("read_only_space", 0x074cd): (135, "CallbackTaskMap"),
("read_only_space", 0x07489): (136, "PromiseResolveThenableJobTaskMap"), ("read_only_space", 0x074f5): (136, "PromiseResolveThenableJobTaskMap"),
("read_only_space", 0x074b1): (139, "FunctionTemplateInfoMap"), ("read_only_space", 0x0751d): (139, "FunctionTemplateInfoMap"),
("read_only_space", 0x074d9): (140, "ObjectTemplateInfoMap"), ("read_only_space", 0x07545): (140, "ObjectTemplateInfoMap"),
("read_only_space", 0x07501): (141, "AccessCheckInfoMap"), ("read_only_space", 0x0756d): (141, "AccessCheckInfoMap"),
("read_only_space", 0x07529): (142, "AccessorPairMap"), ("read_only_space", 0x07595): (142, "AccessorPairMap"),
("read_only_space", 0x07551): (143, "AliasedArgumentsEntryMap"), ("read_only_space", 0x075bd): (143, "AliasedArgumentsEntryMap"),
("read_only_space", 0x07579): (144, "AllocationMementoMap"), ("read_only_space", 0x075e5): (144, "AllocationMementoMap"),
("read_only_space", 0x075a1): (147, "AsmWasmDataMap"), ("read_only_space", 0x0760d): (147, "AsmWasmDataMap"),
("read_only_space", 0x075c9): (148, "AsyncGeneratorRequestMap"), ("read_only_space", 0x07635): (148, "AsyncGeneratorRequestMap"),
("read_only_space", 0x075f1): (149, "BreakPointMap"), ("read_only_space", 0x0765d): (149, "BreakPointMap"),
("read_only_space", 0x07619): (150, "BreakPointInfoMap"), ("read_only_space", 0x07685): (150, "BreakPointInfoMap"),
("read_only_space", 0x07641): (151, "CachedTemplateObjectMap"), ("read_only_space", 0x076ad): (151, "CachedTemplateObjectMap"),
("read_only_space", 0x07669): (152, "CallSiteInfoMap"), ("read_only_space", 0x076d5): (152, "CallSiteInfoMap"),
("read_only_space", 0x07691): (153, "ClassPositionsMap"), ("read_only_space", 0x076fd): (153, "ClassPositionsMap"),
("read_only_space", 0x076b9): (154, "DebugInfoMap"), ("read_only_space", 0x07725): (154, "DebugInfoMap"),
("read_only_space", 0x076e1): (156, "ErrorStackDataMap"), ("read_only_space", 0x0774d): (156, "ErrorStackDataMap"),
("read_only_space", 0x07709): (158, "FunctionTemplateRareDataMap"), ("read_only_space", 0x07775): (158, "FunctionTemplateRareDataMap"),
("read_only_space", 0x07731): (160, "InterpreterDataMap"), ("read_only_space", 0x0779d): (160, "InterpreterDataMap"),
("read_only_space", 0x07759): (161, "ModuleRequestMap"), ("read_only_space", 0x077c5): (161, "ModuleRequestMap"),
("read_only_space", 0x07781): (162, "PromiseCapabilityMap"), ("read_only_space", 0x077ed): (162, "PromiseCapabilityMap"),
("read_only_space", 0x077a9): (163, "PromiseOnStackMap"), ("read_only_space", 0x07815): (163, "PromiseOnStackMap"),
("read_only_space", 0x077d1): (164, "PromiseReactionMap"), ("read_only_space", 0x0783d): (164, "PromiseReactionMap"),
("read_only_space", 0x077f9): (165, "PropertyDescriptorObjectMap"), ("read_only_space", 0x07865): (165, "PropertyDescriptorObjectMap"),
("read_only_space", 0x07821): (166, "PrototypeInfoMap"), ("read_only_space", 0x0788d): (166, "PrototypeInfoMap"),
("read_only_space", 0x07849): (167, "RegExpBoilerplateDescriptionMap"), ("read_only_space", 0x078b5): (167, "RegExpBoilerplateDescriptionMap"),
("read_only_space", 0x07871): (168, "ScriptMap"), ("read_only_space", 0x078dd): (168, "ScriptMap"),
("read_only_space", 0x07899): (169, "ScriptOrModuleMap"), ("read_only_space", 0x07905): (169, "ScriptOrModuleMap"),
("read_only_space", 0x078c1): (170, "SourceTextModuleInfoEntryMap"), ("read_only_space", 0x0792d): (170, "SourceTextModuleInfoEntryMap"),
("read_only_space", 0x078e9): (171, "StackFrameInfoMap"), ("read_only_space", 0x07955): (171, "StackFrameInfoMap"),
("read_only_space", 0x07911): (172, "TemplateObjectDescriptionMap"), ("read_only_space", 0x0797d): (172, "TemplateObjectDescriptionMap"),
("read_only_space", 0x07939): (173, "Tuple2Map"), ("read_only_space", 0x079a5): (173, "Tuple2Map"),
("read_only_space", 0x07961): (174, "WasmExceptionTagMap"), ("read_only_space", 0x079cd): (174, "WasmExceptionTagMap"),
("read_only_space", 0x07989): (175, "WasmIndirectFunctionTableMap"), ("read_only_space", 0x079f5): (175, "WasmIndirectFunctionTableMap"),
("read_only_space", 0x079b1): (195, "SloppyArgumentsElementsMap"), ("read_only_space", 0x07a1d): (195, "SloppyArgumentsElementsMap"),
("read_only_space", 0x079d9): (228, "DescriptorArrayMap"), ("read_only_space", 0x07a45): (228, "DescriptorArrayMap"),
("read_only_space", 0x07a01): (217, "UncompiledDataWithoutPreparseDataMap"), ("read_only_space", 0x07a6d): (217, "UncompiledDataWithoutPreparseDataMap"),
("read_only_space", 0x07a29): (215, "UncompiledDataWithPreparseDataMap"), ("read_only_space", 0x07a95): (215, "UncompiledDataWithPreparseDataMap"),
("read_only_space", 0x07a51): (218, "UncompiledDataWithoutPreparseDataWithJobMap"), ("read_only_space", 0x07abd): (218, "UncompiledDataWithoutPreparseDataWithJobMap"),
("read_only_space", 0x07a79): (216, "UncompiledDataWithPreparseDataAndJobMap"), ("read_only_space", 0x07ae5): (216, "UncompiledDataWithPreparseDataAndJobMap"),
("read_only_space", 0x07aa1): (249, "OnHeapBasicBlockProfilerDataMap"), ("read_only_space", 0x07b0d): (249, "OnHeapBasicBlockProfilerDataMap"),
("read_only_space", 0x07ac9): (196, "TurbofanBitsetTypeMap"), ("read_only_space", 0x07b35): (196, "TurbofanBitsetTypeMap"),
("read_only_space", 0x07af1): (200, "TurbofanUnionTypeMap"), ("read_only_space", 0x07b5d): (200, "TurbofanUnionTypeMap"),
("read_only_space", 0x07b19): (199, "TurbofanRangeTypeMap"), ("read_only_space", 0x07b85): (199, "TurbofanRangeTypeMap"),
("read_only_space", 0x07b41): (197, "TurbofanHeapConstantTypeMap"), ("read_only_space", 0x07bad): (197, "TurbofanHeapConstantTypeMap"),
("read_only_space", 0x07b69): (198, "TurbofanOtherNumberConstantTypeMap"), ("read_only_space", 0x07bd5): (198, "TurbofanOtherNumberConstantTypeMap"),
("read_only_space", 0x07b91): (245, "InternalClassMap"), ("read_only_space", 0x07bfd): (245, "InternalClassMap"),
("read_only_space", 0x07bb9): (256, "SmiPairMap"), ("read_only_space", 0x07c25): (256, "SmiPairMap"),
("read_only_space", 0x07be1): (255, "SmiBoxMap"), ("read_only_space", 0x07c4d): (255, "SmiBoxMap"),
("read_only_space", 0x07c09): (201, "ExportedSubClassBaseMap"), ("read_only_space", 0x07c75): (201, "ExportedSubClassBaseMap"),
("read_only_space", 0x07c31): (202, "ExportedSubClassMap"), ("read_only_space", 0x07c9d): (202, "ExportedSubClassMap"),
("read_only_space", 0x07c59): (226, "AbstractInternalClassSubclass1Map"), ("read_only_space", 0x07cc5): (226, "AbstractInternalClassSubclass1Map"),
("read_only_space", 0x07c81): (227, "AbstractInternalClassSubclass2Map"), ("read_only_space", 0x07ced): (227, "AbstractInternalClassSubclass2Map"),
("read_only_space", 0x07ca9): (194, "InternalClassWithSmiElementsMap"), ("read_only_space", 0x07d15): (194, "InternalClassWithSmiElementsMap"),
("read_only_space", 0x07cd1): (246, "InternalClassWithStructElementsMap"), ("read_only_space", 0x07d3d): (246, "InternalClassWithStructElementsMap"),
("read_only_space", 0x07cf9): (203, "ExportedSubClass2Map"), ("read_only_space", 0x07d65): (203, "ExportedSubClass2Map"),
("read_only_space", 0x07d21): (257, "SortStateMap"), ("read_only_space", 0x07d8d): (257, "SortStateMap"),
("read_only_space", 0x07d49): (263, "WasmStringViewIterMap"), ("read_only_space", 0x07db5): (263, "WasmStringViewIterMap"),
("read_only_space", 0x07d71): (145, "AllocationSiteWithWeakNextMap"), ("read_only_space", 0x07ddd): (145, "AllocationSiteWithWeakNextMap"),
("read_only_space", 0x07d99): (145, "AllocationSiteWithoutWeakNextMap"), ("read_only_space", 0x07e05): (145, "AllocationSiteWithoutWeakNextMap"),
("read_only_space", 0x07e65): (137, "LoadHandler1Map"), ("read_only_space", 0x07ed1): (137, "LoadHandler1Map"),
("read_only_space", 0x07e8d): (137, "LoadHandler2Map"), ("read_only_space", 0x07ef9): (137, "LoadHandler2Map"),
("read_only_space", 0x07eb5): (137, "LoadHandler3Map"), ("read_only_space", 0x07f21): (137, "LoadHandler3Map"),
("read_only_space", 0x07edd): (138, "StoreHandler0Map"), ("read_only_space", 0x07f49): (138, "StoreHandler0Map"),
("read_only_space", 0x07f05): (138, "StoreHandler1Map"), ("read_only_space", 0x07f71): (138, "StoreHandler1Map"),
("read_only_space", 0x07f2d): (138, "StoreHandler2Map"), ("read_only_space", 0x07f99): (138, "StoreHandler2Map"),
("read_only_space", 0x07f55): (138, "StoreHandler3Map"), ("read_only_space", 0x07fc1): (138, "StoreHandler3Map"),
("map_space", 0x02139): (2115, "ExternalMap"), ("map_space", 0x02139): (2115, "ExternalMap"),
("map_space", 0x02161): (2119, "JSMessageObjectMap"), ("map_space", 0x02161): (2119, "JSMessageObjectMap"),
} }
......
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