Skip to content
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

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

Merged
merged 7 commits into from
Jul 15, 2021
Merged
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
4 changes: 4 additions & 0 deletions features.txt
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly here and in other arrow function tests, await is never allowed as an arrow parameter in async function bodies, so shouldn't here either.

Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned by @syg, await should be disallowed here, per tc39/proposal-class-static-block#46

}
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 {});
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be allowed if the intention is that class static blocks are like async function bodies for the purposes of [Await].

async function f() { (class await {}) } doesn't parse.

}
}
28 changes: 28 additions & 0 deletions test/language/expressions/class/static-init-await-reference.js
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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) {});
rwaldron marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -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');
Original file line number Diff line number Diff line change
@@ -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) {});
}
}
Original file line number Diff line number Diff line change
@@ -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');
Original file line number Diff line number Diff line change
@@ -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 });
}
}

Original file line number Diff line number Diff line change
@@ -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 });
}
}

Original file line number Diff line number Diff line change
@@ -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 }));
}
}
Original file line number Diff line number Diff line change
@@ -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) {}});
}
}
Original file line number Diff line number Diff line change
@@ -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) {}});
}
}
Original file line number Diff line number Diff line change
@@ -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) {}});
}
}
Original file line number Diff line number Diff line change
@@ -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');
Original file line number Diff line number Diff line change
@@ -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');
Loading