Add tests for "Class Static Init. Blocks" proposal (#2968)

* Add tests for "Class Static Init. Blocks" proposal

This proposal is currently at "stage 3" in TC39's standardization
process.

* fixup! Add tests for "Class Static Init. Blocks" proposal

* Correct identifier reference

* Update tests for grammar

* Update tests for identifiers

* Add tests for scope derivation
This commit is contained in:
jugglinmike 2021-07-15 08:49:12 -04:00 committed by GitHub
parent f1f3a2d542
commit afe217b318
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
64 changed files with 1582 additions and 0 deletions

View File

@ -217,6 +217,10 @@ align-detached-buffer-semantics-with-web-reality
# https://github.com/tc39/proposal-accessible-object-hasownproperty
Object.hasOwn
# Class static initialization blocks
# https://github.com/tc39/proposal-class-static-block
class-static-block
## Standard language features
#
# Language features that have been included in a published version of the

View File

@ -0,0 +1,18 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: The `await` keyword is disallowed in the BindingIdentifier position
features: [class-static-block]
negative:
phase: parse
type: SyntaxError
---*/
$DONOTEVALUATE();
class C {
static {
(await => 0);
}
}

View File

@ -0,0 +1,18 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: The `await` keyword is disallowed in the IdentifierReference position
features: [class-static-block]
negative:
phase: parse
type: SyntaxError
---*/
$DONOTEVALUATE();
class C {
static {
((x = await) => 0);
}
}

View File

@ -0,0 +1,23 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: The `await` keyword is disallowed as a BindingIdentifier
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
[...]
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true.
features: [class-static-block]
negative:
phase: parse
type: SyntaxError
---*/
$DONOTEVALUATE();
class C {
static {
(class await {});
}
}

View File

@ -0,0 +1,28 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: The `await` keyword is interpreted as a IdentifierReference in method parameter lists
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
[...]
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true.
features: [class-static-block]
---*/
var await = 0;
var fromParam, fromBody;
class C {
static {
new (class {
constructor(x = fromParam = await) {
fromBody = await;
}
});
}
}
assert.sameValue(fromParam, 0, 'from parameter');
assert.sameValue(fromBody, 0, 'from body');

View File

@ -0,0 +1,18 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: The `await` keyword is interpreted as an IdentifierReference within function expressions
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
[...]
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true.
features: [class-static-block]
---*/
class C {
static {
(function await(await) {});
}
}

View File

@ -0,0 +1,26 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: The `await` keyword is interpreted as an IdentifierReference within function expressions
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
[...]
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true.
features: [class-static-block]
---*/
var await = 0;
var fromParam, fromBody;
class C {
static {
(function (x = fromParam = await) {
fromBody = await;
})();
}
}
assert.sameValue(fromParam, 0, 'from parameter');
assert.sameValue(fromBody, 0, 'from body');

View File

@ -0,0 +1,18 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: The `await` keyword is interpreted as an Identifier within generator function expressions
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
[...]
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true.
features: [class-static-block]
---*/
class C {
static {
(function * await (await) {});
}
}

View File

@ -0,0 +1,26 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: The `await` keyword is interpreted as an Identifier within generator function expressions
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
[...]
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true.
features: [class-static-block]
---*/
var await = 0;
var fromParam, fromBody;
class C {
static {
(function * (x = fromParam = await) {
fromBody = await;
})().next();
}
}
assert.sameValue(fromParam, 0, 'from parameter');
assert.sameValue(fromBody, 0, 'from body');

View File

@ -0,0 +1,22 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: The restriction on `await` does not apply to IdentifierName
info: |
BindingIdentifier : Identifier
[...]
- It is a Syntax Error if the code matched by this production is nested,
directly or indirectly (but not crossing function or static initialization
block boundaries), within a ClassStaticBlock and the StringValue of
Identifier is "await".
features: [class-static-block]
---*/
class C {
static {
({ await: 0 });
}
}

View File

@ -0,0 +1,26 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: IdentifierReference may not be `await` within class static blocks
info: |
IdentifierReference : Identifier
- It is a Syntax Error if the code matched by this production is nested,
directly or indirectly (but not crossing function or static initialization
block boundaries), within a ClassStaticBlock and the StringValue of
Identifier is "arguments" or "await".
negative:
phase: parse
type: SyntaxError
features: [class-static-block]
---*/
$DONOTEVALUATE();
class C {
static {
({ await });
}
}

View File

@ -0,0 +1,18 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: The `await` keyword is interpreted as an identifier within the body of arrow functions
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
[...]
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true.
features: [class-static-block]
---*/
class C {
static {
(() => ({ await }));
}
}

View File

@ -0,0 +1,18 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: The `await` keyword is interpreted as an identifier within the body of accessor methods
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
[...]
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true.
features: [class-static-block]
---*/
class C {
static {
({set accessor(await) {}});
}
}

View File

@ -0,0 +1,18 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: The `await` keyword is interpreted as an identifier within the parameter list of generator methods
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
[...]
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true.
features: [class-static-block]
---*/
class C {
static {
({*method(await) {}});
}
}

View File

@ -0,0 +1,18 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: The `await` keyword is interpreted as an identifier within the parameter list of methods
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
[...]
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true.
features: [class-static-block]
---*/
class C {
static {
({method(await) {}});
}
}

View File

@ -0,0 +1,28 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: The `await` keyword is interpreted as an identifier within accessor methods
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
[...]
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true.
features: [class-static-block]
---*/
var await = 0;
var fromParam, fromBody;
class C {
static {
({
set accessor(x = fromParam = await) {
fromBody = await;
}
}).accessor = undefined;
}
}
assert.sameValue(fromParam, 0, 'from parameter');
assert.sameValue(fromBody, 0, 'from body');

View File

@ -0,0 +1,28 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: The `await` keyword is interpreted as an identifier within generator methods
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
[...]
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true.
features: [class-static-block]
---*/
var await = 0;
var fromParam, fromBody;
class C {
static {
({
*method(x = fromParam = await) {
fromBody = await;
}
}).method().next();
}
}
assert.sameValue(fromParam, 0, 'from parameter');
assert.sameValue(fromBody, 0, 'from body');

View File

@ -0,0 +1,28 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: The `await` keyword is interpreted as an identifier within methods
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
[...]
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true.
features: [class-static-block]
---*/
var await = 0;
var fromParam, fromBody;
class C {
static {
({
method(x = fromParam = await) {
fromBody = await;
}
}).method();
}
}
assert.sameValue(fromParam, 0, 'from parameter');
assert.sameValue(fromBody, 0, 'from body');

View File

@ -0,0 +1,25 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: Restriction on `await`
info: |
IdentifierReference : Identifier
- It is a Syntax Error if the code matched by this production is nested,
directly or indirectly (but not crossing function or static initialization
block boundaries), within a ClassStaticBlock and the StringValue of
Identifier is "arguments" or "await".
negative:
phase: parse
type: SyntaxError
features: [class-static-block]
---*/
$DONOTEVALUATE();
class C {
static {
await;
}
}

View File

@ -0,0 +1,27 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-break-statement
description: IterationStatement search does not traverse static initialization block boundaries (no label specified)
info: |
4.2.1 Static Semantics: Early Errors
BreakStatement : break ;
- It is a Syntax Error if this BreakStatement is not nested, directly or
indirectly (but not crossing function or static initialization block
boundaries), within an IterationStatement or a SwitchStatement.
negative:
phase: parse
type: SyntaxError
features: [class-static-block]
---*/
$DONOTEVALUATE();
label: while(false) {
class C {
static {
break;
}
}
}

View File

@ -0,0 +1,46 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: Returns abrupt completion and halts further class body evaluation
info: |
34. For each element elementRecord of staticElements in List order, do
a. If elementRecord is a ClassFieldDefinition Record, then
[...]
b. Else,
i. Assert: fieldRecord is a ClassStaticBlockDefinition Record.
ii. Let status be the result of performing EvaluateStaticBlock(F,
elementRecord).
d. If status is an abrupt completion, then
i. Set the running execution context's LexicalEnvironment to lex.
ii. Set the running execution context's PrivateEnvironment to
outerPrivateEnvironment.
iii. Return Completion(status).
features: [class-static-fields-public, class-static-block]
---*/
var thrown = new Test262Error();
var caught;
var sameBlock = false;
var subsequentField = false;
var subsequentBlock = false;
try {
class C {
static {
throw thrown;
sameBlock = true;
}
static x = subsequentField = true;
static {
subsequentBlock = true;
}
}
} catch (error) {
caught = error;
}
assert.sameValue(caught, thrown);
assert.sameValue(sameBlock, false, 'same block');
assert.sameValue(subsequentField, false, 'subsequent field');
assert.sameValue(subsequentBlock, false, 'subsequent block');

View File

@ -0,0 +1,40 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: The identifier `arguments` is not restricted within function forms
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
- It is a Syntax Error if ContainsArguments of ClassStaticBlockStatementList
is true.
includes: [compareArray.js]
features: [class-static-block]
---*/
var fn, fnParam;
var gen, genParam;
var asyncFn, asyncFnParam;
class C {
static {
(function({test262 = fnParam = arguments}) {
fn = arguments;
})('function');
(function * ({test262 = genParam = arguments}) {
gen = arguments;
})('generator function').next();
(async function ({test262 = asyncFnParam = arguments}) {
asyncFn = arguments;
})('async function');
}
}
assert(compareArray(['function'], fn), 'body');
assert(compareArray(['function'], fnParam), 'parameter');
assert(compareArray(['generator function'], gen), 'body');
assert(compareArray(['generator function'], genParam), 'parameter');
assert(compareArray(['async function'], asyncFn), 'body');
assert(compareArray(['async function'], asyncFnParam), 'parameter');

View File

@ -0,0 +1,58 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: The identifier `arguments` is not restricted within method forms
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
- It is a Syntax Error if ContainsArguments of ClassStaticBlockStatementList
is true.
includes: [compareArray.js]
features: [class-static-block]
---*/
var instance;
var method, methodParam;
var getter;
var setter, setterParam;
var genMethod, genMethodParam;
var asyncMethod, asyncMethodParam;
class C {
static {
instance = new class {
method({test262 = methodParam = arguments}) {
method = arguments;
}
get accessor() {
getter = arguments;
}
set accessor({test262 = setterParam = arguments}) {
setter = arguments;
}
*gen({test262 = genMethodParam = arguments}) {
genMethod = arguments;
}
async async({test262 = asyncMethodParam = arguments}) {
asyncMethod = arguments;
}
}();
}
}
instance.method('method');
instance.accessor;
instance.accessor = 'setter';
instance.gen('generator method').next();
instance.async('async method');
assert(compareArray(['method'], method), 'body');
assert(compareArray(['method'], methodParam), 'parameter');
assert(compareArray([], getter), 'body');
assert(compareArray(['setter'], setter), 'body');
assert(compareArray(['setter'], setterParam), 'parameter');
assert(compareArray(['generator method'], genMethod), 'body');
assert(compareArray(['generator method'], genMethodParam), 'parameter');
assert(compareArray(['async method'], asyncMethod), 'body');
assert(compareArray(['async method'], asyncMethodParam), 'parameter');

View File

@ -0,0 +1,26 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: BindingIdentifier may not be `await` within class static blocks
info: |
BindingIdentifier : Identifier
[...]
- It is a Syntax Error if the code matched by this production is nested,
directly or indirectly (but not crossing function or static initialization
block boundaries), within a ClassStaticBlock and the StringValue of
Identifier is "await".
negative:
phase: parse
type: SyntaxError
features: [class-static-block]
---*/
$DONOTEVALUATE();
class C {
static {
class await {}
}
}

View File

@ -0,0 +1,18 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: The `await` keyword is interpreted as an identifier within arrow function bodies
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
[...]
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true.
features: [class-static-block]
---*/
class C {
static {
(() => { class await {} });
}
}

View File

@ -0,0 +1,23 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-operations-on-objects
description: The "new.target" value within a static initialization block is undefined
info: |
2.1.1 EvaluateStaticBlock ( receiver , blockRecord )
1. Assert: Type(receiver) is Object.
2. Assert: blockRecord is a ClassStaticBlockDefinition Record.
3. Perform ? Call(blockRecord.[[Body]], receiver).
features: [class-static-block]
---*/
var value = null;
class C {
static {
value = new.target;
}
}
assert.sameValue(value, undefined);

View File

@ -0,0 +1,23 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-operations-on-objects
description: The "this" value within a static initialization block is the class
info: |
2.1.1 EvaluateStaticBlock ( receiver , blockRecord )
1. Assert: Type(receiver) is Object.
2. Assert: blockRecord is a ClassStaticBlockDefinition Record.
3. Perform ? Call(blockRecord.[[Body]], receiver).
features: [class-static-block]
---*/
var value;
class C {
static {
value = this;
}
}
assert.sameValue(value, C);

View File

@ -0,0 +1,23 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: Block cannot use `arguments` as an identifier
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
- It is a Syntax Error if ContainsArguments of ClassStaticBlockStatementList
is true.
negative:
phase: parse
type: SyntaxError
features: [class-static-block]
---*/
$DONOTEVALUATE();
class C {
static {
(class { [argument\u0073]() {} });
}
}

View File

@ -0,0 +1,33 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions
description: The "Await" parsing context does not apply to the block's statement list
info: |
Syntax
[...]
ClassStaticBlockStatementList :
StatementList[~Yield, +Await, ~Return]opt
## 15.7.1 Static Semantics: Early Errors
ClassStaticBlockBody : ClassStaticBlockStatementList
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true.
negative:
phase: parse
type: SyntaxError
features: [class-static-block]
---*/
$DONOTEVALUATE();
async function f() {
class C {
static {
await 0;
}
}
}

View File

@ -0,0 +1,24 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: Block cannot declare duplicate labels
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
- It is a Syntax Error if ContainsDuplicateLabels of
ClassStaticBlockStatementList with argument « » is true.
negative:
phase: parse
type: SyntaxError
features: [class-static-block]
---*/
$DONOTEVALUATE();
class C {
static {
x: x: 0;
}
}

View File

@ -0,0 +1,24 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: Block cannot declare duplicate lexically-scoped bindings
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
- It is a Syntax Error if the LexicallyDeclaredNames of
ClassStaticBlockStatementList contains any duplicate entries.
negative:
phase: parse
type: SyntaxError
features: [class-static-block]
---*/
$DONOTEVALUATE();
class C {
static {
let x;
let x;
}
}

View File

@ -0,0 +1,25 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: Block cannot declare a lexically-scoped binding and function-scoped binding with the same name.
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
- It is a Syntax Error if any element of the LexicallyDeclaredNames of
ClassStaticBlockStatementList also occurs in the VarDeclaredNames of
ClassStaticBlockStatementList.
negative:
phase: parse
type: SyntaxError
features: [class-static-block]
---*/
$DONOTEVALUATE();
class C {
static {
let x;
var x;
}
}

View File

@ -0,0 +1,27 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions
description: The "Return" parsing context does not apply to the block's statement list
info: |
Syntax
[...]
ClassStaticBlockStatementList :
StatementList[~Yield, +Await, ~Return]opt
negative:
phase: parse
type: SyntaxError
features: [class-static-block]
---*/
$DONOTEVALUATE();
function f() {
class C {
static {
return;
}
}
}

View File

@ -0,0 +1,22 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: Block cannot contain SuperCall
info: |
ClassStaticBlock : static { ClassStaticBlockBody }
- It is a Syntax Error if HasDirectSuper of ClassStaticBlock is true.
negative:
phase: parse
type: SyntaxError
features: [class-static-block]
---*/
$DONOTEVALUATE();
class C {
static {
super();
}
}

View File

@ -0,0 +1,25 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: Block cannot reference an undefined `break` target
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
- It is a Syntax Error if ContainsUndefinedBreakTarget of
ClassStaticBlockStatementList with argument « » is true.
negative:
phase: parse
type: SyntaxError
features: [class-static-block]
---*/
$DONOTEVALUATE();
class C {
static {
x: while (false) {
break y;
}
}
}

View File

@ -0,0 +1,25 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: Block cannot reference an undefined `continue` target
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
- It is a Syntax Error if ContainsUndefinedContinueTarget of
ClassStaticBlockStatementList with arguments « » and « » is true.
negative:
phase: parse
type: SyntaxError
features: [class-static-block]
---*/
$DONOTEVALUATE();
class C {
static {
x: while (false) {
continue y;
}
}
}

View File

@ -0,0 +1,27 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions
description: The "Yield" parsing context does not apply to the block's statement list
info: |
Syntax
[...]
ClassStaticBlockStatementList :
StatementList[~Yield, +Await, ~Return]opt
negative:
phase: parse
type: SyntaxError
features: [class-static-block]
---*/
$DONOTEVALUATE();
function * g() {
class C {
static {
yield;
}
}
}

View File

@ -0,0 +1,27 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-runtime-semantics-classstaticblockdefinitionevaluation
description: Destruction of environment record for variable-scoped bindings
info: |
ClassStaticBlock : static { ClassStaticBlockBody }
1. Let lex be the running execution context's LexicalEnvironment.
2. Let privateScope be the running execution context's PrivateEnvironment.
3. Let body be OrdinaryFunctionCreate(Method, « », ClassStaticBlockBody, lex, privateScope).
features: [class-static-block]
---*/
var test262 = 'outer scope';
var probe;
class C {
static {
let test262 = 'first block';
}
static {
probe = test262;
}
}
assert.sameValue(probe, 'outer scope');

View File

@ -0,0 +1,23 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-runtime-semantics-classstaticblockdefinitionevaluation
description: Derivation of environment record for lexically-scoped bindings
info: |
ClassStaticBlock : static { ClassStaticBlockBody }
1. Let lex be the running execution context's LexicalEnvironment.
2. Let privateScope be the running execution context's PrivateEnvironment.
3. Let body be OrdinaryFunctionCreate(Method, « », ClassStaticBlockBody, lex, privateScope).
features: [class-static-block]
---*/
let probe;
class C {
static {
probe = C;
}
}
assert.sameValue(probe, C);

View File

@ -0,0 +1,31 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-runtime-semantics-classstaticblockdefinitionevaluation
description: Creation of new environment record for lexically-scoped bindings
info: |
ClassStaticBlock : static { ClassStaticBlockBody }
1. Let lex be the running execution context's LexicalEnvironment.
2. Let privateScope be the running execution context's PrivateEnvironment.
3. Let body be OrdinaryFunctionCreate(Method, « », ClassStaticBlockBody, lex, privateScope).
features: [class-static-block]
---*/
let test262 = 'outer scope';
let probe1, probe2;
class C {
static {
let test262 = 'first block';
probe1 = test262;
}
static {
let test262 = 'second block';
probe2 = test262;
}
}
assert.sameValue(test262, 'outer scope');
assert.sameValue(probe1, 'first block');
assert.sameValue(probe2, 'second block');

View File

@ -0,0 +1,25 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-runtime-semantics-classstaticblockdefinitionevaluation
description: Shares environment record for privately-scoped bindings
info: |
ClassStaticBlock : static { ClassStaticBlockBody }
1. Let lex be the running execution context's LexicalEnvironment.
2. Let privateScope be the running execution context's PrivateEnvironment.
3. Let body be OrdinaryFunctionCreate(Method, « », ClassStaticBlockBody, lex, privateScope).
features: [class-fields-private, class-static-block]
---*/
var probe;
class C {
static #test262 = 'private';
static {
probe = C.#test262;
}
}
assert.sameValue(probe, 'private');

View File

@ -0,0 +1,27 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-runtime-semantics-classstaticblockdefinitionevaluation
description: Destruction of environment record for variable-scoped bindings
info: |
ClassStaticBlock : static { ClassStaticBlockBody }
1. Let lex be the running execution context's LexicalEnvironment.
2. Let privateScope be the running execution context's PrivateEnvironment.
3. Let body be OrdinaryFunctionCreate(Method, « », ClassStaticBlockBody, lex, privateScope).
features: [class-static-block]
---*/
var test262 = 'outer scope';
var probe;
class C {
static {
var test262 = 'first block';
}
static {
probe = test262;
}
}
assert.sameValue(probe, 'outer scope');

View File

@ -0,0 +1,24 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-runtime-semantics-classstaticblockdefinitionevaluation
description: Derivation of environment record for variable-scoped bindings
info: |
ClassStaticBlock : static { ClassStaticBlockBody }
1. Let lex be the running execution context's LexicalEnvironment.
2. Let privateScope be the running execution context's PrivateEnvironment.
3. Let body be OrdinaryFunctionCreate(Method, « », ClassStaticBlockBody, lex, privateScope).
features: [class-static-block]
---*/
var test262 = 'outer scope';
var probe;
class C {
static {
probe = test262;
}
}
assert.sameValue(probe, 'outer scope');

View File

@ -0,0 +1,31 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-runtime-semantics-classstaticblockdefinitionevaluation
description: Creation of new environment record for variable-scoped bindings
info: |
ClassStaticBlock : static { ClassStaticBlockBody }
1. Let lex be the running execution context's LexicalEnvironment.
2. Let privateScope be the running execution context's PrivateEnvironment.
3. Let body be OrdinaryFunctionCreate(Method, « », ClassStaticBlockBody, lex, privateScope).
features: [class-static-block]
---*/
var test262 = 'outer scope';
var probe1, probe2;
class C {
static {
var test262 = 'first block';
probe1 = test262;
}
static {
var test262 = 'second block';
probe2 = test262;
}
}
assert.sameValue(test262, 'outer scope');
assert.sameValue(probe1, 'first block');
assert.sameValue(probe2, 'second block');

View File

@ -0,0 +1,38 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-runtime-semantics-classelementevaluation
description: Static blocks are evaluated in the order they appear in the source text, interleaved with static fields
info: |
5.1.14 Runtime Semantics: ClassDefinitionEvaluation
[...]
34. For each element elementRecord of staticElements in List order, do
a. If elementRecord is a ClassFieldDefinition Record, then
i. Let status be the result of performing DefineField(F,
elementRecord).
b. Else,
i. Assert: fieldRecord is a ClassStaticBlockDefinition Record.
ii. Let status be the result of performing EvaluateStaticBlock(F,
elementRecord).
[...]
features: [class-static-fields-public, class-static-block]
---*/
var sequence = [];
class C {
static x = sequence.push('first field');
static {
sequence.push('first block');
}
static x = sequence.push('second field');
static {
sequence.push('second block');
}
}
assert.sameValue(sequence[0], 'first field');
assert.sameValue(sequence[1], 'first block');
assert.sameValue(sequence[2], 'second field');
assert.sameValue(sequence[3], 'second block');

View File

@ -0,0 +1,18 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions
description: The block's statement list is optional
info: |
Syntax
[...]
ClassStaticBlockStatementList :
StatementList[~Yield, +Await, ~Return]opt
features: [class-static-block]
---*/
class C {
static {}
}

View File

@ -0,0 +1,24 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-runtime-semantics-classstaticblockdefinitionevaluation
description: The home object for a class static initialization block is the parent class
info: |
ClassStaticBlock : static { ClassStaticBlockBody }
[...]
4. Perform MakeMethod(body, homeObject).
features: [class-static-block]
---*/
function Parent() {}
Parent.test262 = 'test262';
var value;
class C extends Parent {
static {
value = super.test262;
}
}
assert.sameValue(value, 'test262');

View File

@ -0,0 +1,26 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: BindingIdentifier may not be `await` within class static blocks
info: |
BindingIdentifier : Identifier
[...]
- It is a Syntax Error if the code matched by this production is nested,
directly or indirectly (but not crossing function or static initialization
block boundaries), within a ClassStaticBlock and the StringValue of
Identifier is "await".
negative:
phase: parse
type: SyntaxError
features: [class-static-block]
---*/
$DONOTEVALUATE();
class C {
static {
const await = 0;
}
}

View File

@ -0,0 +1,18 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: The `await` keyword is interpreted as an identifier within arrow function bodies
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
[...]
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true.
features: [class-static-block]
---*/
class C {
static {
(() => { const await = 0; });
}
}

View File

@ -0,0 +1,28 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-continue-statement
description: IterationStatement search does not traverse static initialization block boundaries (label specified)
info: |
4.1.1 Static Semantics: Early Errors
ContinueStatement : continue ;
ContinueStatement : continue LabelIdentifier ;
- It is a Syntax Error if this ContinueStatement is not nested, directly or
indirectly (but not crossing function or static initialization block
boundaries), within an IterationStatement.
negative:
phase: parse
type: SyntaxError
features: [class-static-block]
---*/
$DONOTEVALUATE();
label: while(false) {
class C {
static {
continue label;
}
}
}

View File

@ -0,0 +1,28 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-continue-statement
description: IterationStatement search does not traverse static initialization block boundaries (no label specified)
info: |
4.1.1 Static Semantics: Early Errors
ContinueStatement : continue ;
ContinueStatement : continue LabelIdentifier ;
- It is a Syntax Error if this ContinueStatement is not nested, directly or
indirectly (but not crossing function or static initialization block
boundaries), within an IterationStatement.
negative:
phase: parse
type: SyntaxError
features: [class-static-block]
---*/
$DONOTEVALUATE();
label: while(false) {
class C {
static {
continue;
}
}
}

View File

@ -0,0 +1,27 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: BindingIdentifier may not be `await` within class static blocks
info: |
BindingIdentifier : Identifier
[...]
- It is a Syntax Error if the code matched by this production is nested,
directly or indirectly (but not crossing function or static initialization
block boundaries), within a ClassStaticBlock and the StringValue of
Identifier is "await".
negative:
phase: parse
type: SyntaxError
features: [class-static-block]
---*/
$DONOTEVALUATE();
class C {
static {
function await() {}
}
}

View File

@ -0,0 +1,18 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: The `await` keyword is interpreted as an identifier within arrow function bodies
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
[...]
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true.
features: [class-static-block]
---*/
class C {
static {
(() => { function await() {} });
}
}

View File

@ -0,0 +1,25 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: Restriction on `await`
info: |
LabelIdentifier : Identifier
- It is a Syntax Error if the code matched by this production is nested,
directly or indirectly (but not crossing function or static initialization
block boundaries), within a ClassStaticBlock and the StringValue of
Identifier is "await".
negative:
phase: parse
type: SyntaxError
features: [class-static-block]
---*/
$DONOTEVALUATE();
class C {
static {
await: 0;
}
}

View File

@ -0,0 +1,26 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: BindingIdentifier may not be `await` within class static blocks
info: |
BindingIdentifier : Identifier
[...]
- It is a Syntax Error if the code matched by this production is nested,
directly or indirectly (but not crossing function or static initialization
block boundaries), within a ClassStaticBlock and the StringValue of
Identifier is "await".
negative:
phase: parse
type: SyntaxError
features: [class-static-block]
---*/
$DONOTEVALUATE();
class C {
static {
let await;
}
}

View File

@ -0,0 +1,18 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: The `await` keyword is interpreted as an identifier within arrow function bodies
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
[...]
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true.
features: [class-static-block]
---*/
class C {
static {
(() => { let await; });
}
}

View File

@ -0,0 +1,26 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: BindingIdentifier may not be `await` within class static blocks
info: |
BindingIdentifier : Identifier
[...]
- It is a Syntax Error if the code matched by this production is nested,
directly or indirectly (but not crossing function or static initialization
block boundaries), within a ClassStaticBlock and the StringValue of
Identifier is "await".
negative:
phase: parse
type: SyntaxError
features: [class-static-block]
---*/
$DONOTEVALUATE();
class C {
static {
try {} catch (await) {}
}
}

View File

@ -0,0 +1,18 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: The `await` keyword is interpreted as an identifier within arrow function bodies
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
[...]
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true.
features: [class-static-block]
---*/
class C {
static {
(() => { try {} catch (await) {} });
}
}

View File

@ -0,0 +1,26 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: BindingIdentifier may not be `await` within class static blocks
info: |
BindingIdentifier : Identifier
[...]
- It is a Syntax Error if the code matched by this production is nested,
directly or indirectly (but not crossing function or static initialization
block boundaries), within a ClassStaticBlock and the StringValue of
Identifier is "await".
negative:
phase: parse
type: SyntaxError
features: [class-static-block]
---*/
$DONOTEVALUATE();
class C {
static {
var [await] = [];
}
}

View File

@ -0,0 +1,18 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: The `await` keyword is interpreted as an identifier within arrow function bodies
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
[...]
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true.
features: [class-static-block]
---*/
class C {
static {
(() => { var [await] = []; });
}
}

View File

@ -0,0 +1,26 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: BindingIdentifier may not be `await` within class static blocks
info: |
BindingIdentifier : Identifier
[...]
- It is a Syntax Error if the code matched by this production is nested,
directly or indirectly (but not crossing function or static initialization
block boundaries), within a ClassStaticBlock and the StringValue of
Identifier is "await".
negative:
phase: parse
type: SyntaxError
features: [class-static-block]
---*/
$DONOTEVALUATE();
class C {
static {
var {await} = {};
}
}

View File

@ -0,0 +1,18 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: The `await` keyword is interpreted as an identifier within arrow function bodies
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
[...]
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true.
features: [class-static-block]
---*/
class C {
static {
(() => { var {await} = {}; });
}
}

View File

@ -0,0 +1,26 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: BindingIdentifier may not be `await` within class static blocks
info: |
BindingIdentifier : Identifier
[...]
- It is a Syntax Error if the code matched by this production is nested,
directly or indirectly (but not crossing function or static initialization
block boundaries), within a ClassStaticBlock and the StringValue of
Identifier is "await".
negative:
phase: parse
type: SyntaxError
features: [class-static-block]
---*/
$DONOTEVALUATE();
class C {
static {
var await;
}
}

View File

@ -0,0 +1,18 @@
// Copyright (C) 2021 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-class-definitions-static-semantics-early-errors
description: The `await` keyword is interpreted as an identifier within arrow function bodies
info: |
ClassStaticBlockBody : ClassStaticBlockStatementList
[...]
- It is a Syntax Error if ContainsAwait of ClassStaticBlockStatementList is true.
features: [class-static-block]
---*/
class C {
static {
(() => { var await; });
}
}