Commit 62a7c080 authored by Sathya Gunasekaran's avatar Sathya Gunasekaran Committed by Commit Bot

[parser] Provide better error when incorrectly using await

Before we try to do ASI and fail with a generic error, we special case
for the await token in the failure case.

Bug: v8:6572, v8:6513
Change-Id: Ia050c98b5a5b20bc326f429a367635b8553e4112
Reviewed-on: https://chromium-review.googlesource.com/582210Reviewed-by: 's avatarDaniel Ehrenberg <littledan@chromium.org>
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46885}
parent eb65f35e
......@@ -270,6 +270,7 @@ class ErrorUtils : public AllStatic {
"ArrayBuffer subclass returned this from species constructor") \
T(ArrayFunctionsOnFrozen, "Cannot modify frozen array elements") \
T(ArrayFunctionsOnSealed, "Cannot add/remove sealed array elements") \
T(AwaitNotInAsyncFunction, "await is only valid in async function") \
T(AtomicsWaitNotAllowed, "Atomics.wait cannot be called in this context") \
T(CalledNonCallable, "% is not a function") \
T(CalledOnNonObject, "% called on non-object") \
......
......@@ -698,7 +698,24 @@ class ParserBase {
tok == Token::EOS) {
return;
}
Expect(Token::SEMICOLON, ok);
Token::Value current = scanner()->current_token();
Scanner::Location current_location = scanner()->location();
Token::Value next = Next();
if (next == Token::SEMICOLON) {
return;
}
*ok = false;
if (current == Token::AWAIT) {
DCHECK(!is_async_function());
ReportMessageAt(current_location,
MessageTemplate::kAwaitNotInAsyncFunction, kSyntaxError);
return;
}
ReportUnexpectedToken(next);
}
// Dummy functions, just useful as arguments to CHECK_OK_CUSTOM.
......
......@@ -419,7 +419,7 @@ bytecodes: [
B(TestTypeOf), U8(5),
B(JumpIfFalse), U8(4),
B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(131),
B(Wide), B(LdaSmi), I16(132),
B(Star), R(19),
B(LdaConstant), U8(15),
B(Star), R(20),
......@@ -720,7 +720,7 @@ bytecodes: [
B(TestTypeOf), U8(5),
B(JumpIfFalse), U8(4),
B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(131),
B(Wide), B(LdaSmi), I16(132),
B(Star), R(16),
B(LdaConstant), U8(21),
B(Star), R(17),
......@@ -784,7 +784,7 @@ bytecodes: [
B(JumpIfToBooleanFalse), U8(4),
B(Jump), U8(7),
B(CallRuntime), U16(Runtime::kThrowIteratorResultNotAnObject), R(7), U8(1),
B(Wide), B(LdaSmi), I16(145),
B(Wide), B(LdaSmi), I16(146),
B(Star), R(16),
B(LdaConstant), U8(21),
B(Star), R(17),
......
......@@ -152,7 +152,7 @@ bytecodes: [
B(TestTypeOf), U8(5),
B(JumpIfFalse), U8(4),
B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(131),
B(Wide), B(LdaSmi), I16(132),
B(Star), R(20),
B(LdaConstant), U8(13),
B(Star), R(21),
......@@ -456,7 +456,7 @@ bytecodes: [
B(TestTypeOf), U8(5),
B(JumpIfFalse), U8(4),
B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(131),
B(Wide), B(LdaSmi), I16(132),
B(Star), R(20),
B(LdaConstant), U8(13),
B(Star), R(21),
......@@ -784,7 +784,7 @@ bytecodes: [
B(TestTypeOf), U8(5),
B(JumpIfFalse), U8(4),
B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(131),
B(Wide), B(LdaSmi), I16(132),
B(Star), R(20),
B(LdaConstant), U8(13),
B(Star), R(21),
......@@ -1039,7 +1039,7 @@ bytecodes: [
B(TestTypeOf), U8(5),
B(JumpIfFalse), U8(4),
B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(131),
B(Wide), B(LdaSmi), I16(132),
B(Star), R(16),
B(LdaConstant), U8(10),
B(Star), R(17),
......
......@@ -85,7 +85,7 @@ bytecodes: [
B(TestTypeOf), U8(5),
B(JumpIfFalse), U8(4),
B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(131),
B(Wide), B(LdaSmi), I16(132),
B(Star), R(11),
B(LdaConstant), U8(8),
B(Star), R(12),
......@@ -225,7 +225,7 @@ bytecodes: [
B(TestTypeOf), U8(5),
B(JumpIfFalse), U8(4),
B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(131),
B(Wide), B(LdaSmi), I16(132),
B(Star), R(12),
B(LdaConstant), U8(8),
B(Star), R(13),
......@@ -377,7 +377,7 @@ bytecodes: [
B(TestTypeOf), U8(5),
B(JumpIfFalse), U8(4),
B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(131),
B(Wide), B(LdaSmi), I16(132),
B(Star), R(11),
B(LdaConstant), U8(8),
B(Star), R(12),
......@@ -519,7 +519,7 @@ bytecodes: [
B(TestTypeOf), U8(5),
B(JumpIfFalse), U8(4),
B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(131),
B(Wide), B(LdaSmi), I16(132),
B(Star), R(10),
B(LdaConstant), U8(10),
B(Star), R(11),
......
......@@ -91,7 +91,7 @@ bytecodes: [
B(TestTypeOf), U8(5),
B(JumpIfFalse), U8(4),
B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(131),
B(Wide), B(LdaSmi), I16(132),
B(Star), R(13),
B(LdaConstant), U8(7),
B(Star), R(14),
......@@ -268,7 +268,7 @@ bytecodes: [
B(TestTypeOf), U8(5),
B(JumpIfFalse), U8(4),
B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(131),
B(Wide), B(LdaSmi), I16(132),
B(Star), R(12),
B(LdaConstant), U8(11),
B(Star), R(13),
......@@ -423,7 +423,7 @@ bytecodes: [
B(TestTypeOf), U8(5),
B(JumpIfFalse), U8(4),
B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(131),
B(Wide), B(LdaSmi), I16(132),
B(Star), R(11),
B(LdaConstant), U8(9),
B(Star), R(12),
......@@ -529,7 +529,7 @@ bytecodes: [
B(JumpIfUndefined), U8(6),
B(Ldar), R(6),
B(JumpIfNotNull), U8(16),
B(LdaSmi), I8(62),
B(LdaSmi), I8(63),
B(Star), R(17),
B(LdaConstant), U8(4),
B(Star), R(18),
......@@ -584,7 +584,7 @@ bytecodes: [
B(TestTypeOf), U8(5),
B(JumpIfFalse), U8(4),
B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(131),
B(Wide), B(LdaSmi), I16(132),
B(Star), R(16),
B(LdaConstant), U8(9),
B(Star), R(17),
......@@ -763,7 +763,7 @@ bytecodes: [
B(TestTypeOf), U8(5),
B(JumpIfFalse), U8(4),
B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(131),
B(Wide), B(LdaSmi), I16(132),
B(Star), R(17),
B(LdaConstant), U8(10),
B(Star), R(18),
......@@ -969,7 +969,7 @@ bytecodes: [
B(TestTypeOf), U8(5),
B(JumpIfFalse), U8(4),
B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(131),
B(Wide), B(LdaSmi), I16(132),
B(Star), R(16),
B(LdaConstant), U8(14),
B(Star), R(17),
......@@ -1135,7 +1135,7 @@ bytecodes: [
B(TestTypeOf), U8(5),
B(JumpIfFalse), U8(4),
B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(131),
B(Wide), B(LdaSmi), I16(132),
B(Star), R(20),
B(LdaConstant), U8(7),
B(Star), R(21),
......@@ -1392,7 +1392,7 @@ bytecodes: [
B(TestTypeOf), U8(5),
B(JumpIfFalse), U8(4),
B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(131),
B(Wide), B(LdaSmi), I16(132),
B(Star), R(21),
B(LdaConstant), U8(9),
B(Star), R(22),
......
......@@ -272,7 +272,7 @@ bytecodes: [
B(TestTypeOf), U8(5),
B(JumpIfFalse), U8(4),
B(Jump), U8(18),
B(Wide), B(LdaSmi), I16(131),
B(Wide), B(LdaSmi), I16(132),
B(Star), R(15),
B(LdaConstant), U8(15),
B(Star), R(16),
......
......@@ -231,7 +231,7 @@ bytecodes: [
B(JumpIfUndefined), U8(6),
B(Ldar), R(3),
B(JumpIfNotNull), U8(16),
B(LdaSmi), I8(62),
B(LdaSmi), I8(63),
B(Star), R(4),
B(LdaConstant), U8(1),
B(Star), R(5),
......
// Copyright 2017 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.
function f() { await Promise.resolve(); }
*%(basename)s:5: SyntaxError: await is only valid in async function
function f() { await Promise.resolve(); }
^^^^^
SyntaxError: await is only valid in async function
......@@ -562,3 +562,42 @@ assertDoesNotThrow(gaga);
%RunMicrotasks();
assertEquals(["a", "b", "c"], log);
}
{
function f1() {
var x;
with ({get await() { return [42] }}) {
x = await
[0];
};
return x;
}
assertEquals(42, f1());
async function f2() {
var x;
with ({get await() { return [42] }}) {
x = await
[0];
};
return x;
}
var ans;
f2().then(x => ans = x).catch(e => ans = e);
%RunMicrotasks();
assertEquals([0], ans);
}
{
function f1() {
var x, y;
with ({get await() { return [42] }}) {
x = await
y = 1
};
return y;
}
assertEquals(1, f1());
}
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