Commit a9b6f3f7 authored by Benedikt Meurer's avatar Benedikt Meurer Committed by Commit Bot

[inspector][stack-traces] Remove support for "displayName".

As outlined in the design document linked below, we're removing the
support for the non-standard Function.displayName property for the
purpose of Error.stack and DevTools Inspector stack traces. The
motivation here is that the negative lookup is costly, and we have
Function.name as a standard alternative (configurable since ES6 for
exactly this reason).

I dediced to go with JSFunction::GetDebugName(), since
JSFunction::GetName() was confusing in that it'd only get the "name"
property's value if it's a data property, but not with accessors.
JSFunction::GetDebugName() makes it clear that this is really a debug
helper function and might not give you the "name" property value.

Doc: https://bit.ly/devtools-function-displayName-removal
Bug: v8:8742, chromium:1177685, chromium:1077657, chromium:17356
Change-Id: I7717585cbace626174b2f2ed2a4f68f75429eca1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2692189
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72715}
parent 695a4490
......@@ -4927,7 +4927,7 @@ Local<Value> Function::GetDisplayName() const {
}
auto func = i::Handle<i::JSFunction>::cast(self);
i::Handle<i::String> property_name =
isolate->factory()->display_name_string();
isolate->factory()->InternalizeString(i::StaticCharVector("displayName"));
i::Handle<i::Object> value =
i::JSReceiver::GetDataProperty(func, property_name);
if (value->IsString()) {
......
......@@ -168,7 +168,6 @@
V(_, defineProperty_string, "defineProperty") \
V(_, deleteProperty_string, "deleteProperty") \
V(_, disjunction_string, "disjunction") \
V(_, display_name_string, "displayName") \
V(_, done_string, "done") \
V(_, dot_brand_string, ".brand") \
V(_, dot_catch_string, ".catch") \
......
......@@ -812,7 +812,7 @@ void JSFunction::PrintName(FILE* out) {
PrintF(out, "%s", shared().DebugNameCStr().get());
}
Handle<String> JSFunction::GetName(Handle<JSFunction> function) {
Handle<String> JSFunction::GetDebugName(Handle<JSFunction> function) {
Isolate* isolate = function->GetIsolate();
Handle<Object> name =
JSReceiver::GetDataProperty(function, isolate->factory()->name_string());
......@@ -820,14 +820,6 @@ Handle<String> JSFunction::GetName(Handle<JSFunction> function) {
return SharedFunctionInfo::DebugName(handle(function->shared(), isolate));
}
Handle<String> JSFunction::GetDebugName(Handle<JSFunction> function) {
Isolate* isolate = function->GetIsolate();
Handle<Object> name = JSReceiver::GetDataProperty(
function, isolate->factory()->display_name_string());
if (name->IsString()) return Handle<String>::cast(name);
return JSFunction::GetName(function);
}
bool JSFunction::SetName(Handle<JSFunction> function, Handle<Name> name,
Handle<String> prefix) {
Isolate* isolate = function->GetIsolate();
......
......@@ -265,8 +265,6 @@ class JSFunction : public JSFunctionOrBoundFunction {
DECL_PRINTER(JSFunction)
DECL_VERIFIER(JSFunction)
// The function's name if it is configured, otherwise shared function info
// debug name.
static Handle<String> GetName(Handle<JSFunction> function);
// ES6 section 9.2.11 SetFunctionName
......@@ -277,8 +275,7 @@ class JSFunction : public JSFunctionOrBoundFunction {
Handle<Name> name,
Handle<String> prefix);
// The function's displayName if it is set, otherwise name if it is
// configured, otherwise shared function info
// The function's name if it is configured, otherwise shared function info
// debug name.
static Handle<String> GetDebugName(Handle<JSFunction> function);
......
......@@ -2009,7 +2009,7 @@ Handle<WasmJSFunction> WasmJSFunction::New(Isolate* isolate,
Handle<String> name = factory->Function_string();
if (callable->IsJSFunction()) {
name = JSFunction::GetName(Handle<JSFunction>::cast(callable));
name = JSFunction::GetDebugName(Handle<JSFunction>::cast(callable));
name = String::Flatten(isolate, name);
}
Handle<Map> function_map =
......
......@@ -209,10 +209,8 @@ static void AnalyzeStackInNativeCode(
const int kOverviewTest = 1;
const int kDetailedTest = 2;
const int kFunctionName = 3;
const int kDisplayName = 4;
const int kFunctionNameAndDisplayName = 5;
const int kDisplayNameIsNotString = 6;
const int kFunctionNameIsNotString = 7;
const int kFunctionNameAndDisplayName = 4;
const int kFunctionNameIsNotString = 5;
CHECK_EQ(args.Length(), 1);
......@@ -254,19 +252,7 @@ static void AnalyzeStackInNativeCode(
CHECK_EQ(3, stackTrace->GetFrameCount());
checkStackFrame(nullptr, "function.name", 3, 1, true, false,
stackTrace->GetFrame(isolate, 0));
} else if (testGroup == kDisplayName) {
v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(
args.GetIsolate(), 5, v8::StackTrace::kOverview);
CHECK_EQ(3, stackTrace->GetFrameCount());
checkStackFrame(nullptr, "function.displayName", 3, 1, true, false,
stackTrace->GetFrame(isolate, 0));
} else if (testGroup == kFunctionNameAndDisplayName) {
v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(
args.GetIsolate(), 5, v8::StackTrace::kOverview);
CHECK_EQ(3, stackTrace->GetFrameCount());
checkStackFrame(nullptr, "function.displayName", 3, 1, true, false,
stackTrace->GetFrame(isolate, 0));
} else if (testGroup == kDisplayNameIsNotString) {
v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(
args.GetIsolate(), 5, v8::StackTrace::kOverview);
CHECK_EQ(3, stackTrace->GetFrameCount());
......@@ -351,10 +337,8 @@ TEST(CaptureStackTrace) {
" f()\n"
"}\n"
"bar('function.name', undefined, 3);\n"
"bar(undefined, 'function.displayName', 4);\n"
"bar('function.name', 'function.displayName', 5);\n"
"bar('function.name', 239, 6);\n"
"bar(239, undefined, 7);\n";
"bar('function.name', 'function.displayName', 4);\n"
"bar(239, undefined, 5);\n";
v8::Local<v8::String> function_name_src =
v8::String::NewFromUtf8Literal(isolate, function_name_source);
v8::ScriptCompiler::Source script_source3(function_name_src,
......
......@@ -17323,35 +17323,37 @@ THREADED_TEST(FunctionGetDebugName) {
const char* code =
"var error = false;"
"function a() { this.x = 1; };"
"a.displayName = 'display_a';"
"Object.defineProperty(a, 'name', {value: 'display_a'});"
"var b = (function() {"
" var f = function() { this.x = 2; };"
" f.displayName = 'display_b';"
" Object.defineProperty(f, 'name', {value: 'display_b'});"
" return f;"
"})();"
"var c = function() {};"
"c.__defineGetter__('displayName', function() {"
"c.__defineGetter__('name', function() {"
" error = true;"
" throw new Error();"
"});"
"function d() {};"
"d.__defineGetter__('displayName', function() {"
"d.__defineGetter__('name', function() {"
" error = true;"
" return 'wrong_display_name';"
"});"
"function e() {};"
"e.displayName = 'wrong_display_name';"
"e.__defineSetter__('displayName', function() {"
"Object.defineProperty(e, 'name', {value: 'wrong_display_name'});"
"e.__defineSetter__('name', function() {"
" error = true;"
" throw new Error();"
"});"
"function f() {};"
"f.displayName = { 'foo': 6, toString: function() {"
"Object.defineProperty(f, 'name', {value: {foo: 6, toString: function() {"
" error = true;"
" return 'wrong_display_name';"
"}};"
"}}});"
"var g = function() {"
" arguments.callee.displayName = 'set_in_runtime';"
" Object.defineProperty(arguments.callee, 'name', {"
" value: 'set_in_runtime'"
" });"
"}; g();"
"var h = function() {};"
"h.displayName = 'displayName';"
......@@ -17378,7 +17380,7 @@ THREADED_TEST(FunctionGetDebugName) {
"e", "e",
"f", "f",
"g", "set_in_runtime",
"h", "displayName",
"h", "function.name",
"i", "function.name",
"j", "function.name",
"k", "foo.bar.baz",
......@@ -17390,8 +17392,9 @@ THREADED_TEST(FunctionGetDebugName) {
v8::String::NewFromUtf8(isolate, functions[i * 2])
.ToLocalChecked())
.ToLocalChecked());
CHECK_EQ(0, strcmp(functions[i * 2 + 1],
*v8::String::Utf8Value(isolate, f->GetDebugName())));
std::string expected(functions[i * 2 + 1]);
std::string actual = *v8::String::Utf8Value(isolate, f->GetDebugName());
CHECK_EQ(expected, actual);
}
}
......@@ -323,69 +323,69 @@ KNOWN_MAPS = {
("read_only_space", 0x03179): (67, "BasicBlockCountersMarkerMap"),
("read_only_space", 0x031bd): (87, "ArrayBoilerplateDescriptionMap"),
("read_only_space", 0x03291): (100, "InterceptorInfoMap"),
("read_only_space", 0x053fd): (72, "PromiseFulfillReactionJobTaskMap"),
("read_only_space", 0x05425): (73, "PromiseRejectReactionJobTaskMap"),
("read_only_space", 0x0544d): (74, "CallableTaskMap"),
("read_only_space", 0x05475): (75, "CallbackTaskMap"),
("read_only_space", 0x0549d): (76, "PromiseResolveThenableJobTaskMap"),
("read_only_space", 0x054c5): (79, "FunctionTemplateInfoMap"),
("read_only_space", 0x054ed): (80, "ObjectTemplateInfoMap"),
("read_only_space", 0x05515): (81, "AccessCheckInfoMap"),
("read_only_space", 0x0553d): (82, "AccessorInfoMap"),
("read_only_space", 0x05565): (83, "AccessorPairMap"),
("read_only_space", 0x0558d): (84, "AliasedArgumentsEntryMap"),
("read_only_space", 0x055b5): (85, "AllocationMementoMap"),
("read_only_space", 0x055dd): (88, "AsmWasmDataMap"),
("read_only_space", 0x05605): (89, "AsyncGeneratorRequestMap"),
("read_only_space", 0x0562d): (90, "BaselineDataMap"),
("read_only_space", 0x05655): (91, "BreakPointMap"),
("read_only_space", 0x0567d): (92, "BreakPointInfoMap"),
("read_only_space", 0x056a5): (93, "CachedTemplateObjectMap"),
("read_only_space", 0x056cd): (95, "ClassPositionsMap"),
("read_only_space", 0x056f5): (96, "DebugInfoMap"),
("read_only_space", 0x0571d): (99, "FunctionTemplateRareDataMap"),
("read_only_space", 0x05745): (101, "InterpreterDataMap"),
("read_only_space", 0x0576d): (102, "ModuleRequestMap"),
("read_only_space", 0x05795): (103, "PromiseCapabilityMap"),
("read_only_space", 0x057bd): (104, "PromiseReactionMap"),
("read_only_space", 0x057e5): (105, "PropertyDescriptorObjectMap"),
("read_only_space", 0x0580d): (106, "PrototypeInfoMap"),
("read_only_space", 0x05835): (107, "RegExpBoilerplateDescriptionMap"),
("read_only_space", 0x0585d): (108, "ScriptMap"),
("read_only_space", 0x05885): (109, "SourceTextModuleInfoEntryMap"),
("read_only_space", 0x058ad): (110, "StackFrameInfoMap"),
("read_only_space", 0x058d5): (111, "TemplateObjectDescriptionMap"),
("read_only_space", 0x058fd): (112, "Tuple2Map"),
("read_only_space", 0x05925): (113, "WasmExceptionTagMap"),
("read_only_space", 0x0594d): (114, "WasmExportedFunctionDataMap"),
("read_only_space", 0x05975): (115, "WasmIndirectFunctionTableMap"),
("read_only_space", 0x0599d): (116, "WasmJSFunctionDataMap"),
("read_only_space", 0x059c5): (135, "SloppyArgumentsElementsMap"),
("read_only_space", 0x059ed): (152, "DescriptorArrayMap"),
("read_only_space", 0x05a15): (157, "UncompiledDataWithoutPreparseDataMap"),
("read_only_space", 0x05a3d): (156, "UncompiledDataWithPreparseDataMap"),
("read_only_space", 0x05a65): (172, "OnHeapBasicBlockProfilerDataMap"),
("read_only_space", 0x05a8d): (182, "WasmCapiFunctionDataMap"),
("read_only_space", 0x05ab5): (169, "InternalClassMap"),
("read_only_space", 0x05add): (178, "SmiPairMap"),
("read_only_space", 0x05b05): (177, "SmiBoxMap"),
("read_only_space", 0x05b2d): (146, "ExportedSubClassBaseMap"),
("read_only_space", 0x05b55): (147, "ExportedSubClassMap"),
("read_only_space", 0x05b7d): (68, "AbstractInternalClassSubclass1Map"),
("read_only_space", 0x05ba5): (69, "AbstractInternalClassSubclass2Map"),
("read_only_space", 0x05bcd): (133, "InternalClassWithSmiElementsMap"),
("read_only_space", 0x05bf5): (170, "InternalClassWithStructElementsMap"),
("read_only_space", 0x05c1d): (148, "ExportedSubClass2Map"),
("read_only_space", 0x05c45): (179, "SortStateMap"),
("read_only_space", 0x05c6d): (86, "AllocationSiteWithWeakNextMap"),
("read_only_space", 0x05c95): (86, "AllocationSiteWithoutWeakNextMap"),
("read_only_space", 0x05cbd): (77, "LoadHandler1Map"),
("read_only_space", 0x05ce5): (77, "LoadHandler2Map"),
("read_only_space", 0x05d0d): (77, "LoadHandler3Map"),
("read_only_space", 0x05d35): (78, "StoreHandler0Map"),
("read_only_space", 0x05d5d): (78, "StoreHandler1Map"),
("read_only_space", 0x05d85): (78, "StoreHandler2Map"),
("read_only_space", 0x05dad): (78, "StoreHandler3Map"),
("read_only_space", 0x053e5): (72, "PromiseFulfillReactionJobTaskMap"),
("read_only_space", 0x0540d): (73, "PromiseRejectReactionJobTaskMap"),
("read_only_space", 0x05435): (74, "CallableTaskMap"),
("read_only_space", 0x0545d): (75, "CallbackTaskMap"),
("read_only_space", 0x05485): (76, "PromiseResolveThenableJobTaskMap"),
("read_only_space", 0x054ad): (79, "FunctionTemplateInfoMap"),
("read_only_space", 0x054d5): (80, "ObjectTemplateInfoMap"),
("read_only_space", 0x054fd): (81, "AccessCheckInfoMap"),
("read_only_space", 0x05525): (82, "AccessorInfoMap"),
("read_only_space", 0x0554d): (83, "AccessorPairMap"),
("read_only_space", 0x05575): (84, "AliasedArgumentsEntryMap"),
("read_only_space", 0x0559d): (85, "AllocationMementoMap"),
("read_only_space", 0x055c5): (88, "AsmWasmDataMap"),
("read_only_space", 0x055ed): (89, "AsyncGeneratorRequestMap"),
("read_only_space", 0x05615): (90, "BaselineDataMap"),
("read_only_space", 0x0563d): (91, "BreakPointMap"),
("read_only_space", 0x05665): (92, "BreakPointInfoMap"),
("read_only_space", 0x0568d): (93, "CachedTemplateObjectMap"),
("read_only_space", 0x056b5): (95, "ClassPositionsMap"),
("read_only_space", 0x056dd): (96, "DebugInfoMap"),
("read_only_space", 0x05705): (99, "FunctionTemplateRareDataMap"),
("read_only_space", 0x0572d): (101, "InterpreterDataMap"),
("read_only_space", 0x05755): (102, "ModuleRequestMap"),
("read_only_space", 0x0577d): (103, "PromiseCapabilityMap"),
("read_only_space", 0x057a5): (104, "PromiseReactionMap"),
("read_only_space", 0x057cd): (105, "PropertyDescriptorObjectMap"),
("read_only_space", 0x057f5): (106, "PrototypeInfoMap"),
("read_only_space", 0x0581d): (107, "RegExpBoilerplateDescriptionMap"),
("read_only_space", 0x05845): (108, "ScriptMap"),
("read_only_space", 0x0586d): (109, "SourceTextModuleInfoEntryMap"),
("read_only_space", 0x05895): (110, "StackFrameInfoMap"),
("read_only_space", 0x058bd): (111, "TemplateObjectDescriptionMap"),
("read_only_space", 0x058e5): (112, "Tuple2Map"),
("read_only_space", 0x0590d): (113, "WasmExceptionTagMap"),
("read_only_space", 0x05935): (114, "WasmExportedFunctionDataMap"),
("read_only_space", 0x0595d): (115, "WasmIndirectFunctionTableMap"),
("read_only_space", 0x05985): (116, "WasmJSFunctionDataMap"),
("read_only_space", 0x059ad): (135, "SloppyArgumentsElementsMap"),
("read_only_space", 0x059d5): (152, "DescriptorArrayMap"),
("read_only_space", 0x059fd): (157, "UncompiledDataWithoutPreparseDataMap"),
("read_only_space", 0x05a25): (156, "UncompiledDataWithPreparseDataMap"),
("read_only_space", 0x05a4d): (172, "OnHeapBasicBlockProfilerDataMap"),
("read_only_space", 0x05a75): (182, "WasmCapiFunctionDataMap"),
("read_only_space", 0x05a9d): (169, "InternalClassMap"),
("read_only_space", 0x05ac5): (178, "SmiPairMap"),
("read_only_space", 0x05aed): (177, "SmiBoxMap"),
("read_only_space", 0x05b15): (146, "ExportedSubClassBaseMap"),
("read_only_space", 0x05b3d): (147, "ExportedSubClassMap"),
("read_only_space", 0x05b65): (68, "AbstractInternalClassSubclass1Map"),
("read_only_space", 0x05b8d): (69, "AbstractInternalClassSubclass2Map"),
("read_only_space", 0x05bb5): (133, "InternalClassWithSmiElementsMap"),
("read_only_space", 0x05bdd): (170, "InternalClassWithStructElementsMap"),
("read_only_space", 0x05c05): (148, "ExportedSubClass2Map"),
("read_only_space", 0x05c2d): (179, "SortStateMap"),
("read_only_space", 0x05c55): (86, "AllocationSiteWithWeakNextMap"),
("read_only_space", 0x05c7d): (86, "AllocationSiteWithoutWeakNextMap"),
("read_only_space", 0x05ca5): (77, "LoadHandler1Map"),
("read_only_space", 0x05ccd): (77, "LoadHandler2Map"),
("read_only_space", 0x05cf5): (77, "LoadHandler3Map"),
("read_only_space", 0x05d1d): (78, "StoreHandler0Map"),
("read_only_space", 0x05d45): (78, "StoreHandler1Map"),
("read_only_space", 0x05d6d): (78, "StoreHandler2Map"),
("read_only_space", 0x05d95): (78, "StoreHandler3Map"),
("map_space", 0x02119): (1057, "ExternalMap"),
("map_space", 0x02141): (1098, "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