| 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 FPDFSDK_SRC_JAVASCRIPT_JS_DEFINE_H_ | 7 #ifndef FPDFSDK_SRC_JAVASCRIPT_JS_DEFINE_H_ |
| 8 #define FPDFSDK_SRC_JAVASCRIPT_JS_DEFINE_H_ | 8 #define FPDFSDK_SRC_JAVASCRIPT_JS_DEFINE_H_ |
| 9 | 9 |
| 10 #include "../../include/jsapi/fxjs_v8.h" | 10 #include "../../include/jsapi/fxjs_v8.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 JSMethodSpec js_class_name::JS_Class_Methods[] = { | 64 JSMethodSpec js_class_name::JS_Class_Methods[] = { |
| 65 #define JS_STATIC_METHOD_ENTRY(method_name) \ | 65 #define JS_STATIC_METHOD_ENTRY(method_name) \ |
| 66 { JS_WIDESTRING(method_name), method_name##_static } \ | 66 { JS_WIDESTRING(method_name), method_name##_static } \ |
| 67 , | 67 , |
| 68 | 68 |
| 69 #define END_JS_STATIC_METHOD() \ | 69 #define END_JS_STATIC_METHOD() \ |
| 70 { 0, 0 } \ | 70 { 0, 0 } \ |
| 71 } \ | 71 } \ |
| 72 ; | 72 ; |
| 73 | 73 |
| 74 template <class C, | 74 template < |
| 75 FX_BOOL (C::*M)(IFXJS_Context* cc, | 75 class C, |
| 76 CJS_PropValue& vp, | 76 FX_BOOL (C::*M)(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)> |
| 77 CFX_WideString& sError)> | |
| 78 void JSPropGetter(const char* prop_name_string, | 77 void JSPropGetter(const char* prop_name_string, |
| 79 const char* class_name_string, | 78 const char* class_name_string, |
| 80 v8::Local<v8::String> property, | 79 v8::Local<v8::String> property, |
| 81 const v8::PropertyCallbackInfo<v8::Value>& info) { | 80 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 82 v8::Isolate* isolate = info.GetIsolate(); | 81 v8::Isolate* isolate = info.GetIsolate(); |
| 83 IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); | 82 IJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); |
| 84 if (!pRuntime) | 83 if (!pRuntime) |
| 85 return; | 84 return; |
| 86 IFXJS_Context* pContext = pRuntime->GetCurrentContext(); | 85 IJS_Context* pContext = pRuntime->GetCurrentContext(); |
| 87 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); | 86 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); |
| 88 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); | 87 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
| 89 CFX_WideString sError; | 88 CFX_WideString sError; |
| 90 CJS_PropValue value(isolate); | 89 CJS_PropValue value(isolate); |
| 91 value.StartGetting(); | 90 value.StartGetting(); |
| 92 if (!(pObj->*M)(pContext, value, sError)) { | 91 if (!(pObj->*M)(pContext, value, sError)) { |
| 93 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, | 92 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, |
| 94 sError)); | 93 sError)); |
| 95 return; | 94 return; |
| 96 } | 95 } |
| 97 info.GetReturnValue().Set((v8::Local<v8::Value>)value); | 96 info.GetReturnValue().Set((v8::Local<v8::Value>)value); |
| 98 } | 97 } |
| 99 | 98 |
| 100 template <class C, | 99 template < |
| 101 FX_BOOL (C::*M)(IFXJS_Context* cc, | 100 class C, |
| 102 CJS_PropValue& vp, | 101 FX_BOOL (C::*M)(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)> |
| 103 CFX_WideString& sError)> | |
| 104 void JSPropSetter(const char* prop_name_string, | 102 void JSPropSetter(const char* prop_name_string, |
| 105 const char* class_name_string, | 103 const char* class_name_string, |
| 106 v8::Local<v8::String> property, | 104 v8::Local<v8::String> property, |
| 107 v8::Local<v8::Value> value, | 105 v8::Local<v8::Value> value, |
| 108 const v8::PropertyCallbackInfo<void>& info) { | 106 const v8::PropertyCallbackInfo<void>& info) { |
| 109 v8::Isolate* isolate = info.GetIsolate(); | 107 v8::Isolate* isolate = info.GetIsolate(); |
| 110 IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); | 108 IJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); |
| 111 if (!pRuntime) | 109 if (!pRuntime) |
| 112 return; | 110 return; |
| 113 IFXJS_Context* pContext = pRuntime->GetCurrentContext(); | 111 IJS_Context* pContext = pRuntime->GetCurrentContext(); |
| 114 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); | 112 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); |
| 115 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); | 113 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
| 116 CFX_WideString sError; | 114 CFX_WideString sError; |
| 117 CJS_PropValue propValue(CJS_Value(isolate, value, CJS_Value::VT_unknown)); | 115 CJS_PropValue propValue(CJS_Value(isolate, value, CJS_Value::VT_unknown)); |
| 118 propValue.StartSetting(); | 116 propValue.StartSetting(); |
| 119 if (!(pObj->*M)(pContext, propValue, sError)) { | 117 if (!(pObj->*M)(pContext, propValue, sError)) { |
| 120 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, | 118 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, |
| 121 sError)); | 119 sError)); |
| 122 } | 120 } |
| 123 } | 121 } |
| 124 | 122 |
| 125 #define JS_STATIC_PROP(prop_name, class_name) \ | 123 #define JS_STATIC_PROP(prop_name, class_name) \ |
| 126 static void get_##prop_name##_static( \ | 124 static void get_##prop_name##_static( \ |
| 127 v8::Local<v8::String> property, \ | 125 v8::Local<v8::String> property, \ |
| 128 const v8::PropertyCallbackInfo<v8::Value>& info) { \ | 126 const v8::PropertyCallbackInfo<v8::Value>& info) { \ |
| 129 JSPropGetter<class_name, &class_name::prop_name>(#prop_name, #class_name, \ | 127 JSPropGetter<class_name, &class_name::prop_name>(#prop_name, #class_name, \ |
| 130 property, info); \ | 128 property, info); \ |
| 131 } \ | 129 } \ |
| 132 static void set_##prop_name##_static( \ | 130 static void set_##prop_name##_static( \ |
| 133 v8::Local<v8::String> property, v8::Local<v8::Value> value, \ | 131 v8::Local<v8::String> property, v8::Local<v8::Value> value, \ |
| 134 const v8::PropertyCallbackInfo<void>& info) { \ | 132 const v8::PropertyCallbackInfo<void>& info) { \ |
| 135 JSPropSetter<class_name, &class_name::prop_name>(#prop_name, #class_name, \ | 133 JSPropSetter<class_name, &class_name::prop_name>(#prop_name, #class_name, \ |
| 136 property, value, info); \ | 134 property, value, info); \ |
| 137 } | 135 } |
| 138 | 136 |
| 139 template <class C, | 137 template <class C, |
| 140 FX_BOOL (C::*M)(IFXJS_Context* cc, | 138 FX_BOOL (C::*M)(IJS_Context* cc, |
| 141 const CJS_Parameters& params, | 139 const CJS_Parameters& params, |
| 142 CJS_Value& vRet, | 140 CJS_Value& vRet, |
| 143 CFX_WideString& sError)> | 141 CFX_WideString& sError)> |
| 144 void JSMethod(const char* method_name_string, | 142 void JSMethod(const char* method_name_string, |
| 145 const char* class_name_string, | 143 const char* class_name_string, |
| 146 const v8::FunctionCallbackInfo<v8::Value>& info) { | 144 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 147 v8::Isolate* isolate = info.GetIsolate(); | 145 v8::Isolate* isolate = info.GetIsolate(); |
| 148 IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); | 146 IJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); |
| 149 if (!pRuntime) | 147 if (!pRuntime) |
| 150 return; | 148 return; |
| 151 IFXJS_Context* cc = pRuntime->GetCurrentContext(); | 149 IJS_Context* cc = pRuntime->GetCurrentContext(); |
| 152 CJS_Parameters parameters; | 150 CJS_Parameters parameters; |
| 153 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { | 151 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { |
| 154 parameters.push_back(CJS_Value(isolate, info[i], CJS_Value::VT_unknown)); | 152 parameters.push_back(CJS_Value(isolate, info[i], CJS_Value::VT_unknown)); |
| 155 } | 153 } |
| 156 CJS_Value valueRes(isolate); | 154 CJS_Value valueRes(isolate); |
| 157 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); | 155 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); |
| 158 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); | 156 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
| 159 CFX_WideString sError; | 157 CFX_WideString sError; |
| 160 if (!(pObj->*M)(cc, parameters, valueRes, sError)) { | 158 if (!(pObj->*M)(cc, parameters, valueRes, sError)) { |
| 161 FXJS_Error(isolate, JSFormatErrorString(class_name_string, | 159 FXJS_Error(isolate, JSFormatErrorString(class_name_string, |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 IMPLEMENT_JS_CLASS_RICH_PART(js_class_name, class_alternate, class_name) \ | 237 IMPLEMENT_JS_CLASS_RICH_PART(js_class_name, class_alternate, class_name) \ |
| 240 void js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \ | 238 void js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \ |
| 241 FXJSOBJTYPE eObjType) { \ | 239 FXJSOBJTYPE eObjType) { \ |
| 242 g_nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::g_pClassName, \ | 240 g_nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::g_pClassName, \ |
| 243 eObjType, JSConstructor, JSDestructor); \ | 241 eObjType, JSConstructor, JSDestructor); \ |
| 244 DefineConsts(pIsolate); \ | 242 DefineConsts(pIsolate); \ |
| 245 DefineProps(pIsolate); \ | 243 DefineProps(pIsolate); \ |
| 246 DefineMethods(pIsolate); \ | 244 DefineMethods(pIsolate); \ |
| 247 } | 245 } |
| 248 | 246 |
| 249 #define DECLARE_JS_CLASS_RICH_PART() \ | 247 #define DECLARE_JS_CLASS_RICH_PART() \ |
| 250 static void JSConstructor(IFXJS_Context* cc, v8::Local<v8::Object> obj); \ | 248 static void JSConstructor(IJS_Context* cc, v8::Local<v8::Object> obj); \ |
| 251 static void JSDestructor(v8::Local<v8::Object> obj); \ | 249 static void JSDestructor(v8::Local<v8::Object> obj); \ |
| 252 static void DefineProps(v8::Isolate* pIsoalte); \ | 250 static void DefineProps(v8::Isolate* pIsoalte); \ |
| 253 static void DefineMethods(v8::Isolate* pIsoalte); \ | 251 static void DefineMethods(v8::Isolate* pIsoalte); \ |
| 254 static JSPropertySpec JS_Class_Properties[]; \ | 252 static JSPropertySpec JS_Class_Properties[]; \ |
| 255 static JSMethodSpec JS_Class_Methods[]; | 253 static JSMethodSpec JS_Class_Methods[]; |
| 256 | 254 |
| 257 #define IMPLEMENT_JS_CLASS_RICH_PART(js_class_name, class_alternate, \ | 255 #define IMPLEMENT_JS_CLASS_RICH_PART(js_class_name, class_alternate, \ |
| 258 class_name) \ | 256 class_name) \ |
| 259 void js_class_name::JSConstructor(IFXJS_Context* cc, \ | 257 void js_class_name::JSConstructor(IJS_Context* cc, \ |
| 260 v8::Local<v8::Object> obj) { \ | 258 v8::Local<v8::Object> obj) { \ |
| 261 CJS_Object* pObj = new js_class_name(obj); \ | 259 CJS_Object* pObj = new js_class_name(obj); \ |
| 262 pObj->SetEmbedObject(new class_alternate(pObj)); \ | 260 pObj->SetEmbedObject(new class_alternate(pObj)); \ |
| 263 FXJS_SetPrivate(nullptr, obj, (void*)pObj); \ | 261 FXJS_SetPrivate(nullptr, obj, (void*)pObj); \ |
| 264 pObj->InitInstance(cc); \ | 262 pObj->InitInstance(cc); \ |
| 265 } \ | 263 } \ |
| 266 void js_class_name::JSDestructor(v8::Local<v8::Object> obj) { \ | 264 void js_class_name::JSDestructor(v8::Local<v8::Object> obj) { \ |
| 267 js_class_name* pObj = (js_class_name*)FXJS_GetPrivate(nullptr, obj); \ | 265 js_class_name* pObj = (js_class_name*)FXJS_GetPrivate(nullptr, obj); \ |
| 268 pObj->ExitInstance(); \ | 266 pObj->ExitInstance(); \ |
| 269 delete pObj; \ | 267 delete pObj; \ |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); | 358 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
| 361 FX_BOOL bRet = pObj->QueryProperty(propname.c_str()); | 359 FX_BOOL bRet = pObj->QueryProperty(propname.c_str()); |
| 362 info.GetReturnValue().Set(bRet ? 4 : 0); | 360 info.GetReturnValue().Set(bRet ? 4 : 0); |
| 363 } | 361 } |
| 364 | 362 |
| 365 template <class Alt> | 363 template <class Alt> |
| 366 void JSSpecialPropGet(const char* class_name, | 364 void JSSpecialPropGet(const char* class_name, |
| 367 v8::Local<v8::String> property, | 365 v8::Local<v8::String> property, |
| 368 const v8::PropertyCallbackInfo<v8::Value>& info) { | 366 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 369 v8::Isolate* isolate = info.GetIsolate(); | 367 v8::Isolate* isolate = info.GetIsolate(); |
| 370 IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); | 368 IJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); |
| 371 if (!pRuntime) | 369 if (!pRuntime) |
| 372 return; | 370 return; |
| 373 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); | 371 IJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); |
| 374 CJS_Object* pJSObj = | 372 CJS_Object* pJSObj = |
| 375 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); | 373 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); |
| 376 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); | 374 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
| 377 v8::String::Utf8Value utf8_value(property); | 375 v8::String::Utf8Value utf8_value(property); |
| 378 CFX_WideString propname = | 376 CFX_WideString propname = |
| 379 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); | 377 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); |
| 380 CFX_WideString sError; | 378 CFX_WideString sError; |
| 381 CJS_PropValue value(isolate); | 379 CJS_PropValue value(isolate); |
| 382 value.StartGetting(); | 380 value.StartGetting(); |
| 383 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), value, sError)) { | 381 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), value, sError)) { |
| 384 FXJS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError)); | 382 FXJS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError)); |
| 385 return; | 383 return; |
| 386 } | 384 } |
| 387 info.GetReturnValue().Set((v8::Local<v8::Value>)value); | 385 info.GetReturnValue().Set((v8::Local<v8::Value>)value); |
| 388 } | 386 } |
| 389 | 387 |
| 390 template <class Alt> | 388 template <class Alt> |
| 391 void JSSpecialPropPut(const char* class_name, | 389 void JSSpecialPropPut(const char* class_name, |
| 392 v8::Local<v8::String> property, | 390 v8::Local<v8::String> property, |
| 393 v8::Local<v8::Value> value, | 391 v8::Local<v8::Value> value, |
| 394 const v8::PropertyCallbackInfo<v8::Value>& info) { | 392 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 395 v8::Isolate* isolate = info.GetIsolate(); | 393 v8::Isolate* isolate = info.GetIsolate(); |
| 396 IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); | 394 IJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); |
| 397 if (!pRuntime) | 395 if (!pRuntime) |
| 398 return; | 396 return; |
| 399 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); | 397 IJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); |
| 400 CJS_Object* pJSObj = | 398 CJS_Object* pJSObj = |
| 401 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); | 399 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); |
| 402 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); | 400 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
| 403 v8::String::Utf8Value utf8_value(property); | 401 v8::String::Utf8Value utf8_value(property); |
| 404 CFX_WideString propname = | 402 CFX_WideString propname = |
| 405 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); | 403 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); |
| 406 CFX_WideString sError; | 404 CFX_WideString sError; |
| 407 CJS_PropValue PropValue(CJS_Value(isolate, value, CJS_Value::VT_unknown)); | 405 CJS_PropValue PropValue(CJS_Value(isolate, value, CJS_Value::VT_unknown)); |
| 408 PropValue.StartSetting(); | 406 PropValue.StartSetting(); |
| 409 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), PropValue, sError)) { | 407 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), PropValue, sError)) { |
| 410 FXJS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError)); | 408 FXJS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError)); |
| 411 } | 409 } |
| 412 } | 410 } |
| 413 | 411 |
| 414 template <class Alt> | 412 template <class Alt> |
| 415 void JSSpecialPropDel(const char* class_name, | 413 void JSSpecialPropDel(const char* class_name, |
| 416 v8::Local<v8::String> property, | 414 v8::Local<v8::String> property, |
| 417 const v8::PropertyCallbackInfo<v8::Boolean>& info) { | 415 const v8::PropertyCallbackInfo<v8::Boolean>& info) { |
| 418 v8::Isolate* isolate = info.GetIsolate(); | 416 v8::Isolate* isolate = info.GetIsolate(); |
| 419 IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); | 417 IJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); |
| 420 if (!pRuntime) | 418 if (!pRuntime) |
| 421 return; | 419 return; |
| 422 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); | 420 IJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); |
| 423 CJS_Object* pJSObj = | 421 CJS_Object* pJSObj = |
| 424 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); | 422 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); |
| 425 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); | 423 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
| 426 v8::String::Utf8Value utf8_value(property); | 424 v8::String::Utf8Value utf8_value(property); |
| 427 CFX_WideString propname = | 425 CFX_WideString propname = |
| 428 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); | 426 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); |
| 429 CFX_WideString sError; | 427 CFX_WideString sError; |
| 430 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) { | 428 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) { |
| 431 CFX_ByteString cbName; | 429 CFX_ByteString cbName; |
| 432 cbName.Format("%s.%s", class_name, "DelProperty"); | 430 cbName.Format("%s.%s", class_name, "DelProperty"); |
| 433 // Probably a missing call to JSFX_Error(). | 431 // Probably a missing call to JSFX_Error(). |
| 434 } | 432 } |
| 435 } | 433 } |
| 436 | 434 |
| 437 template <FX_BOOL (*F)(IFXJS_Context* cc, | 435 template <FX_BOOL (*F)(IJS_Context* cc, |
| 438 const CJS_Parameters& params, | 436 const CJS_Parameters& params, |
| 439 CJS_Value& vRet, | 437 CJS_Value& vRet, |
| 440 CFX_WideString& sError)> | 438 CFX_WideString& sError)> |
| 441 void JSGlobalFunc(const char* func_name_string, | 439 void JSGlobalFunc(const char* func_name_string, |
| 442 const v8::FunctionCallbackInfo<v8::Value>& info) { | 440 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 443 v8::Isolate* isolate = info.GetIsolate(); | 441 v8::Isolate* isolate = info.GetIsolate(); |
| 444 IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); | 442 IJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); |
| 445 if (!pRuntime) | 443 if (!pRuntime) |
| 446 return; | 444 return; |
| 447 IFXJS_Context* cc = pRuntime->GetCurrentContext(); | 445 IJS_Context* cc = pRuntime->GetCurrentContext(); |
| 448 CJS_Parameters parameters; | 446 CJS_Parameters parameters; |
| 449 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { | 447 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { |
| 450 parameters.push_back(CJS_Value(isolate, info[i], CJS_Value::VT_unknown)); | 448 parameters.push_back(CJS_Value(isolate, info[i], CJS_Value::VT_unknown)); |
| 451 } | 449 } |
| 452 CJS_Value valueRes(isolate); | 450 CJS_Value valueRes(isolate); |
| 453 CFX_WideString sError; | 451 CFX_WideString sError; |
| 454 if (!(*F)(cc, parameters, valueRes, sError)) { | 452 if (!(*F)(cc, parameters, valueRes, sError)) { |
| 455 FXJS_Error(isolate, JSFormatErrorString(func_name_string, nullptr, sError)); | 453 FXJS_Error(isolate, JSFormatErrorString(func_name_string, nullptr, sError)); |
| 456 return; | 454 return; |
| 457 } | 455 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 480 for (size_t i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \ | 478 for (size_t i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \ |
| 481 FXJS_DefineGlobalMethod(pIsolate, \ | 479 FXJS_DefineGlobalMethod(pIsolate, \ |
| 482 js_class_name::global_methods[i].pName, \ | 480 js_class_name::global_methods[i].pName, \ |
| 483 js_class_name::global_methods[i].pMethodCall); \ | 481 js_class_name::global_methods[i].pMethodCall); \ |
| 484 } \ | 482 } \ |
| 485 } | 483 } |
| 486 | 484 |
| 487 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p); | 485 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p); |
| 488 | 486 |
| 489 #endif // FPDFSDK_SRC_JAVASCRIPT_JS_DEFINE_H_ | 487 #endif // FPDFSDK_SRC_JAVASCRIPT_JS_DEFINE_H_ |
| OLD | NEW |