Ignore:
Timestamp:
Nov 18, 2015, 2:01:19 PM (10 years ago)
Author:
[email protected]
Message:

There is a bug when default parameter values are mixed with destructuring parameter values
https://bugs.webkit.org/show_bug.cgi?id=151369

Reviewed by Geoffrey Garen and Mark Lam.

This patch changes our parser to no longer declare destructuring
parameters as "var"s. This is a weird bug that just happened
to work in a world without default parameter values. In a world with
default parameter values this is just completely wrong. It would
incorrectly transform this program:
function foo(a = function() { b = 40; }, {b}) { a(); return b; }; foo(undefined, {b: 42}); // Should return 40
into
function foo(a = function() { b = 40; }, {b}) { var b; a(); return b; }; foo(undefined, {b:42}); // Returns 42, not 40.
Which is wrong because we end up with two distinct bindings of "b" when
there should only be one.

  • parser/Parser.cpp:

(JSC::Parser<LexerType>::parseVariableDeclarationList):
(JSC::Parser<LexerType>::createBindingPattern):
(JSC::Parser<LexerType>::parseDestructuringPattern):

  • parser/Parser.h:

(JSC::Scope::declareParameter):
(JSC::Scope::getUsedVariables):
(JSC::Parser::strictMode):
(JSC::Parser::isValidStrictMode):
(JSC::Parser::declareParameter):
(JSC::Parser::breakIsValid):
(JSC::Scope::declareBoundParameter): Deleted.
(JSC::Parser::declareBoundParameter): Deleted.

  • tests/stress/es6-default-parameters.js:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r192561 r192586  
     12015-11-18  Saam barati  <[email protected]>
     2
     3        There is a bug when default parameter values are mixed with destructuring parameter values
     4        https://bugs.webkit.org/show_bug.cgi?id=151369
     5
     6        Reviewed by Geoffrey Garen and Mark Lam.
     7
     8        This patch changes our parser to no longer declare destructuring
     9        parameters as "var"s. This is a weird bug that just happened
     10        to work in a world without default parameter values. In a world with
     11        default parameter values this is just completely wrong. It would
     12        incorrectly transform this program:
     13        ```function foo(a = function() { b = 40; }, {b}) { a(); return b; }; foo(undefined, {b: 42}); // Should return 40```
     14        into
     15        ```function foo(a = function() { b = 40; }, {b}) { var b; a(); return b; }; foo(undefined, {b:42}); // Returns 42, not 40.```
     16        Which is wrong because we end up with two distinct bindings of "b" when
     17        there should only be one.
     18
     19        * parser/Parser.cpp:
     20        (JSC::Parser<LexerType>::parseVariableDeclarationList):
     21        (JSC::Parser<LexerType>::createBindingPattern):
     22        (JSC::Parser<LexerType>::parseDestructuringPattern):
     23        * parser/Parser.h:
     24        (JSC::Scope::declareParameter):
     25        (JSC::Scope::getUsedVariables):
     26        (JSC::Parser::strictMode):
     27        (JSC::Parser::isValidStrictMode):
     28        (JSC::Parser::declareParameter):
     29        (JSC::Parser::breakIsValid):
     30        (JSC::Scope::declareBoundParameter): Deleted.
     31        (JSC::Parser::declareBoundParameter): Deleted.
     32        * tests/stress/es6-default-parameters.js:
     33
    1342015-11-17  Benjamin Poulain  <[email protected]>
    235
Note: See TracChangeset for help on using the changeset viewer.