|
1 | 1 | //-------------------------------------------------------------------------------------------------------
|
2 | 2 | // Copyright (C) Microsoft. All rights reserved.
|
| 3 | +// Copyright (c) ChakraCore Project Contributors. All rights reserved. |
3 | 4 | // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
|
4 | 5 | //-------------------------------------------------------------------------------------------------------
|
5 | 6 |
|
@@ -58,26 +59,26 @@ var tests = [
|
58 | 59 | {
|
59 | 60 | name: "Await in eval global scope",
|
60 | 61 | body: function () {
|
61 |
| - assert.throws(function () { eval("var result = await call();"); }, SyntaxError, "'await' keyword is not allowed in eval global scope", "Expected ';'"); |
62 |
| - assert.throws(function () { eval("await call();"); }, SyntaxError, "'await' keyword is not allowed in eval global scope", "Expected ';'"); |
| 62 | + assert.throws(function () { eval("var result = await call();"); }, SyntaxError, "'await' keyword is not allowed in eval global scope", `'await' expression not allowed in this context`); |
| 63 | + assert.throws(function () { eval("await call();"); }, SyntaxError, "'await' keyword is not allowed in eval global scope", `'await' expression not allowed in this context`); |
63 | 64 |
|
64 |
| - assert.throws(function () { eval("await a;"); }, SyntaxError, "'await' keyword is not allowed in eval global scope", "Expected ';'"); |
65 |
| - assert.throws(function () { eval("await a[0];"); }, SyntaxError, "'await' keyword is not allowed in eval global scope", "Expected ';'"); |
66 |
| - assert.throws(function () { eval("await o.p;"); }, SyntaxError, "'await' keyword is not allowed in eval global scope", "Expected ';'"); |
| 65 | + assert.throws(function () { eval("await a;"); }, SyntaxError, "'await' keyword is not allowed in eval global scope", `'await' expression not allowed in this context`); |
| 66 | + assert.throws(function () { eval("await a[0];"); }, SyntaxError, "'await' keyword is not allowed in eval global scope", `'await' expression not allowed in this context`); |
| 67 | + assert.throws(function () { eval("await o.p;"); }, SyntaxError, "'await' keyword is not allowed in eval global scope", `'await' expression not allowed in this context`); |
67 | 68 | assert.throws(function () { eval("a[await p];"); }, SyntaxError, "'await' keyword is not allowed in eval global scope", "Expected ']'");
|
68 |
| - assert.throws(function () { eval("a + await p;"); }, SyntaxError, "'await' keyword is not allowed in eval global scope", "Expected ';'"); |
69 |
| - assert.throws(function () { eval("await p + await q;"); }, SyntaxError, "'await' keyword is not allowed in eval global scope", "Expected ';'"); |
| 69 | + assert.throws(function () { eval("a + await p;"); }, SyntaxError, "'await' keyword is not allowed in eval global scope", `'await' expression not allowed in this context`); |
| 70 | + assert.throws(function () { eval("await p + await q;"); }, SyntaxError, "'await' keyword is not allowed in eval global scope", `'await' expression not allowed in this context`); |
70 | 71 | assert.throws(function () { eval("foo(await p, await q);"); }, SyntaxError, "'await' keyword is not allowed in eval global scope", "Expected ')'");
|
71 | 72 |
|
72 | 73 | assert.throws(function () { eval("var lambdaParenNoArg = await () => x < y;"); }, SyntaxError, "'await' keyword is not allowed with a non-async lambda expression", "Syntax error");
|
73 |
| - assert.throws(function () { eval("var lambdaArgs = await async (a, b ,c) => a + b + c;"); }, SyntaxError, "There miss parenthises", "Expected ';'"); |
| 74 | + assert.throws(function () { eval("var lambdaArgs = await async (a, b ,c) => a + b + c;"); }, SyntaxError, "There miss parenthises", `'await' expression not allowed in this context`); |
74 | 75 | assert.throws(function () { eval("var lambdaArgs = await (async (a, b ,c) => a + b + c);"); }, ReferenceError, "The 'await' function doesn't exists in this scope", "'await' is not defined");
|
75 | 76 | }
|
76 | 77 | },
|
77 | 78 | {
|
78 | 79 | name: "Await in a non-async function",
|
79 | 80 | body: function () {
|
80 |
| - assert.throws(function () { eval("function method() { var x = await call(); }"); }, SyntaxError, "'await' cannot be used in a non-async function.", "Expected ';'"); |
| 81 | + assert.throws(function () { eval("function method() { var x = await call(); }"); }, SyntaxError, "'await' cannot be used in a non-async function.", `'await' expression not allowed in this context`); |
81 | 82 | }
|
82 | 83 | },
|
83 | 84 | {
|
@@ -216,6 +217,14 @@ var tests = [
|
216 | 217 | assert.throws(function () { eval("async function af() { (b = (c = await => {}) => {}) => {}; }"); }, SyntaxError, "await cannot appear as the formal name of an unparathensized arrow function in a nested case too", "Unexpected token '=>' after 'await'");
|
217 | 218 | }
|
218 | 219 | },
|
| 220 | + { |
| 221 | + name: "Specific error message when using 'await' as a keyword outside 'async' context", |
| 222 | + body: function () { |
| 223 | + assert.throws(function () { |
| 224 | + eval(`await new Promise(() => {});`); |
| 225 | + }, SyntaxError, "await is not a keyword here", `'await' expression not allowed in this context`); |
| 226 | + } |
| 227 | + } |
219 | 228 | ];
|
220 | 229 |
|
221 | 230 | testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });
|
0 commit comments