Skip to content
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,30 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-let-and-const-declarations-static-semantics-early-errors
description: >
using declarations mixed: with, without initializer
info: |
Static Semantics : Early Errors
LexicalBinding : BindingIdentifier Initializer?

- It is a Syntax Error if Initializer is not present and IsConstantDeclaration of the LexicalDeclaration containing
this LexicalBinding is true.

Static Semantics : IsConstantDeclaration
UsingDeclaration :
`using` BindingList ;

1. Return true.

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,30 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-let-and-const-declarations-static-semantics-early-errors
description: >
using declarations mixed: without, with initializer
info: |
Static Semantics : Early Errors
LexicalBinding : BindingIdentifier Initializer?

- It is a Syntax Error if Initializer is not present and IsConstantDeclaration of the LexicalDeclaration containing
this LexicalBinding is true.

Static Semantics : IsConstantDeclaration
UsingDeclaration :
`using` BindingList ;

1. Return true.

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,30 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-let-and-const-declarations-static-semantics-early-errors
description: >
using declarations without initializer
info: |
Static Semantics : Early Errors
LexicalBinding : BindingIdentifier Initializer?

- It is a Syntax Error if Initializer is not present and IsConstantDeclaration of the LexicalDeclaration containing
this LexicalBinding is true.

Static Semantics : IsConstantDeclaration
UsingDeclaration :
`using` BindingList ;

1. Return true.

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: sec-let-const-using-and-await-using-declarations-static-semantics-early-errors
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, 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: sec-let-const-using-and-await-using-declarations
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: sec-let-const-using-and-await-using-declarations
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: sec-let-const-using-and-await-using-declarations
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) 2023 Ron Buckton. All rights reserved.
// 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) 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: >
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: sec-let-const-using-and-await-using-declarations
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: sec-let-const-using-and-await-using-declarations
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: sec-let-const-using-and-await-using-declarations
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,14 @@
// Copyright (C) 2023 Ron Buckton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-declarative-environment-records-setmutablebinding-n-v-s
description: >
using: invalid assignment in next expression. Since a `using` declaration introduces an immutable
binding, any attempt to change it results in a ReferenceError.
features: [explicit-resource-management]
---*/

assert.throws(ReferenceError, function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question about ReferenceError vs TypeError as in the await using PR.

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

/*---
esid: sec-declarative-environment-records-setmutablebinding-n-v-s
description: >
using: invalid assignment in Statement body. Since a `using` declaration introduces an immutable
binding, any attempt to change it results in a ReferenceError.
features: [explicit-resource-management]
---*/

assert.throws(ReferenceError, function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

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) 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: >
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: sec-let-const-using-and-await-using-declarations
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: sec-let-const-using-and-await-using-declarations
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: sec-let-const-using-and-await-using-declarations-static-semantics-early-errors
description: >
using declarations not allowed at the top level of eval. Note that Eval parses text using the Script goal.
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, 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: sec-let-const-using-and-await-using-declarations-static-semantics-early-errors
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, ForStatement, ForInOfStatement, FunctionBody, GeneratorBody,
AsyncGeneratorBody, AsyncFunctionBody, ClassStaticBlockBody, or ClassBody.

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

$DONOTEVALUATE();
using x = null;
Loading
Loading