博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WebKit之Binding案例(testCallback.idl)
阅读量:4027 次
发布时间:2019-05-24

本文共 8508 字,大约阅读时间需要 28 分钟。

## TestCallback.idl

module test {    interface [        Conditional=DATABASE,        Callback    ] TestCallback {      boolean callbackWithNoParam();      boolean callbackWithClass1Param(in Class1 class1Param);      boolean callbackWithClass2Param(in Class2 class2Param, in DOMString strArg);      long callbackWithNonBoolReturnType(in Class3 class3Param);      [Custom] long customCallback(in Class5 class5Param, in Class6 class6Param);      boolean callbackWithStringList(in DOMStringList listParam);    };}
## JSTestCallback.h

#ifndef JSTestCallback_h#define JSTestCallback_h#if ENABLE(DATABASE)#include "ActiveDOMCallback.h"#include "JSCallbackData.h"#include "TestCallback.h"#include 
namespace WebCore {class JSTestCallback : public TestCallback, public ActiveDOMCallback {public: static PassRefPtr
create(JSC::JSObject* callback, JSDOMGlobalObject* globalObject) { return adoptRef(new JSTestCallback(callback, globalObject)); } virtual ~JSTestCallback(); // Functions virtual bool callbackWithNoParam(); virtual bool callbackWithClass1Param(Class1* class1Param); virtual bool callbackWithClass2Param(Class2* class2Param, const String& strArg); COMPILE_ASSERT(false) virtual int callbackWithNonBoolReturnType(Class3* class3Param); virtual int customCallback(Class5* class5Param, Class6* class6Param); virtual bool callbackWithStringList(DOMStringList* listParam);private: JSTestCallback(JSC::JSObject* callback, JSDOMGlobalObject*); JSCallbackData* m_data;};} // namespace WebCore#endif // ENABLE(DATABASE)#endif
## JSTestcallback.cpp

#include "config.h"#if ENABLE(DATABASE)#include "JSTestCallback.h"#include "JSClass1.h"#include "JSClass2.h"#include "JSDOMStringList.h"#include "ScriptExecutionContext.h"#include 
#include
using namespace JSC;namespace WebCore {JSTestCallback::JSTestCallback(JSObject* callback, JSDOMGlobalObject* globalObject) : ActiveDOMCallback(globalObject->scriptExecutionContext()) , m_data(new JSCallbackData(callback, globalObject)){}JSTestCallback::~JSTestCallback(){ ScriptExecutionContext* context = scriptExecutionContext(); // When the context is destroyed, all tasks with a reference to a callback // should be deleted. So if the context is 0, we are on the context thread. if (!context || context->isContextThread()) delete m_data; else context->postTask(DeleteCallbackDataTask::create(m_data));#ifndef NDEBUG m_data = 0;#endif}// Functionsbool JSTestCallback::callbackWithNoParam(){ if (!canInvokeCallback()) return true; RefPtr
protect(this); JSLock lock(SilenceAssertionsOnly); ExecState* exec = m_data->globalObject()->globalExec(); MarkedArgumentBuffer args; bool raisedException = false; m_data->invokeCallback(args, &raisedException); return !raisedException;}bool JSTestCallback::callbackWithClass1Param(Class1* class1Param){ if (!canInvokeCallback()) return true; RefPtr
protect(this); JSLock lock(SilenceAssertionsOnly); ExecState* exec = m_data->globalObject()->globalExec(); MarkedArgumentBuffer args; args.append(toJS(exec, class1Param)); bool raisedException = false; m_data->invokeCallback(args, &raisedException); return !raisedException;}bool JSTestCallback::callbackWithClass2Param(Class2* class2Param, const String& strArg){ if (!canInvokeCallback()) return true; RefPtr
protect(this); JSLock lock(SilenceAssertionsOnly); ExecState* exec = m_data->globalObject()->globalExec(); MarkedArgumentBuffer args; args.append(toJS(exec, class2Param)); args.append(jsString(exec, strArg)); bool raisedException = false; m_data->invokeCallback(args, &raisedException); return !raisedException;}bool JSTestCallback::callbackWithStringList(DOMStringList* listParam){ if (!canInvokeCallback()) return true; RefPtr
protect(this); JSLock lock(SilenceAssertionsOnly); ExecState* exec = m_data->globalObject()->globalExec(); MarkedArgumentBuffer args; args.append(toJS(exec, listParam)); bool raisedException = false; m_data->invokeCallback(args, &raisedException); return !raisedException;}}#endif // ENABLE(DATABASE)

=========================

## V8TestCallback.h

#if ENABLE(DATABASE)#ifndef V8TestCallback_h#define V8TestCallback_h#include "ActiveDOMCallback.h"#include "TestCallback.h"#include "WorldContextHandle.h"#include 
#include
namespace WebCore {class ScriptExecutionContext;class V8TestCallback : public TestCallback, public ActiveDOMCallback {public: static PassRefPtr
create(v8::Local
value, ScriptExecutionContext* context) { ASSERT(value->IsObject()); ASSERT(context); return adoptRef(new V8TestCallback(value->ToObject(), context)); } virtual ~V8TestCallback(); // Functions virtual bool callbackWithNoParam(); virtual bool callbackWithClass1Param(Class1* class1Param); virtual bool callbackWithClass2Param(Class2* class2Param, const String& strArg); COMPILE_ASSERT(false) virtual int callbackWithNonBoolReturnType(Class3* class3Param); virtual int customCallback(Class5* class5Param, Class6* class6Param); virtual bool callbackWithStringList(PassRefPtr
listParam);private: V8TestCallback(v8::Local
, ScriptExecutionContext*); v8::Persistent
m_callback; WorldContextHandle m_worldContext;};}#endif // V8TestCallback_h#endif // ENABLE(DATABASE)
## V8TestCallback.cpp

#include "config.h"#include "V8TestCallback.h"#if ENABLE(DATABASE)#include "ScriptExecutionContext.h"#include "V8Binding.h"#include "V8Class1.h"#include "V8Class2.h"#include "V8CustomVoidCallback.h"#include "V8DOMStringList.h"#include "V8Proxy.h"#include 
#include
#include
#include
namespace WebCore {V8TestCallback::V8TestCallback(v8::Local
callback, ScriptExecutionContext* context) : ActiveDOMCallback(context) , m_callback(v8::Persistent
::New(callback)) , m_worldContext(UseCurrentWorld){}V8TestCallback::~V8TestCallback(){ m_callback.Dispose();}// Functionsbool V8TestCallback::callbackWithNoParam(){ if (!canInvokeCallback()) return true; v8::HandleScope handleScope; v8::Handle
v8Context = toV8Context(scriptExecutionContext(), m_worldContext); if (v8Context.IsEmpty()) return true; v8::Context::Scope scope(v8Context); v8::Handle
*argv = 0; bool callbackReturnValue = false; return !invokeCallback(m_callback, 0, argv, callbackReturnValue, scriptExecutionContext());}bool V8TestCallback::callbackWithClass1Param(Class1* class1Param){ if (!canInvokeCallback()) return true; v8::HandleScope handleScope; v8::Handle
v8Context = toV8Context(scriptExecutionContext(), m_worldContext); if (v8Context.IsEmpty()) return true; v8::Context::Scope scope(v8Context); v8::Handle
class1ParamHandle = toV8(class1Param); if (class1ParamHandle.IsEmpty()) { CRASH(); return true; } v8::Handle
argv[] = { class1ParamHandle }; bool callbackReturnValue = false; return !invokeCallback(m_callback, 1, argv, callbackReturnValue, scriptExecutionContext());}bool V8TestCallback::callbackWithClass2Param(Class2* class2Param, const String& strArg){ if (!canInvokeCallback()) return true; v8::HandleScope handleScope; v8::Handle
v8Context = toV8Context(scriptExecutionContext(), m_worldContext); if (v8Context.IsEmpty()) return true; v8::Context::Scope scope(v8Context); v8::Handle
class2ParamHandle = toV8(class2Param); if (class2ParamHandle.IsEmpty()) { CRASH(); return true; } v8::Handle
strArgHandle = v8String(strArg); if (strArgHandle.IsEmpty()) { CRASH(); return true; } v8::Handle
argv[] = { class2ParamHandle, strArgHandle }; bool callbackReturnValue = false; return !invokeCallback(m_callback, 2, argv, callbackReturnValue, scriptExecutionContext());}bool V8TestCallback::callbackWithStringList(PassRefPtr
listParam){ if (!canInvokeCallback()) return true; v8::HandleScope handleScope; v8::Handle
v8Context = toV8Context(scriptExecutionContext(), m_worldContext); if (v8Context.IsEmpty()) return true; v8::Context::Scope scope(v8Context); v8::Handle
listParamHandle = toV8(listParam); if (listParamHandle.IsEmpty()) { CRASH(); return true; } v8::Handle
argv[] = { listParamHandle }; bool callbackReturnValue = false; return !invokeCallback(m_callback, 1, argv, callbackReturnValue, scriptExecutionContext());}} // namespace WebCore#endif // ENABLE(DATABASE)

转载地址:http://edvbi.baihongyu.com/

你可能感兴趣的文章
mac:移动python包路径
查看>>
mysql:sql create database新建utf8mb4 数据库
查看>>
mysql:sql alter database修改数据库字符集
查看>>
mysql:sql alter table 修改列属性的字符集
查看>>
mysql:sql drop table (删除表)
查看>>
mysql:sql truncate (清除表数据)
查看>>
scrapy:xpath string(.)非常注意问题
查看>>
yuv to rgb 转换失败呀。天呀。谁来帮帮我呀。
查看>>
yuv420 format
查看>>
单纯的把Y通道提取出来能正确显示出灰度图来为什么我的Qt就显示不出来呢转换有问题呀?
查看>>
YUV420只绘制Y通道
查看>>
yuv420 还原为RGB图像
查看>>
LED恒流驱动芯片
查看>>
驱动TFT要SDRAM做为显示缓存
查看>>
使用file查看可执行文件的平台性,x86 or arm ?
查看>>
qt5 everywhere 编译summary
查看>>
qt5 everywhere编译完成后,找不到qmake
查看>>
arm-linux开机读取硬件时钟,设置系统时钟。
查看>>
交叉编译在x86上调试好的qt程序
查看>>
/dev/input/event0 键盘输入
查看>>