Skip to content

[explicit-resource-management] Add remaining tests specific to using statement syntax #4483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: pending
description: >
using declarations mixed: with, without initializer
negative:
phase: parse
type: SyntaxError
features: [explicit-resource-management]
---*/

$DONOTEVALUATE();
{
using x = null, y;
}
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: pending
description: >
using declarations mixed: without, with initializer
negative:
phase: parse
type: SyntaxError
features: [explicit-resource-management]
---*/

$DONOTEVALUATE();
{
using x, y = null;
}
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: pending
description: >
using declarations without initializer
negative:
phase: parse
type: SyntaxError
features: [explicit-resource-management]
---*/

$DONOTEVALUATE();
{
using x;
}
Original file line number Diff line number Diff line change
@@ -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.

/*---
esid: pending
description: >
using declarations allowed at the top level of a module
info: |
UsingDeclaration : using BindingList ;

- It is a Syntax Error if the goal symbol is Script and UsingDeclaration is not contained, either directly or
indirectly, within a Block, CaseBlock, ForStatement, ForInOfStatement, FunctionBody, GeneratorBody,
AsyncGeneratorBody, AsyncFunctionBody, ClassStaticBlockBody, or ClassBody.

flags: [module]
features: [explicit-resource-management]
---*/

using x = null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: pending
description: >
'using' allows BindingIdentifier in lexical bindings
features: [explicit-resource-management]
---*/
{
using x = null;
}
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.

/*---
esid: pending
description: >
'using' allows multiple lexical bindings
features: [explicit-resource-management]
---*/

{
using x = null, y = null;
}
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: pending
description: >
using: |using let| split across two lines is treated as two statements.
info: |
Lexical declarations may not declare a binding named "let".
flags: [noStrict]
features: [explicit-resource-management]
---*/

{
using
let = "irrelevant initializer";

assert(typeof let === "string");
var using, let;
}
14 changes: 14 additions & 0 deletions test/language/statements/using/syntax/using-for-statement.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (C) 2011 the V8 project authors. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy-paste error? (Check this in a few places)

// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-for-statement
description: >
using: 'for (using x = ' and 'for (using of =' are interpreted as for loop
features: [explicit-resource-management]
---*/

for (using x = null;;) break;

// 'using of' lookahead restriction only applies to 'for-of'/'for-await-of'. In 'for' statement it is
// handled similar to `for (let of = null;;)`:
for (using of = null;;) break;
22 changes: 22 additions & 0 deletions test/language/statements/using/syntax/using-for-using-of-of.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (C) 2011 the V8 project authors. 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: >
using: 'for (using of' is always interpreted as identifier
features: [explicit-resource-management]
---*/

var using, of = [[9], [8], [7]], result = [];
for (using of of [0, 1, 2]) {
// ^^^^^ ^^^^^^^^^^^^
// | |
// | interpreted as element access `of[2]`
// |
// interpreted as identifier named `using`

result.push(using);
}

asserts.sameValue(result.length, 1);
asserts.sameValue(result[0], 7);
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: pending
description: >
'using' does not allow ArrayBindingPattern in lexical bindings, even after a valid lexical binding
negative:
phase: parse
type: SyntaxError
features: [explicit-resource-management]
---*/

$DONOTEVALUATE();

{
using x = null, [] = null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: pending
description: >
'using' does not break existing element access
features: [explicit-resource-management]
---*/

var using = [], x = 0;

{
using[x] = null;
}
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: pending
description: >
'using' does not allow ArrayBindingPattern in lexical bindings
negative:
phase: parse
type: SyntaxError
features: [explicit-resource-management]
---*/

$DONOTEVALUATE();

{
using [] = null;
}
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.

/*---
esid: pending
description: >
using: invalid assignment in next expression
features: [explicit-resource-management]
---*/

assert.throws(TypeError, function() {
for (using i = 0; i < 1; i++) {}
});
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.

/*---
esid: pending
description: >
using: invalid assignment in Statement body
features: [explicit-resource-management]
---*/

assert.throws(TypeError, function() {
for (using x of [1, 2, 3]) { x++ }
});
14 changes: 14 additions & 0 deletions test/language/statements/using/syntax/using-invalid-for-in.js
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: sec-for-in-and-for-of-statements
description: >
using: not allowed in for..in
negative:
phase: parse
type: SyntaxError
features: [explicit-resource-management]
---*/

$DONOTEVALUATE();
for (using x in [1, 2, 3]) { }
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: pending
description: >
'using' does not allow ObjectBindingPattern in lexical bindings, even after a valid lexical binding
negative:
phase: parse
type: SyntaxError
features: [explicit-resource-management]
---*/

$DONOTEVALUATE();

{
using x = null, {} = null;
}
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: pending
description: >
'using' does not allow ObjectBindingPattern in lexical bindings
negative:
phase: parse
type: SyntaxError
features: [explicit-resource-management]
---*/

$DONOTEVALUATE();

{
using {} = null;
}
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: pending
description: >
using declarations not allowed at the top level of eval
info: |
UsingDeclaration : using BindingList ;

- It is a Syntax Error if the goal symbol is Script and UsingDeclaration is not contained, either directly or
indirectly, within a Block, CaseBlock, ForStatement, ForInOfStatement, FunctionBody, GeneratorBody,
AsyncGeneratorBody, AsyncFunctionBody, ClassStaticBlockBody, or ClassBody.

features: [explicit-resource-management]
---*/

assert.throws(SyntaxError, function() {
eval('using x = null;')
});
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: >
using declarations not allowed at the top level of a Script
info: |
UsingDeclaration : using BindingList ;

- It is a Syntax Error if the goal symbol is Script and UsingDeclaration is not contained, either directly or
indirectly, within a Block, CaseBlock, ForStatement, ForInOfStatement, FunctionBody, GeneratorBody,
AsyncGeneratorBody, AsyncFunctionBody, ClassStaticBlockBody, or ClassBody.

negative:
phase: parse
type: SyntaxError
features: [explicit-resource-management]
---*/

$DONOTEVALUATE();
using x = null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: pending
description: >
outer using binding unchanged by for-loop using binding
features: [explicit-resource-management]
---*/

const outer_x = { [Symbol.dispose]() {} };
const outer_y = { [Symbol.dispose]() {} };
const inner_x = { [Symbol.dispose]() {} };
const inner_y = { [Symbol.dispose]() {} };

{
using x = outer_x;
using y = outer_y;
var i = 0;

for (using x = inner_x; i < 1; i++) {
using y = inner_y;

assert.sameValue(x, inner_x);
assert.sameValue(y, inner_y);
}
assert.sameValue(x, outer_x);
assert.sameValue(y, outer_y);
}
25 changes: 25 additions & 0 deletions test/language/statements/using/syntax/using.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: pending
description: >
module and block scope using
flags: [module]
features: [explicit-resource-management]
---*/

using z = null;

// Block local
{
using z = undefined;
}

assert.sameValue(z, null);

if (true) {
const obj = { [Symbol.dispose]() { } };
using z = obj;
assert.sameValue(z, obj);
}
Loading