Closed Bug 852762 Opened 7 years ago Closed 7 years ago

Arrow functions are not automatically strict after all

Categories

(Core :: JavaScript Engine, defect)

Other Branch
defect
Not set

Tracking

()

RESOLVED FIXED
mozilla24

People

(Reporter: jorendorff, Assigned: jorendorff)

References

Details

(Keywords: dev-doc-complete)

Attachments

(1 file, 1 obsolete file)

There is also the question of whether they have arguments, which I'll have to figure out from the meeting notes. This bug can address both.

<brendan> rs=me on arguments :-P
Blocks: 846406
In case any future readers are interested, the resolution of record for this decision is here:

https://mail.mozilla.org/pipermail/es-discuss/2013-February/028632.html

(Formatted: https://github.com/rwldrn/tc39-notes/blob/master/es6/2013-01/jan-30.md)
Attached patch v1 (obsolete) — Splinter Review
Assignee: general → jorendorff
Attachment #728097 - Flags: review?(ejpbruel)
Attachment #728097 - Attachment is obsolete: true
Attachment #728097 - Flags: review?(ejpbruel)
Attachment #730273 - Flags: review?(ejpbruel)
Review ping! :)
Comment on attachment 730273 [details] [diff] [review]
v2 - add another test or two

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

Looks mostly good to me. r+ with comments addressed.

::: js/src/jit-test/tests/arrow-functions/arguments-2.js
@@ +1,1 @@
> +// 'arguments' in arrow functions nested in other functions

Based on what this test does, this means that arrow functions get their own instance of arguments, right? That wasn't clear to me from this comment.

::: js/src/jit-test/tests/arrow-functions/arguments-4.js
@@ +10,3 @@
>  ];
>  
> +

Spurious newline here

::: js/src/jit-test/tests/arrow-functions/strict-1.js
@@ +10,3 @@
>  
> +f = (a = {x: 1, x: 2}) => b => { "use strict"; return a.x; };
> +assertEq(f()(0), 2);

I'm not sure what this tests for. Should the inner => be strict here? What about the outer =>? And how does this assertion confirm that?

::: js/src/jit-test/tests/arrow-functions/strict-2.js
@@ +2,5 @@
>  
>  load(libdir + "asserts.js");
>  
>  assertThrowsInstanceOf(
> +    () => Function("(a = function (obj) { with (obj) f(); }) => { 'use strict'; }"),

Why do we need the outer () => Function(...) here? I would assume this test throws even without that.

::: js/src/jit-test/tests/arrow-functions/syntax-errors.js
@@ +14,5 @@
>      "{p} => p",
>      "(...x => expr)",
>      "1 || a => a",
> +    "'use strict' => {}",
> +    "package => {'use strict';}",    // tricky: FutureReservedWord in strict mode code only

How do we make sure that this only throws a syntax error in strict mode? And if we don't, could you file a followup bug for this?
Attachment #730273 - Flags: review?(ejpbruel) → review+
I added a note on MDN about this bug [1] Feel free to remove it when this bug is fixed.

[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/arrow_functions#Upcoming_change
Keywords: dev-doc-needed
(In reply to Eddy Bruel [:ejpbruel] from comment #5)
> > +// 'arguments' in arrow functions nested in other functions
> 
> Based on what this test does, this means that arrow functions get their own
> instance of arguments, right? That wasn't clear to me from this comment.

Yes, they do. I improved the comments in several of the tests.

> ::: js/src/jit-test/tests/arrow-functions/strict-1.js
> @@ +10,3 @@
> >  
> > +f = (a = {x: 1, x: 2}) => b => { "use strict"; return a.x; };
> > +assertEq(f()(0), 2);
> 
> I'm not sure what this tests for. Should the inner => be strict here? What
> about the outer =>? And how does this assertion confirm that?

Yes; no; the fact that it compiles and runs confirms that the outer arrow is non-strict. I only check the return value because why not.

> ::: js/src/jit-test/tests/arrow-functions/strict-2.js
> @@ +2,5 @@
> >  
> >  load(libdir + "asserts.js");
> >  
> >  assertThrowsInstanceOf(
> > +    () => Function("(a = function (obj) { with (obj) f(); }) => { 'use strict'; }"),
> 
> Why do we need the outer () => Function(...) here? I would assume this test
> throws even without that.

Another way to write this test would be:

    // |jit-test| error: SyntaxError
    (a = function (obj) { with (obj) f(); }) => { "use strict"; };

Using assertThrowsInstanceOf requires putting the test case in quotes and using ()=>Function(...) to parse it on demand. Otherwise the error would be thrown at parse time, before assertThrowsInstanceOf is ever called, so the test would fail.

> ::: js/src/jit-test/tests/arrow-functions/syntax-errors.js
> > +    "package => {'use strict';}",    // tricky: FutureReservedWord in strict mode code only
> 
> How do we make sure that this only throws a syntax error in strict mode? And
> if we don't, could you file a followup bug for this?

Added a test for this (in the same file).
https://hg.mozilla.org/mozilla-central/rev/60d580712ec0
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla24
Depends on: 889158
You need to log in before you can comment on or make changes to this bug.