Changeset 151749 in webkit


Ignore:
Timestamp:
Jun 19, 2013 1:09:33 PM (11 years ago)
Author:
mhahnenberg@apple.com
Message:

Refactor ObjCCallbackFunction to inherit directly from InternalFunction
https://bugs.webkit.org/show_bug.cgi?id=117595

Reviewed by Geoffrey Garen.

  • API/APICallbackFunction.h: Added. New struct that allows JSCallbackFunction and

ObjCCallbackFunction to share their host call() implementation through the magic of
templates.
(JSC::APICallbackFunction::call):

  • API/JSCallbackFunction.cpp:

(JSC::JSCallbackFunction::getCallData): Changed to get the template-ized version of
the host function.

  • API/JSCallbackFunction.h:
  • API/ObjCCallbackFunction.h: Now inherits directly from InternalFunction.
  • API/ObjCCallbackFunction.mm:

(JSC::ObjCCallbackFunction::ObjCCallbackFunction):
(JSC::ObjCCallbackFunction::getCallData): Ditto.

Location:
branches/dfgFourthTier/Source/JavaScriptCore
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • branches/dfgFourthTier/Source/JavaScriptCore/API/JSCallbackFunction.cpp

    r149636 r151749  
    2727#include "JSCallbackFunction.h"
    2828
     29#include "APICallbackFunction.h"
     30#include "APICast.h"
    2931#include "APIShims.h"
    30 #include "APICast.h"
    3132#include "CodeBlock.h"
    3233#include "Error.h"
     
    6465}
    6566
    66 EncodedJSValue JSCallbackFunction::call(ExecState* exec)
    67 {
    68     JSContextRef execRef = toRef(exec);
    69     JSObjectRef functionRef = toRef(exec->callee());
    70     JSObjectRef thisObjRef = toRef(jsCast<JSObject*>(exec->hostThisValue().toThis(exec, NotStrictMode)));
    71 
    72     int argumentCount = static_cast<int>(exec->argumentCount());
    73     Vector<JSValueRef, 16> arguments(argumentCount);
    74     for (int i = 0; i < argumentCount; i++)
    75         arguments[i] = toRef(exec, exec->argument(i));
    76 
    77     JSValueRef exception = 0;
    78     JSValueRef result;
    79     {
    80         APICallbackShim callbackShim(exec);
    81         result = jsCast<JSCallbackFunction*>(toJS(functionRef))->m_callback(execRef, functionRef, thisObjRef, argumentCount, arguments.data(), &exception);
    82     }
    83     if (exception)
    84         throwError(exec, toJS(exec, exception));
    85 
    86     // result must be a valid JSValue.
    87     if (!result)
    88         return JSValue::encode(jsUndefined());
    89 
    90     return JSValue::encode(toJS(exec, result));
    91 }
    92 
    9367CallType JSCallbackFunction::getCallData(JSCell*, CallData& callData)
    9468{
    95     callData.native.function = call;
     69    callData.native.function = APICallbackFunction::call<JSCallbackFunction>;
    9670    return CallTypeHost;
    9771}
  • branches/dfgFourthTier/Source/JavaScriptCore/API/JSCallbackFunction.h

    r148697 r151749  
    3333
    3434class JSCallbackFunction : public InternalFunction {
    35 protected:
    36     JSCallbackFunction(JSGlobalObject*, Structure*, JSObjectCallAsFunctionCallback);
    37     void finishCreation(VM&, const String& name);
    38 
     35    friend struct APICallbackFunction;
    3936public:
    4037    typedef InternalFunction Base;
     
    5148    }
    5249
    53 protected:
     50private:
     51    JSCallbackFunction(JSGlobalObject*, Structure*, JSObjectCallAsFunctionCallback);
     52    void finishCreation(VM&, const String& name);
     53
    5454    static CallType getCallData(JSCell*, CallData&);
    55 
    56 private:
    57     static EncodedJSValue JSC_HOST_CALL call(ExecState*);
    5855
    5956    JSObjectCallAsFunctionCallback m_callback;
  • branches/dfgFourthTier/Source/JavaScriptCore/API/ObjCCallbackFunction.h

    r148697 r151749  
    4343class ObjCCallbackFunctionImpl;
    4444
    45 class ObjCCallbackFunction : public JSCallbackFunction {
     45class ObjCCallbackFunction : public InternalFunction {
     46    friend struct APICallbackFunction;
    4647public:
    47     typedef JSCallbackFunction Base;
     48    typedef InternalFunction Base;
    4849
    4950    static ObjCCallbackFunction* create(ExecState*, JSGlobalObject*, const String& name, PassOwnPtr<ObjCCallbackFunctionImpl>);
     
    6465
    6566private:
     67    static CallType getCallData(JSCell*, CallData&);
     68
     69    JSObjectCallAsFunctionCallback m_callback;
    6670    OwnPtr<ObjCCallbackFunctionImpl> m_impl;
    6771};
  • branches/dfgFourthTier/Source/JavaScriptCore/API/ObjCCallbackFunction.mm

    r148697 r151749  
    2929#if JSC_OBJC_API_ENABLED
    3030
     31#import "APICallbackFunction.h"
    3132#import "APICast.h"
    3233#import "APIShims.h"
     
    470471
    471472ObjCCallbackFunction::ObjCCallbackFunction(JSC::JSGlobalObject* globalObject, JSObjectCallAsFunctionCallback callback, PassOwnPtr<ObjCCallbackFunctionImpl> impl)
    472     : Base(globalObject, globalObject->objcCallbackFunctionStructure(), callback)
     473    : Base(globalObject, globalObject->objcCallbackFunctionStructure())
     474    , m_callback(callback)
    473475    , m_impl(impl)
    474476{
     
    485487{
    486488    static_cast<ObjCCallbackFunction*>(cell)->ObjCCallbackFunction::~ObjCCallbackFunction();
     489}
     490
     491CallType ObjCCallbackFunction::getCallData(JSCell*, CallData& callData)
     492{
     493    callData.native.function = APICallbackFunction::call<ObjCCallbackFunction>;
     494    return CallTypeHost;
    487495}
    488496
  • branches/dfgFourthTier/Source/JavaScriptCore/ChangeLog

    r151744 r151749  
     12013-06-19  Mark Hahnenberg  <mhahnenberg@apple.com>
     2
     3        Refactor ObjCCallbackFunction to inherit directly from InternalFunction
     4        https://bugs.webkit.org/show_bug.cgi?id=117595
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        * API/APICallbackFunction.h: Added. New struct that allows JSCallbackFunction and
     9        ObjCCallbackFunction to share their host call() implementation through the magic of
     10        templates.
     11        (JSC::APICallbackFunction::call):
     12        * API/JSCallbackFunction.cpp:
     13        (JSC::JSCallbackFunction::getCallData): Changed to get the template-ized version of
     14        the host function.
     15        * API/JSCallbackFunction.h:
     16        * API/ObjCCallbackFunction.h: Now inherits directly from InternalFunction.
     17        * API/ObjCCallbackFunction.mm:
     18        (JSC::ObjCCallbackFunction::ObjCCallbackFunction):
     19        (JSC::ObjCCallbackFunction::getCallData): Ditto.
     20        * GNUmakefile.list.am: Build files!
     21        * JavaScriptCore.vcxproj/JavaScriptCore.vcxproj:
     22        * JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters:
     23        * JavaScriptCore.xcodeproj/project.pbxproj:
     24
    1252013-06-19  Michael Saboff  <msaboff@apple.com>
    226
  • branches/dfgFourthTier/Source/JavaScriptCore/GNUmakefile.list.am

    r151651 r151749  
    3333
    3434javascriptcore_sources += \
     35    Source/JavaScriptCore/API/APICallbackFunction.h \
    3536        Source/JavaScriptCore/API/APICast.h \
    3637        Source/JavaScriptCore/API/APIShims.h \
  • branches/dfgFourthTier/Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj

    r151651 r151749  
    402402  </ItemGroup>
    403403  <ItemGroup>
     404    <ClInclude Include="..\API\APICallbackFunction.h" />
    404405    <ClInclude Include="..\API\APICast.h" />
    405406    <ClInclude Include="..\API\JavaScript.h" />
  • branches/dfgFourthTier/Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters

    r151651 r151749  
    765765  </ItemGroup>
    766766  <ItemGroup>
     767    <ClInclude Include="..\API\APICallbackFunction.h">
     768      <Filter>API</Filter>
     769    </ClInclude>
    767770    <ClInclude Include="..\API\APICast.h">
    768771      <Filter>API</Filter>
  • branches/dfgFourthTier/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r151651 r151749  
    599599                2600B5A6152BAAA70091EE5F /* JSStringJoiner.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2600B5A4152BAAA70091EE5F /* JSStringJoiner.cpp */; };
    600600                2600B5A7152BAAA70091EE5F /* JSStringJoiner.h in Headers */ = {isa = PBXBuildFile; fileRef = 2600B5A5152BAAA70091EE5F /* JSStringJoiner.h */; };
     601                2A48D1911772365B00C65A5F /* APICallbackFunction.h in Headers */ = {isa = PBXBuildFile; fileRef = C211B574176A224D000E2A23 /* APICallbackFunction.h */; };
    601602                41359CF30FDD89AD00206180 /* DateConversion.h in Headers */ = {isa = PBXBuildFile; fileRef = D21202290AD4310C00ED79B6 /* DateConversion.h */; };
    602603                4443AE3316E188D90076F110 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 51F0EB6105C86C6B00E6DF1B /* Foundation.framework */; };
     
    19181919                C21122DF15DD9AB300790E3A /* GCThreadSharedData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCThreadSharedData.h; sourceTree = "<group>"; };
    19191920                C21122E015DD9AB300790E3A /* MarkStackInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MarkStackInlines.h; sourceTree = "<group>"; };
     1921                C211B574176A224D000E2A23 /* APICallbackFunction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APICallbackFunction.h; sourceTree = "<group>"; };
    19201922                C218D13F1655CFD50062BB81 /* CopyWorkList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CopyWorkList.h; sourceTree = "<group>"; };
    19211923                C2239D1216262BDD005AC5FD /* CopyVisitor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CopyVisitor.cpp; sourceTree = "<group>"; };
     
    24472449                        isa = PBXGroup;
    24482450                        children = (
     2451                                C211B574176A224D000E2A23 /* APICallbackFunction.h */,
    24492452                                1482B78A0A4305AB00517CFC /* APICast.h */,
    24502453                                865F408710E7D56300947361 /* APIShims.h */,
     
    37233726                                C2FE18A416BAEC4000AF3061 /* StructureRareData.h in Headers */,
    37243727                                C20BA92D16BB1C1500B3AEA2 /* StructureRareDataInlines.h in Headers */,
     3728                                2A48D1911772365B00C65A5F /* APICallbackFunction.h in Headers */,
    37253729                                0F9332A514CA7DDD0085F3C6 /* StructureSet.h in Headers */,
    37263730                                0F766D3915AE4A1F008F363E /* StructureStubClearingWatchpoint.h in Headers */,
Note: See TracChangeset for help on using the changeset viewer.