Closed
Bug 1272784
Opened 9 years ago
Closed 8 years ago
|function f(a = 1) { "use strict"; }| should throw Early Error.
Categories
(Core :: JavaScript Engine, defect)
Core
JavaScript Engine
Tracking
()
RESOLVED
FIXED
mozilla52
People
(Reporter: arai, Assigned: anba)
References
Details
(Keywords: addon-compat, dev-doc-complete, site-compat)
Attachments
(2 files, 2 obsolete files)
16.28 KB,
patch
|
anba
:
review+
|
Details | Diff | Splinter Review |
13.04 KB,
patch
|
anba
:
review+
|
Details | Diff | Splinter Review |
(separated from bug 1185106 comment #90)
https://tc39.github.io/ecma262/#sec-function-definitions-static-semantics-early-errors
> FunctionDeclaration:functionBindingIdentifier(FormalParameters){FunctionBody}
> FunctionDeclaration:function(FormalParameters){FunctionBody}
> FunctionExpression:functionBindingIdentifier(FormalParameters){FunctionBody}
>
> * It is a Syntax Error if ContainsUseStrict of FunctionBody is true and IsSimpleParameterList of FormalParameters is false.
The above rule means the following code should throw SyntaxError.
function f(a = 1) { "use strict"; }
Comment 1•9 years ago
|
||
I think the intent of the rule is implementation convenience: we can avoid rewinding when we encounter a "use strict" declaration.
ES6 allows this function. I think V8 never implemented it, which is why TC39 can drop the requirement. It'll be a relief to be rid of the rewinding code. This needs a declaration of "intent to un-ship" on dev.platform though.
Reporter | ||
Comment 2•9 years ago
|
||
ah, so, we can remove the following loop, right?
https://dxr.mozilla.org/mozilla-central/rev/a884b96685aa13b65601feddb24e5f85ba861561/js/src/frontend/Parser.cpp#2846
> template <typename ParseHandler>
> typename ParseHandler::Node
> Parser<ParseHandler>::functionDef(InHandling inHandling,
> ...
> {
> ...
> while (true) {
> if (functionArgsAndBody(inHandling, pn, fun, kind, generatorKind, directives,
> &newDirectives))
> {
> break;
> }
> if (tokenStream.hadError() || directives == newDirectives)
> return null();
>
> // Assignment must be monotonic to prevent reparsing iloops
> MOZ_ASSERT_IF(directives.strict(), newDirectives.strict());
> MOZ_ASSERT_IF(directives.asmJS(), newDirectives.asmJS());
> directives = newDirectives;
>
> tokenStream.seek(start);
>
> // functionArgsAndBody may have already set pn->pn_body before failing.
> handler.setFunctionBody(pn, null());
> }
>
> return pn;
> }
Comment 3•9 years ago
|
||
Bah, I guess not, because of "use asm".
But we can do less rewinding. Search in Parser.cpp for "Request that this function be reparsed as strict." I think we can change that to a simple check for the few possible strict errors that can occur in argument lists.
Comment 4•9 years ago
|
||
This kind of rewinding causes parsing to take O(n^2) time:
var x = "0";
for (let i = 0; i < 300; i++)
x = "(function (a = " + x + ") { 'use strict'; return a; })";
var t0 = Date.now();
eval(x);
print(Date.now() - t0);
This takes half a second on my machine, which is rather silly.
But arrow function rewinding is even worse: it's O(2^n).
Assignee | ||
Comment 6•8 years ago
|
||
Part 1: Implement the new checks, but functions with "use strict" directives are still rewound.
Assignee: nobody → andrebargull
Status: NEW → ASSIGNED
Attachment #8796263 -
Flags: review?(arai.unmht)
Assignee | ||
Comment 7•8 years ago
|
||
Part 2: Don't rewind functions with "use strict" directives (except for error reporting).
Attachment #8796266 -
Flags: review?(arai.unmht)
Assignee | ||
Comment 8•8 years ago
|
||
(In reply to Jason Orendorff [:jorendorff] from comment #1)
> This needs a declaration of "intent to un-ship" on dev.platform though.
Did this actually happen? FWIW Chrome, JSC (*) and Edge already implement the new semantics.
(*) I don't know if stable Safari contains the changes.
Reporter | ||
Comment 9•8 years ago
|
||
Comment on attachment 8796263 [details] [diff] [review]
bug1272784.part1.patch
Review of attachment 8796263 [details] [diff] [review]:
-----------------------------------------------------------------
The code change itself looks good, but the change in the existing tests sounds scary, as it implies this can be hit also in add-ons or firefox-specific code on the web.
This at least needs add-on compatibility note.
Attachment #8796263 -
Flags: review?(arai.unmht) → review+
Reporter | ||
Comment 10•8 years ago
|
||
adding some keywords.
site-compat might be inappropriate, feel free to clear it.
Reporter | ||
Updated•8 years ago
|
Attachment #8796266 -
Flags: review?(arai.unmht) → review+
Reporter | ||
Comment 11•8 years ago
|
||
Have this passed try run?
wasn't there anything hit this in-tree?
Assignee | ||
Comment 12•8 years ago
|
||
(In reply to Tooru Fujisawa [:arai] from comment #11)
> Have this passed try run?
> wasn't there anything hit this in-tree?
I've only tried jstests + jit-tests. Still need to request access to Try (bug 1306713). :-D
Assignee | ||
Comment 13•8 years ago
|
||
(In reply to Tooru Fujisawa [:arai] from comment #9)
> The code change itself looks good, but the change in the existing tests
> sounds scary, as it implies this can be hit also in add-ons or
> firefox-specific code on the web.
> This at least needs add-on compatibility note.
We could also just warn for now and remove support at a later point.
Comment 14•8 years ago
|
||
Please do a try run now :) If it passes I am for landing this, addon can be deal with a little breakage.
Flags: needinfo?(andrebargull)
Assignee | ||
Updated•8 years ago
|
Comment 15•8 years ago
|
||
(In reply to André Bargull from comment #8)
> (In reply to Jason Orendorff [:jorendorff] from comment #1)
> > This needs a declaration of "intent to un-ship" on dev.platform though.
>
> Did this actually happen?
I don't see an answer to this question in the bug?
Assignee | ||
Comment 16•8 years ago
|
||
(In reply to Tom Schuster [:evilpie] from comment #14)
> Please do a try run now :) If it passes I am for landing this, addon can be
> deal with a little breakage.
Try finished:
https://treeherder.mozilla.org/#/jobs?repo=try&revision=72197f72300b
Comment 17•8 years ago
|
||
(In reply to :Ms2ger (⌚ UTC+1/+2) from comment #15)
> (In reply to André Bargull from comment #8)
> > (In reply to Jason Orendorff [:jorendorff] from comment #1)
> > > This needs a declaration of "intent to un-ship" on dev.platform though.
> >
> > Did this actually happen?
>
> I don't see an answer to this question in the bug?
Sorry, I missed this. We can't land before. André do you feel comfortable doing this? Otherwise Jason or me can probably do it.
Assignee | ||
Comment 18•8 years ago
|
||
(In reply to Tom Schuster [:evilpie] from comment #17)
> Sorry, I missed this. We can't land before. André do you feel comfortable
> doing this? Otherwise Jason or me can probably do it.
I'd prefer if you (or Jason) do this. Thank you!
Comment 19•8 years ago
|
||
Will post a site compat doc for this, just in case.
Comment 20•8 years ago
|
||
I did post to dev-platform a while back. There were some concerns about telemetry and breakage, but as shu suggested we need to land this to find real world issues.
Assignee | ||
Comment 21•8 years ago
|
||
Updated patch to apply cleanly on inbound. Carrying r+ from arai.
Attachment #8796263 -
Attachment is obsolete: true
Attachment #8803989 -
Flags: review+
Assignee | ||
Comment 22•8 years ago
|
||
Updated patch to apply cleanly on inbound. Carrying r+ from arai.
Attachment #8796266 -
Attachment is obsolete: true
Attachment #8803990 -
Flags: review+
Assignee | ||
Comment 23•8 years ago
|
||
New try: https://treeherder.mozilla.org/#/jobs?repo=try&revision=91d7485902e6a5ccd2a0b2a86059a56eb58b0516
(Test failure in ecma_6/Reflect/argumentsList.js already fixed in updated part 1 patch.)
Assignee | ||
Updated•8 years ago
|
Keywords: checkin-needed
Comment 24•8 years ago
|
||
Pushed by cbook@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/f066bb4bc6f0
Part 1: Disallow 'use strict' directive in function with non-simple parameters list. r=arai
https://hg.mozilla.org/integration/mozilla-inbound/rev/a42b25de7402
Part 2: Don't reparse functions with 'use strict' directives. r=arai
Keywords: checkin-needed
Comment 25•8 years ago
|
||
Posted the site compatibility doc: https://www.fxsitecompat.com/en-CA/docs/2016/use-strict-can-no-longer-be-used-in-function-with-non-simple-parameters/
Comment 26•8 years ago
|
||
The developer documentation should follow the same layout as other error messages[1]. The name of the newly created MDN page should be referenced in the devtools[2], which maps JS error key with the page name.
[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors
[2] http://searchfox.org/mozilla-central/source/devtools/server/actors/errordocs.js
Flags: needinfo?(andrebargull)
Reporter | ||
Comment 27•8 years ago
|
||
I'm writing a documentation.
will post a URL here once it's ready.
then it can be linked from devtools.
Reporter | ||
Comment 28•8 years ago
|
||
Added document.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Strict_Non_Simple_Params
Feel free to fix/update :)
Comment 29•8 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/f066bb4bc6f0
https://hg.mozilla.org/mozilla-central/rev/a42b25de7402
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
status-firefox52:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla52
Assignee | ||
Comment 30•8 years ago
|
||
(In reply to Nicolas B. Pierron [:nbp] from comment #26)
> The developer documentation should follow the same layout as other error
> messages[1].
Filed bug 1315772.
Flags: needinfo?(andrebargull)
Comment 31•8 years ago
|
||
Thanks for the doc arai! It has been reviewed by nbp and me.
André also wrote and landed the DevTools patch (one version later, Fx53, bug 1315772), so that it will be linked.
Keywords: dev-doc-needed → dev-doc-complete
You need to log in
before you can comment on or make changes to this bug.
Description
•