[explicit-resource-management] Add remaining tests specific to using in for-of and for-await-of syntax (#4484)

This commit is contained in:
Ron Buckton 2025-05-21 16:45:41 -04:00 committed by GitHub
parent 4b5d36ab6e
commit 419d85ad21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 233 additions and 0 deletions

View File

@ -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 []) {}
}

View File

@ -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 []) {}
}

View File

@ -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]) {}
});
});

View File

@ -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;
}

View File

@ -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 []) {}
}

View File

@ -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`");

View File

@ -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 []) {}
}

View File

@ -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]) {}
});

View File

@ -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;
}

View File

@ -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 []) {}

View File

@ -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`");

View File

@ -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 []) {}