-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add additional tests for 'for-of' and 'for-await-of'
- Loading branch information
Showing
14 changed files
with
261 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
test/language/statements/await-using/syntax/await-using-valid-for-await-using-of-of.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (C) 2011 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: pending | ||
description: > | ||
await using: 'for (await using of of' interpreted as 'await using' | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
async function f() { | ||
for (await using of of []) { } | ||
} |
21 changes: 21 additions & 0 deletions
21
test/language/statements/for-await-of/head-await-using-init.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 []) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 []) {} | ||
} |
17 changes: 17 additions & 0 deletions
17
test/language/statements/for-of/head-await-using-bound-names-fordecl-tdz.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
/*--- | ||
es6id: 13.6.4.12_S2 | ||
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]) {} | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
test/language/statements/for-of/head-await-using-bound-names-in-stmt.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
/*--- | ||
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 | ||
es6id: 13.7.5 | ||
flags: [module] | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
$DONOTEVALUATE(); | ||
|
||
for (await using x of []) { | ||
var x; | ||
} |
18 changes: 18 additions & 0 deletions
18
test/language/statements/for-of/head-await-using-bound-names-let.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 []) {} | ||
} |
23 changes: 23 additions & 0 deletions
23
test/language/statements/for-of/head-await-using-fresh-binding-per-iteration.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: pending | ||
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`"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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-iteration-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 []) {} | ||
} |
13 changes: 13 additions & 0 deletions
13
test/language/statements/for-of/head-using-bound-names-fordecl-tdz.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
/*--- | ||
es6id: 13.6.4.12_S2 | ||
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]) {} | ||
}); |
20 changes: 20 additions & 0 deletions
20
test/language/statements/for-of/head-using-bound-names-in-stmt.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
es6id: 13.7.5 | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
$DONOTEVALUATE(); | ||
|
||
for (using x of []) { | ||
var x; | ||
} |
17 changes: 17 additions & 0 deletions
17
test/language/statements/for-of/head-using-bound-names-let.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 []) {} |
22 changes: 22 additions & 0 deletions
22
test/language/statements/for-of/head-using-fresh-binding-per-iteration.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: pending | ||
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`"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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-iteration-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 []) {} |
14 changes: 14 additions & 0 deletions
14
test/language/statements/using/syntax/using-invalid-for-using-of-of.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright (C) 2011 the V8 project authors. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
/*--- | ||
esid: pending | ||
description: > | ||
using: 'for (using of' is always interpreted as identifier | ||
negative: | ||
phase: parse | ||
type: SyntaxError | ||
features: [explicit-resource-management] | ||
---*/ | ||
|
||
$DONOTEVALUATE(); | ||
for (using of of [1, 2, 3]) { } |