[parser] Improve error message for import()
Currently, dynamic `import()` throws the following SyntaxError when used without a specifier: > import(); < Uncaught SyntaxError: Unexpected token ) From the error message, it seems this the result of the code snippet being seen as static `import` followed by parens, as opposed to `import()` with no specifier. This patch makes this error message more clear: > import(); < SyntaxError: import() requires a specifier BUG=v8:7020,v8:6513 Change-Id: I3519dfd0029f38d23da858a5499f1d226e794935 Reviewed-on: https://chromium-review.googlesource.com/747141 Reviewed-by: Sathya Gunasekaran <gsathya@chromium.org> Commit-Queue: Mathias Bynens <mathias@chromium.org> Cr-Commit-Position: refs/heads/master@{#49058}
This commit is contained in:
parent
17b97fe928
commit
dbcea11564
@ -324,6 +324,7 @@ class ErrorUtils : public AllStatic {
|
|||||||
"Immutable prototype object '%' cannot have their prototype set") \
|
"Immutable prototype object '%' cannot have their prototype set") \
|
||||||
T(ImportCallNotNewExpression, "Cannot use new with import") \
|
T(ImportCallNotNewExpression, "Cannot use new with import") \
|
||||||
T(ImportMetaOutsideModule, "Cannot use 'import.meta' outside a module") \
|
T(ImportMetaOutsideModule, "Cannot use 'import.meta' outside a module") \
|
||||||
|
T(ImportMissingSpecifier, "import() requires a specifier") \
|
||||||
T(IncompatibleMethodReceiver, "Method % called on incompatible receiver %") \
|
T(IncompatibleMethodReceiver, "Method % called on incompatible receiver %") \
|
||||||
T(InstanceofNonobjectProto, \
|
T(InstanceofNonobjectProto, \
|
||||||
"Function has non-object prototype '%' in instanceof check") \
|
"Function has non-object prototype '%' in instanceof check") \
|
||||||
|
@ -3565,6 +3565,12 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseImportExpressions(
|
|||||||
return impl()->ImportMetaExpression(pos);
|
return impl()->ImportMetaExpression(pos);
|
||||||
}
|
}
|
||||||
Expect(Token::LPAREN, CHECK_OK);
|
Expect(Token::LPAREN, CHECK_OK);
|
||||||
|
if (peek() == Token::RPAREN) {
|
||||||
|
impl()->ReportMessageAt(scanner()->location(),
|
||||||
|
MessageTemplate::kImportMissingSpecifier);
|
||||||
|
*ok = false;
|
||||||
|
return impl()->NullExpression();
|
||||||
|
}
|
||||||
ExpressionT arg = ParseAssignmentExpression(true, CHECK_OK);
|
ExpressionT arg = ParseAssignmentExpression(true, CHECK_OK);
|
||||||
Expect(Token::RPAREN, CHECK_OK);
|
Expect(Token::RPAREN, CHECK_OK);
|
||||||
return factory()->NewImportCallExpression(arg, pos);
|
return factory()->NewImportCallExpression(arg, pos);
|
||||||
|
@ -428,7 +428,7 @@ bytecodes: [
|
|||||||
B(TestTypeOf), U8(5),
|
B(TestTypeOf), U8(5),
|
||||||
B(JumpIfFalse), U8(4),
|
B(JumpIfFalse), U8(4),
|
||||||
B(Jump), U8(18),
|
B(Jump), U8(18),
|
||||||
B(Wide), B(LdaSmi), I16(141),
|
B(Wide), B(LdaSmi), I16(142),
|
||||||
B(Star), R(18),
|
B(Star), R(18),
|
||||||
B(LdaConstant), U8(16),
|
B(LdaConstant), U8(16),
|
||||||
B(Star), R(19),
|
B(Star), R(19),
|
||||||
|
@ -143,7 +143,7 @@ bytecodes: [
|
|||||||
B(TestTypeOf), U8(5),
|
B(TestTypeOf), U8(5),
|
||||||
B(JumpIfFalse), U8(4),
|
B(JumpIfFalse), U8(4),
|
||||||
B(Jump), U8(18),
|
B(Jump), U8(18),
|
||||||
B(Wide), B(LdaSmi), I16(141),
|
B(Wide), B(LdaSmi), I16(142),
|
||||||
B(Star), R(19),
|
B(Star), R(19),
|
||||||
B(LdaConstant), U8(13),
|
B(LdaConstant), U8(13),
|
||||||
B(Star), R(20),
|
B(Star), R(20),
|
||||||
@ -432,7 +432,7 @@ bytecodes: [
|
|||||||
B(TestTypeOf), U8(5),
|
B(TestTypeOf), U8(5),
|
||||||
B(JumpIfFalse), U8(4),
|
B(JumpIfFalse), U8(4),
|
||||||
B(Jump), U8(18),
|
B(Jump), U8(18),
|
||||||
B(Wide), B(LdaSmi), I16(141),
|
B(Wide), B(LdaSmi), I16(142),
|
||||||
B(Star), R(19),
|
B(Star), R(19),
|
||||||
B(LdaConstant), U8(13),
|
B(LdaConstant), U8(13),
|
||||||
B(Star), R(20),
|
B(Star), R(20),
|
||||||
@ -743,7 +743,7 @@ bytecodes: [
|
|||||||
B(TestTypeOf), U8(5),
|
B(TestTypeOf), U8(5),
|
||||||
B(JumpIfFalse), U8(4),
|
B(JumpIfFalse), U8(4),
|
||||||
B(Jump), U8(18),
|
B(Jump), U8(18),
|
||||||
B(Wide), B(LdaSmi), I16(141),
|
B(Wide), B(LdaSmi), I16(142),
|
||||||
B(Star), R(19),
|
B(Star), R(19),
|
||||||
B(LdaConstant), U8(13),
|
B(LdaConstant), U8(13),
|
||||||
B(Star), R(20),
|
B(Star), R(20),
|
||||||
@ -991,7 +991,7 @@ bytecodes: [
|
|||||||
B(TestTypeOf), U8(5),
|
B(TestTypeOf), U8(5),
|
||||||
B(JumpIfFalse), U8(4),
|
B(JumpIfFalse), U8(4),
|
||||||
B(Jump), U8(18),
|
B(Jump), U8(18),
|
||||||
B(Wide), B(LdaSmi), I16(141),
|
B(Wide), B(LdaSmi), I16(142),
|
||||||
B(Star), R(16),
|
B(Star), R(16),
|
||||||
B(LdaConstant), U8(10),
|
B(LdaConstant), U8(10),
|
||||||
B(Star), R(17),
|
B(Star), R(17),
|
||||||
|
@ -86,7 +86,7 @@ bytecodes: [
|
|||||||
B(TestTypeOf), U8(5),
|
B(TestTypeOf), U8(5),
|
||||||
B(JumpIfFalse), U8(4),
|
B(JumpIfFalse), U8(4),
|
||||||
B(Jump), U8(18),
|
B(Jump), U8(18),
|
||||||
B(Wide), B(LdaSmi), I16(141),
|
B(Wide), B(LdaSmi), I16(142),
|
||||||
B(Star), R(11),
|
B(Star), R(11),
|
||||||
B(LdaConstant), U8(8),
|
B(LdaConstant), U8(8),
|
||||||
B(Star), R(12),
|
B(Star), R(12),
|
||||||
@ -227,7 +227,7 @@ bytecodes: [
|
|||||||
B(TestTypeOf), U8(5),
|
B(TestTypeOf), U8(5),
|
||||||
B(JumpIfFalse), U8(4),
|
B(JumpIfFalse), U8(4),
|
||||||
B(Jump), U8(18),
|
B(Jump), U8(18),
|
||||||
B(Wide), B(LdaSmi), I16(141),
|
B(Wide), B(LdaSmi), I16(142),
|
||||||
B(Star), R(12),
|
B(Star), R(12),
|
||||||
B(LdaConstant), U8(8),
|
B(LdaConstant), U8(8),
|
||||||
B(Star), R(13),
|
B(Star), R(13),
|
||||||
@ -380,7 +380,7 @@ bytecodes: [
|
|||||||
B(TestTypeOf), U8(5),
|
B(TestTypeOf), U8(5),
|
||||||
B(JumpIfFalse), U8(4),
|
B(JumpIfFalse), U8(4),
|
||||||
B(Jump), U8(18),
|
B(Jump), U8(18),
|
||||||
B(Wide), B(LdaSmi), I16(141),
|
B(Wide), B(LdaSmi), I16(142),
|
||||||
B(Star), R(11),
|
B(Star), R(11),
|
||||||
B(LdaConstant), U8(8),
|
B(LdaConstant), U8(8),
|
||||||
B(Star), R(12),
|
B(Star), R(12),
|
||||||
@ -523,7 +523,7 @@ bytecodes: [
|
|||||||
B(TestTypeOf), U8(5),
|
B(TestTypeOf), U8(5),
|
||||||
B(JumpIfFalse), U8(4),
|
B(JumpIfFalse), U8(4),
|
||||||
B(Jump), U8(18),
|
B(Jump), U8(18),
|
||||||
B(Wide), B(LdaSmi), I16(141),
|
B(Wide), B(LdaSmi), I16(142),
|
||||||
B(Star), R(10),
|
B(Star), R(10),
|
||||||
B(LdaConstant), U8(10),
|
B(LdaConstant), U8(10),
|
||||||
B(Star), R(11),
|
B(Star), R(11),
|
||||||
|
@ -90,7 +90,7 @@ bytecodes: [
|
|||||||
B(TestTypeOf), U8(5),
|
B(TestTypeOf), U8(5),
|
||||||
B(JumpIfFalse), U8(4),
|
B(JumpIfFalse), U8(4),
|
||||||
B(Jump), U8(18),
|
B(Jump), U8(18),
|
||||||
B(Wide), B(LdaSmi), I16(141),
|
B(Wide), B(LdaSmi), I16(142),
|
||||||
B(Star), R(13),
|
B(Star), R(13),
|
||||||
B(LdaConstant), U8(7),
|
B(LdaConstant), U8(7),
|
||||||
B(Star), R(14),
|
B(Star), R(14),
|
||||||
@ -268,7 +268,7 @@ bytecodes: [
|
|||||||
B(TestTypeOf), U8(5),
|
B(TestTypeOf), U8(5),
|
||||||
B(JumpIfFalse), U8(4),
|
B(JumpIfFalse), U8(4),
|
||||||
B(Jump), U8(18),
|
B(Jump), U8(18),
|
||||||
B(Wide), B(LdaSmi), I16(141),
|
B(Wide), B(LdaSmi), I16(142),
|
||||||
B(Star), R(13),
|
B(Star), R(13),
|
||||||
B(LdaConstant), U8(11),
|
B(LdaConstant), U8(11),
|
||||||
B(Star), R(14),
|
B(Star), R(14),
|
||||||
@ -422,7 +422,7 @@ bytecodes: [
|
|||||||
B(TestTypeOf), U8(5),
|
B(TestTypeOf), U8(5),
|
||||||
B(JumpIfFalse), U8(4),
|
B(JumpIfFalse), U8(4),
|
||||||
B(Jump), U8(18),
|
B(Jump), U8(18),
|
||||||
B(Wide), B(LdaSmi), I16(141),
|
B(Wide), B(LdaSmi), I16(142),
|
||||||
B(Star), R(11),
|
B(Star), R(11),
|
||||||
B(LdaConstant), U8(9),
|
B(LdaConstant), U8(9),
|
||||||
B(Star), R(12),
|
B(Star), R(12),
|
||||||
@ -524,7 +524,7 @@ bytecodes: [
|
|||||||
B(JumpIfUndefined), U8(6),
|
B(JumpIfUndefined), U8(6),
|
||||||
B(Ldar), R(6),
|
B(Ldar), R(6),
|
||||||
B(JumpIfNotNull), U8(16),
|
B(JumpIfNotNull), U8(16),
|
||||||
B(LdaSmi), I8(71),
|
B(LdaSmi), I8(72),
|
||||||
B(Star), R(17),
|
B(Star), R(17),
|
||||||
B(LdaConstant), U8(4),
|
B(LdaConstant), U8(4),
|
||||||
B(Star), R(18),
|
B(Star), R(18),
|
||||||
@ -580,7 +580,7 @@ bytecodes: [
|
|||||||
B(TestTypeOf), U8(5),
|
B(TestTypeOf), U8(5),
|
||||||
B(JumpIfFalse), U8(4),
|
B(JumpIfFalse), U8(4),
|
||||||
B(Jump), U8(18),
|
B(Jump), U8(18),
|
||||||
B(Wide), B(LdaSmi), I16(141),
|
B(Wide), B(LdaSmi), I16(142),
|
||||||
B(Star), R(16),
|
B(Star), R(16),
|
||||||
B(LdaConstant), U8(9),
|
B(LdaConstant), U8(9),
|
||||||
B(Star), R(17),
|
B(Star), R(17),
|
||||||
@ -754,7 +754,7 @@ bytecodes: [
|
|||||||
B(TestTypeOf), U8(5),
|
B(TestTypeOf), U8(5),
|
||||||
B(JumpIfFalse), U8(4),
|
B(JumpIfFalse), U8(4),
|
||||||
B(Jump), U8(18),
|
B(Jump), U8(18),
|
||||||
B(Wide), B(LdaSmi), I16(141),
|
B(Wide), B(LdaSmi), I16(142),
|
||||||
B(Star), R(16),
|
B(Star), R(16),
|
||||||
B(LdaConstant), U8(10),
|
B(LdaConstant), U8(10),
|
||||||
B(Star), R(17),
|
B(Star), R(17),
|
||||||
@ -953,7 +953,7 @@ bytecodes: [
|
|||||||
B(TestTypeOf), U8(5),
|
B(TestTypeOf), U8(5),
|
||||||
B(JumpIfFalse), U8(4),
|
B(JumpIfFalse), U8(4),
|
||||||
B(Jump), U8(18),
|
B(Jump), U8(18),
|
||||||
B(Wide), B(LdaSmi), I16(141),
|
B(Wide), B(LdaSmi), I16(142),
|
||||||
B(Star), R(15),
|
B(Star), R(15),
|
||||||
B(LdaConstant), U8(14),
|
B(LdaConstant), U8(14),
|
||||||
B(Star), R(16),
|
B(Star), R(16),
|
||||||
@ -1116,7 +1116,7 @@ bytecodes: [
|
|||||||
B(TestTypeOf), U8(5),
|
B(TestTypeOf), U8(5),
|
||||||
B(JumpIfFalse), U8(4),
|
B(JumpIfFalse), U8(4),
|
||||||
B(Jump), U8(18),
|
B(Jump), U8(18),
|
||||||
B(Wide), B(LdaSmi), I16(141),
|
B(Wide), B(LdaSmi), I16(142),
|
||||||
B(Star), R(20),
|
B(Star), R(20),
|
||||||
B(LdaConstant), U8(7),
|
B(LdaConstant), U8(7),
|
||||||
B(Star), R(21),
|
B(Star), R(21),
|
||||||
@ -1358,7 +1358,7 @@ bytecodes: [
|
|||||||
B(TestTypeOf), U8(5),
|
B(TestTypeOf), U8(5),
|
||||||
B(JumpIfFalse), U8(4),
|
B(JumpIfFalse), U8(4),
|
||||||
B(Jump), U8(18),
|
B(Jump), U8(18),
|
||||||
B(Wide), B(LdaSmi), I16(141),
|
B(Wide), B(LdaSmi), I16(142),
|
||||||
B(Star), R(20),
|
B(Star), R(20),
|
||||||
B(LdaConstant), U8(9),
|
B(LdaConstant), U8(9),
|
||||||
B(Star), R(21),
|
B(Star), R(21),
|
||||||
|
@ -257,7 +257,7 @@ bytecodes: [
|
|||||||
B(TestTypeOf), U8(5),
|
B(TestTypeOf), U8(5),
|
||||||
B(JumpIfFalse), U8(4),
|
B(JumpIfFalse), U8(4),
|
||||||
B(Jump), U8(18),
|
B(Jump), U8(18),
|
||||||
B(Wide), B(LdaSmi), I16(141),
|
B(Wide), B(LdaSmi), I16(142),
|
||||||
B(Star), R(14),
|
B(Star), R(14),
|
||||||
B(LdaConstant), U8(15),
|
B(LdaConstant), U8(15),
|
||||||
B(Star), R(15),
|
B(Star), R(15),
|
||||||
|
@ -231,7 +231,7 @@ bytecodes: [
|
|||||||
B(JumpIfUndefined), U8(6),
|
B(JumpIfUndefined), U8(6),
|
||||||
B(Ldar), R(3),
|
B(Ldar), R(3),
|
||||||
B(JumpIfNotNull), U8(16),
|
B(JumpIfNotNull), U8(16),
|
||||||
B(LdaSmi), I8(71),
|
B(LdaSmi), I8(72),
|
||||||
B(Star), R(4),
|
B(Star), R(4),
|
||||||
B(LdaConstant), U8(1),
|
B(LdaConstant), U8(1),
|
||||||
B(Star), R(5),
|
B(Star), R(5),
|
||||||
|
7
test/message/fail/dynamic-import-missing-specifier.js
Normal file
7
test/message/fail/dynamic-import-missing-specifier.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// Copyright 2016 the V8 project authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
//
|
||||||
|
// Flags: --harmony-dynamic-import
|
||||||
|
|
||||||
|
import();
|
4
test/message/fail/dynamic-import-missing-specifier.out
Normal file
4
test/message/fail/dynamic-import-missing-specifier.out
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
*%(basename)s:7: SyntaxError: import() requires a specifier
|
||||||
|
import();
|
||||||
|
^
|
||||||
|
SyntaxError: import() requires a specifier
|
Loading…
Reference in New Issue
Block a user