Commit d08fd93b authored by gsathya's avatar gsathya Committed by Commit bot

[ESnext] Disallow using new with import()

Throw a syntax error on "new import(1)"  expression. Adds a new error msg as well.

BUG=v8:5785

Review-Url: https://codereview.chromium.org/2661113002
Cr-Commit-Position: refs/heads/master@{#42827}
parent ea96fdec
......@@ -308,6 +308,7 @@ class ErrorUtils : public AllStatic {
T(IllegalInvocation, "Illegal invocation") \
T(ImmutablePrototypeSet, \
"Immutable prototype object '%' cannot have their prototype set") \
T(ImportCallNotNewExpression, "Cannot use new with import") \
T(IncompatibleMethodReceiver, "Method % called on incompatible receiver %") \
T(InstanceofNonobjectProto, \
"Function has non-object prototype '%' in instanceof check") \
......
......@@ -3321,6 +3321,11 @@ ParserBase<Impl>::ParseMemberWithNewPrefixesExpression(bool* is_async,
if (peek() == Token::SUPER) {
const bool is_new = true;
result = ParseSuperExpression(is_new, CHECK_OK);
} else if (allow_harmony_dynamic_import() && peek() == Token::IMPORT) {
impl()->ReportMessageAt(scanner()->peek_location(),
MessageTemplate::kImportCallNotNewExpression);
*ok = false;
return impl()->EmptyExpression();
} else if (peek() == Token::PERIOD) {
return ParseNewTargetExpression(CHECK_OK);
} else {
......
......@@ -88,7 +88,7 @@ bytecodes: [
B(TestEqualStrict), R(12), U8(21),
B(JumpIfFalse), U8(4),
B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(130),
B(Wide), B(LdaSmi), I16(131),
B(Star), R(12),
B(LdaConstant), U8(9),
B(Star), R(13),
......@@ -233,7 +233,7 @@ bytecodes: [
B(TestEqualStrict), R(13), U8(20),
B(JumpIfFalse), U8(4),
B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(130),
B(Wide), B(LdaSmi), I16(131),
B(Star), R(13),
B(LdaConstant), U8(9),
B(Star), R(14),
......@@ -391,7 +391,7 @@ bytecodes: [
B(TestEqualStrict), R(12), U8(23),
B(JumpIfFalse), U8(4),
B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(130),
B(Wide), B(LdaSmi), I16(131),
B(Star), R(12),
B(LdaConstant), U8(9),
B(Star), R(13),
......@@ -539,7 +539,7 @@ bytecodes: [
B(TestEqualStrict), R(11), U8(26),
B(JumpIfFalse), U8(4),
B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(130),
B(Wide), B(LdaSmi), I16(131),
B(Star), R(11),
B(LdaConstant), U8(11),
B(Star), R(12),
......
......@@ -496,7 +496,7 @@ bytecodes: [
B(TestEqualStrict), R(11), U8(21),
B(JumpIfFalse), U8(4),
B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(130),
B(Wide), B(LdaSmi), I16(131),
B(Star), R(11),
B(LdaConstant), U8(11),
B(Star), R(12),
......
......@@ -4153,7 +4153,6 @@ TEST(ImportExpressionSuccess) {
};
const char* data[] = {
"new import(x)",
"import(1)",
"import(y=x)",
"f(...[import(y=x)])",
......@@ -4231,6 +4230,7 @@ TEST(ImportExpressionErrors) {
"import+",
"import = 1",
"import.wat",
"new import(x)",
NULL
};
......
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