Changeset 195581 in webkit


Ignore:
Timestamp:
Jan 25, 2016 9:43:11 PM (8 years ago)
Author:
commit-queue@webkit.org
Message:

[ES6] Arrow function syntax. Arrow function specific features. Lexical bind "arguments"
https://bugs.webkit.org/show_bug.cgi?id=145132

Patch by Skachkov Oleksandr <gskachkov@gmail.com> on 2016-01-25
Reviewed by Saam Barati.
Source/JavaScriptCore:

Added support of ES6 arrow function specific feature, lexical bind of arguments.
http://www.ecma-international.org/ecma-262/6.0/#sec-arrow-function-definitions-runtime-semantics-evaluation
'arguments' variable in arrow function must resolve to a binding in a lexically enclosing environment.
In srict mode it points to arguments object, and in non-stric mode it points to arguments object or varible
with name 'arguments' if it was declared.

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::BytecodeGenerator):

  • parser/Parser.h:

(JSC::Scope::Scope):
(JSC::Scope::setSourceParseMode):
(JSC::Scope::isArrowFunction):
(JSC::Scope::collectFreeVariables):
(JSC::Scope::setIsArrowFunction):

  • tests/es6.yaml:
  • tests/stress/arrowfunction-lexical-bind-arguments-non-strict-1.js: Added.
  • tests/stress/arrowfunction-lexical-bind-arguments-non-strict-2.js: Added.
  • tests/stress/arrowfunction-lexical-bind-arguments-strict.js: Added.

Source/WebInspectorUI:

Current patch is implementing lexical bind of arguments, so in this callback we need
to return to ordinary function.

  • UserInterface/Base/Object.js:

(WebInspector.Object.singleFireEventListener.let.wrappedCallback):
(WebInspector.Object.singleFireEventListener):

LayoutTests:

  • js/arrowfunction-lexical-bind-arguments-non-strict-expected.txt: Added.
  • js/arrowfunction-lexical-bind-arguments-non-strict.html: Added.
  • js/arrowfunction-lexical-bind-arguments-strict-expected.txt: Added.
  • js/arrowfunction-lexical-bind-arguments-strict.html: Added.
  • js/script-tests/arrowfunction-lexical-bind-arguments-non-strict.js: Added.
  • js/script-tests/arrowfunction-lexical-bind-arguments-strict.js: Added.
Location:
trunk
Files:
9 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r195579 r195581  
     12016-01-25  Skachkov Oleksandr  <gskachkov@gmail.com>
     2
     3        [ES6] Arrow function syntax. Arrow function specific features. Lexical bind "arguments"
     4        https://bugs.webkit.org/show_bug.cgi?id=145132
     5
     6        Reviewed by Saam Barati.
     7
     8        * js/arrowfunction-lexical-bind-arguments-non-strict-expected.txt: Added.
     9        * js/arrowfunction-lexical-bind-arguments-non-strict.html: Added.
     10        * js/arrowfunction-lexical-bind-arguments-strict-expected.txt: Added.
     11        * js/arrowfunction-lexical-bind-arguments-strict.html: Added.
     12        * js/script-tests/arrowfunction-lexical-bind-arguments-non-strict.js: Added.
     13        * js/script-tests/arrowfunction-lexical-bind-arguments-strict.js: Added.
     14
    1152016-01-25  Simon Fraser  <simon.fraser@apple.com>
    216
  • trunk/Source/JavaScriptCore/ChangeLog

    r195578 r195581  
     12016-01-25  Skachkov Oleksandr  <gskachkov@gmail.com>
     2
     3        [ES6] Arrow function syntax. Arrow function specific features. Lexical bind "arguments"
     4        https://bugs.webkit.org/show_bug.cgi?id=145132
     5
     6        Reviewed by Saam Barati.
     7       
     8        Added support of ES6 arrow function specific feature, lexical bind of arguments.
     9        http://www.ecma-international.org/ecma-262/6.0/#sec-arrow-function-definitions-runtime-semantics-evaluation
     10        'arguments' variable in arrow function must resolve to a binding in a lexically enclosing environment.
     11        In srict mode it points to arguments object, and in non-stric mode it points to arguments object or varible
     12        with name 'arguments' if it was declared.
     13
     14        * bytecompiler/BytecodeGenerator.cpp:
     15        (JSC::BytecodeGenerator::BytecodeGenerator):
     16        * parser/Parser.h:
     17        (JSC::Scope::Scope):
     18        (JSC::Scope::setSourceParseMode):
     19        (JSC::Scope::isArrowFunction):
     20        (JSC::Scope::collectFreeVariables):
     21        (JSC::Scope::setIsArrowFunction):
     22        * tests/es6.yaml:
     23        * tests/stress/arrowfunction-lexical-bind-arguments-non-strict-1.js: Added.
     24        * tests/stress/arrowfunction-lexical-bind-arguments-non-strict-2.js: Added.
     25        * tests/stress/arrowfunction-lexical-bind-arguments-strict.js: Added.
     26
    1272016-01-25  Benjamin Poulain  <bpoulain@apple.com>
    228
  • trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp

    r195439 r195581  
    244244
    245245    bool shouldCaptureAllOfTheThings = m_shouldEmitDebugHooks || codeBlock->usesEval();
    246     bool needsArguments = functionNode->usesArguments() || codeBlock->usesEval();
     246    bool needsArguments = (functionNode->usesArguments() || codeBlock->usesEval() || (functionNode->usesArrowFunction() && !codeBlock->isArrowFunction()));
    247247
    248248    // Generator never provides "arguments". "arguments" reference will be resolved in an upper generator function scope.
     
    509509            }
    510510        }
    511        
    512         if (!haveParameterNamedArguments) {
     511
     512        // Do not create arguments variable in case of Arrow function. Value will be loaded from parent scope
     513        if (!haveParameterNamedArguments && !m_codeBlock->isArrowFunction()) {
    513514            createVariable(
    514515                propertyNames().arguments, varKind(propertyNames().arguments.impl()), functionSymbolTable);
     516
    515517            m_needToInitializeArguments = true;
    516518        }
  • trunk/Source/JavaScriptCore/parser/Parser.h

    r195484 r195581  
    171171        , m_isFunction(isFunction)
    172172        , m_isGenerator(isGenerator)
     173        , m_isArrowFunction(false)
    173174        , m_isLexicalScope(false)
    174175        , m_isFunctionBoundary(false)
     
    192193        , m_isFunction(rhs.m_isFunction)
    193194        , m_isGenerator(rhs.m_isGenerator)
     195        , m_isArrowFunction(rhs.m_isArrowFunction)
    194196        , m_isLexicalScope(rhs.m_isLexicalScope)
    195197        , m_isFunctionBoundary(rhs.m_isFunctionBoundary)
     
    258260        case SourceParseMode::SetterMode:
    259261        case SourceParseMode::MethodMode:
     262            setIsFunction();
     263            break;
     264
    260265        case SourceParseMode::ArrowFunctionMode:
    261             setIsFunction();
     266            setIsArrowFunction();
    262267            break;
    263268
     
    447452    void setNeedsFullActivation() { m_needsFullActivation = true; }
    448453    bool needsFullActivation() const { return m_needsFullActivation; }
     454    bool isArrowFunction() { return m_isArrowFunction; }
    449455
    450456    bool hasDirectSuper() { return m_hasDirectSuper; }
     
    465471
    466472                // "arguments" reference should be resolved at function boudary.
    467                 if (nestedScope->isFunctionBoundary() && nestedScope->hasArguments() && impl == m_vm->propertyNames->arguments.impl())
     473                if (nestedScope->isFunctionBoundary() && nestedScope->hasArguments() && impl == m_vm->propertyNames->arguments.impl() && !nestedScope->isArrowFunction())
    468474                    continue;
    469475
     
    581587        m_hasArguments = false;
    582588    }
     589   
     590    void setIsArrowFunction()
     591    {
     592        setIsFunction();
     593        m_isArrowFunction = true;
     594    }
    583595
    584596    void setIsModule()
     
    598610    bool m_isFunction : 1;
    599611    bool m_isGenerator : 1;
     612    bool m_isArrowFunction : 1;
    600613    bool m_isLexicalScope : 1;
    601614    bool m_isFunctionBoundary : 1;
  • trunk/Source/JavaScriptCore/tests/es6.yaml

    r195480 r195581  
    746746  cmd: runES6 :normal
    747747- path: es6/arrow_functions_lexical_arguments_binding.js
    748   cmd: runES6 :fail
     748  cmd: runES6 :normal
    749749- path: es6/arrow_functions_lexical_new.target_binding.js
    750750  cmd: runES6 :normal
  • trunk/Source/WebInspectorUI/ChangeLog

    r195566 r195581  
     12016-01-25  Skachkov Oleksandr  <gskachkov@gmail.com>
     2
     3        [ES6] Arrow function syntax. Arrow function specific features. Lexical bind "arguments"
     4        https://bugs.webkit.org/show_bug.cgi?id=145132
     5
     6        Reviewed by Saam Barati.
     7
     8        Current patch is implementing lexical bind of arguments, so in this callback we need
     9        to return to ordinary function.
     10
     11        * UserInterface/Base/Object.js:
     12        (WebInspector.Object.singleFireEventListener.let.wrappedCallback):
     13        (WebInspector.Object.singleFireEventListener):
     14
    1152016-01-25  Saam barati  <sbarati@apple.com>
    216
  • trunk/Source/WebInspectorUI/UserInterface/Base/Object.js

    r195442 r195581  
    5959    static singleFireEventListener(eventType, listener, thisObject)
    6060    {
    61         let wrappedCallback = () => {
     61        let wrappedCallback = function() {
    6262            this.removeEventListener(eventType, wrappedCallback, null);
    6363            listener.apply(thisObject, arguments);
    64         };
     64        }.bind(this);
    6565
    6666        this.addEventListener(eventType, wrappedCallback, null);
Note: See TracChangeset for help on using the changeset viewer.