Arrow functions are not automatically strict after all

RESOLVED FIXED in mozilla24

Status

()

Core
JavaScript Engine
RESOLVED FIXED
4 years ago
4 years ago

People

(Reporter: jorendorff, Assigned: jorendorff)

Tracking

({dev-doc-complete})

Other Branch
mozilla24
dev-doc-complete
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment, 1 obsolete attachment)

(Assignee)

Description

4 years ago
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
(Assignee)

Updated

4 years ago
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)
(Assignee)

Comment 2

4 years ago
Created attachment 728097 [details] [diff] [review]
v1
Assignee: general → jorendorff
Attachment #728097 - Flags: review?(ejpbruel)
(Assignee)

Comment 3

4 years ago
Created attachment 730273 [details] [diff] [review]
v2 - add another test or two
Attachment #728097 - Attachment is obsolete: true
Attachment #728097 - Flags: review?(ejpbruel)
Attachment #730273 - Flags: review?(ejpbruel)
(Assignee)

Comment 4

4 years ago
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+

Comment 6

4 years ago
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
(Assignee)

Comment 7

4 years ago
(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).
(Assignee)

Comment 8

4 years ago
https://hg.mozilla.org/integration/mozilla-inbound/rev/60d580712ec0
https://hg.mozilla.org/mozilla-central/rev/60d580712ec0
Status: NEW → RESOLVED
Last Resolved: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla24
(Assignee)

Updated

4 years ago
Depends on: 889158
Noted on:
https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Releases/24
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/arrow_functions
Keywords: dev-doc-needed → dev-doc-complete
You need to log in before you can comment on or make changes to this bug.