Add support for callback interfaces using other callback names than "handleEvent"
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 25 Aug 2015 17:04:47 +0000 (17:04 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 25 Aug 2015 17:04:47 +0000 (17:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=148418

Reviewed by Ryosuke Niwa.

Add support for callback interfaces using other callback names than
"handleEvent" [1].

This is a pre-requirement for Bug 148415, as NodeFilter's callback
function name is "acceptNode":
- https://dom.spec.whatwg.org/#interface-nodefilter

[1] https://heycam.github.io/webidl/#es-user-objects

* bindings/js/JSCallbackData.cpp:
(WebCore::JSCallbackData::invokeCallback):
* bindings/js/JSCallbackData.h:
* bindings/js/JSCustomSQLStatementErrorCallback.cpp:
(WebCore::JSSQLStatementErrorCallback::handleEvent):
* bindings/scripts/CodeGeneratorJS.pm:
(GenerateCallbackImplementation):
* bindings/scripts/test/JS/JSTestCallback.cpp:
(WebCore::JSTestCallback::callbackWithNoParam):
(WebCore::JSTestCallback::callbackWithArrayParam):
(WebCore::JSTestCallback::callbackWithSerializedScriptValueParam):
(WebCore::JSTestCallback::callbackWithStringList):
(WebCore::JSTestCallback::callbackWithBoolean):
(WebCore::JSTestCallback::callbackRequiresThisToPass):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@188913 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSCallbackData.cpp
Source/WebCore/bindings/js/JSCallbackData.h
Source/WebCore/bindings/js/JSCustomSQLStatementErrorCallback.cpp
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/bindings/scripts/test/JS/JSTestCallback.cpp

index 665fab5..59a3081 100644 (file)
@@ -1,5 +1,36 @@
 2015-08-25  Chris Dumez  <cdumez@apple.com>
 
+        Add support for callback interfaces using other callback names than "handleEvent"
+        https://bugs.webkit.org/show_bug.cgi?id=148418
+
+        Reviewed by Ryosuke Niwa.
+
+        Add support for callback interfaces using other callback names than
+        "handleEvent" [1].
+
+        This is a pre-requirement for Bug 148415, as NodeFilter's callback
+        function name is "acceptNode":
+        - https://dom.spec.whatwg.org/#interface-nodefilter
+
+        [1] https://heycam.github.io/webidl/#es-user-objects
+
+        * bindings/js/JSCallbackData.cpp:
+        (WebCore::JSCallbackData::invokeCallback):
+        * bindings/js/JSCallbackData.h:
+        * bindings/js/JSCustomSQLStatementErrorCallback.cpp:
+        (WebCore::JSSQLStatementErrorCallback::handleEvent):
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GenerateCallbackImplementation):
+        * bindings/scripts/test/JS/JSTestCallback.cpp:
+        (WebCore::JSTestCallback::callbackWithNoParam):
+        (WebCore::JSTestCallback::callbackWithArrayParam):
+        (WebCore::JSTestCallback::callbackWithSerializedScriptValueParam):
+        (WebCore::JSTestCallback::callbackWithStringList):
+        (WebCore::JSTestCallback::callbackWithBoolean):
+        (WebCore::JSTestCallback::callbackRequiresThisToPass):
+
+2015-08-25  Chris Dumez  <cdumez@apple.com>
+
         Get rid of custom bindings for RequestAnimationFrameCallback.handleEvent()
         https://bugs.webkit.org/show_bug.cgi?id=148417
 
index 44f3f66..8d97756 100644 (file)
@@ -43,13 +43,13 @@ void JSCallbackData::deleteData(void* context)
     delete static_cast<JSCallbackData*>(context);
 }
 
-JSValue JSCallbackData::invokeCallback(MarkedArgumentBuffer& args, bool* raisedException)
+JSValue JSCallbackData::invokeCallback(MarkedArgumentBuffer& args, PropertyName functionName, bool* raisedException)
 {
     ASSERT(callback());
-    return invokeCallback(callback(), args, raisedException);
+    return invokeCallback(callback(), args, functionName, raisedException);
 }
 
-JSValue JSCallbackData::invokeCallback(JSValue thisValue, MarkedArgumentBuffer& args, bool* raisedException)
+JSValue JSCallbackData::invokeCallback(JSValue thisValue, MarkedArgumentBuffer& args, PropertyName functionName, bool* raisedException)
 {
     ASSERT(callback());
     ASSERT(globalObject());
@@ -60,7 +60,7 @@ JSValue JSCallbackData::invokeCallback(JSValue thisValue, MarkedArgumentBuffer&
     CallData callData;
     CallType callType = callback()->methodTable()->getCallData(callback(), callData);
     if (callType == CallTypeNone) {
-        function = callback()->get(exec, Identifier::fromString(exec, "handleEvent"));
+        function = callback()->get(exec, functionName);
         callType = getCallData(function, callData);
         if (callType == CallTypeNone)
             return JSValue();
index 83ae897..b5239a8 100644 (file)
@@ -66,8 +66,8 @@ public:
     JSC::JSObject* callback() { return m_callback.get(); }
     JSDOMGlobalObject* globalObject() { return m_globalObject.get(); }
     
-    JSC::JSValue invokeCallback(JSC::MarkedArgumentBuffer&, bool* raisedException = 0);
-    JSC::JSValue invokeCallback(JSC::JSValue thisValue, JSC::MarkedArgumentBuffer&, bool* raisedException = 0);
+    JSC::JSValue invokeCallback(JSC::MarkedArgumentBuffer&, JSC::PropertyName functionName, bool* raisedException = nullptr);
+    JSC::JSValue invokeCallback(JSC::JSValue thisValue, JSC::MarkedArgumentBuffer&, JSC::PropertyName functionName, bool* raisedException = nullptr);
 
 private:
     JSC::Strong<JSC::JSObject> m_callback;
index 011ff9a..d3372bd 100644 (file)
@@ -54,7 +54,7 @@ bool JSSQLStatementErrorCallback::handleEvent(SQLTransaction* transaction, SQLEr
     args.append(toJS(exec, m_data->globalObject(), error));
 
     bool raisedException = false;
-    JSValue result = m_data->invokeCallback(args, &raisedException);
+    JSValue result = m_data->invokeCallback(args, Identifier::fromString(exec, "handleEvent"), &raisedException);
     if (raisedException) {
         // The spec says:
         // "If the error callback returns false, then move on to the next statement..."
index e83cbdc..6a61940 100644 (file)
@@ -3570,7 +3570,8 @@ sub GenerateCallbackImplementation
             }
 
             AddIncludesForTypeInImpl($function->signature->type);
-            push(@implContent, "\n" . GetNativeTypeForCallbacks($function->signature->type) . " ${className}::" . $function->signature->name . "(");
+            my $functionName = $function->signature->name;
+            push(@implContent, "\n" . GetNativeTypeForCallbacks($function->signature->type) . " ${className}::${functionName}(");
 
             my @args = ();
             my @argsCheck = ();
@@ -3588,10 +3589,7 @@ sub GenerateCallbackImplementation
             push(@implContent, "        return true;\n\n");
             push(@implContent, "    Ref<$className> protect(*this);\n\n");
             push(@implContent, "    JSLockHolder lock(m_data->globalObject()->vm());\n\n");
-            if (@params) {
-                push(@implContent, "    ExecState* exec = m_data->globalObject()->globalExec();\n");
-                push(@implContent, "    UNUSED_PARAM(exec);\n");
-            }
+            push(@implContent, "    ExecState* exec = m_data->globalObject()->globalExec();\n");
             push(@implContent, "    MarkedArgumentBuffer args;\n");
 
             foreach my $param (@params) {
@@ -3600,7 +3598,7 @@ sub GenerateCallbackImplementation
             }
 
             push(@implContent, "\n    bool raisedException = false;\n");
-            push(@implContent, "    m_data->invokeCallback(args, &raisedException);\n");
+            push(@implContent, "    m_data->invokeCallback(args, Identifier::fromString(exec, \"${functionName}\"), &raisedException);\n");
             push(@implContent, "    return !raisedException;\n");
             push(@implContent, "}\n");
         }
index 6f7bcb0..3920446 100644 (file)
@@ -71,10 +71,11 @@ bool JSTestCallback::callbackWithNoParam()
 
     JSLockHolder lock(m_data->globalObject()->vm());
 
+    ExecState* exec = m_data->globalObject()->globalExec();
     MarkedArgumentBuffer args;
 
     bool raisedException = false;
-    m_data->invokeCallback(args, &raisedException);
+    m_data->invokeCallback(args, Identifier::fromString(exec, "callbackWithNoParam"), &raisedException);
     return !raisedException;
 }
 
@@ -88,12 +89,11 @@ bool JSTestCallback::callbackWithArrayParam(RefPtr<Float32Array> arrayParam)
     JSLockHolder lock(m_data->globalObject()->vm());
 
     ExecState* exec = m_data->globalObject()->globalExec();
-    UNUSED_PARAM(exec);
     MarkedArgumentBuffer args;
     args.append(toJS(exec, m_data->globalObject(), WTF::getPtr(arrayParam)));
 
     bool raisedException = false;
-    m_data->invokeCallback(args, &raisedException);
+    m_data->invokeCallback(args, Identifier::fromString(exec, "callbackWithArrayParam"), &raisedException);
     return !raisedException;
 }
 
@@ -107,13 +107,12 @@ bool JSTestCallback::callbackWithSerializedScriptValueParam(PassRefPtr<Serialize
     JSLockHolder lock(m_data->globalObject()->vm());
 
     ExecState* exec = m_data->globalObject()->globalExec();
-    UNUSED_PARAM(exec);
     MarkedArgumentBuffer args;
     args.append(srzParam ? srzParam->deserialize(exec, castedThis->globalObject(), 0) : jsNull());
     args.append(jsStringWithCache(exec, strArg));
 
     bool raisedException = false;
-    m_data->invokeCallback(args, &raisedException);
+    m_data->invokeCallback(args, Identifier::fromString(exec, "callbackWithSerializedScriptValueParam"), &raisedException);
     return !raisedException;
 }
 
@@ -127,12 +126,11 @@ bool JSTestCallback::callbackWithStringList(PassRefPtr<DOMStringList> listParam)
     JSLockHolder lock(m_data->globalObject()->vm());
 
     ExecState* exec = m_data->globalObject()->globalExec();
-    UNUSED_PARAM(exec);
     MarkedArgumentBuffer args;
     args.append(toJS(exec, m_data->globalObject(), WTF::getPtr(listParam)));
 
     bool raisedException = false;
-    m_data->invokeCallback(args, &raisedException);
+    m_data->invokeCallback(args, Identifier::fromString(exec, "callbackWithStringList"), &raisedException);
     return !raisedException;
 }
 
@@ -146,12 +144,11 @@ bool JSTestCallback::callbackWithBoolean(bool boolParam)
     JSLockHolder lock(m_data->globalObject()->vm());
 
     ExecState* exec = m_data->globalObject()->globalExec();
-    UNUSED_PARAM(exec);
     MarkedArgumentBuffer args;
     args.append(jsBoolean(boolParam));
 
     bool raisedException = false;
-    m_data->invokeCallback(args, &raisedException);
+    m_data->invokeCallback(args, Identifier::fromString(exec, "callbackWithBoolean"), &raisedException);
     return !raisedException;
 }
 
@@ -165,13 +162,12 @@ bool JSTestCallback::callbackRequiresThisToPass(int longParam, TestNode* testNod
     JSLockHolder lock(m_data->globalObject()->vm());
 
     ExecState* exec = m_data->globalObject()->globalExec();
-    UNUSED_PARAM(exec);
     MarkedArgumentBuffer args;
     args.append(jsNumber(longParam));
     args.append(toJS(exec, m_data->globalObject(), WTF::getPtr(testNodeParam)));
 
     bool raisedException = false;
-    m_data->invokeCallback(args, &raisedException);
+    m_data->invokeCallback(args, Identifier::fromString(exec, "callbackRequiresThisToPass"), &raisedException);
     return !raisedException;
 }