// Copyright 2025 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: --js-staging
// Note that 'await' and 'yield' are allowed as BindingIdentifiers.
constreservedWords=
'break case catch class const continue debugger default delete do else enum export extends false finally for function if import in instanceof new null return super switch this throw true try typeof var void while with'
.split(' ');
(asyncfunctionAsyncLoops(){
// Keywords disallowed.
for(constrwofreservedWords){
assertThrows(
()=>Function(`async function() { for (await using ${rw} of []) {} }`),
SyntaxError);
assertThrows(
()=>Function(
`async function() { for await (await using ${rw} of []) {} }`),
SyntaxError);
}
// 'await' is a keyword inside async functions.
assertThrows(
()=>Function(`async function() { for (await using await of []) {} }`),
SyntaxError);
assertThrows(
()=>Function(
`async function() { for await (await using await of []) {} }`),
SyntaxError);
// Patterns disallowed.
assertThrows(
()=>Function('async function() { for (await using {a} of []) {} }'),
SyntaxError);
assertThrows(
()=>Function('async function() { for (await using [a] of []) {} }'),
SyntaxError);
assertThrows(
()=>
Function('async function() { for await (await using {a} of []) {} }'),
SyntaxError);
assertThrows(
()=>
Function('async function() { for await (await using [a] of []) {} }'),
SyntaxError);
// Disallowed in sync contexts.
assertThrows(()=>Function('for (await x of []) {}'),SyntaxError);
// The first 'of' is an identifier, second 'of' is the for-of.
for(awaitusingofof[]){}
forawait(awaitusingofof[]){}
// Other idents.
for(awaitusingstaticof[]){}
for(awaitusingyieldof[]){}
for(awaitusinggetof[]){}
for(awaitusingsetof[]){}
for(awaitusingusingof[]){}
for(awaitusingasyncof[]){}
for(awaitusingfooof[]){}
forawait(awaitusingstaticof[]){}
forawait(awaitusingyieldof[]){}
forawait(awaitusinggetof[]){}
forawait(awaitusingsetof[]){}
forawait(awaitusingusingof[]){}
forawait(awaitusingasyncof[]){}
forawait(awaitusingfooof[]){}
})();
(functionSyncLoops(){
// Keywords disallowed.
for(constrwofreservedWords){
assertThrows(()=>Function(`for (using ${rw} of []) {}`),SyntaxError);
}
// Patterns disallowed.
assertThrows(()=>Function('for (using {a} of []) {}'),SyntaxError);