Implement Function.prototype.bind
authorbarraclough@apple.com <barraclough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Sep 2011 21:22:17 +0000 (21:22 +0000)
committerbarraclough@apple.com <barraclough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Sep 2011 21:22:17 +0000 (21:22 +0000)
commit222156651dec660bb861b6df0cfeb3218eec7dfe
tree2510cb67321e88a474118f1cfcf10a51d862ae6b
parent0c6cd7ae166e329e4e395af36ab618636f48a46e
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.

* JavaScriptCore.JSVALUE32_64only.exp:
* JavaScriptCore.JSVALUE64only.exp:
* JavaScriptCore.exp:
* JavaScriptCore.xcodeproj/project.pbxproj:
* jit/JITStubs.cpp:
(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:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@95751 268f45cc-cd09-0410-ab3c-d52691b4dbfc
63 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/js/Object-getOwnPropertyNames-expected.txt
LayoutTests/fast/js/basic-strict-mode-expected.txt
LayoutTests/fast/js/function-bind-expected.txt [new file with mode: 0644]
LayoutTests/fast/js/function-bind.html [new file with mode: 0644]
LayoutTests/fast/js/mozilla/strict/15.3.4.5-expected.txt
LayoutTests/fast/js/script-tests/function-bind.js [new file with mode: 0644]
LayoutTests/ietestcenter/Javascript/15.2.3.3-4-38-expected.txt
LayoutTests/ietestcenter/Javascript/15.3.4.5-0-1-expected.txt
LayoutTests/ietestcenter/Javascript/15.3.4.5-0-2-expected.txt
LayoutTests/ietestcenter/Javascript/15.3.4.5-13.b-1-expected.txt
LayoutTests/ietestcenter/Javascript/15.3.4.5-13.b-2-expected.txt
LayoutTests/ietestcenter/Javascript/15.3.4.5-13.b-3-expected.txt
LayoutTests/ietestcenter/Javascript/15.3.4.5-13.b-4-expected.txt
LayoutTests/ietestcenter/Javascript/15.3.4.5-13.b-5-expected.txt
LayoutTests/ietestcenter/Javascript/15.3.4.5-15-1-expected.txt
LayoutTests/ietestcenter/Javascript/15.3.4.5-15-2-expected.txt
LayoutTests/ietestcenter/Javascript/15.3.4.5-16-1-expected.txt
LayoutTests/ietestcenter/Javascript/15.3.4.5-2-1-expected.txt
LayoutTests/ietestcenter/Javascript/15.3.4.5-2-2-expected.txt
LayoutTests/ietestcenter/Javascript/15.3.4.5-2-3-expected.txt
LayoutTests/ietestcenter/Javascript/15.3.4.5-2-4-expected.txt
LayoutTests/ietestcenter/Javascript/15.3.4.5-2-5-expected.txt
LayoutTests/ietestcenter/Javascript/15.3.4.5-2-6-expected.txt
LayoutTests/ietestcenter/Javascript/15.3.4.5-2-7-expected.txt
LayoutTests/ietestcenter/Javascript/15.3.4.5-2-8-expected.txt
LayoutTests/ietestcenter/Javascript/15.3.4.5-2-9-expected.txt
LayoutTests/ietestcenter/Javascript/15.3.4.5-8-1-expected.txt
LayoutTests/ietestcenter/Javascript/15.3.4.5-8-2-expected.txt
LayoutTests/ietestcenter/Javascript/15.3.4.5-9-1-expected.txt
LayoutTests/ietestcenter/Javascript/15.3.4.5-9-2-expected.txt
Source/JavaScriptCore/CMakeLists.txt
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/GNUmakefile.list.am
Source/JavaScriptCore/JavaScriptCore.JSVALUE32_64only.exp
Source/JavaScriptCore/JavaScriptCore.JSVALUE64only.exp
Source/JavaScriptCore/JavaScriptCore.exp
Source/JavaScriptCore/JavaScriptCore.gypi
Source/JavaScriptCore/JavaScriptCore.pro
Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/jit/JITStubs.cpp
Source/JavaScriptCore/jit/JITStubs.h
Source/JavaScriptCore/jsc.cpp
Source/JavaScriptCore/runtime/CommonIdentifiers.h
Source/JavaScriptCore/runtime/ConstructData.h
Source/JavaScriptCore/runtime/Executable.h
Source/JavaScriptCore/runtime/FunctionPrototype.cpp
Source/JavaScriptCore/runtime/FunctionPrototype.h
Source/JavaScriptCore/runtime/JSBoundFunction.cpp [new file with mode: 0644]
Source/JavaScriptCore/runtime/JSBoundFunction.h [new file with mode: 0644]
Source/JavaScriptCore/runtime/JSFunction.cpp
Source/JavaScriptCore/runtime/JSFunction.h
Source/JavaScriptCore/runtime/JSGlobalData.cpp
Source/JavaScriptCore/runtime/JSGlobalData.h
Source/JavaScriptCore/runtime/JSGlobalObject.cpp
Source/JavaScriptCore/runtime/JSGlobalObject.h
Source/JavaScriptCore/runtime/Lookup.cpp
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSDOMBinding.cpp
Source/WebCore/bindings/js/JSDOMWindowCustom.cpp
Source/WebCore/bindings/js/JSHistoryCustom.cpp
Source/WebCore/bindings/js/JSLocationCustom.cpp