Ignore:
Timestamp:
Sep 22, 2011, 2:22:17 PM (14 years ago)
Author:
[email protected]
Message:

Implement Function.prototype.bind
https://bugs.webkit.org/show_bug.cgi?id=26382

Reviewed by Sam Weinig.

Source/JavaScriptCore:

This patch provides a basic functional implementation
for Function.bind. It should (hopefully!) be fully
functionally correct, and the bound functions can be
called to quickly (since they are a subclass of
JSFunction, not InternalFunction), but we'll probably
want to follow up with some optimization work to keep
bound calls in JIT code.

(JSC::JITThunks::hostFunctionStub):

  • jit/JITStubs.h:
  • jsc.cpp:

(GlobalObject::addFunction):

  • runtime/CommonIdentifiers.h:
  • runtime/ConstructData.h:
  • runtime/Executable.h:

(JSC::NativeExecutable::NativeExecutable):

  • runtime/FunctionPrototype.cpp:

(JSC::FunctionPrototype::addFunctionProperties):
(JSC::functionProtoFuncBind):

  • runtime/FunctionPrototype.h:
  • runtime/JSBoundFunction.cpp: Added.

(JSC::boundFunctionCall):
(JSC::boundFunctionConstruct):
(JSC::JSBoundFunction::create):
(JSC::JSBoundFunction::hasInstance):
(JSC::JSBoundFunction::getOwnPropertySlot):
(JSC::JSBoundFunction::getOwnPropertyDescriptor):
(JSC::JSBoundFunction::JSBoundFunction):
(JSC::JSBoundFunction::finishCreation):

  • runtime/JSBoundFunction.h: Added.

(JSC::JSBoundFunction::targetFunction):
(JSC::JSBoundFunction::boundThis):
(JSC::JSBoundFunction::boundArgs):
(JSC::JSBoundFunction::createStructure):

  • runtime/JSFunction.cpp:

(JSC::JSFunction::create):
(JSC::JSFunction::finishCreation):
(JSC::createDescriptorForThrowingProperty):
(JSC::JSFunction::getOwnPropertySlot):

  • runtime/JSFunction.h:
  • runtime/JSGlobalData.cpp:

(JSC::JSGlobalData::getHostFunction):

  • runtime/JSGlobalData.h:
  • runtime/JSGlobalObject.cpp:

(JSC::JSGlobalObject::reset):
(JSC::JSGlobalObject::visitChildren):

  • runtime/JSGlobalObject.h:

(JSC::JSGlobalObject::boundFunctionStructure):

  • runtime/Lookup.cpp:

(JSC::setUpStaticFunctionSlot):

Source/WebCore:

Test: fast/js/function-bind.html

  • bindings/js/JSDOMBinding.cpp:

(WebCore::objectToStringFunctionGetter):

  • bindings/js/JSDOMWindowCustom.cpp:

(WebCore::nonCachingStaticFunctionGetter):

  • bindings/js/JSHistoryCustom.cpp:

(WebCore::nonCachingStaticBackFunctionGetter):
(WebCore::nonCachingStaticForwardFunctionGetter):
(WebCore::nonCachingStaticGoFunctionGetter):

  • bindings/js/JSLocationCustom.cpp:

(WebCore::nonCachingStaticReplaceFunctionGetter):
(WebCore::nonCachingStaticReloadFunctionGetter):
(WebCore::nonCachingStaticAssignFunctionGetter):

  • Function::create no longer requires functionStructure() to be passed.

LayoutTests:

We now pass Function.bind tests.

  • fast/js/Object-getOwnPropertyNames-expected.txt:
  • fast/js/basic-strict-mode-expected.txt:
  • fast/js/function-bind-expected.txt: Added.
  • fast/js/function-bind.html: Added.
  • fast/js/mozilla/strict/15.3.4.5-expected.txt:
  • fast/js/script-tests/function-bind.js: Added.
  • ietestcenter/Javascript/15.2.3.3-4-38-expected.txt:
  • ietestcenter/Javascript/15.3.4.5-0-1-expected.txt:
  • ietestcenter/Javascript/15.3.4.5-0-2-expected.txt:
  • ietestcenter/Javascript/15.3.4.5-13.b-1-expected.txt:
  • ietestcenter/Javascript/15.3.4.5-13.b-2-expected.txt:
  • ietestcenter/Javascript/15.3.4.5-13.b-3-expected.txt:
  • ietestcenter/Javascript/15.3.4.5-13.b-4-expected.txt:
  • ietestcenter/Javascript/15.3.4.5-13.b-5-expected.txt:
  • ietestcenter/Javascript/15.3.4.5-15-1-expected.txt:
  • ietestcenter/Javascript/15.3.4.5-15-2-expected.txt:
  • ietestcenter/Javascript/15.3.4.5-16-1-expected.txt:
  • ietestcenter/Javascript/15.3.4.5-2-1-expected.txt:
  • ietestcenter/Javascript/15.3.4.5-2-2-expected.txt:
  • ietestcenter/Javascript/15.3.4.5-2-3-expected.txt:
  • ietestcenter/Javascript/15.3.4.5-2-4-expected.txt:
  • ietestcenter/Javascript/15.3.4.5-2-5-expected.txt:
  • ietestcenter/Javascript/15.3.4.5-2-6-expected.txt:
  • ietestcenter/Javascript/15.3.4.5-2-7-expected.txt:
  • ietestcenter/Javascript/15.3.4.5-2-8-expected.txt:
  • ietestcenter/Javascript/15.3.4.5-2-9-expected.txt:
  • ietestcenter/Javascript/15.3.4.5-8-1-expected.txt:
  • ietestcenter/Javascript/15.3.4.5-8-2-expected.txt:
  • ietestcenter/Javascript/15.3.4.5-9-1-expected.txt:
  • ietestcenter/Javascript/15.3.4.5-9-2-expected.txt:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/Executable.h

    r95681 r95751  
    202202
    203203        NativeFunction function() { return m_function; }
     204        NativeFunction constructor() { return m_constructor; }
    204205
    205206        static Structure* createStructure(JSGlobalData& globalData, JSGlobalObject* globalObject, JSValue proto) { return Structure::create(globalData, globalObject, proto, TypeInfo(LeafType, StructureFlags), &s_info); }
     
    229230 
    230231    private:
    231 #if ENABLE(JIT)
    232232        NativeExecutable(JSGlobalData& globalData, NativeFunction function, NativeFunction constructor)
    233233            : ExecutableBase(globalData, globalData.nativeExecutableStructure.get(), NUM_PARAMETERS_IS_HOST)
     
    236236        {
    237237        }
    238 #else
    239         NativeExecutable(JSGlobalData& globalData, NativeFunction function, NativeFunction constructor)
    240             : ExecutableBase(globalData, globalData.nativeExecutableStructure.get(), NUM_PARAMETERS_IS_HOST)
    241             , m_function(function)
    242             , m_constructor(constructor)
    243         {
    244         }
    245 #endif
    246238
    247239        NativeFunction m_function;
    248         // Probably should be a NativeConstructor, but this will currently require rewriting the JIT
    249         // trampoline. It may be easier to make NativeFunction be passed 'this' as a part of the ArgList.
    250240        NativeFunction m_constructor;
    251241       
     
    639629    }
    640630
     631    inline NativeFunction JSFunction::nativeConstructor()
     632    {
     633        ASSERT(isHostFunction());
     634        return static_cast<NativeExecutable*>(m_executable.get())->constructor();
     635    }
     636
    641637    inline bool isHostFunction(JSValue value, NativeFunction nativeFunction)
    642638    {
Note: See TracChangeset for help on using the changeset viewer.