RESOLVED FIXED 156673
We allow assignments to const variables when in a for-in/for-of loop
https://bugs.webkit.org/show_bug.cgi?id=156673
Summary We allow assignments to const variables when in a for-in/for-of loop
Saam Barati
Reported 2016-04-17 00:22:13 PDT
``` const x = 20; for (x in/of [1,2,3]) ; // We don't throw an exception even though we should. ```
Attachments
patch (6.72 KB, patch)
2016-08-17 12:21 PDT, JF Bastien
fpizlo: review-
buildbot: commit-queue-
Archive of layout-test-results from ews100 for mac-yosemite (952.04 KB, application/zip)
2016-08-17 12:53 PDT, Build Bot
no flags
patch (6.82 KB, patch)
2016-08-17 14:59 PDT, JF Bastien
no flags
Marcus Buffett
Comment 1 2016-04-24 13:14:23 PDT
Tried to reproduce with the following: ``` const x = 20; for (x in [1,2,3]) { } ``` A syntax error was thrown, specifically `TypeError: Assignment to constant variable`. Close?
Saam Barati
Comment 2 2016-04-24 16:09:21 PDT
(In reply to comment #1) > Tried to reproduce with the following: > ``` > const x = 20; > for (x in [1,2,3]) { > } > ``` > A syntax error was thrown, specifically `TypeError: Assignment to constant > variable`. Close? Did you try: ``` function foo() { const x = 20; for (x in [1,2,3]) { } } foo() ``` ?
Marcus Buffett
Comment 3 2016-04-24 18:10:10 PDT
I did not, confirmed that reproduces the issue. Thank you!
JF Bastien
Comment 4 2016-08-17 12:21:10 PDT
Build Bot
Comment 5 2016-08-17 12:53:31 PDT
Comment on attachment 286315 [details] patch Attachment 286315 [details] did not pass mac-ews (mac): Output: http://webkit-queues.webkit.org/results/1888656 New failing tests: webgl/1.0.2/conformance/extensions/webgl-compressed-texture-s3tc.html js/arguments-iterator.html inspector/formatting/formatting-json.html
Build Bot
Comment 6 2016-08-17 12:53:35 PDT
Created attachment 286318 [details] Archive of layout-test-results from ews100 for mac-yosemite The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: ews100 Port: mac-yosemite Platform: Mac OS X 10.10.5
Filip Pizlo
Comment 7 2016-08-17 12:56:11 PDT
Comment on attachment 286315 [details] patch Looks like you have some test failures in layout tests. Some of our JS test coverage comes from layout tests, especially weird things like the WebGL tests (which have lots of weird JS) and the inspector tests (giant pile of JS). You'll either need to rebase the tests or figure out if maybe you created a legit regression.
Saam Barati
Comment 8 2016-08-17 14:40:33 PDT
Comment on attachment 286315 [details] patch View in context: https://bugs.webkit.org/attachment.cgi?id=286315&action=review > JSTests/stress/for-in-of-const.js:5 > + print("Executing: " + why); Remove this. > JSTests/stress/for-in-of-const.js:10 > + print("Executing: " + why); remove this.
JF Bastien
Comment 9 2016-08-17 14:57:05 PDT
Comment on attachment 286315 [details] patch View in context: https://bugs.webkit.org/attachment.cgi?id=286315&action=review >> JSTests/stress/for-in-of-const.js:5 >> + print("Executing: " + why); > > Remove this. Done. >> JSTests/stress/for-in-of-const.js:10 >> + print("Executing: " + why); > > remove this. Done.
JF Bastien
Comment 10 2016-08-17 14:59:54 PDT
Created attachment 286332 [details] patch Updated patch, checks for var.isReadOnly() because isStrictMode otherwise fires and throws when it shouldn't. I'll file a separate bug to refactor that (isReadOnly versus isConst).
Saam Barati
Comment 11 2016-08-17 15:02:32 PDT
Comment on attachment 286332 [details] patch View in context: https://bugs.webkit.org/attachment.cgi?id=286332&action=review > Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:2562 > + if (var.isReadOnly()) > + generator.emitReadOnlyExceptionIfNeeded(var); I think you want these before emitExpressionInfo(). > Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:2795 > + if (var.isReadOnly()) > + generator.emitReadOnlyExceptionIfNeeded(var); Ditto.
Saam Barati
Comment 12 2016-08-17 16:37:22 PDT
(In reply to comment #11) > Comment on attachment 286332 [details] > patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=286332&action=review > > > Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:2562 > > + if (var.isReadOnly()) > > + generator.emitReadOnlyExceptionIfNeeded(var); > > I think you want these before emitExpressionInfo(). > > > Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:2795 > > + if (var.isReadOnly()) > > + generator.emitReadOnlyExceptionIfNeeded(var); > > Ditto. I spoke with JF in person about this. My above comments are wrong. Basically, we either emit code to throw an exception, in which case, this code is correct. Or, we don't emit code to throw an exception, in which case, we have the same bytecode as we had before this patch. So it's OK to put the emitExpressionInfos where they are.
WebKit Commit Bot
Comment 13 2016-08-17 16:58:40 PDT
Comment on attachment 286332 [details] patch Clearing flags on attachment: 286332 Committed r204586: <http://trac.webkit.org/changeset/204586>
WebKit Commit Bot
Comment 14 2016-08-17 16:58:45 PDT
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.