Status: New
Owner: ----

New issue 3975 by [email protected]: Incorrect restriction on BindingIdentifier of FunctionDeclaration
https://code.google.com/p/v8/issues/detail?id=3975

The BindingIdentifier of FunctionDeclarations is incorrectly interpreted
according to the strictness of the declared function (and not according to the
strictness of the code in which it was declared):

    d8> function static() {}
    undefined
    d8> function static() { 'use strict'; }
    (d8):1: SyntaxError: Unexpected strict mode reserved word
    function static() { 'use strict'; }
             ^^^^^^
    SyntaxError: Unexpected strict mode reserved word

Expected: no eror is thrown for either statement.
Actual: an error is thrown when the body of the declared function opts in to
strict mode
V8 revision: 22d62cea4d4d01d30286411cd11a6f3e15083cc0 (Thu Mar 19 08:04:47 2015 -0700)


From the ES5 spec:

The following tokens are also considered to be FutureReservedWords when they
occur within strict mode code (see 10.1.1). [1]

...which defines "strict mode code":

Function code that is part of a FunctionDeclaration, FunctionExpression, or
accessor PropertyAssignment is strict function code if its
FunctionDeclaration, FunctionExpression, or PropertyAssignment is contained in strict mode code or if the function code begins with a Directive Prologue
that contains a Use Strict Directive. [2]

...and "function code":

Function code is source text that is parsed as part of a FunctionBody. The
function code of a particular FunctionBody does not include any source text that is parsed as part of a nested FunctionBody. Function code also denotes
the source text supplied when using the built-in Function object as a
constructor. More precisely, the last parameter provided to the Function
constructor is converted to a String and treated as the FunctionBody. If more
than one parameter is provided to the Function constructor, all parameters
except the last one are converted to Strings and concatenated together,
separated by commas. The resulting String is interpreted as the
FormalParameterList for the FunctionBody defined by the last parameter. The function code for a particular instantiation of a Function does not include
any source text that is parsed as part of a nested FunctionBody. [3]

So since the BindingIdentifier is not considered part of the function code, it should not be interpreted according to the strictness of the function itself.
This interpretation also holds in ECMAScript 6 [4].

[1] http://es5.github.io/#x11
[2] http://es5.github.io/#x10.1.1
[3] http://es5.github.io/#function-code
[4] Relevant definitions in the ES6 spec draft:
- https://people.mozilla.org/~jorendorff/es6-draft.html#sec-identifiers-static-semantics-early-errors - https://people.mozilla.org/~jorendorff/es6-draft.html#sec-strict-mode-code - https://people.mozilla.org/~jorendorff/es6-draft.html#sec-types-of-source-code - https://people.mozilla.org/~jorendorff/es6-draft.html#sec-function-definitions


--
You received this message because this project is configured to send all issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to