Title: [153233] trunk/Source/_javascript_Core
Revision
153233
Author
[email protected]
Date
2013-07-24 21:03:12 -0700 (Wed, 24 Jul 2013)

Log Message

fourthTier: 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.
* GNUmakefile.list.am: Build files!
* _javascript_Core.vcxproj/_javascript_Core.vcxproj:
* _javascript_Core.vcxproj/_javascript_Core.vcxproj.filters:
* _javascript_Core.xcodeproj/project.pbxproj:

Modified Paths

Added Paths

Diff

Copied: trunk/Source/_javascript_Core/API/APICallbackFunction.h (from rev 153232, trunk/Source/_javascript_Core/API/ObjCCallbackFunction.h) (0 => 153233)


--- trunk/Source/_javascript_Core/API/APICallbackFunction.h	                        (rev 0)
+++ trunk/Source/_javascript_Core/API/APICallbackFunction.h	2013-07-25 04:03:12 UTC (rev 153233)
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef APICallbackFunction_h
+#define APICallbackFunction_h
+
+#include "APICast.h"
+#include "APIShims.h"
+#include "Error.h"
+#include <wtf/Vector.h>
+
+namespace JSC {
+
+struct APICallbackFunction {
+
+template <typename T> static EncodedJSValue JSC_HOST_CALL call(ExecState*);
+
+};
+
+template <typename T>
+EncodedJSValue APICallbackFunction::call(ExecState* exec)
+{
+    JSContextRef execRef = toRef(exec);
+    JSObjectRef functionRef = toRef(exec->callee());
+    JSObjectRef thisObjRef = toRef(jsCast<JSObject*>(exec->hostThisValue().toThis(exec, NotStrictMode)));
+
+    int argumentCount = static_cast<int>(exec->argumentCount());
+    Vector<JSValueRef, 16> arguments;
+    arguments.reserveInitialCapacity(argumentCount);
+    for (int i = 0; i < argumentCount; i++)
+        arguments.uncheckedAppend(toRef(exec, exec->argument(i)));
+
+    JSValueRef exception = 0;
+    JSValueRef result;
+    {
+        APICallbackShim callbackShim(exec);
+        result = jsCast<T*>(toJS(functionRef))->m_callback(execRef, functionRef, thisObjRef, argumentCount, arguments.data(), &exception);
+    }
+    if (exception)
+        throwError(exec, toJS(exec, exception));
+
+    // result must be a valid JSValue.
+    if (!result)
+        return JSValue::encode(jsUndefined());
+
+    return JSValue::encode(toJS(exec, result));
+}
+} // namespace JSC
+
+#endif // APICallbackFunction_h

Modified: trunk/Source/_javascript_Core/API/JSCallbackFunction.cpp (153232 => 153233)


--- trunk/Source/_javascript_Core/API/JSCallbackFunction.cpp	2013-07-25 04:03:10 UTC (rev 153232)
+++ trunk/Source/_javascript_Core/API/JSCallbackFunction.cpp	2013-07-25 04:03:12 UTC (rev 153233)
@@ -26,8 +26,9 @@
 #include "config.h"
 #include "JSCallbackFunction.h"
 
-#include "APIShims.h"
+#include "APICallbackFunction.h"
 #include "APICast.h"
+#include "APIShims.h"
 #include "CodeBlock.h"
 #include "Error.h"
 #include "ExceptionHelpers.h"
@@ -63,37 +64,9 @@
     return function;
 }
 
-EncodedJSValue JSCallbackFunction::call(ExecState* exec)
-{
-    JSContextRef execRef = toRef(exec);
-    JSObjectRef functionRef = toRef(exec->callee());
-    JSObjectRef thisObjRef = toRef(jsCast<JSObject*>(exec->hostThisValue().toThis(exec, NotStrictMode)));
-
-    size_t argumentCount = exec->argumentCount();
-    Vector<JSValueRef, 16> arguments;
-    arguments.reserveInitialCapacity(argumentCount);
-    for (size_t i = 0; i < argumentCount; ++i)
-        arguments.uncheckedAppend(toRef(exec, exec->argument(i)));
-
-    JSValueRef exception = 0;
-    JSValueRef result;
-    {
-        APICallbackShim callbackShim(exec);
-        result = jsCast<JSCallbackFunction*>(toJS(functionRef))->m_callback(execRef, functionRef, thisObjRef, argumentCount, arguments.data(), &exception);
-    }
-    if (exception)
-        throwError(exec, toJS(exec, exception));
-
-    // result must be a valid JSValue.
-    if (!result)
-        return JSValue::encode(jsUndefined());
-
-    return JSValue::encode(toJS(exec, result));
-}
-
 CallType JSCallbackFunction::getCallData(JSCell*, CallData& callData)
 {
-    callData.native.function = call;
+    callData.native.function = APICallbackFunction::call<JSCallbackFunction>;
     return CallTypeHost;
 }
 

Modified: trunk/Source/_javascript_Core/API/JSCallbackFunction.h (153232 => 153233)


--- trunk/Source/_javascript_Core/API/JSCallbackFunction.h	2013-07-25 04:03:10 UTC (rev 153232)
+++ trunk/Source/_javascript_Core/API/JSCallbackFunction.h	2013-07-25 04:03:12 UTC (rev 153233)
@@ -32,10 +32,7 @@
 namespace JSC {
 
 class JSCallbackFunction : public InternalFunction {
-protected:
-    JSCallbackFunction(JSGlobalObject*, Structure*, JSObjectCallAsFunctionCallback);
-    void finishCreation(VM&, const String& name);
-
+    friend struct APICallbackFunction;
 public:
     typedef InternalFunction Base;
 
@@ -50,12 +47,12 @@
         return Structure::create(vm, globalObject, proto, TypeInfo(ObjectType, StructureFlags), &s_info); 
     }
 
-protected:
-    static CallType getCallData(JSCell*, CallData&);
-
 private:
-    static EncodedJSValue JSC_HOST_CALL call(ExecState*);
+    JSCallbackFunction(JSGlobalObject*, Structure*, JSObjectCallAsFunctionCallback);
+    void finishCreation(VM&, const String& name);
 
+    static CallType getCallData(JSCell*, CallData&);
+
     JSObjectCallAsFunctionCallback m_callback;
 };
 

Modified: trunk/Source/_javascript_Core/API/ObjCCallbackFunction.h (153232 => 153233)


--- trunk/Source/_javascript_Core/API/ObjCCallbackFunction.h	2013-07-25 04:03:10 UTC (rev 153232)
+++ trunk/Source/_javascript_Core/API/ObjCCallbackFunction.h	2013-07-25 04:03:12 UTC (rev 153233)
@@ -42,9 +42,10 @@
 
 class ObjCCallbackFunctionImpl;
 
-class ObjCCallbackFunction : public JSCallbackFunction {
+class ObjCCallbackFunction : public InternalFunction {
+    friend struct APICallbackFunction;
 public:
-    typedef JSCallbackFunction Base;
+    typedef InternalFunction Base;
 
     static ObjCCallbackFunction* create(ExecState*, JSGlobalObject*, const String& name, PassOwnPtr<ObjCCallbackFunctionImpl>);
     static void destroy(JSCell*);
@@ -63,6 +64,9 @@
     ObjCCallbackFunction(JSGlobalObject*, JSObjectCallAsFunctionCallback, PassOwnPtr<ObjCCallbackFunctionImpl>);
 
 private:
+    static CallType getCallData(JSCell*, CallData&);
+
+    JSObjectCallAsFunctionCallback m_callback;
     OwnPtr<ObjCCallbackFunctionImpl> m_impl;
 };
 

Modified: trunk/Source/_javascript_Core/API/ObjCCallbackFunction.mm (153232 => 153233)


--- trunk/Source/_javascript_Core/API/ObjCCallbackFunction.mm	2013-07-25 04:03:10 UTC (rev 153232)
+++ trunk/Source/_javascript_Core/API/ObjCCallbackFunction.mm	2013-07-25 04:03:12 UTC (rev 153233)
@@ -28,6 +28,7 @@
 
 #if JSC_OBJC_API_ENABLED
 
+#import "APICallbackFunction.h"
 #import "APICast.h"
 #import "APIShims.h"
 #import "Error.h"
@@ -469,7 +470,8 @@
 const JSC::ClassInfo ObjCCallbackFunction::s_info = { "CallbackFunction", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(ObjCCallbackFunction) };
 
 ObjCCallbackFunction::ObjCCallbackFunction(JSC::JSGlobalObject* globalObject, JSObjectCallAsFunctionCallback callback, PassOwnPtr<ObjCCallbackFunctionImpl> impl)
-    : Base(globalObject, globalObject->objcCallbackFunctionStructure(), callback)
+    : Base(globalObject, globalObject->objcCallbackFunctionStructure())
+    , m_callback(callback)
     , m_impl(impl)
 {
 }
@@ -486,6 +488,12 @@
     static_cast<ObjCCallbackFunction*>(cell)->ObjCCallbackFunction::~ObjCCallbackFunction();
 }
 
+CallType ObjCCallbackFunction::getCallData(JSCell*, CallData& callData)
+{
+    callData.native.function = APICallbackFunction::call<ObjCCallbackFunction>;
+    return CallTypeHost;
+}
+
 JSValueRef ObjCCallbackFunctionImpl::call(JSContext *context, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
 {
     JSGlobalContextRef contextRef = [context JSGlobalContextRef];

Modified: trunk/Source/_javascript_Core/ChangeLog (153232 => 153233)


--- trunk/Source/_javascript_Core/ChangeLog	2013-07-25 04:03:10 UTC (rev 153232)
+++ trunk/Source/_javascript_Core/ChangeLog	2013-07-25 04:03:12 UTC (rev 153233)
@@ -1,3 +1,27 @@
+2013-06-19  Mark Hahnenberg  <[email protected]>
+
+        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.
+        * GNUmakefile.list.am: Build files!
+        * _javascript_Core.vcxproj/_javascript_Core.vcxproj:
+        * _javascript_Core.vcxproj/_javascript_Core.vcxproj.filters:
+        * _javascript_Core.xcodeproj/project.pbxproj:
+
 2013-06-19  Michael Saboff  <[email protected]>
 
         fourthTier: Arity fixup should be done while on same stack

Modified: trunk/Source/_javascript_Core/GNUmakefile.list.am (153232 => 153233)


--- trunk/Source/_javascript_Core/GNUmakefile.list.am	2013-07-25 04:03:10 UTC (rev 153232)
+++ trunk/Source/_javascript_Core/GNUmakefile.list.am	2013-07-25 04:03:12 UTC (rev 153233)
@@ -32,6 +32,7 @@
 	DerivedSources/_javascript_Core/LLIntAssembly.h
 
 _javascript_core_sources += \
+    Source/_javascript_Core/API/APICallbackFunction.h \
 	Source/_javascript_Core/API/APICast.h \
 	Source/_javascript_Core/API/APIShims.h \
 	Source/_javascript_Core/API/JSAPIWrapperObject.h \

Modified: trunk/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_Core.vcxproj (153232 => 153233)


--- trunk/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_Core.vcxproj	2013-07-25 04:03:10 UTC (rev 153232)
+++ trunk/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_Core.vcxproj	2013-07-25 04:03:12 UTC (rev 153233)
@@ -533,6 +533,7 @@
     <ClInclude Include="$(ConfigurationBuildDir)\obj32\$(ProjectName)\DerivedSources\StringConstructor.lut.h" />
   </ItemGroup>
   <ItemGroup>
+    <ClInclude Include="..\API\APICallbackFunction.h" />
     <ClInclude Include="..\API\APICast.h" />
     <ClInclude Include="..\API\_javascript_.h" />
     <ClInclude Include="..\API\_javascript_Core.h" />
@@ -935,4 +936,4 @@
   <ImportGroup Label="ExtensionTargets">
     <Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
   </ImportGroup>
-</Project>
\ No newline at end of file
+</Project>

Modified: trunk/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_Core.vcxproj.filters (153232 => 153233)


--- trunk/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_Core.vcxproj.filters	2013-07-25 04:03:10 UTC (rev 153232)
+++ trunk/Source/_javascript_Core/_javascript_Core.vcxproj/_javascript_Core.vcxproj.filters	2013-07-25 04:03:12 UTC (rev 153233)
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup>
     <Filter Include="assembler">
@@ -767,6 +767,9 @@
     </ClCompile>
   </ItemGroup>
   <ItemGroup>
+    <ClInclude Include="..\API\APICallbackFunction.h">
+      <Filter>API</Filter>
+    </ClInclude>
     <ClInclude Include="..\API\APICast.h">
       <Filter>API</Filter>
     </ClInclude>

Modified: trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj (153232 => 153233)


--- trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2013-07-25 04:03:10 UTC (rev 153232)
+++ trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2013-07-25 04:03:12 UTC (rev 153233)
@@ -579,6 +579,7 @@
 		1ACF7377171CA6FB00C9BB1E /* Weak.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1ACF7376171CA6FB00C9BB1E /* Weak.cpp */; };
 		2600B5A6152BAAA70091EE5F /* JSStringJoiner.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2600B5A4152BAAA70091EE5F /* JSStringJoiner.cpp */; };
 		2600B5A7152BAAA70091EE5F /* JSStringJoiner.h in Headers */ = {isa = PBXBuildFile; fileRef = 2600B5A5152BAAA70091EE5F /* JSStringJoiner.h */; };
+		2A48D1911772365B00C65A5F /* APICallbackFunction.h in Headers */ = {isa = PBXBuildFile; fileRef = C211B574176A224D000E2A23 /* APICallbackFunction.h */; };
 		41359CF30FDD89AD00206180 /* DateConversion.h in Headers */ = {isa = PBXBuildFile; fileRef = D21202290AD4310C00ED79B6 /* DateConversion.h */; };
 		4443AE3316E188D90076F110 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 51F0EB6105C86C6B00E6DF1B /* Foundation.framework */; };
 		451539B912DC994500EF7AC4 /* Yarr.h in Headers */ = {isa = PBXBuildFile; fileRef = 451539B812DC994500EF7AC4 /* Yarr.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -1947,6 +1948,7 @@
 		C21122DE15DD9AB300790E3A /* GCThreadSharedData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GCThreadSharedData.cpp; sourceTree = "<group>"; };
 		C21122DF15DD9AB300790E3A /* GCThreadSharedData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCThreadSharedData.h; sourceTree = "<group>"; };
 		C21122E015DD9AB300790E3A /* MarkStackInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MarkStackInlines.h; sourceTree = "<group>"; };
+		C211B574176A224D000E2A23 /* APICallbackFunction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APICallbackFunction.h; sourceTree = "<group>"; };
 		C218D13F1655CFD50062BB81 /* CopyWorkList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CopyWorkList.h; sourceTree = "<group>"; };
 		C2239D1216262BDD005AC5FD /* CopyVisitor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CopyVisitor.cpp; sourceTree = "<group>"; };
 		C2239D1316262BDD005AC5FD /* CopyVisitor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CopyVisitor.h; sourceTree = "<group>"; };
@@ -2484,6 +2486,7 @@
 		1432EBD70A34CAD400717B9F /* API */ = {
 			isa = PBXGroup;
 			children = (
+				C211B574176A224D000E2A23 /* APICallbackFunction.h */,
 				1482B78A0A4305AB00517CFC /* APICast.h */,
 				865F408710E7D56300947361 /* APIShims.h */,
 				1CAA8B4A0D32C39A0041BCFF /* _javascript_.h */,
@@ -3801,6 +3804,7 @@
 				0FD2C92416D01EE900C7803F /* StructureInlines.h in Headers */,
 				C2FE18A416BAEC4000AF3061 /* StructureRareData.h in Headers */,
 				C20BA92D16BB1C1500B3AEA2 /* StructureRareDataInlines.h in Headers */,
+				2A48D1911772365B00C65A5F /* APICallbackFunction.h in Headers */,
 				0F9332A514CA7DDD0085F3C6 /* StructureSet.h in Headers */,
 				0F766D3915AE4A1F008F363E /* StructureStubClearingWatchpoint.h in Headers */,
 				BCCF0D080EF0AAB900413C8F /* StructureStubInfo.h in Headers */,
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to