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/jit/JITStubs.cpp

    r95681 r95751  
    20872087    ASSERT(typeInfo.type() != UnspecifiedType);
    20882088
    2089     if (!typeInfo.overridesHasInstance()) {
    2090         if (!value.isObject())
    2091             return JSValue::encode(jsBoolean(false));
    2092 
    2093         if (!proto.isObject()) {
    2094             throwError(callFrame, createTypeError(callFrame, "instanceof called on an object with an invalid prototype property."));
    2095             VM_THROW_EXCEPTION();
    2096         }
    2097     }
     2089    if (!typeInfo.overridesHasInstance() && !value.isObject())
     2090        return JSValue::encode(jsBoolean(false));
    20982091
    20992092    JSValue result = jsBoolean(asObject(baseVal)->hasInstance(callFrame, value, proto));
     
    38273820}
    38283821
    3829 NativeExecutable* JITThunks::hostFunctionStub(JSGlobalData* globalData, NativeFunction function)
     3822NativeExecutable* JITThunks::hostFunctionStub(JSGlobalData* globalData, NativeFunction function, NativeFunction constructor)
    38303823{
    38313824    std::pair<HostFunctionStubMap::iterator, bool> entry = m_hostFunctionStubMap->add(function, Weak<NativeExecutable>());
    38323825    if (!*entry.first->second)
    3833         entry.first->second.set(*globalData, NativeExecutable::create(*globalData, JIT::compileCTINativeCall(globalData, function), function, MacroAssemblerCodeRef::createSelfManagedCodeRef(ctiNativeConstruct()), callHostFunctionAsConstructor, DFG::NoIntrinsic));
     3826        entry.first->second.set(*globalData, NativeExecutable::create(*globalData, JIT::compileCTINativeCall(globalData, function), function, MacroAssemblerCodeRef::createSelfManagedCodeRef(ctiNativeConstruct()), constructor, DFG::NoIntrinsic));
    38343827    return entry.first->second.get();
    38353828}
Note: See TracChangeset for help on using the changeset viewer.