1// Copyright JS Foundation and other contributors, http://js.foundation 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15/* This test checks await expressions (nothing else). */ 16 17function check_syntax_error (code) 18{ 19 try { 20 eval (code) 21 assert (false) 22 } catch (e) { 23 assert (e instanceof SyntaxError) 24 } 25} 26 27check_syntax_error("(async function await() {})") 28check_syntax_error("(async function *await() {})") 29check_syntax_error("async function f(await) {}") 30check_syntax_error("(async function f(await) {})") 31check_syntax_error("async function f(a = await new Promise) {}") 32check_syntax_error("async function f() { function await() {} }") 33check_syntax_error("async await => 0"); 34check_syntax_error("async (await) => 0"); 35check_syntax_error("async function f() { await () => 0 }"); 36check_syntax_error("async (a) => a\\u0077ait a"); 37check_syntax_error("async (a) => { () => 0\na\\u0077ait a }"); 38 39// Valid uses of await 40 41async a => await a 42async a => { await a } 43async (a) => await a 44async(a) => { await a } 45 46// Nested async and non-async functions 47 48async (a) => { 49 () => await 50 await a 51} 52 53(a) => { 54 await 55 async (a) => await a 56 await 57 async (a) => await a 58 a\u0077ait 59} 60 61async function f1(a) { 62 await a 63 (function () { await ? async function(a) { await a } : await }) 64 await a 65} 66 67async (a) => { 68 await a; 69 () => await ? async (a) => await a : await 70 await a 71} 72 73async (a) => { 74 (a = () => await, [b] = (c)) 75 await a 76 (a, b = () => await) 77 await a 78} 79 80// Object initializers 81 82var o = { 83 async await(a) { 84 await a; 85 () => await 86 await a 87 }, 88 89 f(a) { 90 await 91 async (a) => await a 92 await 93 async (a) => await a 94 a\u0077ait 95 }, 96 97 async ["g"] () { 98 await a; 99 () => await 100 await a 101 } 102} 103 104async function f2(a) { 105 var o = { 106 [await a]() { await % await } 107 } 108 await a; 109} 110 111class C { 112 async await(a) { 113 await a; 114 () => await 115 await a 116 } 117 118 f(a) { 119 await 120 async (a) => await a 121 await 122 async (a) => await a 123 a\u0077ait 124 } 125 126 async ["g"] () { 127 await a; 128 () => await 129 await a 130 } 131} 132 133async function f3(a) { 134 class C { 135 [await a]() { await % await } 136 } 137 await a; 138} 139