Add back partial support for |for (var i = 0 in obj);| syntax, ignoring the initializer rather than failing on it

RESOLVED FIXED in Firefox 40

Status

()

RESOLVED FIXED
4 years ago
4 years ago

People

(Reporter: Waldo, Assigned: Waldo)

Tracking

({dev-doc-complete, site-compat})

unspecified
mozilla41
dev-doc-complete, site-compat
Points:
---
Bug Flags:
in-testsuite +

Firefox Tracking Flags

(firefox40 fixed, firefox41 fixed)

Details

(Whiteboard: [DocArea=JS])

Attachments

(1 attachment, 1 obsolete attachment)

(Assignee)

Description

4 years ago
Instead of removing the syntax completely just yet (bug 748550), let's just try ignoring the initializer instead.  That'll give a little more time for sites that used this to fix their code.  (I have yet to see a site that actually used this deliberately, expecting its semantics.)
(Assignee)

Comment 1

4 years ago
Posted patch Ignore the initializer (obsolete) — Splinter Review
Relevant context for reviewing this consists of https://hg.mozilla.org/mozilla-central/rev/dfdcce6b319a which removed |for (var i = 0 in foo)| syntax.  The tests added are almost entirely readding all the test changes made in that rev -- except to a new test file, to ease removal at some future time.  (Plus a couple other tests for over-removal in that rev, and for a testcase I accidentally made assert at one point while writing this test.)

Requesting double the reviews because jorendorff looked at the original thing, and because efaust reviewed the grammar parametrization work that's going to come into play with this in bugwork to be posted Very Soon, to get rid of parsingForInit.  Plus it probably doesn't hurt, for a bug to backport to the branch cut earlier this week.
Attachment #8605609 - Flags: review?(jorendorff)
(Assignee)

Updated

4 years ago
Attachment #8605609 - Flags: review?(efaustbmo)
JSC also reverted their for-in initializer changes for compatibility reasons: https://bugs.webkit.org/show_bug.cgi?id=130269. In JSC the initializer is only allowed in for-in loops without a destructuring pattern and the initializer expression itself is ignored:
---
>>> for (var a = print("never executed") in {p: 0});
undefined

>>> for (var [a] = 0 in {p: 0});
Exception: SyntaxError: Unexpected keyword 'in'. Cannot use initialiser syntax when binding to a pattern during enumeration.

>>> for (var {a} = 0 in {p: 0});
Exception: SyntaxError: Unexpected keyword 'in'. Cannot use initialiser syntax when binding to a pattern during enumeration.

>>> for (var [a] = 0 of [0]);
Exception: SyntaxError: Unexpected identifier 'of'. Cannot use initialiser syntax when binding to a pattern during enumeration.

>>> for (var {a} = 0 of [0]);
Exception: SyntaxError: Unexpected identifier 'of'. Cannot use initialiser syntax when binding to a pattern during enumeration.

>>> for (var a = 0 of [0]);
Exception: SyntaxError: Unexpected identifier 'of'. Cannot use initialiser syntax in a for-of enumeration.
---
(Assignee)

Comment 3

4 years ago
Yeah, it's reasonable to prohibit this for destructuring patterns.  Gave me an opportunity to make this warn, too, when a name's used.
Attachment #8605609 - Attachment is obsolete: true
Attachment #8605609 - Flags: review?(jorendorff)
Attachment #8605609 - Flags: review?(efaustbmo)
Attachment #8606059 - Flags: review?(jorendorff)
Attachment #8606059 - Flags: review?(efaustbmo)
Keywords: dev-doc-needed, site-compat
Whiteboard: [DocArea=JS]
Comment on attachment 8606059 [details] [diff] [review]
Altered to JSC semantics (for now)

Review of attachment 8606059 [details] [diff] [review]:
-----------------------------------------------------------------

r=me

::: js/src/frontend/Parser.cpp
@@ +3928,5 @@
> +                // |for (var foo = ... in ...);|.  This was Dumb and permitted
> +                // only because of grammar Dumb, and ES6 doesn't include it.
> +                // Make this a syntax error when the variable name is a
> +                // destructuring pattern, so that code using new features can't
> +                // use this fatuity.

This seems a little long and editorial to me; if you want, you could just write:

    // Ban the nonsensical |for (var V = E1 in E2);| where V is a destructuring
    // pattern. See bug 1164741 for background.

@@ +4001,5 @@
> +                // looking in the console knows to fix this.  Initializer
> +                // semantics were defined by ES3-5 but abandoned in ES6, and
> +                // handling them in this case is incredibly difficult for
> +                // extraordinarily little gain: just pretend the initializer
> +                // isn't there.

The last sentence here could be shortened too.

::: js/src/tests/ecma_6/extensions/for-in-with-assignments.js
@@ +16,5 @@
> + **************/
> +
> +// This is a total grab-bag of junk originally in tests changed when this
> +// syntax was removed.  Leaving it all in one file will make it easier to
> +// eventually remove.  Avert your eyes!

"I looked at the trap, Ray"

@@ +62,5 @@
> +
> +/******************************************************************************/
> +
> +with (0)
> +  for (var b = 0 in 0);  // don't assert in parser

Add a test or two for the new initializer-ignoring behavior, please.
Attachment #8606059 - Flags: review?(jorendorff) → review+
Comment on attachment 8606059 [details] [diff] [review]
Altered to JSC semantics (for now)

Review of attachment 8606059 [details] [diff] [review]:
-----------------------------------------------------------------

I second Jason's comments about needing another test and shortening that comment. The rest looks good.

::: js/src/frontend/Parser.cpp
@@ +3928,5 @@
> +                // |for (var foo = ... in ...);|.  This was Dumb and permitted
> +                // only because of grammar Dumb, and ES6 doesn't include it.
> +                // Make this a syntax error when the variable name is a
> +                // destructuring pattern, so that code using new features can't
> +                // use this fatuity.

"Gee, Jeff. Tell us how you really feel"

::: js/src/tests/ecma_6/Statements/for-in-with-destructuring-assignments.js
@@ +25,5 @@
> +
> +/******************************************************************************/
> +
> +assertThrowsInstanceOf(function() {
> +  // Abandon all hope, ye who try to read this.

Good lord.
Attachment #8606059 - Flags: review?(efaustbmo) → review+
(Assignee)

Comment 6

4 years ago
(In reply to Jason Orendorff [:jorendorff] from comment #4)
> This seems a little long and editorial to me; if you want, you could just
> write:
> The last sentence here could be shortened too.

Yeah, probably.  But I liked "fatuity" so much here!  :-)

> Add a test or two for the new initializer-ignoring behavior, please.

That file does contain a couple tests that exercise/check this.  I'm shocked, shocked that you missed them.
https://hg.mozilla.org/mozilla-central/rev/9841c5d229b8
Status: ASSIGNED → RESOLVED
Last Resolved: 4 years ago
status-firefox41: --- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla41
(Assignee)

Comment 9

4 years ago
Comment on attachment 8606059 [details] [diff] [review]
Altered to JSC semantics (for now)

Approval Request Comment
[Feature/regressing bug #]: bug 748550
[User impact if declined]: an extraordinarily small number of sites might not work, or work quite as desired
[Describe test coverage new/current, TreeHerder]: tests in patch
[Risks and why]: Relevant parsing code is a little finicky logic-wise, but it tracks out, and at least one reviewer noticed this tracking-out.  It should be solid on that front.
[String/UUID change made/needed]: N/A
Attachment #8606059 - Flags: approval-mozilla-aurora?
status-firefox40: --- → affected
Comment on attachment 8606059 [details] [diff] [review]
Altered to JSC semantics (for now)

Taking it because webcompat matters.

Even if the patch is a bit big in a critical section, it is early in the aurora cycle and we would have time to find and fix potential regressions.
Attachment #8606059 - Flags: approval-mozilla-aurora? → approval-mozilla-aurora+
https://hg.mozilla.org/releases/mozilla-aurora/rev/b852ee9e576f
status-firefox40: affected → fixed
Flags: in-testsuite+
You need to log in before you can comment on or make changes to this bug.