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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 } \ | 129 } \ |
130 static void set_##prop_name##_static( \ | 130 static void set_##prop_name##_static( \ |
131 v8::Local<v8::String> property, v8::Local<v8::Value> value, \ | 131 v8::Local<v8::String> property, v8::Local<v8::Value> value, \ |
132 const v8::PropertyCallbackInfo<void>& info) { \ | 132 const v8::PropertyCallbackInfo<void>& info) { \ |
133 JSPropSetter<class_name, &class_name::prop_name>(#prop_name, #class_name, \ | 133 JSPropSetter<class_name, &class_name::prop_name>(#prop_name, #class_name, \ |
134 property, value, info); \ | 134 property, value, info); \ |
135 } | 135 } |
136 | 136 |
137 template <class C, | 137 template <class C, |
138 FX_BOOL (C::*M)(IJS_Context*, | 138 FX_BOOL (C::*M)(IJS_Context*, |
139 const CJS_Parameters&, | 139 const std::vector<CJS_Value>&, |
140 CJS_Value&, | 140 CJS_Value&, |
141 CFX_WideString&)> | 141 CFX_WideString&)> |
142 void JSMethod(const char* method_name_string, | 142 void JSMethod(const char* method_name_string, |
143 const char* class_name_string, | 143 const char* class_name_string, |
144 const v8::FunctionCallbackInfo<v8::Value>& info) { | 144 const v8::FunctionCallbackInfo<v8::Value>& info) { |
145 v8::Isolate* isolate = info.GetIsolate(); | 145 v8::Isolate* isolate = info.GetIsolate(); |
146 CJS_Runtime* pRuntime = | 146 CJS_Runtime* pRuntime = |
147 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); | 147 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); |
148 if (!pRuntime) | 148 if (!pRuntime) |
149 return; | 149 return; |
150 IJS_Context* pContext = pRuntime->GetCurrentContext(); | 150 IJS_Context* pContext = pRuntime->GetCurrentContext(); |
151 CJS_Parameters parameters; | 151 std::vector<CJS_Value> parameters; |
152 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { | 152 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { |
153 parameters.push_back(CJS_Value(pRuntime, info[i], CJS_Value::VT_unknown)); | 153 parameters.push_back(CJS_Value(pRuntime, info[i], CJS_Value::VT_unknown)); |
154 } | 154 } |
155 CJS_Value valueRes(pRuntime); | 155 CJS_Value valueRes(pRuntime); |
156 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); | 156 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); |
157 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); | 157 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
158 CFX_WideString sError; | 158 CFX_WideString sError; |
159 if (!(pObj->*M)(pContext, parameters, valueRes, sError)) { | 159 if (!(pObj->*M)(pContext, parameters, valueRes, sError)) { |
160 FXJS_Error(isolate, JSFormatErrorString(class_name_string, | 160 FXJS_Error(isolate, JSFormatErrorString(class_name_string, |
161 method_name_string, sError)); | 161 method_name_string, sError)); |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 CFX_WideString propname = | 428 CFX_WideString propname = |
429 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); | 429 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); |
430 CFX_WideString sError; | 430 CFX_WideString sError; |
431 if (!pObj->DelProperty(pContext, propname.c_str(), sError)) { | 431 if (!pObj->DelProperty(pContext, propname.c_str(), sError)) { |
432 CFX_ByteString cbName; | 432 CFX_ByteString cbName; |
433 cbName.Format("%s.%s", class_name, "DelProperty"); | 433 cbName.Format("%s.%s", class_name, "DelProperty"); |
434 // Probably a missing call to JSFX_Error(). | 434 // Probably a missing call to JSFX_Error(). |
435 } | 435 } |
436 } | 436 } |
437 | 437 |
438 template <FX_BOOL ( | 438 template <FX_BOOL (*F)(IJS_Context*, |
439 *F)(IJS_Context*, const CJS_Parameters&, CJS_Value&, CFX_WideString&)> | 439 const std::vector<CJS_Value>&, |
| 440 CJS_Value&, |
| 441 CFX_WideString&)> |
440 void JSGlobalFunc(const char* func_name_string, | 442 void JSGlobalFunc(const char* func_name_string, |
441 const v8::FunctionCallbackInfo<v8::Value>& info) { | 443 const v8::FunctionCallbackInfo<v8::Value>& info) { |
442 CJS_Runtime* pRuntime = | 444 CJS_Runtime* pRuntime = |
443 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(info.GetIsolate())); | 445 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(info.GetIsolate())); |
444 if (!pRuntime) | 446 if (!pRuntime) |
445 return; | 447 return; |
446 IJS_Context* pContext = pRuntime->GetCurrentContext(); | 448 IJS_Context* pContext = pRuntime->GetCurrentContext(); |
447 CJS_Parameters parameters; | 449 std::vector<CJS_Value> parameters; |
448 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { | 450 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { |
449 parameters.push_back(CJS_Value(pRuntime, info[i], CJS_Value::VT_unknown)); | 451 parameters.push_back(CJS_Value(pRuntime, info[i], CJS_Value::VT_unknown)); |
450 } | 452 } |
451 CJS_Value valueRes(pRuntime); | 453 CJS_Value valueRes(pRuntime); |
452 CFX_WideString sError; | 454 CFX_WideString sError; |
453 if (!(*F)(pContext, parameters, valueRes, sError)) { | 455 if (!(*F)(pContext, parameters, valueRes, sError)) { |
454 FXJS_Error(pRuntime->GetIsolate(), | 456 FXJS_Error(pRuntime->GetIsolate(), |
455 JSFormatErrorString(func_name_string, nullptr, sError)); | 457 JSFormatErrorString(func_name_string, nullptr, sError)); |
456 return; | 458 return; |
457 } | 459 } |
(...skipping 22 matching lines...) Expand all Loading... |
480 for (size_t i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \ | 482 for (size_t i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \ |
481 FXJS_DefineGlobalMethod(pIsolate, \ | 483 FXJS_DefineGlobalMethod(pIsolate, \ |
482 js_class_name::global_methods[i].pName, \ | 484 js_class_name::global_methods[i].pName, \ |
483 js_class_name::global_methods[i].pMethodCall); \ | 485 js_class_name::global_methods[i].pMethodCall); \ |
484 } \ | 486 } \ |
485 } | 487 } |
486 | 488 |
487 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p); | 489 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p); |
488 | 490 |
489 #endif // FPDFSDK_SRC_JAVASCRIPT_JS_DEFINE_H_ | 491 #endif // FPDFSDK_SRC_JAVASCRIPT_JS_DEFINE_H_ |
OLD | NEW |