mirror of
https://github.com/tc39/test262.git
synced 2025-07-28 00:14:35 +02:00
[explicit-resource-management] Add remaining tests specific to using in for-of and for-await-of syntax (#4484)
This commit is contained in:
parent
4b5d36ab6e
commit
419d85ad21
@ -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 []) {}
|
||||
}
|
21
test/language/statements/for-await-of/head-using-init.js
Normal file
21
test/language/statements/for-await-of/head-using-init.js
Normal 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 []) {}
|
||||
}
|
@ -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]) {}
|
||||
});
|
||||
});
|
@ -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;
|
||||
}
|
@ -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 []) {}
|
||||
}
|
@ -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`");
|
22
test/language/statements/for-of/head-await-using-init.js
Normal file
22
test/language/statements/for-of/head-await-using-init.js
Normal 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 []) {}
|
||||
}
|
@ -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]) {}
|
||||
});
|
@ -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;
|
||||
}
|
@ -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 []) {}
|
@ -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`");
|
20
test/language/statements/for-of/head-using-init.js
Normal file
20
test/language/statements/for-of/head-using-init.js
Normal 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 []) {}
|
Loading…
x
Reference in New Issue
Block a user