Commit d8d2757f authored by commit-queue@webkit.org's avatar commit-queue@webkit.org
Browse files

Add PassThis=* to support the callbacks which requires to pass "this" value.

https://bugs.webkit.org/show_bug.cgi?id=84232

Patch by Vineet Chaudhary <rgf748@motorola.com> on 2012-04-18
Reviewed by Kentaro Hara.

Adding PassThisToCallback=XXX to attributes will be useful for the callbacks which requires to pass "this".
This will help to identify the type(XXX) of "this" value in codegenerator.

Tests: bindings/scripts/test/TestCallback.idl

* bindings/scripts/CodeGeneratorJS.pm:
(GenerateCallbackImplementation): Modified codegenerator to support [PassThisToCallback]
* bindings/scripts/CodeGeneratorV8.pm:
(GenerateCallbackImplementation): Ditto.
* bindings/scripts/IDLAttributes.txt: Added PassThisToCallback=*
* bindings/scripts/test/CPP/WebDOMTestCallback.cpp: Modofied results from run-bindings-tests.
(WebDOMTestCallback::callbackWithBoolean):
(WebDOMTestCallback::callbackRequiresThisToPass):
* bindings/scripts/test/CPP/WebDOMTestCallback.h: Ditto.
(WebDOMTestCallback):
* bindings/scripts/test/GObject/WebKitDOMTestCallback.cpp: Ditto.
(webkit_dom_test_callback_callback_with_boolean):
(webkit_dom_test_callback_callback_requires_this_to_pass):
* bindings/scripts/test/GObject/WebKitDOMTestCallback.h: Ditto.
* bindings/scripts/test/JS/JSTestCallback.cpp: Ditto.
(WebCore::JSTestCallback::callbackWithBoolean):
(WebCore):
(WebCore::JSTestCallback::callbackRequiresThisToPass):
* bindings/scripts/test/JS/JSTestCallback.h: Ditto.
(JSTestCallback):
* bindings/scripts/test/ObjC/DOMTestCallback.h: Ditto.
* bindings/scripts/test/ObjC/DOMTestCallback.mm: Ditto.
(-[DOMTestCallback callbackWithBoolean:]):
(-[DOMTestCallback callbackRequiresThisToPass:thisClassParam:]):
* bindings/scripts/test/TestCallback.idl: Added test to verify generated code.
* bindings/scripts/test/V8/V8TestCallback.cpp: Ditto.
(WebCore::V8TestCallback::callbackWithBoolean):
(WebCore):
(WebCore::V8TestCallback::callbackRequiresThisToPass):
* bindings/scripts/test/V8/V8TestCallback.h: Ditto.
(V8TestCallback):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@114502 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 7abf47e0
2012-04-18 Vineet Chaudhary <rgf748@motorola.com>
Add PassThis=* to support the callbacks which requires to pass "this" value.
https://bugs.webkit.org/show_bug.cgi?id=84232
Reviewed by Kentaro Hara.
Adding PassThisToCallback=XXX to attributes will be useful for the callbacks which requires to pass "this".
This will help to identify the type(XXX) of "this" value in codegenerator.
Tests: bindings/scripts/test/TestCallback.idl
* bindings/scripts/CodeGeneratorJS.pm:
(GenerateCallbackImplementation): Modified codegenerator to support [PassThisToCallback]
* bindings/scripts/CodeGeneratorV8.pm:
(GenerateCallbackImplementation): Ditto.
* bindings/scripts/IDLAttributes.txt: Added PassThisToCallback=*
* bindings/scripts/test/CPP/WebDOMTestCallback.cpp: Modofied results from run-bindings-tests.
(WebDOMTestCallback::callbackWithBoolean):
(WebDOMTestCallback::callbackRequiresThisToPass):
* bindings/scripts/test/CPP/WebDOMTestCallback.h: Ditto.
(WebDOMTestCallback):
* bindings/scripts/test/GObject/WebKitDOMTestCallback.cpp: Ditto.
(webkit_dom_test_callback_callback_with_boolean):
(webkit_dom_test_callback_callback_requires_this_to_pass):
* bindings/scripts/test/GObject/WebKitDOMTestCallback.h: Ditto.
* bindings/scripts/test/JS/JSTestCallback.cpp: Ditto.
(WebCore::JSTestCallback::callbackWithBoolean):
(WebCore):
(WebCore::JSTestCallback::callbackRequiresThisToPass):
* bindings/scripts/test/JS/JSTestCallback.h: Ditto.
(JSTestCallback):
* bindings/scripts/test/ObjC/DOMTestCallback.h: Ditto.
* bindings/scripts/test/ObjC/DOMTestCallback.mm: Ditto.
(-[DOMTestCallback callbackWithBoolean:]):
(-[DOMTestCallback callbackRequiresThisToPass:thisClassParam:]):
* bindings/scripts/test/TestCallback.idl: Added test to verify generated code.
* bindings/scripts/test/V8/V8TestCallback.cpp: Ditto.
(WebCore::V8TestCallback::callbackWithBoolean):
(WebCore):
(WebCore::V8TestCallback::callbackRequiresThisToPass):
* bindings/scripts/test/V8/V8TestCallback.h: Ditto.
(V8TestCallback):
2012-04-18 'Pavel Feldman' <pfeldman@chromium.org>
 
Not reviewed: fixing Chromium win compilation.
......@@ -2685,14 +2685,24 @@ sub GenerateCallbackImplementation
push(@implContent, "\n" . GetNativeType($function->signature->type) . " ${className}::" . $function->signature->name . "(");
my @args = ();
my @argsCheck = ();
my $thisType = $function->signature->extendedAttributes->{"PassThisToCallback"};
foreach my $param (@params) {
my $paramName = $param->name;
AddIncludesForTypeInImpl($param->type, 1);
push(@args, GetNativeType($param->type) . " " . $param->name);
push(@args, GetNativeType($param->type) . " " . $paramName);
if ($thisType and $thisType eq $param->type) {
push(@argsCheck, <<END);
ASSERT(${paramName});
END
}
}
push(@implContent, join(", ", @args));
push(@implContent, ")\n");
push(@implContent, "{\n");
push(@implContent, @argsCheck) if @argsCheck;
push(@implContent, " if (!canInvokeCallback())\n");
push(@implContent, " return true;\n\n");
push(@implContent, " RefPtr<$className> protect(this);\n\n");
......@@ -2712,7 +2722,20 @@ sub GenerateCallbackImplementation
}
push(@implContent, "\n bool raisedException = false;\n");
push(@implContent, " m_data->invokeCallback(args, &raisedException);\n");
if ($thisType) {
foreach my $param (@params) {
next if $param->type ne $thisType;
my $paramName = $param->name;
push(@implContent, <<END);
JSValue js${paramName} = toJS(exec, m_data->globalObject(), ${paramName});
m_data->invokeCallback(js${paramName}, args, &raisedException);
END
last;
}
} else {
push(@implContent, " m_data->invokeCallback(args, &raisedException);\n");
}
push(@implContent, " return !raisedException;\n");
push(@implContent, "}\n");
}
......
......@@ -3031,14 +3031,24 @@ END
push(@implContent, "\n" . GetNativeTypeForCallbacks($function->signature->type) . " ${className}::" . $function->signature->name . "(");
my @args = ();
my @argsCheck = ();
my $thisType = $function->signature->extendedAttributes->{"PassThisToCallback"};
foreach my $param (@params) {
my $paramName = $param->name;
AddIncludesForType($param->type);
push(@args, GetNativeTypeForCallbacks($param->type) . " " . $param->name);
push(@args, GetNativeTypeForCallbacks($param->type) . " " . $paramName);
if ($thisType and $thisType eq $param->type) {
push(@argsCheck, <<END);
ASSERT(${paramName});
END
}
}
push(@implContent, join(", ", @args));
push(@implContent, ")\n");
push(@implContent, "{\n");
push(@implContent, @argsCheck) if @argsCheck;
push(@implContent, " if (!canInvokeCallback())\n");
push(@implContent, " return true;\n\n");
push(@implContent, " v8::HandleScope handleScope;\n\n");
......@@ -3067,7 +3077,16 @@ END
push(@implContent, "\n v8::Handle<v8::Value> *argv = 0;\n\n");
}
push(@implContent, " bool callbackReturnValue = false;\n");
push(@implContent, " return !invokeCallback(m_callback, " . scalar(@params) . ", argv, callbackReturnValue, scriptExecutionContext());\n");
if ($thisType) {
foreach my $param (@params) {
next if $param->type ne $thisType;
my $paramName = $param->name;
push(@implContent, " return !invokeCallback(m_callback, v8::Handle<v8::Object>::Cast(${paramName}Handle), " . scalar(@params) . ", argv, callbackReturnValue, scriptExecutionContext());\n");
last;
}
} else {
push(@implContent, " return !invokeCallback(m_callback, " . scalar(@params) . ", argv, callbackReturnValue, scriptExecutionContext());\n");
}
push(@implContent, "}\n");
}
}
......
......@@ -91,6 +91,7 @@ ObjCPolymorphic
ObjCProtocol
OmitConstructor
Optional=|DefaultIsNullString|DefaultIsUndefined
PassThisToCallback=*
Reflect=*
Replaceable
ReplaceableConstructor
......
......@@ -27,14 +27,18 @@
#include "Class1.h"
#include "Class2.h"
#include "Class3.h"
#include "Class8.h"
#include "DOMStringList.h"
#include "KURL.h"
#include "TestCallback.h"
#include "ThisClass.h"
#include "WebDOMClass1.h"
#include "WebDOMClass2.h"
#include "WebDOMClass3.h"
#include "WebDOMClass8.h"
#include "WebDOMDOMStringList.h"
#include "WebDOMString.h"
#include "WebDOMThisClass.h"
#include "WebExceptionHandler.h"
#include "wtf/text/AtomicString.h"
#include <wtf/GetPtr.h>
......@@ -133,6 +137,14 @@ bool WebDOMTestCallback::callbackWithBoolean(bool boolParam)
return impl()->callbackWithBoolean(boolParam);
}
bool WebDOMTestCallback::callbackRequiresThisToPass(const WebDOMClass8& class8Param, const WebDOMThisClass& thisClassParam)
{
if (!impl())
return false;
return impl()->callbackRequiresThisToPass(toWebCore(class8Param), toWebCore(thisClassParam));
}
WebCore::TestCallback* toWebCore(const WebDOMTestCallback& wrapper)
{
return wrapper.impl();
......
......@@ -35,7 +35,9 @@ class TestCallback;
class WebDOMClass1;
class WebDOMClass2;
class WebDOMClass3;
class WebDOMClass8;
class WebDOMDOMStringList;
class WebDOMThisClass;
class WebDOMTestCallback : public WebDOMObject {
public:
......@@ -51,6 +53,7 @@ public:
int callbackWithNonBoolReturnType(const WebDOMClass3& class3Param);
bool callbackWithStringList(const WebDOMDOMStringList& listParam);
bool callbackWithBoolean(bool boolParam);
bool callbackRequiresThisToPass(const WebDOMClass8& class8Param, const WebDOMThisClass& thisClassParam);
WebCore::TestCallback* impl() const;
......
......@@ -35,9 +35,13 @@
#include "webkit/WebKitDOMClass2Private.h"
#include "webkit/WebKitDOMClass3.h"
#include "webkit/WebKitDOMClass3Private.h"
#include "webkit/WebKitDOMClass8.h"
#include "webkit/WebKitDOMClass8Private.h"
#include "webkit/WebKitDOMDOMStringList.h"
#include "webkit/WebKitDOMDOMStringListPrivate.h"
#include "webkit/WebKitDOMTestCallbackPrivate.h"
#include "webkit/WebKitDOMThisClass.h"
#include "webkit/WebKitDOMThisClassPrivate.h"
#include "webkitdefines.h"
#include "webkitglobalsprivate.h"
#include "webkitmarshal.h"
......@@ -267,3 +271,30 @@ webkit_dom_test_callback_callback_with_boolean(WebKitDOMTestCallback* self, gboo
#endif /* ENABLE(SQL_DATABASE) */
}
gboolean
webkit_dom_test_callback_callback_requires_this_to_pass(WebKitDOMTestCallback* self, WebKitDOMClass8* class8Param, WebKitDOMThisClass* thisClassParam)
{
#if ENABLE(SQL_DATABASE)
g_return_val_if_fail(self, 0);
WebCore::JSMainThreadNullState state;
WebCore::TestCallback* item = WebKit::core(self);
g_return_val_if_fail(class8Param, 0);
g_return_val_if_fail(thisClassParam, 0);
WebCore::Class8* convertedClass8Param = 0;
if (class8Param) {
convertedClass8Param = WebKit::core(class8Param);
g_return_val_if_fail(convertedClass8Param, 0);
}
WebCore::ThisClass* convertedThisClassParam = 0;
if (thisClassParam) {
convertedThisClassParam = WebKit::core(thisClassParam);
g_return_val_if_fail(convertedThisClassParam, 0);
}
gboolean result = item->callbackRequiresThisToPass(convertedClass8Param, convertedThisClassParam);
return result;
#else
WEBKIT_WARN_FEATURE_NOT_PRESENT("SQL Database")
return static_cast<gboolean>(0);
#endif /* ENABLE(SQL_DATABASE) */
}
......@@ -111,6 +111,18 @@ webkit_dom_test_callback_callback_with_string_list(WebKitDOMTestCallback* self,
WEBKIT_API gboolean
webkit_dom_test_callback_callback_with_boolean(WebKitDOMTestCallback* self, gboolean boolParam);
/**
* webkit_dom_test_callback_callback_requires_this_to_pass:
* @self: A #WebKitDOMTestCallback
* @class8Param: A #WebKitDOMClass8
* @thisClassParam: A #WebKitDOMThisClass
*
* Returns:
*
**/
WEBKIT_API gboolean
webkit_dom_test_callback_callback_requires_this_to_pass(WebKitDOMTestCallback* self, WebKitDOMClass8* class8Param, WebKitDOMThisClass* thisClassParam);
G_END_DECLS
#endif /* WebKitDOMTestCallback_h */
......@@ -26,7 +26,9 @@
#include "JSClass1.h"
#include "JSClass2.h"
#include "JSClass8.h"
#include "JSDOMStringList.h"
#include "JSThisClass.h"
#include "ScriptExecutionContext.h"
#include <runtime/JSLock.h>
......@@ -146,6 +148,29 @@ bool JSTestCallback::callbackWithBoolean(bool boolParam)
return !raisedException;
}
bool JSTestCallback::callbackRequiresThisToPass(Class8* class8Param, ThisClass* thisClassParam)
{
ASSERT(thisClassParam);
if (!canInvokeCallback())
return true;
RefPtr<JSTestCallback> protect(this);
JSLock lock(SilenceAssertionsOnly);
ExecState* exec = m_data->globalObject()->globalExec();
MarkedArgumentBuffer args;
args.append(toJS(exec, m_data->globalObject(), class8Param));
args.append(toJS(exec, m_data->globalObject(), thisClassParam));
bool raisedException = false;
JSValue jsthisClassParam = toJS(exec, m_data->globalObject(), thisClassParam);
m_data->invokeCallback(jsthisClassParam, args, &raisedException);
return !raisedException;
}
}
#endif // ENABLE(SQL_DATABASE)
......@@ -47,6 +47,7 @@ public:
virtual int customCallback(Class5* class5Param, Class6* class6Param);
virtual bool callbackWithStringList(DOMStringList* listParam);
virtual bool callbackWithBoolean(bool boolParam);
virtual bool callbackRequiresThisToPass(Class8* class8Param, ThisClass* thisClassParam);
private:
JSTestCallback(JSC::JSObject* callback, JSDOMGlobalObject*);
......
......@@ -33,7 +33,9 @@
@class DOMClass3;
@class DOMClass5;
@class DOMClass6;
@class DOMClass8;
@class DOMDOMStringList;
@class DOMThisClass;
@class NSString;
@interface DOMTestCallback : DOMObject
......@@ -44,6 +46,7 @@
- (int)customCallback:(DOMClass5 *)class5Param class6Param:(DOMClass6 *)class6Param;
- (BOOL)callbackWithStringList:(DOMDOMStringList *)listParam;
- (BOOL)callbackWithBoolean:(BOOL)boolParam;
- (BOOL)callbackRequiresThisToPass:(DOMClass8 *)class8Param thisClassParam:(DOMThisClass *)thisClassParam;
@end
#endif
......@@ -37,6 +37,7 @@
#import "Class3.h"
#import "Class5.h"
#import "Class6.h"
#import "Class8.h"
#import "DOMBlobInternal.h"
#import "DOMCSSRuleInternal.h"
#import "DOMCSSValueInternal.h"
......@@ -45,16 +46,19 @@
#import "DOMClass3Internal.h"
#import "DOMClass5Internal.h"
#import "DOMClass6Internal.h"
#import "DOMClass8Internal.h"
#import "DOMDOMStringListInternal.h"
#import "DOMEventInternal.h"
#import "DOMNodeInternal.h"
#import "DOMStringList.h"
#import "DOMStyleSheetInternal.h"
#import "DOMTestCallbackInternal.h"
#import "DOMThisClassInternal.h"
#import "ExceptionHandlers.h"
#import "JSMainThreadExecState.h"
#import "KURL.h"
#import "TestCallback.h"
#import "ThisClass.h"
#import "ThreadCheck.h"
#import "WebCoreObjCExtras.h"
#import "WebScriptObjectPrivate.h"
......@@ -123,6 +127,12 @@
return IMPL->callbackWithBoolean(boolParam);
}
- (BOOL)callbackRequiresThisToPass:(DOMClass8 *)class8Param thisClassParam:(DOMThisClass *)thisClassParam
{
WebCore::JSMainThreadNullState state;
return IMPL->callbackRequiresThisToPass(core(class8Param), core(thisClassParam));
}
@end
WebCore::TestCallback* core(DOMTestCallback *wrapper)
......
......@@ -40,5 +40,6 @@ module test {
[Custom] long customCallback(in Class5 class5Param, in Class6 class6Param);
boolean callbackWithStringList(in DOMStringList listParam);
boolean callbackWithBoolean(in boolean boolParam);
[PassThisToCallback=ThisClass] boolean callbackRequiresThisToPass(in Class8 class8Param, in ThisClass thisClassParam);
};
}
......@@ -27,9 +27,11 @@
#include "V8Binding.h"
#include "V8Class1.h"
#include "V8Class2.h"
#include "V8Class8.h"
#include "V8CustomVoidCallback.h"
#include "V8DOMStringList.h"
#include "V8Proxy.h"
#include "V8ThisClass.h"
#include <wtf/GetPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
......@@ -191,6 +193,43 @@ bool V8TestCallback::callbackWithBoolean(bool boolParam)
return !invokeCallback(m_callback, 1, argv, callbackReturnValue, scriptExecutionContext());
}
bool V8TestCallback::callbackRequiresThisToPass(Class8* class8Param, ThisClass* thisClassParam)
{
ASSERT(thisClassParam);
if (!canInvokeCallback())
return true;
v8::HandleScope handleScope;
v8::Handle<v8::Context> v8Context = toV8Context(scriptExecutionContext(), m_worldContext);
if (v8Context.IsEmpty())
return true;
v8::Context::Scope scope(v8Context);
v8::Handle<v8::Value> class8ParamHandle = toV8(class8Param);
if (class8ParamHandle.IsEmpty()) {
if (!isScriptControllerTerminating())
CRASH();
return true;
}
v8::Handle<v8::Value> thisClassParamHandle = toV8(thisClassParam);
if (thisClassParamHandle.IsEmpty()) {
if (!isScriptControllerTerminating())
CRASH();
return true;
}
v8::Handle<v8::Value> argv[] = {
class8ParamHandle,
thisClassParamHandle
};
bool callbackReturnValue = false;
return !invokeCallback(m_callback, v8::Handle<v8::Object>::Cast(thisClassParamHandle), 2, argv, callbackReturnValue, scriptExecutionContext());
}
} // namespace WebCore
#endif // ENABLE(SQL_DATABASE)
......@@ -52,6 +52,7 @@ public:
virtual int customCallback(Class5* class5Param, Class6* class6Param);
virtual bool callbackWithStringList(RefPtr<DOMStringList> listParam);
virtual bool callbackWithBoolean(bool boolParam);
virtual bool callbackRequiresThisToPass(Class8* class8Param, ThisClass* thisClassParam);
private:
V8TestCallback(v8::Local<v8::Object>, ScriptExecutionContext*);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment