[class] Improve error message for calling anonymous class constructors
The current error message assumes all classes are named, which results in a double space and awkward wording when calling an anonymous class constructor. Bug: v8:10025 Change-Id: Ibe913152c0816cbbaaa0c7a88db4e415762ae9bb Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1947336 Commit-Queue: Shu-yu Guo <syg@chromium.org> Auto-Submit: Shu-yu Guo <syg@chromium.org> Reviewed-by: Leszek Swirski <leszeks@chromium.org> Cr-Commit-Position: refs/heads/master@{#65354}
This commit is contained in:
parent
666668f1f5
commit
33eb473037
@ -65,6 +65,8 @@ namespace internal {
|
||||
T(ConstructorClassField, "Classes may not have a field named 'constructor'") \
|
||||
T(ConstructorNonCallable, \
|
||||
"Class constructor % cannot be invoked without 'new'") \
|
||||
T(AnonymousConstructorNonCallable, \
|
||||
"Class constructors cannot be invoked without 'new'") \
|
||||
T(ConstructorNotFunction, "Constructor % requires 'new'") \
|
||||
T(ConstructorNotReceiver, "The .constructor property is not an object") \
|
||||
T(CurrencyCode, "Currency code is required with currency style.") \
|
||||
@ -269,7 +271,7 @@ namespace internal {
|
||||
T(RegExpNonObject, "% getter called on non-object %") \
|
||||
T(RegExpNonRegExp, "% getter called on non-RegExp object") \
|
||||
T(RegExpGlobalInvokedOnNonGlobal, \
|
||||
"% called with a non-global RegExp argument") \
|
||||
"% called with a non-global RegExp argument") \
|
||||
T(RelativeDateTimeFormatterBadParameters, \
|
||||
"Incorrect RelativeDateTimeFormatter provided") \
|
||||
T(ResolverNotAFunction, "Promise resolver % is not a function") \
|
||||
|
@ -39,6 +39,11 @@ RUNTIME_FUNCTION(Runtime_ThrowConstructorNonCallableError) {
|
||||
DCHECK_EQ(1, args.length());
|
||||
CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 0);
|
||||
Handle<String> name(constructor->shared().Name(), isolate);
|
||||
if (name->length() == 0) {
|
||||
THROW_NEW_ERROR_RETURN_FAILURE(
|
||||
isolate,
|
||||
NewTypeError(MessageTemplate::kAnonymousConstructorNonCallable));
|
||||
}
|
||||
THROW_NEW_ERROR_RETURN_FAILURE(
|
||||
isolate, NewTypeError(MessageTemplate::kConstructorNonCallable, name));
|
||||
}
|
||||
|
@ -296,7 +296,7 @@ bytecodes: [
|
||||
B(Mov), R(context), R(16),
|
||||
B(TestTypeOf), U8(6),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(159),
|
||||
B(Wide), B(LdaSmi), I16(160),
|
||||
B(Star), R(17),
|
||||
B(LdaConstant), U8(11),
|
||||
B(Star), R(18),
|
||||
|
@ -61,7 +61,7 @@ bytecodes: [
|
||||
B(Mov), R(context), R(11),
|
||||
B(TestTypeOf), U8(6),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(159),
|
||||
B(Wide), B(LdaSmi), I16(160),
|
||||
B(Star), R(12),
|
||||
B(LdaConstant), U8(5),
|
||||
B(Star), R(13),
|
||||
@ -191,7 +191,7 @@ bytecodes: [
|
||||
B(Mov), R(context), R(12),
|
||||
B(TestTypeOf), U8(6),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(159),
|
||||
B(Wide), B(LdaSmi), I16(160),
|
||||
B(Star), R(13),
|
||||
B(LdaConstant), U8(5),
|
||||
B(Star), R(14),
|
||||
@ -308,7 +308,7 @@ bytecodes: [
|
||||
B(Mov), R(context), R(13),
|
||||
B(TestTypeOf), U8(6),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(159),
|
||||
B(Wide), B(LdaSmi), I16(160),
|
||||
B(Star), R(14),
|
||||
B(LdaConstant), U8(6),
|
||||
B(Star), R(15),
|
||||
|
@ -93,7 +93,7 @@ bytecodes: [
|
||||
B(Mov), R(context), R(15),
|
||||
B(TestTypeOf), U8(6),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(159),
|
||||
B(Wide), B(LdaSmi), I16(160),
|
||||
B(Star), R(16),
|
||||
B(LdaConstant), U8(9),
|
||||
B(Star), R(17),
|
||||
@ -260,7 +260,7 @@ bytecodes: [
|
||||
B(Mov), R(context), R(15),
|
||||
B(TestTypeOf), U8(6),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(159),
|
||||
B(Wide), B(LdaSmi), I16(160),
|
||||
B(Star), R(16),
|
||||
B(LdaConstant), U8(9),
|
||||
B(Star), R(17),
|
||||
@ -443,7 +443,7 @@ bytecodes: [
|
||||
B(Mov), R(context), R(15),
|
||||
B(TestTypeOf), U8(6),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(159),
|
||||
B(Wide), B(LdaSmi), I16(160),
|
||||
B(Star), R(16),
|
||||
B(LdaConstant), U8(9),
|
||||
B(Star), R(17),
|
||||
@ -590,7 +590,7 @@ bytecodes: [
|
||||
B(Mov), R(context), R(12),
|
||||
B(TestTypeOf), U8(6),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(159),
|
||||
B(Wide), B(LdaSmi), I16(160),
|
||||
B(Star), R(13),
|
||||
B(LdaConstant), U8(7),
|
||||
B(Star), R(14),
|
||||
|
@ -58,7 +58,7 @@ bytecodes: [
|
||||
B(Mov), R(context), R(10),
|
||||
B(TestTypeOf), U8(6),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(159),
|
||||
B(Wide), B(LdaSmi), I16(160),
|
||||
B(Star), R(11),
|
||||
B(LdaConstant), U8(5),
|
||||
B(Star), R(12),
|
||||
@ -154,7 +154,7 @@ bytecodes: [
|
||||
B(Mov), R(context), R(11),
|
||||
B(TestTypeOf), U8(6),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(159),
|
||||
B(Wide), B(LdaSmi), I16(160),
|
||||
B(Star), R(12),
|
||||
B(LdaConstant), U8(5),
|
||||
B(Star), R(13),
|
||||
@ -261,7 +261,7 @@ bytecodes: [
|
||||
B(Mov), R(context), R(10),
|
||||
B(TestTypeOf), U8(6),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(159),
|
||||
B(Wide), B(LdaSmi), I16(160),
|
||||
B(Star), R(11),
|
||||
B(LdaConstant), U8(5),
|
||||
B(Star), R(12),
|
||||
@ -361,7 +361,7 @@ bytecodes: [
|
||||
B(Mov), R(context), R(10),
|
||||
B(TestTypeOf), U8(6),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(159),
|
||||
B(Wide), B(LdaSmi), I16(160),
|
||||
B(Star), R(11),
|
||||
B(LdaConstant), U8(7),
|
||||
B(Star), R(12),
|
||||
|
@ -61,7 +61,7 @@ bytecodes: [
|
||||
B(Mov), R(context), R(12),
|
||||
B(TestTypeOf), U8(6),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(159),
|
||||
B(Wide), B(LdaSmi), I16(160),
|
||||
B(Star), R(13),
|
||||
B(LdaConstant), U8(4),
|
||||
B(Star), R(14),
|
||||
@ -192,7 +192,7 @@ bytecodes: [
|
||||
B(Mov), R(context), R(13),
|
||||
B(TestTypeOf), U8(6),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(159),
|
||||
B(Wide), B(LdaSmi), I16(160),
|
||||
B(Star), R(14),
|
||||
B(LdaConstant), U8(9),
|
||||
B(Star), R(15),
|
||||
@ -300,7 +300,7 @@ bytecodes: [
|
||||
B(Mov), R(context), R(11),
|
||||
B(TestTypeOf), U8(6),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(159),
|
||||
B(Wide), B(LdaSmi), I16(160),
|
||||
B(Star), R(12),
|
||||
B(LdaConstant), U8(6),
|
||||
B(Star), R(13),
|
||||
@ -400,7 +400,7 @@ bytecodes: [
|
||||
B(Mov), R(context), R(14),
|
||||
B(TestTypeOf), U8(6),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(159),
|
||||
B(Wide), B(LdaSmi), I16(160),
|
||||
B(Star), R(15),
|
||||
B(LdaConstant), U8(6),
|
||||
B(Star), R(16),
|
||||
@ -510,7 +510,7 @@ bytecodes: [
|
||||
B(Mov), R(context), R(13),
|
||||
B(TestTypeOf), U8(6),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(159),
|
||||
B(Wide), B(LdaSmi), I16(160),
|
||||
B(Star), R(14),
|
||||
B(LdaConstant), U8(7),
|
||||
B(Star), R(15),
|
||||
@ -635,7 +635,7 @@ bytecodes: [
|
||||
B(Mov), R(context), R(12),
|
||||
B(TestTypeOf), U8(6),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(159),
|
||||
B(Wide), B(LdaSmi), I16(160),
|
||||
B(Star), R(13),
|
||||
B(LdaConstant), U8(10),
|
||||
B(Star), R(14),
|
||||
@ -744,7 +744,7 @@ bytecodes: [
|
||||
B(Mov), R(context), R(14),
|
||||
B(TestTypeOf), U8(6),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(159),
|
||||
B(Wide), B(LdaSmi), I16(160),
|
||||
B(Star), R(15),
|
||||
B(LdaConstant), U8(4),
|
||||
B(Star), R(16),
|
||||
@ -877,7 +877,7 @@ bytecodes: [
|
||||
B(Mov), R(context), R(13),
|
||||
B(TestTypeOf), U8(6),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(159),
|
||||
B(Wide), B(LdaSmi), I16(160),
|
||||
B(Star), R(14),
|
||||
B(LdaConstant), U8(5),
|
||||
B(Star), R(15),
|
||||
|
@ -176,7 +176,7 @@ bytecodes: [
|
||||
B(Mov), R(context), R(12),
|
||||
B(TestTypeOf), U8(6),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(159),
|
||||
B(Wide), B(LdaSmi), I16(160),
|
||||
B(Star), R(13),
|
||||
B(LdaConstant), U8(11),
|
||||
B(Star), R(14),
|
||||
|
@ -86,7 +86,7 @@ bytecodes: [
|
||||
B(Mov), R(this), R(0),
|
||||
B(Mov), R(context), R(2),
|
||||
B(CallRuntime), U16(Runtime::kAddPrivateBrand), R(0), U8(3),
|
||||
/* 53 S> */ B(Wide), B(LdaSmi), I16(264),
|
||||
/* 53 S> */ B(Wide), B(LdaSmi), I16(265),
|
||||
B(Star), R(3),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(4),
|
||||
@ -118,7 +118,7 @@ bytecodes: [
|
||||
B(Mov), R(this), R(0),
|
||||
B(Mov), R(context), R(2),
|
||||
B(CallRuntime), U16(Runtime::kAddPrivateBrand), R(0), U8(3),
|
||||
/* 46 S> */ B(Wide), B(LdaSmi), I16(263),
|
||||
/* 46 S> */ B(Wide), B(LdaSmi), I16(264),
|
||||
B(Star), R(3),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(4),
|
||||
@ -150,7 +150,7 @@ bytecodes: [
|
||||
B(Mov), R(this), R(0),
|
||||
B(Mov), R(context), R(2),
|
||||
B(CallRuntime), U16(Runtime::kAddPrivateBrand), R(0), U8(3),
|
||||
/* 53 S> */ B(Wide), B(LdaSmi), I16(264),
|
||||
/* 53 S> */ B(Wide), B(LdaSmi), I16(265),
|
||||
B(Star), R(3),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(4),
|
||||
@ -182,7 +182,7 @@ bytecodes: [
|
||||
B(Mov), R(this), R(0),
|
||||
B(Mov), R(context), R(2),
|
||||
B(CallRuntime), U16(Runtime::kAddPrivateBrand), R(0), U8(3),
|
||||
/* 46 S> */ B(Wide), B(LdaSmi), I16(263),
|
||||
/* 46 S> */ B(Wide), B(LdaSmi), I16(264),
|
||||
B(Star), R(4),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(5),
|
||||
|
@ -59,7 +59,7 @@ bytecodes: [
|
||||
B(Mov), R(this), R(0),
|
||||
B(Mov), R(context), R(2),
|
||||
B(CallRuntime), U16(Runtime::kAddPrivateBrand), R(0), U8(3),
|
||||
/* 49 S> */ B(Wide), B(LdaSmi), I16(262),
|
||||
/* 49 S> */ B(Wide), B(LdaSmi), I16(263),
|
||||
B(Star), R(3),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(4),
|
||||
@ -92,7 +92,7 @@ bytecodes: [
|
||||
B(Mov), R(this), R(0),
|
||||
B(Mov), R(context), R(2),
|
||||
B(CallRuntime), U16(Runtime::kAddPrivateBrand), R(0), U8(3),
|
||||
/* 49 S> */ B(Wide), B(LdaSmi), I16(262),
|
||||
/* 49 S> */ B(Wide), B(LdaSmi), I16(263),
|
||||
B(Star), R(3),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(4),
|
||||
|
@ -26,7 +26,7 @@ bytecodes: [
|
||||
B(TestReferenceEqual), R(this),
|
||||
B(Mov), R(this), R(1),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(260),
|
||||
B(Wide), B(LdaSmi), I16(261),
|
||||
B(Star), R(2),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(3),
|
||||
@ -58,7 +58,7 @@ parameter count: 1
|
||||
bytecode array length: 17
|
||||
bytecodes: [
|
||||
/* 51 E> */ B(StackCheck),
|
||||
/* 56 S> */ B(Wide), B(LdaSmi), I16(262),
|
||||
/* 56 S> */ B(Wide), B(LdaSmi), I16(263),
|
||||
B(Star), R(0),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(1),
|
||||
@ -86,7 +86,7 @@ parameter count: 1
|
||||
bytecode array length: 17
|
||||
bytecodes: [
|
||||
/* 51 E> */ B(StackCheck),
|
||||
/* 56 S> */ B(Wide), B(LdaSmi), I16(262),
|
||||
/* 56 S> */ B(Wide), B(LdaSmi), I16(263),
|
||||
B(Star), R(0),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(1),
|
||||
@ -126,7 +126,7 @@ bytecodes: [
|
||||
/* 94 E> */ B(TestReferenceEqual), R(this),
|
||||
B(Mov), R(this), R(0),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(260),
|
||||
B(Wide), B(LdaSmi), I16(261),
|
||||
B(Star), R(2),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(3),
|
||||
@ -148,7 +148,7 @@ bytecodes: [
|
||||
/* 109 E> */ B(TestReferenceEqual), R(this),
|
||||
B(Mov), R(this), R(1),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(261),
|
||||
B(Wide), B(LdaSmi), I16(262),
|
||||
B(Star), R(3),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(4),
|
||||
@ -163,7 +163,7 @@ bytecodes: [
|
||||
/* 133 E> */ B(TestReferenceEqual), R(this),
|
||||
B(Mov), R(this), R(0),
|
||||
B(JumpIfTrue), U8(18),
|
||||
B(Wide), B(LdaSmi), I16(260),
|
||||
B(Wide), B(LdaSmi), I16(261),
|
||||
B(Star), R(2),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(3),
|
||||
@ -194,7 +194,7 @@ parameter count: 1
|
||||
bytecode array length: 17
|
||||
bytecodes: [
|
||||
/* 55 E> */ B(StackCheck),
|
||||
/* 60 S> */ B(Wide), B(LdaSmi), I16(264),
|
||||
/* 60 S> */ B(Wide), B(LdaSmi), I16(265),
|
||||
B(Star), R(0),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(1),
|
||||
@ -221,7 +221,7 @@ parameter count: 1
|
||||
bytecode array length: 17
|
||||
bytecodes: [
|
||||
/* 48 E> */ B(StackCheck),
|
||||
/* 53 S> */ B(Wide), B(LdaSmi), I16(263),
|
||||
/* 53 S> */ B(Wide), B(LdaSmi), I16(264),
|
||||
B(Star), R(0),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(1),
|
||||
@ -248,7 +248,7 @@ parameter count: 1
|
||||
bytecode array length: 17
|
||||
bytecodes: [
|
||||
/* 55 E> */ B(StackCheck),
|
||||
/* 60 S> */ B(Wide), B(LdaSmi), I16(264),
|
||||
/* 60 S> */ B(Wide), B(LdaSmi), I16(265),
|
||||
B(Star), R(0),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(1),
|
||||
@ -275,7 +275,7 @@ parameter count: 1
|
||||
bytecode array length: 17
|
||||
bytecodes: [
|
||||
/* 41 E> */ B(StackCheck),
|
||||
/* 46 S> */ B(Wide), B(LdaSmi), I16(263),
|
||||
/* 46 S> */ B(Wide), B(LdaSmi), I16(264),
|
||||
B(Star), R(1),
|
||||
B(LdaConstant), U8(0),
|
||||
B(Star), R(2),
|
||||
|
@ -8,9 +8,9 @@ PASS A() threw exception TypeError: Class constructor A cannot be invoked withou
|
||||
PASS new B did not throw exception.
|
||||
PASS B() threw exception TypeError: Class constructor B cannot be invoked without 'new'.
|
||||
PASS new (class { constructor() {} })() did not throw exception.
|
||||
PASS (class { constructor() {} })() threw exception TypeError: Class constructor cannot be invoked without 'new'.
|
||||
PASS (class { constructor() {} })() threw exception TypeError: Class constructors cannot be invoked without 'new'.
|
||||
PASS new (class extends null { constructor() { super() } })() threw exception TypeError: Super constructor null of anonymous class is not a constructor.
|
||||
PASS (class extends null { constructor() { super() } })() threw exception TypeError: Class constructor cannot be invoked without 'new'.
|
||||
PASS (class extends null { constructor() { super() } })() threw exception TypeError: Class constructors cannot be invoked without 'new'.
|
||||
PASS successfullyParsed is true
|
||||
|
||||
TEST COMPLETE
|
||||
|
@ -31,8 +31,8 @@ shouldThrow('A()', '"TypeError: Class constructor A cannot be invoked without \'
|
||||
shouldNotThrow('new B');
|
||||
shouldThrow('B()', '"TypeError: Class constructor B cannot be invoked without \'new\'"');
|
||||
shouldNotThrow('new (class { constructor() {} })()');
|
||||
shouldThrow('(class { constructor() {} })()', '"TypeError: Class constructor cannot be invoked without \'new\'"');
|
||||
shouldThrow('(class { constructor() {} })()', '"TypeError: Class constructors cannot be invoked without \'new\'"');
|
||||
shouldThrow('new (class extends null { constructor() { super() } })()', '"TypeError: Super constructor null of anonymous class is not a constructor"');
|
||||
shouldThrow('(class extends null { constructor() { super() } })()', '"TypeError: Class constructor cannot be invoked without \'new\'"');
|
||||
shouldThrow('(class extends null { constructor() { super() } })()', '"TypeError: Class constructors cannot be invoked without \'new\'"');
|
||||
|
||||
var successfullyParsed = true;
|
||||
|
Loading…
Reference in New Issue
Block a user