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

TypeError is expected when reassigning to const during destructuring in for statement #6390

Merged
merged 1 commit into from Nov 11, 2022

Conversation

hyjorc1
Copy link
Contributor

@hyjorc1 hyjorc1 commented Nov 11, 2022

c228e7c

TypeError is expected when reassigning to `const` during destructuring in for statement
https://bugs.webkit.org/show_bug.cgi?id=247432
rdar://102064568

Reviewed by Yusuke Suzuki.

Running this JavaScript program should throw TypeError.
```
class x { static #y = { x = 0 } = 0 ; }
```

V8
```
class x { static #y = { x = 0 } = 0 ; }
                        ^
TypeError: Assignment to constant variable.
```

GraalJS
```
TypeError: Assignment to constant "x"
```

To fix this, we should use AssignmentContext::AssignmentExpression
to construct destructuring pattern in for...in/of statement. In this case,
symbolTablePut will check for read-only variable without ignoring.

* JSTests/stress/destructuring-for-in-of.js: Added.
(shouldThrow):
* Source/JavaScriptCore/parser/Parser.cpp:
(JSC::Parser<LexerType>::parseForStatement):

Canonical link: https://commits.webkit.org/256580@main

e5d27c1

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe   πŸ›  πŸ§ͺ win
βœ… πŸ›  ios-sim βœ… πŸ›  mac-debug βœ… πŸ›  gtk   πŸ›  wincairo
βœ… πŸ§ͺ webkitperl   πŸ§ͺ ios-wk2 βœ… πŸ›  mac-AS-debug   πŸ§ͺ gtk-wk2
  πŸ§ͺ api-ios   πŸ§ͺ api-mac   πŸ§ͺ api-gtk
βœ… πŸ›  πŸ§ͺ jsc βœ… πŸ›  tv   πŸ§ͺ mac-wk1 βœ… πŸ›  jsc-armv7
βœ… πŸ›  tv-sim   πŸ§ͺ mac-wk2 βœ… πŸ§ͺ jsc-armv7-tests
βœ… πŸ›  πŸ§ͺ merge βœ… πŸ›  watch   πŸ§ͺ mac-AS-debug-wk2 βœ… πŸ›  jsc-mips
βœ… πŸ›  watch-sim   πŸ§ͺ mac-wk2-stress βœ… πŸ§ͺ jsc-mips-tests

@hyjorc1 hyjorc1 self-assigned this Nov 11, 2022
@hyjorc1 hyjorc1 added JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues. WebKit Local Build labels Nov 11, 2022
@hyjorc1 hyjorc1 marked this pull request as ready for review November 11, 2022 08:14
@hyjorc1 hyjorc1 requested a review from a team as a code owner November 11, 2022 08:14
@rkirsling
Copy link
Member

How do we know what's expected though? I would expect a patch like this to resolve a test262 failure; if such a test doesn't exist, then (we should contribute one, and) the commit message should include other engines' behavior / spec text.

Copy link
Member

@Constellation Constellation left a comment

Choose a reason for hiding this comment

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

r=me

@hyjorc1
Copy link
Contributor Author

hyjorc1 commented Nov 11, 2022

How do we know what's expected though? I would expect a patch like this to resolve a test262 failure; if such a test doesn't exist, then (we should contribute one, and) the commit message should include other engines' behavior / spec text.

Hi @rkirsling, thanks for your comments. The bug report https://bugs.webkit.org/show_bug.cgi?id=247432 already contains the problem and the expectation behavior with other engines. Do we need to confirm that in the commit message?

we should contribute one

Should we add the test to the original test262 repository or the test262 test cases in WebKit?

@hyjorc1 hyjorc1 added the merge-queue Applied to send a pull request to merge-queue label Nov 11, 2022
…g in for statement

https://bugs.webkit.org/show_bug.cgi?id=247432
rdar://102064568

Reviewed by Yusuke Suzuki.

Running this JavaScript program should throw TypeError.
```
class x { static #y = { x = 0 } = 0 ; }
```

V8
```
class x { static #y = { x = 0 } = 0 ; }
                        ^
TypeError: Assignment to constant variable.
```

GraalJS
```
TypeError: Assignment to constant "x"
```

To fix this, we should use AssignmentContext::AssignmentExpression
to construct destructuring pattern in for...in/of statement. In this case,
symbolTablePut will check for read-only variable without ignoring.

* JSTests/stress/destructuring-for-in-of.js: Added.
(shouldThrow):
* Source/JavaScriptCore/parser/Parser.cpp:
(JSC::Parser<LexerType>::parseForStatement):

Canonical link: https://commits.webkit.org/256580@main
@webkit-commit-queue
Copy link
Collaborator

Committed 256580@main (c228e7c): https://commits.webkit.org/256580@main

Reviewed commits have been landed. Closing PR #6390 and removing active labels.

@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Nov 11, 2022
@rkirsling
Copy link
Member

Hi @rkirsling, thanks for your comments. The bug report https://bugs.webkit.org/show_bug.cgi?id=247432 already contains the problem and the expectation behavior with other engines. Do we need to confirm that in the commit message?

Ah, I had no idea that there was a bug report; bugzilla is mostly just PR placeholders at this point, so I'm no longer expecting it to contain useful information. πŸ˜… In this case, the bug report doesn't link to the spec, doesn't mention SM's behavior, and doesn't have a representative test262 case, so it would require further investigation before handlingβ€”we might find that V8 and SM disagree, or that V8 and SM agree but differ from the spec. This information is what we should have in the commit message, in order to justify the correctness of the change. (test262 cases are convenient because "this patch fixes a test262 failure" is usually an adequate justification on its own.)

Should we add the test to the original test262 repository or the test262 test cases in WebKit?

The former. We regularly sync JSTests/test262 with upstream test262, so we can't modify those test cases directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues.
Projects
None yet
5 participants