| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #ifndef _JS_DEFINE_H_ | 7 #ifndef _JS_DEFINE_H_ |
| 8 #define _JS_DEFINE_H_ | 8 #define _JS_DEFINE_H_ |
| 9 | 9 |
| 10 typedef v8::Value JSValue; | 10 typedef v8::Value JSValue; |
| 11 typedef v8::Handle<v8::Object> JSObject; | 11 typedef v8::Handle<v8::Object> JSObject; |
| 12 typedef v8::Handle<v8::Object> JSFXObject; | 12 typedef v8::Handle<v8::Object> JSFXObject; |
| 13 typedef unsigned JSBool; | 13 typedef unsigned JSBool; |
| 14 | 14 |
| 15 #include "JS_Object.h" |
| 16 #include "JS_Value.h" |
| 17 |
| 15 struct JSConstSpec | 18 struct JSConstSpec |
| 16 { | 19 { |
| 17 const wchar_t* pName; | 20 const wchar_t* pName; |
| 18 double number; | 21 double number; |
| 19 const wchar_t* string; | 22 const wchar_t* string; |
| 20 FX_BYTE t; //0:double 1:str | 23 FX_BYTE t; //0:double 1:str |
| 21 }; | 24 }; |
| 22 | 25 |
| 23 struct JSPropertySpec | 26 struct JSPropertySpec |
| 24 { | 27 { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 51 #define JS_STATIC_CONST_ENTRY_STRING(const_name, pValue) {JS_WIDESTRING(const_na
me), 0, JS_WIDESTRING(pValue), 1}, | 54 #define JS_STATIC_CONST_ENTRY_STRING(const_name, pValue) {JS_WIDESTRING(const_na
me), 0, JS_WIDESTRING(pValue), 1}, |
| 52 #define END_JS_STATIC_CONST() {0, 0, 0, 0}}; | 55 #define END_JS_STATIC_CONST() {0, 0, 0, 0}}; |
| 53 | 56 |
| 54 #define BEGIN_JS_STATIC_PROP(js_class_name) JSPropertySpec js_class_name::JS_Cla
ss_Properties[] = { | 57 #define BEGIN_JS_STATIC_PROP(js_class_name) JSPropertySpec js_class_name::JS_Cla
ss_Properties[] = { |
| 55 #define JS_STATIC_PROP_ENTRY(prop_name) {JS_WIDESTRING(prop_name), get_##prop_na
me##_static, set_##prop_name##_static}, | 58 #define JS_STATIC_PROP_ENTRY(prop_name) {JS_WIDESTRING(prop_name), get_##prop_na
me##_static, set_##prop_name##_static}, |
| 56 #define END_JS_STATIC_PROP() {0, 0, 0}}; | 59 #define END_JS_STATIC_PROP() {0, 0, 0}}; |
| 57 | 60 |
| 58 #define BEGIN_JS_STATIC_METHOD(js_class_name) JSMethodSpec js_class_name::JS_Cla
ss_Methods[] = { | 61 #define BEGIN_JS_STATIC_METHOD(js_class_name) JSMethodSpec js_class_name::JS_Cla
ss_Methods[] = { |
| 59 #define JS_STATIC_METHOD_ENTRY(method_name, nargs) {JS_WIDESTRING(method_name),
method_name##_static, nargs}, | 62 #define JS_STATIC_METHOD_ENTRY(method_name, nargs) {JS_WIDESTRING(method_name),
method_name##_static, nargs}, |
| 60 #define END_JS_STATIC_METHOD() {0, 0, 0}}; | 63 #define END_JS_STATIC_METHOD() {0, 0, 0}}; |
| 61 #define MEMLEAKCHECK_1() ((void)0) | |
| 62 #define MEMLEAKCHECK_2(main_name, sub_name) ((void)0) | |
| 63 | |
| 64 | |
| 65 /* | |
| 66 #ifdef _DEBUG | |
| 67 #define MEMLEAKCHECK_1() \ | |
| 68 _CrtMemState state1;\ | |
| 69 _CrtMemCheckpoint(&state1); | |
| 70 | |
| 71 #define MEMLEAKCHECK_2(main_name,sub_name) \ | |
| 72 _CrtMemState state2;\ | |
| 73 _CrtMemCheckpoint(&state2);\ | |
| 74 _CrtMemState diff;\ | |
| 75 _CrtMemDifference(&diff,&state1,&state2);\ | |
| 76 if (diff.lSizes[_NORMAL_BLOCK] > 0)\ | |
| 77 {\ | |
| 78 TRACE("Detected normal block memory leaks in JS Module! [%s.%s]\
n",#main_name,#sub_name);\ | |
| 79 _CrtMemDumpStatistics(&diff);\ | |
| 80 } | |
| 81 #else | |
| 82 #define MEMLEAKCHECK_1() ((void)0) | |
| 83 #define MEMLEAKCHECK_2(main_name,sub_name) ((void)0) | |
| 84 #endif | |
| 85 */ | |
| 86 | 64 |
| 87 /* ======================================== PROP CALLBACK ======================
====================== */ | 65 /* ======================================== PROP CALLBACK ======================
====================== */ |
| 88 | 66 |
| 89 #define JS_STATIC_PROP_GET(prop_name, class_name)\ | 67 template <class C, FX_BOOL (C::*M)(IFXJS_Context*, CJS_PropValue&, JS_ErrorStrin
g&)> |
| 90 static void get_##prop_name##_static(v8::Local<v8::String> property, \ | 68 void JSPropGetter(const char* prop_name_string, |
| 91 const v8::PropertyCallbackInfo<v8::Value>
& info) \ | 69 const char* class_name_string, |
| 92 {\ | 70 v8::Local<v8::String> property, |
| 93 » v8::Isolate* isolate = info.GetIsolate();\ | 71 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 94 » v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | 72 v8::Isolate* isolate = info.GetIsolate(); |
| 95 » IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ | 73 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); |
| 96 » if (pRuntime == NULL) return;\ | 74 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); |
| 97 » IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | 75 CJS_PropValue value(isolate); |
| 98 » CJS_PropValue value(isolate);\ | 76 value.StartGetting(); |
| 99 » value.StartGetting();\ | 77 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder()); |
| 100 » CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ | 78 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
| 101 » ASSERT(pJSObj != NULL);\ | 79 JS_ErrorString sError; |
| 102 » class_name* pObj = (class_name*)pJSObj->GetEmbedObject();\ | 80 if (!(pObj->*M)(pRuntimeContext, value, sError)) { |
| 103 » ASSERT(pObj != NULL);\ | 81 CFX_ByteString cbName; |
| 104 » JS_ErrorString sError;\ | 82 cbName.Format("%s.%s", class_name_string, prop_name_string); |
| 105 » FX_BOOL bRet = FALSE;\ | 83 JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError); |
| 106 » MEMLEAKCHECK_1();\ | 84 return; |
| 107 » bRet = pObj->prop_name(cc, value, sError);\ | 85 } |
| 108 » MEMLEAKCHECK_2(class_name, prop_name);\ | 86 info.GetReturnValue().Set((v8::Handle<v8::Value>)value); |
| 109 » if (bRet)\ | |
| 110 » {\ | |
| 111 » » info.GetReturnValue().Set((v8::Handle<v8::Value>)value);\ | |
| 112 » » return ;\ | |
| 113 » }\ | |
| 114 » else\ | |
| 115 » {\ | |
| 116 » CFX_ByteString cbName;\ | |
| 117 » » cbName.Format("%s.%s", #class_name, #prop_name);\ | |
| 118 » » JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ | |
| 119 » » return ;\ | |
| 120 » }\ | |
| 121 } | 87 } |
| 122 | 88 |
| 123 #define JS_STATIC_PROP_SET(prop_name, class_name)\ | 89 template <class C, FX_BOOL (C::*M)(IFXJS_Context*, CJS_PropValue&, JS_ErrorStrin
g&)> |
| 124 static void set_##prop_name##_static(v8::Local<v8::String> property, \ | 90 void JSPropSetter(const char* prop_name_string, |
| 125 v8::Local<v8::Value> value, \ | 91 const char* class_name_string, |
| 126 const v8::PropertyCallbackInfo<void>& inf
o) \ | 92 v8::Local<v8::String> property, |
| 127 {\ | 93 v8::Local<v8::Value> value, |
| 128 » v8::Isolate* isolate = info.GetIsolate();\ | 94 const v8::PropertyCallbackInfo<void>& info) { |
| 129 » v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | 95 v8::Isolate* isolate = info.GetIsolate(); |
| 130 » IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ | 96 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); |
| 131 » if (pRuntime == NULL) return;\ | 97 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); |
| 132 » IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | 98 CJS_PropValue propValue(CJS_Value(isolate, value, VT_unknown)); |
| 133 » CJS_PropValue propValue(CJS_Value(isolate,value,VT_unknown));\ | 99 propValue.StartSetting(); |
| 134 » propValue.StartSetting();\ | 100 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder()); |
| 135 » CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ | 101 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
| 136 » ASSERT(pJSObj != NULL);\ | 102 JS_ErrorString sError; |
| 137 » class_name* pObj = (class_name*)pJSObj->GetEmbedObject();\ | 103 if (!(pObj->*M)(pRuntimeContext, propValue, sError)) { |
| 138 » ASSERT(pObj != NULL);\ | 104 CFX_ByteString cbName; |
| 139 » JS_ErrorString sError;\ | 105 cbName.Format("%s.%s", class_name_string, prop_name_string); |
| 140 » FX_BOOL bRet = FALSE;\ | 106 JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError); |
| 141 » MEMLEAKCHECK_1();\ | 107 } |
| 142 » bRet = pObj->prop_name(cc, propValue, sError);\ | |
| 143 » MEMLEAKCHECK_2(class_name, prop_name);\ | |
| 144 » if (bRet)\ | |
| 145 » {\ | |
| 146 » » return ;\ | |
| 147 » }\ | |
| 148 » else\ | |
| 149 » {\ | |
| 150 » » CFX_ByteString cbName;\ | |
| 151 » » cbName.Format("%s.%s", #class_name, #prop_name);\ | |
| 152 » » JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ | |
| 153 » » return ;\ | |
| 154 » }\ | |
| 155 } | 108 } |
| 156 | 109 |
| 157 #define JS_STATIC_PROP(prop_name, class_name)\ | 110 #define JS_STATIC_PROP(prop_name, class_name) \ |
| 158 JS_STATIC_PROP_GET(prop_name, class_name);\ | 111 static void get_##prop_name##_static( \ |
| 159 JS_STATIC_PROP_SET(prop_name, class_name) | 112 v8::Local<v8::String> property, \ |
| 113 const v8::PropertyCallbackInfo<v8::Value>& info) { \ |
| 114 JSPropGetter<class_name, &class_name::prop_name>( \ |
| 115 #prop_name, #class_name, property, info); \ |
| 116 } \ |
| 117 static void set_##prop_name##_static( \ |
| 118 v8::Local<v8::String> property, \ |
| 119 v8::Local<v8::Value> value, \ |
| 120 const v8::PropertyCallbackInfo<void>& info) { \ |
| 121 JSPropSetter<class_name, &class_name::prop_name>( \ |
| 122 #prop_name, #class_name, property, value, info); \ |
| 123 } |
| 160 | 124 |
| 161 /* ========================================= METHOD CALLBACK ===================
======================== */ | 125 /* ========================================= METHOD CALLBACK ===================
======================== */ |
| 162 | 126 |
| 163 #define JS_STATIC_METHOD(method_name, class_name)\ | 127 template <class C, FX_BOOL (C::*M)(IFXJS_Context*, const CJS_Parameters&, CJS_Va
lue&, JS_ErrorString&)> |
| 164 static void method_name##_static(const v8::FunctionCallbackInfo<v8::Value>& in
fo) \ | 128 void JSMethod(const char* method_name_string, |
| 165 {\ | 129 const char* class_name_string, |
| 166 » v8::Isolate* isolate = info.GetIsolate();\ | 130 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 167 » v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | 131 v8::Isolate* isolate = info.GetIsolate(); |
| 168 » IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ | 132 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); |
| 169 » if (pRuntime == NULL) return;\ | 133 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); |
| 170 » IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | 134 CJS_Parameters parameters; |
| 171 » CJS_Parameters parameters;\ | 135 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++) { |
| 172 » for (unsigned int i = 0; i<(unsigned int)info.Length(); i++)\ | 136 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown)); |
| 173 {\ | 137 } |
| 174 » » parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));\ | 138 CJS_Value valueRes(isolate); |
| 175 » }\ | 139 CJS_Object* pJSObj = (CJS_Object *)JS_GetPrivate(isolate,info.Holder()); |
| 176 » CJS_Value valueRes(isolate);\ | 140 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
| 177 » CJS_Object* pJSObj = (CJS_Object *)JS_GetPrivate(isolate,info.Holder());
\ | 141 JS_ErrorString sError; |
| 178 » ASSERT(pJSObj != NULL);\ | 142 if (!(pObj->*M)(pRuntimeContext, parameters, valueRes, sError)) { |
| 179 » class_name* pObj = (class_name*)pJSObj->GetEmbedObject();\ | 143 CFX_ByteString cbName; |
| 180 » ASSERT(pObj != NULL);\ | 144 cbName.Format("%s.%s", class_name_string, method_name_string); |
| 181 » JS_ErrorString sError;\ | 145 JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError); |
| 182 » FX_BOOL bRet = FALSE;\ | 146 return; |
| 183 » MEMLEAKCHECK_1();\ | 147 } |
| 184 » bRet = pObj->method_name(cc, parameters, valueRes, sError);\ | 148 info.GetReturnValue().Set(valueRes.ToJSValue()); |
| 185 » MEMLEAKCHECK_2(class_name, method_name);\ | |
| 186 » if (bRet)\ | |
| 187 » {\ | |
| 188 » » info.GetReturnValue().Set(valueRes.ToJSValue());\ | |
| 189 » » return ;\ | |
| 190 » }\ | |
| 191 » else\ | |
| 192 » {\ | |
| 193 » » CFX_ByteString cbName;\ | |
| 194 » » cbName.Format("%s.%s", #class_name, #method_name);\ | |
| 195 » » JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError);\ | |
| 196 » » return ;\ | |
| 197 » }\ | |
| 198 } | 149 } |
| 199 | 150 |
| 151 #define JS_STATIC_METHOD(method_name, class_name) \ |
| 152 static void method_name##_static( \ |
| 153 const v8::FunctionCallbackInfo<v8::Value>& info) { \ |
| 154 JSMethod<class_name, &class_name::method_name>( \ |
| 155 #class_name, #method_name, info); \ |
| 156 } |
| 157 |
| 158 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name) \ |
| 159 static void method_name##_static( \ |
| 160 const v8::FunctionCallbackInfo<v8::Value>& info) { \ |
| 161 JSMethod<class_alternate, &class_alternate::method_name>( \ |
| 162 #class_name, #method_name, info); \ |
| 163 } |
| 164 |
| 200 /* ===================================== JS CLASS ==============================
================= */ | 165 /* ===================================== JS CLASS ==============================
================= */ |
| 201 | 166 |
| 202 #define DECLARE_JS_CLASS(js_class_name) \ | 167 #define DECLARE_JS_CLASS(js_class_name) \ |
| 203 static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj,JSFXObject
global);\ | 168 static JSBool JSConstructor(IFXJS_Context* cc, JSFXObject obj,JSFXObject
global);\ |
| 204 static JSBool JSDestructor(JSFXObject obj);\ | 169 static JSBool JSDestructor(JSFXObject obj);\ |
| 205 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\ | 170 static int Init(IJS_Runtime* pRuntime, FXJSOBJTYPE eObjType);\ |
| 206 static void GetConsts(JSConstSpec*& pConsts, int& nSize);\ | 171 static void GetConsts(JSConstSpec*& pConsts, int& nSize);\ |
| 207 static void GetProperties(JSPropertySpec*& pProperties, int& nSize);\ | 172 static void GetProperties(JSPropertySpec*& pProperties, int& nSize);\ |
| 208 static void GetMethods(JSMethodSpec*& pMethods, int& nSize);\ | 173 static void GetMethods(JSMethodSpec*& pMethods, int& nSize);\ |
| 209 static JSConstSpec JS_Class_Consts[];\ | 174 static JSConstSpec JS_Class_Consts[];\ |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 void js_class_name::queryprop_##js_class_name##_static(JS_PROPQUERY_ARGS
)\ | 290 void js_class_name::queryprop_##js_class_name##_static(JS_PROPQUERY_ARGS
)\ |
| 326 {\ | 291 {\ |
| 327 v8::Isolate* isolate = info.GetIsolate();\ | 292 v8::Isolate* isolate = info.GetIsolate();\ |
| 328 v8::String::Utf8Value utf8_value(property);\ | 293 v8::String::Utf8Value utf8_value(property);\ |
| 329 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val
ue.length());\ | 294 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val
ue.length());\ |
| 330 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ | 295 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ |
| 331 ASSERT(pJSObj != NULL);\ | 296 ASSERT(pJSObj != NULL);\ |
| 332 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ | 297 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ |
| 333 ASSERT(pObj != NULL);\ | 298 ASSERT(pObj != NULL);\ |
| 334 FX_BOOL bRet = FALSE;\ | 299 FX_BOOL bRet = FALSE;\ |
| 335 MEMLEAKCHECK_1();\ | |
| 336 bRet = pObj->QueryProperty(propname.c_str());\ | 300 bRet = pObj->QueryProperty(propname.c_str());\ |
| 337 MEMLEAKCHECK_2(class_name, prop_name.c_str());\ | |
| 338 if (bRet)\ | 301 if (bRet)\ |
| 339 {\ | 302 {\ |
| 340 info.GetReturnValue().Set(0x004);\ | 303 info.GetReturnValue().Set(0x004);\ |
| 341 return ;\ | 304 return ;\ |
| 342 }\ | 305 }\ |
| 343 else\ | 306 else\ |
| 344 {\ | 307 {\ |
| 345 info.GetReturnValue().Set(0);\ | 308 info.GetReturnValue().Set(0);\ |
| 346 return ;\ | 309 return ;\ |
| 347 }\ | 310 }\ |
| 348 return ;\ | 311 return ;\ |
| 349 }\ | 312 }\ |
| 350 void js_class_name::getprop_##js_class_name##_static(JS_NAMED_PROPGET_AR
GS)\ | 313 void js_class_name::getprop_##js_class_name##_static(JS_NAMED_PROPGET_AR
GS)\ |
| 351 {\ | 314 {\ |
| 352 v8::Isolate* isolate = info.GetIsolate();\ | 315 v8::Isolate* isolate = info.GetIsolate();\ |
| 353 v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | 316 v8::Local<v8::Context> context = isolate->GetCurrentContext();\ |
| 354 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ | 317 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ |
| 355 if (pRuntime == NULL) return;\ | 318 if (pRuntime == NULL) return;\ |
| 356 IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | 319 IFXJS_Context* cc = pRuntime->GetCurrentContext();\ |
| 357 v8::String::Utf8Value utf8_value(property);\ | 320 v8::String::Utf8Value utf8_value(property);\ |
| 358 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val
ue.length());\ | 321 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val
ue.length());\ |
| 359 CJS_PropValue value(isolate);\ | 322 CJS_PropValue value(isolate);\ |
| 360 value.StartGetting();\ | 323 value.StartGetting();\ |
| 361 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ | 324 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ |
| 362 ASSERT(pJSObj != NULL);\ | 325 ASSERT(pJSObj != NULL);\ |
| 363 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ | 326 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ |
| 364 ASSERT(pObj != NULL);\ | 327 ASSERT(pObj != NULL);\ |
| 365 JS_ErrorString sError;\ | 328 JS_ErrorString sError;\ |
| 366 FX_BOOL bRet = FALSE;\ | 329 FX_BOOL bRet = FALSE;\ |
| 367 MEMLEAKCHECK_1();\ | |
| 368 bRet = pObj->DoProperty(cc, propname.c_str(), value, sError);\ | 330 bRet = pObj->DoProperty(cc, propname.c_str(), value, sError);\ |
| 369 MEMLEAKCHECK_2(class_name, L"GetProperty");\ | |
| 370 if (bRet)\ | 331 if (bRet)\ |
| 371 {\ | 332 {\ |
| 372 info.GetReturnValue().Set((v8::Handle<v8::Value>)value);\ | 333 info.GetReturnValue().Set((v8::Handle<v8::Value>)value);\ |
| 373 return ;\ | 334 return ;\ |
| 374 }\ | 335 }\ |
| 375 else\ | 336 else\ |
| 376 {\ | 337 {\ |
| 377 CFX_ByteString cbName;\ | 338 CFX_ByteString cbName;\ |
| 378 cbName.Format("%s.%s", #class_name, L"GetProperty");\ | 339 cbName.Format("%s.%s", #class_name, L"GetProperty");\ |
| 379 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ | 340 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ |
| (...skipping 12 matching lines...) Expand all Loading... |
| 392 v8::String::Utf8Value utf8_value(property);\ | 353 v8::String::Utf8Value utf8_value(property);\ |
| 393 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val
ue.length());\ | 354 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val
ue.length());\ |
| 394 CJS_PropValue PropValue(CJS_Value(isolate,value,VT_unknown));\ | 355 CJS_PropValue PropValue(CJS_Value(isolate,value,VT_unknown));\ |
| 395 PropValue.StartSetting();\ | 356 PropValue.StartSetting();\ |
| 396 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ | 357 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ |
| 397 if(!pJSObj) return;\ | 358 if(!pJSObj) return;\ |
| 398 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ | 359 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ |
| 399 ASSERT(pObj != NULL);\ | 360 ASSERT(pObj != NULL);\ |
| 400 JS_ErrorString sError;\ | 361 JS_ErrorString sError;\ |
| 401 FX_BOOL bRet = FALSE;\ | 362 FX_BOOL bRet = FALSE;\ |
| 402 MEMLEAKCHECK_1();\ | |
| 403 bRet = pObj->DoProperty(cc, propname.c_str(), PropValue, sError);\ | 363 bRet = pObj->DoProperty(cc, propname.c_str(), PropValue, sError);\ |
| 404 MEMLEAKCHECK_2(class_name,L"PutProperty");\ | |
| 405 if (bRet)\ | 364 if (bRet)\ |
| 406 {\ | 365 {\ |
| 407 return ;\ | 366 return ;\ |
| 408 }\ | 367 }\ |
| 409 else\ | 368 else\ |
| 410 {\ | 369 {\ |
| 411 CFX_ByteString cbName;\ | 370 CFX_ByteString cbName;\ |
| 412 cbName.Format("%s.%s", #class_name, "PutProperty");\ | 371 cbName.Format("%s.%s", #class_name, "PutProperty");\ |
| 413 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ | 372 JS_Error(NULL,CFX_WideString::FromLocal(cbName), sError);\ |
| 414 return ;\ | 373 return ;\ |
| 415 }\ | 374 }\ |
| 416 JS_Error(NULL,L"PutProperty", L"Embeded object not found!");\ | 375 JS_Error(NULL,L"PutProperty", L"Embeded object not found!");\ |
| 417 return ;\ | 376 return ;\ |
| 418 }\ | 377 }\ |
| 419 void js_class_name::delprop_##js_class_name##_static(JS_PROPDEL_ARGS)\ | 378 void js_class_name::delprop_##js_class_name##_static(JS_PROPDEL_ARGS)\ |
| 420 {\ | 379 {\ |
| 421 v8::Isolate* isolate = info.GetIsolate();\ | 380 v8::Isolate* isolate = info.GetIsolate();\ |
| 422 v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | 381 v8::Local<v8::Context> context = isolate->GetCurrentContext();\ |
| 423 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ | 382 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ |
| 424 if (pRuntime == NULL) return;\ | 383 if (pRuntime == NULL) return;\ |
| 425 IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | 384 IFXJS_Context* cc = pRuntime->GetCurrentContext();\ |
| 426 v8::String::Utf8Value utf8_value(property);\ | 385 v8::String::Utf8Value utf8_value(property);\ |
| 427 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val
ue.length());\ | 386 CFX_WideString propname = CFX_WideString::FromUTF8(*utf8_value, utf8_val
ue.length());\ |
| 428 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ | 387 CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate,info.Holder());\ |
| 429 ASSERT(pJSObj != NULL);\ | 388 ASSERT(pJSObj != NULL);\ |
| 430 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ | 389 class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ |
| 431 ASSERT(pObj != NULL);\ | 390 ASSERT(pObj != NULL);\ |
| 432 JS_ErrorString sError;\ | 391 JS_ErrorString sError;\ |
| 433 FX_BOOL bRet = FALSE;\ | 392 FX_BOOL bRet = FALSE;\ |
| 434 MEMLEAKCHECK_1();\ | |
| 435 bRet = pObj->DelProperty(cc, propname.c_str(), sError);\ | 393 bRet = pObj->DelProperty(cc, propname.c_str(), sError);\ |
| 436 MEMLEAKCHECK_2(class_name,L"DelProperty");\ | |
| 437 if (bRet)\ | 394 if (bRet)\ |
| 438 {\ | 395 {\ |
| 439 return ;\ | 396 return ;\ |
| 440 }\ | 397 }\ |
| 441 else\ | 398 else\ |
| 442 {\ | 399 {\ |
| 443 CFX_ByteString cbName;\ | 400 CFX_ByteString cbName;\ |
| 444 cbName.Format("%s.%s", #class_name, "DelProperty");\ | 401 cbName.Format("%s.%s", #class_name, "DelProperty");\ |
| 445 return ;\ | 402 return ;\ |
| 446 }\ | 403 }\ |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 {\ | 453 {\ |
| 497 pProperties = JS_Class_Properties;\ | 454 pProperties = JS_Class_Properties;\ |
| 498 nSize = sizeof(JS_Class_Properties)/sizeof(JSPropertySpec)-1;\ | 455 nSize = sizeof(JS_Class_Properties)/sizeof(JSPropertySpec)-1;\ |
| 499 }\ | 456 }\ |
| 500 void js_class_name::GetMethods(JSMethodSpec*& pMethods, int& nSize)\ | 457 void js_class_name::GetMethods(JSMethodSpec*& pMethods, int& nSize)\ |
| 501 {\ | 458 {\ |
| 502 pMethods = JS_Class_Methods;\ | 459 pMethods = JS_Class_Methods;\ |
| 503 nSize = sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-1;\ | 460 nSize = sizeof(JS_Class_Methods)/sizeof(JSMethodSpec)-1;\ |
| 504 } | 461 } |
| 505 | 462 |
| 506 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name)\ | 463 /* ======================================== GLOBAL METHODS =====================
======================= */ |
| 507 » static void method_name##_static(const v8::FunctionCallbackInfo<v8::Valu
e>& info)\ | 464 |
| 508 {\ | 465 template <FX_BOOL (*F)(IFXJS_Context*, const CJS_Parameters&, CJS_Value&, JS_Err
orString&)> |
| 509 » v8::Isolate* isolate = info.GetIsolate();\ | 466 void JSGlobalFunc(const char *func_name_string, |
| 510 » v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | 467 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 511 » IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ | 468 v8::Isolate* isolate = info.GetIsolate(); |
| 512 » if (pRuntime == NULL) return;\ | 469 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); |
| 513 » IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | 470 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); |
| 514 » CJS_Parameters parameters;\ | 471 CJS_Parameters parameters; |
| 515 » for (unsigned int i = 0; i<(unsigned int)info.Length(); i++)\ | 472 for (unsigned int i = 0; i<(unsigned int)info.Length(); i++) { |
| 516 » {\ | 473 parameters.push_back(CJS_Value(isolate, info[i], VT_unknown)); |
| 517 » parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));\ | 474 } |
| 518 » }\ | 475 CJS_Value valueRes(isolate); |
| 519 » CJS_Value valueRes(isolate);\ | 476 JS_ErrorString sError; |
| 520 » CJS_Object* pJSObj = (CJS_Object *)JS_GetPrivate(isolate, info.Holder())
;\ | 477 if (!(*F)(pRuntimeContext, parameters, valueRes, sError)) |
| 521 » ASSERT(pJSObj != NULL);\ | 478 { |
| 522 » class_alternate* pObj = (class_alternate*)pJSObj->GetEmbedObject();\ | 479 JS_Error(NULL, JS_WIDESTRING(fun_name), sError); |
| 523 » ASSERT(pObj != NULL);\ | 480 return; |
| 524 » JS_ErrorString sError;\ | 481 } |
| 525 » FX_BOOL bRet = FALSE;\ | 482 info.GetReturnValue().Set(valueRes.ToJSValue()); |
| 526 » MEMLEAKCHECK_1();\ | |
| 527 » bRet = pObj->method_name(cc, parameters, valueRes, sError);\ | |
| 528 » MEMLEAKCHECK_2(class_name, method_name);\ | |
| 529 » if (bRet)\ | |
| 530 » {\ | |
| 531 » » info.GetReturnValue().Set(valueRes.ToJSValue());\ | |
| 532 » » return ;\ | |
| 533 » }\ | |
| 534 » else\ | |
| 535 » {\ | |
| 536 » » CFX_ByteString cbName;\ | |
| 537 » » cbName.Format("%s.%s", #class_name, #method_name);\ | |
| 538 » » JS_Error(NULL, CFX_WideString::FromLocal(cbName), sError);\ | |
| 539 » » return ;\ | |
| 540 » }\ | |
| 541 » JS_Error(NULL, JS_WIDESTRING(method_name), L"Embeded object not found!"
);\ | |
| 542 return ;\ | |
| 543 } | 483 } |
| 544 | 484 |
| 545 /* ======================================== GLOBAL METHODS =====================
======================= */ | |
| 546 #define JS_STATIC_GLOBAL_FUN(fun_name) \ | 485 #define JS_STATIC_GLOBAL_FUN(fun_name) \ |
| 547 static void fun_name##_static(const v8::FunctionCallbackInfo<v8::Value>& info)\ | 486 static void fun_name##_static(const v8::FunctionCallbackInfo<v8::Value>& info)
{ \ |
| 548 {\ | 487 JSGlobalFunc<fun_name>(#fun_name, info); \ |
| 549 » v8::Isolate* isolate = info.GetIsolate();\ | 488 } |
| 550 » v8::Local<v8::Context> context = isolate->GetCurrentContext();\ | |
| 551 » IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);\ | |
| 552 » if (pRuntime == NULL) return;\ | |
| 553 » IFXJS_Context* cc = pRuntime->GetCurrentContext();\ | |
| 554 » CJS_Parameters parameters;\ | |
| 555 » for (unsigned int i = 0; i<(unsigned int)info.Length(); i++)\ | |
| 556 » {\ | |
| 557 » parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));\ | |
| 558 » }\ | |
| 559 » CJS_Value valueRes(isolate);\ | |
| 560 » JS_ErrorString sError;\ | |
| 561 » if (!fun_name(cc, parameters, valueRes, sError))\ | |
| 562 » {\ | |
| 563 » » JS_Error(NULL, JS_WIDESTRING(fun_name), sError);\ | |
| 564 » » return ;\ | |
| 565 » }\ | |
| 566 » info.GetReturnValue().Set(valueRes.ToJSValue());\ | |
| 567 » return ;\ | |
| 568 } | |
| 569 | 489 |
| 570 #define JS_STATIC_DECLARE_GLOBAL_FUN() \ | 490 #define JS_STATIC_DECLARE_GLOBAL_FUN() \ |
| 571 static JSMethodSpec global_methods[]; \ | 491 static JSMethodSpec global_methods[]; \ |
| 572 static int Init(IJS_Runtime* pRuntime) | 492 static int Init(IJS_Runtime* pRuntime) |
| 573 | 493 |
| 574 #define BEGIN_JS_STATIC_GLOBAL_FUN(js_class_name) \ | 494 #define BEGIN_JS_STATIC_GLOBAL_FUN(js_class_name) \ |
| 575 JSMethodSpec js_class_name::global_methods[] = { | 495 JSMethodSpec js_class_name::global_methods[] = { |
| 576 | 496 |
| 577 #define JS_STATIC_GLOBAL_FUN_ENTRY(method_name,nargs) JS_STATIC_METHOD_ENTRY(met
hod_name,nargs) | 497 #define JS_STATIC_GLOBAL_FUN_ENTRY(method_name,nargs) JS_STATIC_METHOD_ENTRY(met
hod_name,nargs) |
| 578 | 498 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 | 534 |
| 615 #define VALUE_NAME_STRING L"string" | 535 #define VALUE_NAME_STRING L"string" |
| 616 #define VALUE_NAME_NUMBER L"number" | 536 #define VALUE_NAME_NUMBER L"number" |
| 617 #define VALUE_NAME_BOOLEAN L"boolean" | 537 #define VALUE_NAME_BOOLEAN L"boolean" |
| 618 #define VALUE_NAME_DATE L"date" | 538 #define VALUE_NAME_DATE L"date" |
| 619 #define VALUE_NAME_OBJECT L"object" | 539 #define VALUE_NAME_OBJECT L"object" |
| 620 #define VALUE_NAME_FXOBJ L"fxobj" | 540 #define VALUE_NAME_FXOBJ L"fxobj" |
| 621 #define VALUE_NAME_NULL L"null" | 541 #define VALUE_NAME_NULL L"null" |
| 622 #define VALUE_NAME_UNDEFINED L"undefined" | 542 #define VALUE_NAME_UNDEFINED L"undefined" |
| 623 | 543 |
| 624 #define CLASSNAME_ARRAY L"Array" | |
| 625 #define CLASSNAME_DATE L"Date" | |
| 626 #define CLASSNAME_STRING L"v8::String" | |
| 627 | |
| 628 FXJSVALUETYPE GET_VALUE_TYPE(v8::Handle<v8::Value> p); | 544 FXJSVALUETYPE GET_VALUE_TYPE(v8::Handle<v8::Value> p); |
| 629 | 545 |
| 630 #endif //_JS_DEFINE_H_ | 546 #endif //_JS_DEFINE_H_ |
| OLD | NEW |