Skip to content

Commit

Permalink
Add tests for "Class Static Init. Blocks" proposal (#2968)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jugglinmike committed Jul 15, 2021
1 parent f1f3a2d commit afe217b
Show file tree
Hide file tree
Showing 64 changed files with 1,582 additions and 0 deletions.
4 changes: 4 additions & 0 deletions features.txt
Expand Up @@ -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
Expand Down
@@ -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);
}
}
@@ -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);
}
}
23 changes: 23 additions & 0 deletions test/language/expressions/class/static-init-await-binding.js
@@ -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 {});
}
}
28 changes: 28 additions & 0 deletions test/language/expressions/class/static-init-await-reference.js
@@ -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');
18 changes: 18 additions & 0 deletions test/language/expressions/function/static-init-await-binding.js
@@ -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) {});
}
}
26 changes: 26 additions & 0 deletions test/language/expressions/function/static-init-await-reference.js
@@ -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');
18 changes: 18 additions & 0 deletions test/language/expressions/generators/static-init-await-binding.js
@@ -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) {});
}
}
@@ -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');
@@ -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 });
}
}

@@ -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 });
}
}

@@ -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 }));
}
}
@@ -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) {}});
}
}
@@ -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) {}});
}
}
@@ -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) {}});
}
}
@@ -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');
@@ -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');

0 comments on commit afe217b

Please sign in to comment.