Commit 104b574b authored by Shu-yu Guo's avatar Shu-yu Guo Committed by Commit Bot

[weakrefs] Fix creation of WeakRef and FinalizationRegistry constructors

Use the InstallFunction helper to create the initial map and prototypes
instead of manually doing so. WeakRef is currently creating an unused
Map tied to JS_WEAK_REF_TYPE that would cause the various LogMaps
cctests to fail when the feature ships.

Bug: v8:8179
Change-Id: Ic1b35ebe5da722fa030af336099fff6153b4baed
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2158488
Commit-Queue: Shu-yu Guo <syg@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67294}
parent de6ef577
......@@ -4275,17 +4275,11 @@ void Genesis::InitializeGlobal_harmony_weak_refs() {
Handle<JSGlobalObject> global(native_context()->global_object(), isolate());
{
// Create %FinalizationRegistryPrototype%
Handle<String> finalization_registry_name =
factory->NewStringFromStaticChars("FinalizationRegistry");
Handle<JSObject> finalization_registry_prototype = factory->NewJSObject(
isolate()->object_function(), AllocationType::kOld);
// Create %FinalizationRegistry%
Handle<JSFunction> finalization_registry_fun = CreateFunction(
isolate(), finalization_registry_name, JS_FINALIZATION_REGISTRY_TYPE,
JSFinalizationRegistry::kHeaderSize, 0, finalization_registry_prototype,
Builtins::kFinalizationRegistryConstructor);
Handle<JSFunction> finalization_registry_fun = InstallFunction(
isolate(), global, factory->FinalizationRegistry_string(),
JS_FINALIZATION_REGISTRY_TYPE, JSFinalizationRegistry::kHeaderSize, 0,
factory->the_hole_value(), Builtins::kFinalizationRegistryConstructor);
InstallWithIntrinsicDefaultProto(
isolate(), finalization_registry_fun,
Context::JS_FINALIZATION_REGISTRY_FUNCTION_INDEX);
......@@ -4293,16 +4287,12 @@ void Genesis::InitializeGlobal_harmony_weak_refs() {
finalization_registry_fun->shared().DontAdaptArguments();
finalization_registry_fun->shared().set_length(1);
// Install the "constructor" property on the prototype.
JSObject::AddProperty(isolate(), finalization_registry_prototype,
factory->constructor_string(),
finalization_registry_fun, DONT_ENUM);
Handle<JSObject> finalization_registry_prototype(
JSObject::cast(finalization_registry_fun->instance_prototype()),
isolate());
InstallToStringTag(isolate(), finalization_registry_prototype,
finalization_registry_name);
JSObject::AddProperty(isolate(), global, finalization_registry_name,
finalization_registry_fun, DONT_ENUM);
factory->FinalizationRegistry_string());
SimpleInstallFunction(isolate(), finalization_registry_prototype,
"register", Builtins::kFinalizationRegistryRegister,
......@@ -4322,39 +4312,25 @@ void Genesis::InitializeGlobal_harmony_weak_refs() {
native_context()->set_finalization_registry_cleanup_some(*cleanup_some_fun);
}
{
// Create %WeakRefPrototype%
Handle<Map> weak_ref_map =
factory->NewMap(JS_WEAK_REF_TYPE, JSWeakRef::kHeaderSize);
DCHECK(weak_ref_map->IsJSObjectMap());
Handle<JSObject> weak_ref_prototype = factory->NewJSObject(
isolate()->object_function(), AllocationType::kOld);
Map::SetPrototype(isolate(), weak_ref_map, weak_ref_prototype);
InstallToStringTag(isolate(), weak_ref_prototype,
factory->WeakRef_string());
SimpleInstallFunction(isolate(), weak_ref_prototype, "deref",
Builtins::kWeakRefDeref, 0, false);
// Create %WeakRef%
Handle<String> weak_ref_name = factory->InternalizeUtf8String("WeakRef");
Handle<JSFunction> weak_ref_fun = CreateFunction(
isolate(), weak_ref_name, JS_WEAK_REF_TYPE, JSWeakRef::kHeaderSize, 0,
weak_ref_prototype, Builtins::kWeakRefConstructor);
Handle<JSFunction> weak_ref_fun = InstallFunction(
isolate(), global, factory->WeakRef_string(), JS_WEAK_REF_TYPE,
JSWeakRef::kHeaderSize, 0, factory->the_hole_value(),
Builtins::kWeakRefConstructor);
InstallWithIntrinsicDefaultProto(isolate(), weak_ref_fun,
Context::JS_WEAK_REF_FUNCTION_INDEX);
weak_ref_fun->shared().DontAdaptArguments();
weak_ref_fun->shared().set_length(1);
// Install the "constructor" property on the prototype.
JSObject::AddProperty(isolate(), weak_ref_prototype,
factory->constructor_string(), weak_ref_fun,
DONT_ENUM);
Handle<JSObject> weak_ref_prototype(
JSObject::cast(weak_ref_fun->instance_prototype()), isolate());
JSObject::AddProperty(isolate(), global, weak_ref_name, weak_ref_fun,
DONT_ENUM);
InstallToStringTag(isolate(), weak_ref_prototype,
factory->WeakRef_string());
SimpleInstallFunction(isolate(), weak_ref_prototype, "deref",
Builtins::kWeakRefDeref, 0, false);
}
}
......
......@@ -186,6 +186,7 @@
V(_, EvalError_string, "EvalError") \
V(_, exec_string, "exec") \
V(_, false_string, "false") \
V(_, FinalizationRegistry_string, "FinalizationRegistry") \
V(_, flags_string, "flags") \
V(_, Float32Array_string, "Float32Array") \
V(_, Float64Array_string, "Float64Array") \
......
......@@ -291,61 +291,61 @@ KNOWN_MAPS = {
("read_only_space", 0x01179): (95, "EnumCacheMap"),
("read_only_space", 0x011c9): (86, "ArrayBoilerplateDescriptionMap"),
("read_only_space", 0x012c5): (98, "InterceptorInfoMap"),
("read_only_space", 0x03315): (71, "PromiseFulfillReactionJobTaskMap"),
("read_only_space", 0x0333d): (72, "PromiseRejectReactionJobTaskMap"),
("read_only_space", 0x03365): (73, "CallableTaskMap"),
("read_only_space", 0x0338d): (74, "CallbackTaskMap"),
("read_only_space", 0x033b5): (75, "PromiseResolveThenableJobTaskMap"),
("read_only_space", 0x033dd): (78, "FunctionTemplateInfoMap"),
("read_only_space", 0x03405): (79, "ObjectTemplateInfoMap"),
("read_only_space", 0x0342d): (80, "AccessCheckInfoMap"),
("read_only_space", 0x03455): (81, "AccessorInfoMap"),
("read_only_space", 0x0347d): (82, "AccessorPairMap"),
("read_only_space", 0x034a5): (83, "AliasedArgumentsEntryMap"),
("read_only_space", 0x034cd): (84, "AllocationMementoMap"),
("read_only_space", 0x034f5): (87, "AsmWasmDataMap"),
("read_only_space", 0x0351d): (88, "AsyncGeneratorRequestMap"),
("read_only_space", 0x03545): (89, "BreakPointMap"),
("read_only_space", 0x0356d): (90, "BreakPointInfoMap"),
("read_only_space", 0x03595): (91, "CachedTemplateObjectMap"),
("read_only_space", 0x035bd): (93, "ClassPositionsMap"),
("read_only_space", 0x035e5): (94, "DebugInfoMap"),
("read_only_space", 0x0360d): (97, "FunctionTemplateRareDataMap"),
("read_only_space", 0x03635): (99, "InterpreterDataMap"),
("read_only_space", 0x0365d): (100, "PromiseCapabilityMap"),
("read_only_space", 0x03685): (101, "PromiseReactionMap"),
("read_only_space", 0x036ad): (102, "PropertyDescriptorObjectMap"),
("read_only_space", 0x036d5): (103, "PrototypeInfoMap"),
("read_only_space", 0x036fd): (104, "ScriptMap"),
("read_only_space", 0x03725): (105, "SourceTextModuleInfoEntryMap"),
("read_only_space", 0x0374d): (106, "StackFrameInfoMap"),
("read_only_space", 0x03775): (107, "StackTraceFrameMap"),
("read_only_space", 0x0379d): (108, "TemplateObjectDescriptionMap"),
("read_only_space", 0x037c5): (109, "Tuple2Map"),
("read_only_space", 0x037ed): (110, "WasmCapiFunctionDataMap"),
("read_only_space", 0x03815): (111, "WasmDebugInfoMap"),
("read_only_space", 0x0383d): (112, "WasmExceptionTagMap"),
("read_only_space", 0x03865): (113, "WasmExportedFunctionDataMap"),
("read_only_space", 0x0388d): (114, "WasmIndirectFunctionTableMap"),
("read_only_space", 0x038b5): (115, "WasmJSFunctionDataMap"),
("read_only_space", 0x038dd): (116, "WasmValueMap"),
("read_only_space", 0x03905): (165, "InternalClassMap"),
("read_only_space", 0x0392d): (173, "SmiPairMap"),
("read_only_space", 0x03955): (172, "SmiBoxMap"),
("read_only_space", 0x0397d): (68, "ExportedSubClassBaseMap"),
("read_only_space", 0x039a5): (69, "ExportedSubClassMap"),
("read_only_space", 0x039cd): (135, "InternalClassWithSmiElementsMap"),
("read_only_space", 0x039f5): (166, "InternalClassWithStructElementsMap"),
("read_only_space", 0x03a1d): (174, "SortStateMap"),
("read_only_space", 0x03a45): (85, "AllocationSiteWithWeakNextMap"),
("read_only_space", 0x03a6d): (85, "AllocationSiteWithoutWeakNextMap"),
("read_only_space", 0x03a95): (76, "LoadHandler1Map"),
("read_only_space", 0x03abd): (76, "LoadHandler2Map"),
("read_only_space", 0x03ae5): (76, "LoadHandler3Map"),
("read_only_space", 0x03b0d): (77, "StoreHandler0Map"),
("read_only_space", 0x03b35): (77, "StoreHandler1Map"),
("read_only_space", 0x03b5d): (77, "StoreHandler2Map"),
("read_only_space", 0x03b85): (77, "StoreHandler3Map"),
("read_only_space", 0x03335): (71, "PromiseFulfillReactionJobTaskMap"),
("read_only_space", 0x0335d): (72, "PromiseRejectReactionJobTaskMap"),
("read_only_space", 0x03385): (73, "CallableTaskMap"),
("read_only_space", 0x033ad): (74, "CallbackTaskMap"),
("read_only_space", 0x033d5): (75, "PromiseResolveThenableJobTaskMap"),
("read_only_space", 0x033fd): (78, "FunctionTemplateInfoMap"),
("read_only_space", 0x03425): (79, "ObjectTemplateInfoMap"),
("read_only_space", 0x0344d): (80, "AccessCheckInfoMap"),
("read_only_space", 0x03475): (81, "AccessorInfoMap"),
("read_only_space", 0x0349d): (82, "AccessorPairMap"),
("read_only_space", 0x034c5): (83, "AliasedArgumentsEntryMap"),
("read_only_space", 0x034ed): (84, "AllocationMementoMap"),
("read_only_space", 0x03515): (87, "AsmWasmDataMap"),
("read_only_space", 0x0353d): (88, "AsyncGeneratorRequestMap"),
("read_only_space", 0x03565): (89, "BreakPointMap"),
("read_only_space", 0x0358d): (90, "BreakPointInfoMap"),
("read_only_space", 0x035b5): (91, "CachedTemplateObjectMap"),
("read_only_space", 0x035dd): (93, "ClassPositionsMap"),
("read_only_space", 0x03605): (94, "DebugInfoMap"),
("read_only_space", 0x0362d): (97, "FunctionTemplateRareDataMap"),
("read_only_space", 0x03655): (99, "InterpreterDataMap"),
("read_only_space", 0x0367d): (100, "PromiseCapabilityMap"),
("read_only_space", 0x036a5): (101, "PromiseReactionMap"),
("read_only_space", 0x036cd): (102, "PropertyDescriptorObjectMap"),
("read_only_space", 0x036f5): (103, "PrototypeInfoMap"),
("read_only_space", 0x0371d): (104, "ScriptMap"),
("read_only_space", 0x03745): (105, "SourceTextModuleInfoEntryMap"),
("read_only_space", 0x0376d): (106, "StackFrameInfoMap"),
("read_only_space", 0x03795): (107, "StackTraceFrameMap"),
("read_only_space", 0x037bd): (108, "TemplateObjectDescriptionMap"),
("read_only_space", 0x037e5): (109, "Tuple2Map"),
("read_only_space", 0x0380d): (110, "WasmCapiFunctionDataMap"),
("read_only_space", 0x03835): (111, "WasmDebugInfoMap"),
("read_only_space", 0x0385d): (112, "WasmExceptionTagMap"),
("read_only_space", 0x03885): (113, "WasmExportedFunctionDataMap"),
("read_only_space", 0x038ad): (114, "WasmIndirectFunctionTableMap"),
("read_only_space", 0x038d5): (115, "WasmJSFunctionDataMap"),
("read_only_space", 0x038fd): (116, "WasmValueMap"),
("read_only_space", 0x03925): (165, "InternalClassMap"),
("read_only_space", 0x0394d): (173, "SmiPairMap"),
("read_only_space", 0x03975): (172, "SmiBoxMap"),
("read_only_space", 0x0399d): (68, "ExportedSubClassBaseMap"),
("read_only_space", 0x039c5): (69, "ExportedSubClassMap"),
("read_only_space", 0x039ed): (135, "InternalClassWithSmiElementsMap"),
("read_only_space", 0x03a15): (166, "InternalClassWithStructElementsMap"),
("read_only_space", 0x03a3d): (174, "SortStateMap"),
("read_only_space", 0x03a65): (85, "AllocationSiteWithWeakNextMap"),
("read_only_space", 0x03a8d): (85, "AllocationSiteWithoutWeakNextMap"),
("read_only_space", 0x03ab5): (76, "LoadHandler1Map"),
("read_only_space", 0x03add): (76, "LoadHandler2Map"),
("read_only_space", 0x03b05): (76, "LoadHandler3Map"),
("read_only_space", 0x03b2d): (77, "StoreHandler0Map"),
("read_only_space", 0x03b55): (77, "StoreHandler1Map"),
("read_only_space", 0x03b7d): (77, "StoreHandler2Map"),
("read_only_space", 0x03ba5): (77, "StoreHandler3Map"),
("map_space", 0x00121): (1057, "ExternalMap"),
("map_space", 0x00149): (1073, "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