| 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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* cc = pRuntime->GetCurrentContext(); | 150 IJS_Context* pContext = pRuntime->GetCurrentContext(); |
| 151 CJS_Parameters parameters; | 151 CJS_Parameters 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)(cc, 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)); |
| 162 return; | 162 return; |
| 163 } | 163 } |
| 164 info.GetReturnValue().Set(valueRes.ToV8Value()); | 164 info.GetReturnValue().Set(valueRes.ToV8Value()); |
| 165 } | 165 } |
| 166 | 166 |
| 167 #define JS_STATIC_METHOD(method_name, class_name) \ | 167 #define JS_STATIC_METHOD(method_name, class_name) \ |
| 168 static void method_name##_static( \ | 168 static void method_name##_static( \ |
| 169 const v8::FunctionCallbackInfo<v8::Value>& info) { \ | 169 const v8::FunctionCallbackInfo<v8::Value>& info) { \ |
| (...skipping 258 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(pRuntimeContext, propname.c_str(), sError)) { | 431 if (!pObj->DelProperty(pRuntimeContext, 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 (*F)(IJS_Context* cc, | 438 template <FX_BOOL ( |
| 439 const CJS_Parameters& params, | 439 *F)(IJS_Context*, const CJS_Parameters&, CJS_Value&, CFX_WideString&)> |
| 440 CJS_Value& vRet, | |
| 441 CFX_WideString& sError)> | |
| 442 void JSGlobalFunc(const char* func_name_string, | 440 void JSGlobalFunc(const char* func_name_string, |
| 443 const v8::FunctionCallbackInfo<v8::Value>& info) { | 441 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 444 CJS_Runtime* pRuntime = | 442 CJS_Runtime* pRuntime = |
| 445 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(info.GetIsolate())); | 443 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(info.GetIsolate())); |
| 446 if (!pRuntime) | 444 if (!pRuntime) |
| 447 return; | 445 return; |
| 448 IJS_Context* cc = pRuntime->GetCurrentContext(); | 446 IJS_Context* pContext = pRuntime->GetCurrentContext(); |
| 449 CJS_Parameters parameters; | 447 CJS_Parameters parameters; |
| 450 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { | 448 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { |
| 451 parameters.push_back(CJS_Value(pRuntime, info[i], CJS_Value::VT_unknown)); | 449 parameters.push_back(CJS_Value(pRuntime, info[i], CJS_Value::VT_unknown)); |
| 452 } | 450 } |
| 453 CJS_Value valueRes(pRuntime); | 451 CJS_Value valueRes(pRuntime); |
| 454 CFX_WideString sError; | 452 CFX_WideString sError; |
| 455 if (!(*F)(cc, parameters, valueRes, sError)) { | 453 if (!(*F)(pContext, parameters, valueRes, sError)) { |
| 456 FXJS_Error(pRuntime->GetIsolate(), | 454 FXJS_Error(pRuntime->GetIsolate(), |
| 457 JSFormatErrorString(func_name_string, nullptr, sError)); | 455 JSFormatErrorString(func_name_string, nullptr, sError)); |
| 458 return; | 456 return; |
| 459 } | 457 } |
| 460 info.GetReturnValue().Set(valueRes.ToV8Value()); | 458 info.GetReturnValue().Set(valueRes.ToV8Value()); |
| 461 } | 459 } |
| 462 | 460 |
| 463 #define JS_STATIC_GLOBAL_FUN(fun_name) \ | 461 #define JS_STATIC_GLOBAL_FUN(fun_name) \ |
| 464 static void fun_name##_static( \ | 462 static void fun_name##_static( \ |
| 465 const v8::FunctionCallbackInfo<v8::Value>& info) { \ | 463 const v8::FunctionCallbackInfo<v8::Value>& info) { \ |
| (...skipping 16 matching lines...) Expand all Loading... |
| 482 for (size_t i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \ | 480 for (size_t i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \ |
| 483 FXJS_DefineGlobalMethod(pIsolate, \ | 481 FXJS_DefineGlobalMethod(pIsolate, \ |
| 484 js_class_name::global_methods[i].pName, \ | 482 js_class_name::global_methods[i].pName, \ |
| 485 js_class_name::global_methods[i].pMethodCall); \ | 483 js_class_name::global_methods[i].pMethodCall); \ |
| 486 } \ | 484 } \ |
| 487 } | 485 } |
| 488 | 486 |
| 489 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p); | 487 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p); |
| 490 | 488 |
| 491 #endif // FPDFSDK_SRC_JAVASCRIPT_JS_DEFINE_H_ | 489 #endif // FPDFSDK_SRC_JAVASCRIPT_JS_DEFINE_H_ |
| OLD | NEW |