Commit c830799d authored by Sathya Gunasekaran's avatar Sathya Gunasekaran Committed by Commit Bot

[class] Give a name to initializer functions

Makes for a nicer stack trace

Bug: v8:5367
Change-Id: I6d77907e08c2c4efc7a1b25016c7e83841c7c574
Reviewed-on: https://chromium-review.googlesource.com/1211444
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarDaniel Ehrenberg <littledan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55736}
parent 1742e575
......@@ -386,6 +386,13 @@ Handle<Object> JSStackFrame::GetMethodName() {
}
Handle<String> name(function_->shared()->Name(), isolate_);
// The static initializer function is not a method, so don't add a
// class name, just return the function name.
if (name->IsUtf8EqualTo(CStrVector("<static_fields_initializer>"), true)) {
return name;
}
// ES2015 gives getters and setters name prefixes which must
// be stripped to find the property name.
if (name->IsUtf8EqualTo(CStrVector("get "), true) ||
......
......@@ -3239,7 +3239,8 @@ void Parser::DeclareClassProperty(const AstRawString* class_name,
}
FunctionLiteral* Parser::CreateInitializerFunction(
DeclarationScope* scope, ZonePtrList<ClassLiteral::Property>* fields) {
const char* name, DeclarationScope* scope,
ZonePtrList<ClassLiteral::Property>* fields) {
DCHECK_EQ(scope->function_kind(),
FunctionKind::kClassFieldsInitializerFunction);
// function() { .. class fields initializer .. }
......@@ -3248,7 +3249,7 @@ FunctionLiteral* Parser::CreateInitializerFunction(
factory()->NewInitializeClassFieldsStatement(fields, kNoSourcePosition);
statements->Add(static_fields, zone());
return factory()->NewFunctionLiteral(
ast_value_factory()->empty_string(), scope, statements, 0, 0, 0,
ast_value_factory()->GetOneByteString(name), scope, statements, 0, 0, 0,
FunctionLiteral::kNoDuplicateParameters,
FunctionLiteral::kAnonymousExpression,
FunctionLiteral::kShouldEagerCompile, scope->start_position(), true,
......@@ -3286,13 +3287,15 @@ Expression* Parser::RewriteClassLiteral(Scope* block_scope,
FunctionLiteral* static_fields_initializer = nullptr;
if (class_info->has_static_class_fields) {
static_fields_initializer = CreateInitializerFunction(
class_info->static_fields_scope, class_info->static_fields);
"<static_fields_initializer>", class_info->static_fields_scope,
class_info->static_fields);
}
FunctionLiteral* instance_fields_initializer_function = nullptr;
if (class_info->has_instance_class_fields) {
instance_fields_initializer_function = CreateInitializerFunction(
class_info->instance_fields_scope, class_info->instance_fields);
"<instance_fields_initializer>", class_info->instance_fields_scope,
class_info->instance_fields);
class_info->constructor->set_requires_instance_fields_initializer(true);
}
......
......@@ -317,7 +317,8 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
Variable* CreateSyntheticContextVariable(const AstRawString* synthetic_name,
bool* ok);
FunctionLiteral* CreateInitializerFunction(
DeclarationScope* scope, ZonePtrList<ClassLiteral::Property>* fields);
const char* name, DeclarationScope* scope,
ZonePtrList<ClassLiteral::Property>* fields);
V8_INLINE Statement* DeclareClass(const AstRawString* variable_name,
Expression* value,
ZonePtrList<const AstRawString>* names,
......
......@@ -43,13 +43,15 @@ function testClassConstruction() {
// ReferenceError: FAIL is not defined
// at thrower
// at Function.<anonymous>
// at <static_fields_initializer>
// at testClassConstruction
// at testTrace
testTrace("during class construction", testClassConstruction, [
"thrower",
"Function.<anonymous>"
]);
testTrace(
"during class construction",
testClassConstruction,
["thrower", "<static_fields_initializer>"],
["anonymous"]
);
function testClassConstruction2() {
class X {
......@@ -61,9 +63,7 @@ function testClassConstruction2() {
// at thrower
// at testClassConstruction2
// at testTrace
testTrace("during class construction2", testClassConstruction2, [
"thrower"
]);
testTrace("during class construction2", testClassConstruction2, ["thrower"]);
function testClassInstantiation() {
class X {
......@@ -75,15 +75,16 @@ function testClassInstantiation() {
// ReferenceError: FAIL is not defined
// at thrower
// at X.<anonymous>
// at X.<instance_fields_initializer>
// at new X
// at testClassInstantiation
// at testTrace
testTrace("during class instantiation", testClassInstantiation, [
"thrower",
"X.<anonymous>",
"new X"
]);
testTrace(
"during class instantiation",
testClassInstantiation,
["thrower", "X.<instance_fields_initializer>", "new X"],
["anonymous"]
);
function testClassInstantiationWithSuper() {
class Base {}
......@@ -97,15 +98,15 @@ function testClassInstantiationWithSuper() {
// ReferenceError: FAIL is not defined
// at thrower
// at X.<anonymous>
// at X.<instance_fields_initializer>
// at new X
// at testClassInstantiation
// at testTrace
testTrace(
"during class instantiation with super",
testClassInstantiationWithSuper,
["thrower", "X.<anonymous>", "new X"],
["Base"]
["thrower", "X.<instance_fields_initializer>", "new X"],
["Base", "anonymous"]
);
function testClassInstantiationWithSuper2() {
......@@ -123,15 +124,15 @@ function testClassInstantiationWithSuper2() {
// ReferenceError: FAIL is not defined
// at thrower
// at X.<anonymous>
// at X.<instance_fields_initializer>
// at new X
// at testClassInstantiation
// at testTrace
testTrace(
"during class instantiation with super2",
testClassInstantiationWithSuper2,
["thrower", "X.<anonymous>", "new X"],
["Base"]
["thrower", "X.<instance_fields_initializer>", "new X"],
["Base", "anonymous"]
);
function testClassInstantiationWithSuper3() {
......@@ -150,7 +151,7 @@ function testClassInstantiationWithSuper3() {
// ReferenceError: FAIL is not defined
// at thrower
// at X.<anonymous>
// at X.<instance_fields_initializer>
// at new Base
// at new X
// at testClassInstantiationWithSuper3
......@@ -158,7 +159,8 @@ function testClassInstantiationWithSuper3() {
testTrace(
"during class instantiation with super3",
testClassInstantiationWithSuper3,
["thrower", "X.<anonymous>", "new Base", "new X"]
["thrower", "X.<instance_fields_initializer>", "new Base", "new X"],
["anonymous"]
);
function testClassFieldCall() {
......
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