diff --git a/test/language/statements/for-await-of/head-await-using-init.js b/test/language/statements/for-await-of/head-await-using-init.js new file mode 100644 index 0000000000..0217069641 --- /dev/null +++ b/test/language/statements/for-await-of/head-await-using-init.js @@ -0,0 +1,21 @@ +// Copyright (C) 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-iteration-statements +description: > + ForDeclaration containing 'await using' does not allow initializer. +info: | + IterationStatement: + for await (ForDeclaration of AssignmentExpression) Statement +negative: + phase: parse + type: SyntaxError +features: [async-iteration, explicit-resource-management] +---*/ + +$DONOTEVALUATE(); + +async function fn() { + const obj = { async [Symbol.asyncDispose]() {} }; + for await (await using x = obj of []) {} +} diff --git a/test/language/statements/for-await-of/head-using-init.js b/test/language/statements/for-await-of/head-using-init.js new file mode 100644 index 0000000000..98dabb9ac0 --- /dev/null +++ b/test/language/statements/for-await-of/head-using-init.js @@ -0,0 +1,21 @@ +// Copyright (C) 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-iteration-statements +description: > + ForDeclaration containing 'using' does not allow initializer. +info: | + IterationStatement: + for await (ForDeclaration of AssignmentExpression) Statement +negative: + phase: parse + type: SyntaxError +features: [async-iteration, explicit-resource-management] +---*/ + +$DONOTEVALUATE(); + +async function fn() { + const obj = { [Symbol.dispose]() {} }; + for await (using x = obj of []) {} +} diff --git a/test/language/statements/for-of/head-await-using-bound-names-fordecl-tdz.js b/test/language/statements/for-of/head-await-using-bound-names-fordecl-tdz.js new file mode 100644 index 0000000000..c03a371aa8 --- /dev/null +++ b/test/language/statements/for-of/head-await-using-bound-names-fordecl-tdz.js @@ -0,0 +1,17 @@ +// Copyright (C) 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-for-in-and-for-of-statements +description: > + ForIn/Of: Bound names of ForDeclaration are in TDZ (for-of) +flags: [async] +includes: [asyncHelpers.js] +features: [explicit-resource-management] +---*/ + +asyncTest(async function () { + await assert.throwsAsync(ReferenceError, async function() { + let x = { async [Symbol.asyncDispose]() { } }; + for (await using x of [x]) {} + }); +}); diff --git a/test/language/statements/for-of/head-await-using-bound-names-in-stmt.js b/test/language/statements/for-of/head-await-using-bound-names-in-stmt.js new file mode 100644 index 0000000000..a13104a725 --- /dev/null +++ b/test/language/statements/for-of/head-await-using-bound-names-in-stmt.js @@ -0,0 +1,20 @@ +// Copyright (C) 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: The body may not re-declare variables declared in the head +negative: + phase: parse + type: SyntaxError +info: | + It is a Syntax Error if any element of the BoundNames of ForDeclaration + also occurs in the VarDeclaredNames of Statement. +esid: sec-for-in-and-for-of-statements +flags: [module] +features: [explicit-resource-management] +---*/ + +$DONOTEVALUATE(); + +for (await using x of []) { + var x; +} diff --git a/test/language/statements/for-of/head-await-using-bound-names-let.js b/test/language/statements/for-of/head-await-using-bound-names-let.js new file mode 100644 index 0000000000..bf6b1ef311 --- /dev/null +++ b/test/language/statements/for-of/head-await-using-bound-names-let.js @@ -0,0 +1,18 @@ +// Copyright (C) 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-for-in-and-for-of-statements +description: ForDeclaration containing 'await using' may not contain a binding for `let` +negative: + phase: parse + type: SyntaxError +info: | + It is a Syntax Error if the BoundNames of ForDeclaration contains "let". +flags: [noStrict] +features: [explicit-resource-management] +---*/ + +$DONOTEVALUATE(); +async function f() { + for (await using let of []) {} +} diff --git a/test/language/statements/for-of/head-await-using-fresh-binding-per-iteration.js b/test/language/statements/for-of/head-await-using-fresh-binding-per-iteration.js new file mode 100644 index 0000000000..75c85c0911 --- /dev/null +++ b/test/language/statements/for-of/head-await-using-fresh-binding-per-iteration.js @@ -0,0 +1,23 @@ +// Copyright (C) 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-for-in-and-for-of-statements +description: > + ForDeclaration containing 'await using' creates a fresh binding per iteration +flags: [module] +features: [explicit-resource-management] +---*/ + +let f = [undefined, undefined, undefined]; + +const obj1 = { async [Symbol.asyncDispose]() { } }; +const obj2 = { async [Symbol.asyncDispose]() { } }; +const obj3 = { async [Symbol.asyncDispose]() { } }; + +let i = 0; +for (await using x of [obj1, obj2, obj3]) { + f[i++] = function() { return x; }; +} +assert.sameValue(f[0](), obj1, "`f[0]()` returns `obj1`"); +assert.sameValue(f[1](), obj2, "`f[1]()` returns `obj2`"); +assert.sameValue(f[2](), obj3, "`f[2]()` returns `obj3`"); diff --git a/test/language/statements/for-of/head-await-using-init.js b/test/language/statements/for-of/head-await-using-init.js new file mode 100644 index 0000000000..fdb1744639 --- /dev/null +++ b/test/language/statements/for-of/head-await-using-init.js @@ -0,0 +1,22 @@ +// Copyright (C) 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-for-in-and-for-of-statements +description: > + ForDeclaration containing 'await using' does not support an initializer +info: | + IterationStatement: + for (ForDeclaration of AssignmentExpression) Statement +negative: + phase: parse + type: SyntaxError +features: [explicit-resource-management] +---*/ + +$DONOTEVALUATE(); + +const obj = { [Symbol.dispose]() { } }; +async function f() { + for (await using x = obj of []) {} +} diff --git a/test/language/statements/for-of/head-using-bound-names-fordecl-tdz.js b/test/language/statements/for-of/head-using-bound-names-fordecl-tdz.js new file mode 100644 index 0000000000..60e7e5de45 --- /dev/null +++ b/test/language/statements/for-of/head-using-bound-names-fordecl-tdz.js @@ -0,0 +1,13 @@ +// Copyright (C) 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-for-in-and-for-of-statements +description: > + ForIn/Of: Bound names of ForDeclaration are in TDZ (for-of) +features: [explicit-resource-management] +---*/ + +assert.throws(ReferenceError, function() { + let x = { [Symbol.dispose]() { } }; + for (using x of [x]) {} +}); diff --git a/test/language/statements/for-of/head-using-bound-names-in-stmt.js b/test/language/statements/for-of/head-using-bound-names-in-stmt.js new file mode 100644 index 0000000000..9ab26d06f5 --- /dev/null +++ b/test/language/statements/for-of/head-using-bound-names-in-stmt.js @@ -0,0 +1,19 @@ +// Copyright (C) 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: The body may not re-declare variables declared in the head +negative: + phase: parse + type: SyntaxError +info: | + It is a Syntax Error if any element of the BoundNames of ForDeclaration + also occurs in the VarDeclaredNames of Statement. +esid: sec-for-in-and-for-of-statements +features: [explicit-resource-management] +---*/ + +$DONOTEVALUATE(); + +for (using x of []) { + var x; +} diff --git a/test/language/statements/for-of/head-using-bound-names-let.js b/test/language/statements/for-of/head-using-bound-names-let.js new file mode 100644 index 0000000000..7d86a15e2e --- /dev/null +++ b/test/language/statements/for-of/head-using-bound-names-let.js @@ -0,0 +1,17 @@ +// Copyright (C) 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-for-in-and-for-of-statements +description: ForDeclaration containing 'using' may not contain a binding for `let` +negative: + phase: parse + type: SyntaxError +info: | + It is a Syntax Error if the BoundNames of ForDeclaration contains "let". +flags: [noStrict] +features: [explicit-resource-management] +---*/ + +$DONOTEVALUATE(); + +for (using let of []) {} diff --git a/test/language/statements/for-of/head-using-fresh-binding-per-iteration.js b/test/language/statements/for-of/head-using-fresh-binding-per-iteration.js new file mode 100644 index 0000000000..baaacd3756 --- /dev/null +++ b/test/language/statements/for-of/head-using-fresh-binding-per-iteration.js @@ -0,0 +1,22 @@ +// Copyright (C) 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-for-in-and-for-of-statements +description: > + ForDeclaration containing 'using' creates a fresh binding per iteration +features: [explicit-resource-management] +---*/ + +let f = [undefined, undefined, undefined]; + +const obj1 = { [Symbol.dispose]() { } }; +const obj2 = { [Symbol.dispose]() { } }; +const obj3 = { [Symbol.dispose]() { } }; + +let i = 0; +for (using x of [obj1, obj2, obj3]) { + f[i++] = function() { return x; }; +} +assert.sameValue(f[0](), obj1, "`f[0]()` returns `obj1`"); +assert.sameValue(f[1](), obj2, "`f[1]()` returns `obj2`"); +assert.sameValue(f[2](), obj3, "`f[2]()` returns `obj3`"); diff --git a/test/language/statements/for-of/head-using-init.js b/test/language/statements/for-of/head-using-init.js new file mode 100644 index 0000000000..6fb01937fa --- /dev/null +++ b/test/language/statements/for-of/head-using-init.js @@ -0,0 +1,20 @@ +// Copyright (C) 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-for-in-and-for-of-statements +description: > + ForDeclaration containing 'using' does not support an initializer +info: | + IterationStatement: + for (ForDeclaration of AssignmentExpression) Statement +negative: + phase: parse + type: SyntaxError +features: [explicit-resource-management] +---*/ + +$DONOTEVALUATE(); + +const obj = { [Symbol.dispose]() { } }; +for (using x = obj of []) {}