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

Conversation

jugglinmike
Copy link
Contributor

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

@rwaldron
Copy link
Contributor

@rbuckton I need you to review these. Thanks!

ghost
ghost previously approved these changes Apr 30, 2021
@ghost
Copy link

ghost commented Apr 30, 2021 via email

@rwaldron
Copy link
Contributor

rwaldron commented May 4, 2021

@rbuckton ping

@rwaldron
Copy link
Contributor

These look great! I just tested in v8/d8 with --harmony-class-static-blocks turned on and wanted to give @syg the heads up on the following failures:

  • test/language/expressions/arrow-function/static-init-await-binding.js

    • Expected no error, got SyntaxError: Unexpected reserved word
  • test/language/expressions/arrow-function/static-init-await-reference.js

    • Expected no error, got SyntaxError: Unexpected reserved word
  • test/language/expressions/class/static-init-await-binding.js

    • Expected no error, got SyntaxError: Unexpected reserved word
  • test/language/expressions/object/identifier-shorthand-static-init-await-invalid.js

    • Expected test to throw error of type SyntaxError, got Test262: This statement should not be evaluated.
  • test/language/statements/class/static-init-await-binding-invalid.js

    • Expected test to throw error of type SyntaxError, got Test262: This statement should not be evaluated.
  • test/language/statements/class/static-init-invalid-return.js

    • Expected test to throw error of type SyntaxError, got Test262: This statement should not be evaluated.
  • test/language/statements/function/static-init-await-binding-invalid.js

    • Expected test to throw error of type SyntaxError, got Test262: This statement should not be evaluated.
  • test/language/statements/try/static-init-await-binding-invalid.js

    • Expected test to throw error of type SyntaxError, got Test262: This statement should not be evaluated.
  • test/language/statements/variable/dstr/obj-ptrn-elem-id-static-init-await-invalid.js

    • Expected test to throw error of type SyntaxError, got Test262: This statement should not be evaluated.

rwaldron
rwaldron previously approved these changes May 14, 2021
@rwaldron
Copy link
Contributor

@jugglinmike could you rebase your fixups and push back to the branch? Thanks!!

This proposal is currently at "stage 3" in TC39's standardization
process.
@jugglinmike jugglinmike dismissed stale reviews from rwaldron and ghost via ff9be07 May 14, 2021 16:37
@jugglinmike jugglinmike force-pushed the class-static-initialization-blocks branch from 6ed4671 to ff9be07 Compare May 14, 2021 16:37
@jugglinmike
Copy link
Contributor Author

These look great! I just tested in v8/d8 with --harmony-class-static-blocks turned on and wanted to give @syg the heads up on the following failures:

What service! Good news, V8 has tickets for these:

@jugglinmike could you rebase your fixups and push back to the branch? Thanks!!

Certainly. That's done, and the original version of this branch is available here in case that's interesting to anybody.

@JLHwung
Copy link
Contributor

JLHwung commented May 14, 2021

@rbuckton mentioned in tc39/proposal-class-static-block#27 (comment) that another way to handle await is to parse the static block in +Await and disallows if it Contains AwaitExpression or for-await-of.

If so, the following examples would throw, they are marked as valid as of ff9be07.

await is not allowed in arrow parameters in +Await

  • test/language/expressions/arrow-function/static-init-await-binding.js
  • test/language/expressions/arrow-function/static-init-await-reference.js

await not allowed in class binding in +Await

  • test/language/expressions/class/static-init-await-binding.js

I agree with tc39/proposal-class-static-block#43 (comment), either we come up a formal definition of function boundaries or we do in another way.

let test262 = 'first block';
}
static {
probe = test262;

Choose a reason for hiding this comment

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

I couldn't figure out how we're using probe - should there be an assertion for ti?

var test262 = 'first block';
}
static {
probe = test262;

Choose a reason for hiding this comment

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

Similar comment to my other comment above - should we be using probe in an assertion?

@jugglinmike
Copy link
Contributor Author

Great catch, @alflennik! Fixed in another fixup commit

@syg
Copy link
Contributor

syg commented May 15, 2021

I'm confused about some of the await as identifier tests.

For class expression, ClassExpression's BindingIdentifier doesn't have [~Await], why should await be allowed? This is plausibly a spec bug. Talked to @bakkot, class inherits async-ness from function context, so it makes sense the binding identifier also would.

For arrow parameters, ArrowFunction's ArrowParameters also doesn't have [~Await]. By comparison, FunctionExpression's FormalParameters has [~Await].


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.


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

@jugglinmike
Copy link
Contributor Author

@syg,

I'm confused about some of the await as identifier tests.

Currently, the proposal's restrictions on await are not expressed in terms of the Await production parameter. Although the text doesn't appear to align with the intent expressed in this GitHub comment, I've been trying to resolve the incongruities in the proposal itself. In the mean time, this patch is my attempt to be as faithful as possible to what's formally proposed.

@syg
Copy link
Contributor

syg commented May 20, 2021

Currently, the proposal's restrictions on await are not expressed in terms of the Await production parameter. Although the text doesn't appear to align with the intent expressed in this GitHub comment, I've been trying to resolve the incongruities in the proposal itself. In the mean time, this patch is my attempt to be as faithful as possible to what's formally proposed.

Right enough. The editors would really like the draft spec to be reworked so that the await-as-identifier restrictions are expressed here exactly as they would be for async function bodies so the two align. We can wait for @rbuckton to do that.

@rwaldron
Copy link
Contributor

@alflennik thanks for taking time to review this! Syntax testing is not for the faint of heart, so I commend your willingness to dive right in to a review. That aside, we (which includes you) would benefit from the champion of this proposal being actively engaged. My understanding is that the proposal itself is now stale (that is, it does not reflect the intended semantics of the feature), which is not good for anyone. I also commend @jugglinmike for sticking to a disciplined approach and only testing the feature as it's currently written, not as its "intended". I'm going to attempt to escalate attention to this PR.

@mgaudet
Copy link

mgaudet commented May 27, 2021

Just want to leave a comment here: SpiderMonkey's prototype implmentation, landed under Bug 1712138 passes all these tests except some of the the await static semantic tests, so we're definitely interested in seeing more clarification around await semantics as well.

We currently fail:

expressions/object/identifier-shorthand-static-init-await-invalid.js
language/identifier-resolution/static-init-invalid-await.js
language/statements/class/static-init-await-binding-invalid.js

@rwaldron
Copy link
Contributor

rwaldron commented Jun 4, 2021

@mgaudet Thanks for reporting in, that's actually really helpful.

I've made several attempts to reach @rbuckton both here and via IRC (before and during the recent TC39 meeting). I'm not sure what to do when a champion refuses to engage with a required step in the process. Can someone else take over the proposal?

@rbuckton
Copy link
Contributor

rbuckton commented Jun 5, 2021

I'd like to apologize for the delay on this, I've been out of the office this last week. I'm hoping to get caught up early next week.

@rbuckton
Copy link
Contributor

rbuckton commented Jun 6, 2021

I put up a PR for proposal-class-static-block that should clarify some of the parsing behavior based on conversation's I've had with @bakkot and others: tc39/proposal-class-static-block#46

I plan to fully review the test-262 tests and will start working on a PR for ECMA-262 this upcoming week.

Copy link
Contributor

@rbuckton rbuckton left a comment

Choose a reason for hiding this comment

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

This looks good, though all of the esid: sec-identifier cases will need to be updated once tc39/proposal-class-static-block#46 has merged. That should help to clarify the intended await behavior.

Also, while I saw tests for SuperProperty and ThisExpression in a static block, I did not see any for accessing the bound name of the class, i.e.:

var value;
class C { static { value = C; } }
// or
export default class C { static { value = C; } }
// or
(class C { static { value = C; } });

This is permitted in static fields today (i.e., class C { static x = C; })

BindingIdentifier : Identifier

[...]
- It is a Syntax Error if the code matched by this production is nested,
Copy link
Contributor

Choose a reason for hiding this comment

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

As of tc39/proposal-class-static-block#46, this is changing such that the block is parsed in +Await and we issue an error if ContainsAwait returns true, so this section has been removed.

// 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-identifiers
Copy link
Contributor

Choose a reason for hiding this comment

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

As of tc39/proposal-class-static-block#46, there are no longer any changes to sec-identifiers, these tests will likely need to be moved to sec-class-definitions (due to the change to use +Await), or to sec-class-definitions-static-semantics-early-errors (due to the new early error when ContainsAwait is true).

[...]

ClassStaticBlockStatementList :
StatementList[~Yield, ~Await, ~Return]opt
Copy link
Contributor

Choose a reason for hiding this comment

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

Per tc39/proposal-class-static-block#46, this changes to:

Suggested change
StatementList[~Yield, ~Await, ~Return]opt
StatementList[~Yield, +Await, ~Return]opt

However AwaitExpression and for await are both early errors in static semantics.

[...]

ClassStaticBlockStatementList :
StatementList[~Yield, ~Await, ~Return]opt
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
StatementList[~Yield, ~Await, ~Return]opt
StatementList[~Yield, +Await, ~Return]opt

}
}

assert.sameValue(probe262, 'outer scope');
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assert.sameValue(probe262, 'outer scope');
assert.sameValue(probe, 'outer scope');

@rwaldron
Copy link
Contributor

@rbuckton thanks for the review!

@rbuckton
Copy link
Contributor

rbuckton commented Jun 24, 2021

A few updates regarding the proposal:

tc39/ecma262#2440 will be the definitive source for the specification going forward, though I'll try to keep tc39/proposal-class-static-block#47 up to date with any changes for now.

@jugglinmike
Copy link
Contributor Author

Thanks for those updates, @rbuckton --with other proposals, I've sometimes been confused about where development was happening.

Anyway, I'll be updating this patch as per the latest corrections today.

@jugglinmike
Copy link
Contributor Author

@rbuckton regarding access to the bound names of the class, I decided to express that as a new kind of scope-probing test--one focused on the environment record's derivation (that also highlighted the need for a corresponding test for the variable lexical environment).

This patch is ready for another review.

Copy link
Contributor

@rbuckton rbuckton left a comment

Choose a reason for hiding this comment

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

This looks good to me, thanks for the hard work!

moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Jul 14, 2021
…k r=arai

This has been verified with the current version of
tc39/test262#2968, rev a502d69

Differential Revision: https://phabricator.services.mozilla.com/D119793
@rwaldron rwaldron merged commit afe217b into tc39:main Jul 15, 2021
jamienicol pushed a commit to jamienicol/gecko that referenced this pull request Jul 20, 2021
…k r=arai

This has been verified with the current version of
tc39/test262#2968, rev a502d69

Differential Revision: https://phabricator.services.mozilla.com/D119793
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants