[error] Improve error message for static methods

This CL changes frame message from `Function.${staticMethodName}`
to `${className}.${staticMethodName}` for stack trace in class
static methods.

Bug: v8:12778
Change-Id: Ie2b9471066a6ba38265412f4af471789bd375c98
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3575759
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Commit-Queue: 王澳 <wangao.james@bytedance.com>
Cr-Commit-Position: refs/heads/main@{#79898}
This commit is contained in:
jameslahm 2022-04-09 09:06:56 +08:00 committed by V8 LUCI CQ
parent 6078cb5283
commit 14718889ee
4 changed files with 18 additions and 10 deletions

View File

@ -673,6 +673,14 @@ void AppendMethodCall(Isolate* isolate, Handle<CallSiteInfo> frame,
Handle<Object> method_name = CallSiteInfo::GetMethodName(frame);
Handle<Object> function_name = CallSiteInfo::GetFunctionName(frame);
Handle<Object> receiver(frame->receiver_or_instance(), isolate);
if (receiver->IsJSClassConstructor()) {
Handle<JSFunction> function = Handle<JSFunction>::cast(receiver);
Handle<String> class_name = JSFunction::GetDebugName(function);
if (class_name->length() != 0) {
type_name = class_name;
}
}
if (IsNonEmptyString(function_name)) {
Handle<String> function_string = Handle<String>::cast(function_name);
if (IsNonEmptyString(type_name)) {

View File

@ -121,7 +121,7 @@ Evaluating this.#inc(); from the base class
columnNumber : 4
exception : {
className : SyntaxError
description : SyntaxError: Private field '#inc' must be declared in an enclosing class at Function.test (<anonymous>:24:7) at run (<anonymous>:28:5) at <anonymous>:1:1
description : SyntaxError: Private field '#inc' must be declared in an enclosing class at B.test (<anonymous>:24:7) at run (<anonymous>:28:5) at <anonymous>:1:1
objectId : <objectId>
subtype : error
type : object
@ -133,7 +133,7 @@ Evaluating this.#inc(); from the base class
}
result : {
className : SyntaxError
description : SyntaxError: Private field '#inc' must be declared in an enclosing class at Function.test (<anonymous>:24:7) at run (<anonymous>:28:5) at <anonymous>:1:1
description : SyntaxError: Private field '#inc' must be declared in an enclosing class at B.test (<anonymous>:24:7) at run (<anonymous>:28:5) at <anonymous>:1:1
objectId : <objectId>
subtype : error
type : object

View File

@ -19,7 +19,7 @@ Access A.#staticMethod() in testStatic()
columnNumber : 0
exception : {
className : ReferenceError
description : ReferenceError: A is not defined at eval (eval at testStatic (:1:1), <anonymous>:1:1) at Function.testStatic (<anonymous>:6:29) at run (<anonymous>:9:7) at <anonymous>:1:1
description : ReferenceError: A is not defined at eval (eval at testStatic (:1:1), <anonymous>:1:1) at A.testStatic (<anonymous>:6:29) at run (<anonymous>:9:7) at <anonymous>:1:1
objectId : <objectId>
subtype : error
type : object
@ -31,7 +31,7 @@ Access A.#staticMethod() in testStatic()
}
result : {
className : ReferenceError
description : ReferenceError: A is not defined at eval (eval at testStatic (:1:1), <anonymous>:1:1) at Function.testStatic (<anonymous>:6:29) at run (<anonymous>:9:7) at <anonymous>:1:1
description : ReferenceError: A is not defined at eval (eval at testStatic (:1:1), <anonymous>:1:1) at A.testStatic (<anonymous>:6:29) at run (<anonymous>:9:7) at <anonymous>:1:1
objectId : <objectId>
subtype : error
type : object
@ -43,7 +43,7 @@ Access this.#staticMethod() in testStatic()
columnNumber : 5
exception : {
className : Error
description : Error: Unused static private method '#staticMethod' cannot be accessed at debug time at eval (eval at testStatic (:1:1), <anonymous>:1:6) at Function.testStatic (<anonymous>:6:29) at run (<anonymous>:9:7) at <anonymous>:1:1
description : Error: Unused static private method '#staticMethod' cannot be accessed at debug time at eval (eval at testStatic (:1:1), <anonymous>:1:6) at A.testStatic (<anonymous>:6:29) at run (<anonymous>:9:7) at <anonymous>:1:1
objectId : <objectId>
subtype : error
type : object
@ -55,7 +55,7 @@ Access this.#staticMethod() in testStatic()
}
result : {
className : Error
description : Error: Unused static private method '#staticMethod' cannot be accessed at debug time at eval (eval at testStatic (:1:1), <anonymous>:1:6) at Function.testStatic (<anonymous>:6:29) at run (<anonymous>:9:7) at <anonymous>:1:1
description : Error: Unused static private method '#staticMethod' cannot be accessed at debug time at eval (eval at testStatic (:1:1), <anonymous>:1:6) at A.testStatic (<anonymous>:6:29) at run (<anonymous>:9:7) at <anonymous>:1:1
objectId : <objectId>
subtype : error
type : object

View File

@ -183,13 +183,13 @@ function testStaticClassFieldCall() {
}
// ReferenceError: FAIL is not defined
// at Function.thrower [as x]
// at X.thrower [as x]
// at testStaticClassFieldCall
// at testTrace
testTrace(
"during static class field call",
testStaticClassFieldCall,
["Function.thrower"],
["X.thrower"],
["anonymous"]
);
@ -226,12 +226,12 @@ function testStaticClassFieldCallWithFNI() {
}
// ReferenceError: FAIL is not defined
// at Function.x
// at X.x
// at testStaticClassFieldCallWithFNI
// at testTrace
testTrace(
"during static class field call with FNI",
testStaticClassFieldCallWithFNI,
["Function.x"],
["X.x"],
["anonymous"]
);