Ignore:
Timestamp:
Apr 13, 2014, 11:01:54 AM (11 years ago)
Author:
[email protected]
Message:

Rewrite Function.bind as a builtin
https://bugs.webkit.org/show_bug.cgi?id=131083

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

This change removes the existing function.bind implementation
entirely so JSBoundFunction is no more.

Instead we just return a regular JS closure with a few
private properties hanging off it that allow us to perform
the necessary bound function fakery. While most of this is
simple, a couple of key changes:

  • The parser and lexer now directly track whether they're parsing code for call or construct and convert the private name @IsConstructor into TRUETOK or FALSETOK as appropriate. This automatically gives us the ability to vary behaviour from within the builtin. It also leaves a lot of headroom for trivial future improvements.
  • The instanceof operator now uses the prototypeForHasInstance private name, and we have a helper function to ensure that all objects that need to can update their magical 'prototype' property pair correctly.
  • API/JSScriptRef.cpp:

(parseScript):

  • JavaScriptCore.xcodeproj/project.pbxproj:
  • builtins/BuiltinExecutables.cpp:

(JSC::BuiltinExecutables::createBuiltinExecutable):

  • builtins/Function.prototype.js:

(bind.bindingFunction):
(bind.else.bindingFunction):
(bind):

  • bytecode/UnlinkedCodeBlock.cpp:

(JSC::generateFunctionCodeBlock):

  • bytecompiler/NodesCodegen.cpp:

(JSC::InstanceOfNode::emitBytecode):

  • interpreter/Interpreter.cpp:
  • parser/Lexer.cpp:

(JSC::Lexer<T>::Lexer):
(JSC::Lexer<LChar>::parseIdentifier):
(JSC::Lexer<UChar>::parseIdentifier):

  • parser/Lexer.h:
  • parser/Parser.cpp:

(JSC::Parser<LexerType>::Parser):
(JSC::Parser<LexerType>::parseInner):

  • parser/Parser.h:

(JSC::parse):

  • parser/ParserModes.h:
  • runtime/CodeCache.cpp:

(JSC::CodeCache::getGlobalCodeBlock):
(JSC::CodeCache::getFunctionExecutableFromGlobalCode):

  • runtime/CommonIdentifiers.h:
  • runtime/Completion.cpp:

(JSC::checkSyntax):

  • runtime/Executable.cpp:

(JSC::ProgramExecutable::checkSyntax):

  • runtime/FunctionPrototype.cpp:

(JSC::FunctionPrototype::addFunctionProperties):
(JSC::functionProtoFuncBind): Deleted.

  • runtime/JSBoundFunction.cpp: Removed.
  • runtime/JSBoundFunction.h: Removed.
  • runtime/JSFunction.cpp:

(JSC::RetrieveCallerFunctionFunctor::RetrieveCallerFunctionFunctor):
(JSC::RetrieveCallerFunctionFunctor::operator()):
(JSC::retrieveCallerFunction):
(JSC::JSFunction::getOwnPropertySlot):
(JSC::JSFunction::defineOwnProperty):

  • runtime/JSGlobalObject.cpp:

(JSC::JSGlobalObject::reset):

  • runtime/JSGlobalObjectFunctions.cpp:

(JSC::globalFuncSetTypeErrorAccessor):

  • runtime/JSGlobalObjectFunctions.h:
  • runtime/JSObject.h:

(JSC::JSObject::inlineGetOwnPropertySlot):

Source/WebCore:

Switch WebCore to use the helper functions when defining the
prototype properties on DOM constructors, and update bindings
tests accordingly.

  • bindings/js/JSImageConstructor.cpp:

(WebCore::JSImageConstructor::finishCreation):

  • bindings/scripts/CodeGeneratorJS.pm:

(GenerateConstructorHelperMethods):

  • bindings/scripts/test/JS/JSTestActiveDOMObject.cpp:

(WebCore::JSTestActiveDOMObjectConstructor::finishCreation):

  • bindings/scripts/test/JS/JSTestCustomNamedGetter.cpp:

(WebCore::JSTestCustomNamedGetterConstructor::finishCreation):

  • bindings/scripts/test/JS/JSTestEventConstructor.cpp:

(WebCore::JSTestEventConstructorConstructor::finishCreation):

  • bindings/scripts/test/JS/JSTestEventTarget.cpp:

(WebCore::JSTestEventTargetConstructor::finishCreation):

  • bindings/scripts/test/JS/JSTestException.cpp:

(WebCore::JSTestExceptionConstructor::finishCreation):

  • bindings/scripts/test/JS/JSTestGenerateIsReachable.cpp:

(WebCore::JSTestGenerateIsReachableConstructor::finishCreation):

  • bindings/scripts/test/JS/JSTestInterface.cpp:

(WebCore::JSTestInterfaceConstructor::finishCreation):

  • bindings/scripts/test/JS/JSTestMediaQueryListListener.cpp:

(WebCore::JSTestMediaQueryListListenerConstructor::finishCreation):

  • bindings/scripts/test/JS/JSTestNamedConstructor.cpp:

(WebCore::JSTestNamedConstructorConstructor::finishCreation):
(WebCore::JSTestNamedConstructorNamedConstructor::finishCreation):

  • bindings/scripts/test/JS/JSTestNode.cpp:

(WebCore::JSTestNodeConstructor::finishCreation):

  • bindings/scripts/test/JS/JSTestObj.cpp:

(WebCore::JSTestObjConstructor::finishCreation):

  • bindings/scripts/test/JS/JSTestOverloadedConstructors.cpp:

(WebCore::JSTestOverloadedConstructorsConstructor::finishCreation):

  • bindings/scripts/test/JS/JSTestSerializedScriptValueInterface.cpp:

(WebCore::JSTestSerializedScriptValueInterfaceConstructor::finishCreation):

  • bindings/scripts/test/JS/JSTestTypedefs.cpp:

(WebCore::JSTestTypedefsConstructor::finishCreation):

  • bindings/scripts/test/JS/JSattribute.cpp:

(WebCore::JSattributeConstructor::finishCreation):

  • bindings/scripts/test/JS/JSreadonly.cpp:

(WebCore::JSreadonlyConstructor::finishCreation):

LayoutTests:

Testing.

  • js/dom/function-bind-expected.txt:
  • js/regress/function-bind-expected.txt: Added.
  • js/regress/function-bind.html: Added.
  • js/regress/script-tests/function-bind.js: Added.

(foo):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r167189 r167199  
     12014-04-08  Oliver Hunt  <[email protected]>
     2
     3        Rewrite Function.bind as a builtin
     4        https://bugs.webkit.org/show_bug.cgi?id=131083
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        This change removes the existing function.bind implementation
     9        entirely so JSBoundFunction is no more.
     10
     11        Instead we just return a regular JS closure with a few
     12        private properties hanging off it that allow us to perform
     13        the necessary bound function fakery.  While most of this is
     14        simple, a couple of key changes:
     15
     16        - The parser and lexer now directly track whether they're
     17          parsing code for call or construct and convert the private
     18          name @IsConstructor into TRUETOK or FALSETOK as appropriate.
     19          This automatically gives us the ability to vary behaviour
     20          from within the builtin. It also leaves a lot of headroom
     21          for trivial future improvements.
     22        - The instanceof operator now uses the prototypeForHasInstance
     23          private name, and we have a helper function to ensure that
     24          all objects that need to can update their magical 'prototype'
     25          property pair correctly.
     26
     27        * API/JSScriptRef.cpp:
     28        (parseScript):
     29        * JavaScriptCore.xcodeproj/project.pbxproj:
     30        * builtins/BuiltinExecutables.cpp:
     31        (JSC::BuiltinExecutables::createBuiltinExecutable):
     32        * builtins/Function.prototype.js:
     33        (bind.bindingFunction):
     34        (bind.else.bindingFunction):
     35        (bind):
     36        * bytecode/UnlinkedCodeBlock.cpp:
     37        (JSC::generateFunctionCodeBlock):
     38        * bytecompiler/NodesCodegen.cpp:
     39        (JSC::InstanceOfNode::emitBytecode):
     40        * interpreter/Interpreter.cpp:
     41        * parser/Lexer.cpp:
     42        (JSC::Lexer<T>::Lexer):
     43        (JSC::Lexer<LChar>::parseIdentifier):
     44        (JSC::Lexer<UChar>::parseIdentifier):
     45        * parser/Lexer.h:
     46        * parser/Parser.cpp:
     47        (JSC::Parser<LexerType>::Parser):
     48        (JSC::Parser<LexerType>::parseInner):
     49        * parser/Parser.h:
     50        (JSC::parse):
     51        * parser/ParserModes.h:
     52        * runtime/CodeCache.cpp:
     53        (JSC::CodeCache::getGlobalCodeBlock):
     54        (JSC::CodeCache::getFunctionExecutableFromGlobalCode):
     55        * runtime/CommonIdentifiers.h:
     56        * runtime/Completion.cpp:
     57        (JSC::checkSyntax):
     58        * runtime/Executable.cpp:
     59        (JSC::ProgramExecutable::checkSyntax):
     60        * runtime/FunctionPrototype.cpp:
     61        (JSC::FunctionPrototype::addFunctionProperties):
     62        (JSC::functionProtoFuncBind): Deleted.
     63        * runtime/JSBoundFunction.cpp: Removed.
     64        * runtime/JSBoundFunction.h: Removed.
     65        * runtime/JSFunction.cpp:
     66        (JSC::RetrieveCallerFunctionFunctor::RetrieveCallerFunctionFunctor):
     67        (JSC::RetrieveCallerFunctionFunctor::operator()):
     68        (JSC::retrieveCallerFunction):
     69        (JSC::JSFunction::getOwnPropertySlot):
     70        (JSC::JSFunction::defineOwnProperty):
     71        * runtime/JSGlobalObject.cpp:
     72        (JSC::JSGlobalObject::reset):
     73        * runtime/JSGlobalObjectFunctions.cpp:
     74        (JSC::globalFuncSetTypeErrorAccessor):
     75        * runtime/JSGlobalObjectFunctions.h:
     76        * runtime/JSObject.h:
     77        (JSC::JSObject::inlineGetOwnPropertySlot):
     78
    1792014-04-12  Filip Pizlo  <[email protected]>
    280
Note: See TracChangeset for help on using the changeset viewer.