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_JAVASCRIPT_JS_DEFINE_H_ | 7 #ifndef FPDFSDK_JAVASCRIPT_JS_DEFINE_H_ |
8 #define FPDFSDK_JAVASCRIPT_JS_DEFINE_H_ | 8 #define FPDFSDK_JAVASCRIPT_JS_DEFINE_H_ |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 const v8::PropertyCallbackInfo<void>& info) { | 104 const v8::PropertyCallbackInfo<void>& info) { |
105 v8::Isolate* isolate = info.GetIsolate(); | 105 v8::Isolate* isolate = info.GetIsolate(); |
106 CJS_Runtime* pRuntime = | 106 CJS_Runtime* pRuntime = |
107 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); | 107 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); |
108 if (!pRuntime) | 108 if (!pRuntime) |
109 return; | 109 return; |
110 IJS_Context* pContext = pRuntime->GetCurrentContext(); | 110 IJS_Context* pContext = pRuntime->GetCurrentContext(); |
111 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); | 111 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); |
112 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); | 112 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
113 CFX_WideString sError; | 113 CFX_WideString sError; |
114 CJS_PropValue propValue(CJS_Value(pRuntime, value, CJS_Value::VT_unknown)); | 114 CJS_PropValue propValue(CJS_Value(pRuntime, value)); |
115 propValue.StartSetting(); | 115 propValue.StartSetting(); |
116 if (!(pObj->*M)(pContext, propValue, sError)) { | 116 if (!(pObj->*M)(pContext, propValue, sError)) { |
117 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, | 117 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, |
118 sError)); | 118 sError)); |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
122 #define JS_STATIC_PROP(prop_name, class_name) \ | 122 #define JS_STATIC_PROP(prop_name, class_name) \ |
123 static void get_##prop_name##_static( \ | 123 static void get_##prop_name##_static( \ |
124 v8::Local<v8::String> property, \ | 124 v8::Local<v8::String> property, \ |
(...skipping 17 matching lines...) Expand all Loading... |
142 const char* class_name_string, | 142 const char* class_name_string, |
143 const v8::FunctionCallbackInfo<v8::Value>& info) { | 143 const v8::FunctionCallbackInfo<v8::Value>& info) { |
144 v8::Isolate* isolate = info.GetIsolate(); | 144 v8::Isolate* isolate = info.GetIsolate(); |
145 CJS_Runtime* pRuntime = | 145 CJS_Runtime* pRuntime = |
146 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); | 146 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); |
147 if (!pRuntime) | 147 if (!pRuntime) |
148 return; | 148 return; |
149 IJS_Context* pContext = pRuntime->GetCurrentContext(); | 149 IJS_Context* pContext = pRuntime->GetCurrentContext(); |
150 std::vector<CJS_Value> parameters; | 150 std::vector<CJS_Value> parameters; |
151 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { | 151 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { |
152 parameters.push_back(CJS_Value(pRuntime, info[i], CJS_Value::VT_unknown)); | 152 parameters.push_back(CJS_Value(pRuntime, info[i])); |
153 } | 153 } |
154 CJS_Value valueRes(pRuntime); | 154 CJS_Value valueRes(pRuntime); |
155 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); | 155 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); |
156 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); | 156 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
157 CFX_WideString sError; | 157 CFX_WideString sError; |
158 if (!(pObj->*M)(pContext, parameters, valueRes, sError)) { | 158 if (!(pObj->*M)(pContext, parameters, valueRes, sError)) { |
159 FXJS_Error(isolate, JSFormatErrorString(class_name_string, | 159 FXJS_Error(isolate, JSFormatErrorString(class_name_string, |
160 method_name_string, sError)); | 160 method_name_string, sError)); |
161 return; | 161 return; |
162 } | 162 } |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 if (!pRuntime) | 397 if (!pRuntime) |
398 return; | 398 return; |
399 IJS_Context* pContext = pRuntime->GetCurrentContext(); | 399 IJS_Context* pContext = pRuntime->GetCurrentContext(); |
400 CJS_Object* pJSObj = | 400 CJS_Object* pJSObj = |
401 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); | 401 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); |
402 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); | 402 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
403 v8::String::Utf8Value utf8_value(property); | 403 v8::String::Utf8Value utf8_value(property); |
404 CFX_WideString propname = CFX_WideString::FromUTF8( | 404 CFX_WideString propname = CFX_WideString::FromUTF8( |
405 CFX_ByteStringC(*utf8_value, utf8_value.length())); | 405 CFX_ByteStringC(*utf8_value, utf8_value.length())); |
406 CFX_WideString sError; | 406 CFX_WideString sError; |
407 CJS_PropValue PropValue(CJS_Value(pRuntime, value, CJS_Value::VT_unknown)); | 407 CJS_PropValue PropValue(CJS_Value(pRuntime, value)); |
408 PropValue.StartSetting(); | 408 PropValue.StartSetting(); |
409 if (!pObj->DoProperty(pContext, propname.c_str(), PropValue, sError)) { | 409 if (!pObj->DoProperty(pContext, propname.c_str(), PropValue, sError)) { |
410 FXJS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError)); | 410 FXJS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError)); |
411 } | 411 } |
412 } | 412 } |
413 | 413 |
414 template <class Alt> | 414 template <class Alt> |
415 void JSSpecialPropDel(const char* class_name, | 415 void JSSpecialPropDel(const char* class_name, |
416 v8::Local<v8::String> property, | 416 v8::Local<v8::String> property, |
417 const v8::PropertyCallbackInfo<v8::Boolean>& info) { | 417 const v8::PropertyCallbackInfo<v8::Boolean>& info) { |
(...skipping 22 matching lines...) Expand all Loading... |
440 CFX_WideString&)> | 440 CFX_WideString&)> |
441 void JSGlobalFunc(const char* func_name_string, | 441 void JSGlobalFunc(const char* func_name_string, |
442 const v8::FunctionCallbackInfo<v8::Value>& info) { | 442 const v8::FunctionCallbackInfo<v8::Value>& info) { |
443 CJS_Runtime* pRuntime = | 443 CJS_Runtime* pRuntime = |
444 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(info.GetIsolate())); | 444 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(info.GetIsolate())); |
445 if (!pRuntime) | 445 if (!pRuntime) |
446 return; | 446 return; |
447 IJS_Context* pContext = pRuntime->GetCurrentContext(); | 447 IJS_Context* pContext = pRuntime->GetCurrentContext(); |
448 std::vector<CJS_Value> parameters; | 448 std::vector<CJS_Value> parameters; |
449 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { | 449 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { |
450 parameters.push_back(CJS_Value(pRuntime, info[i], CJS_Value::VT_unknown)); | 450 parameters.push_back(CJS_Value(pRuntime, info[i])); |
451 } | 451 } |
452 CJS_Value valueRes(pRuntime); | 452 CJS_Value valueRes(pRuntime); |
453 CFX_WideString sError; | 453 CFX_WideString sError; |
454 if (!(*F)(pContext, parameters, valueRes, sError)) { | 454 if (!(*F)(pContext, parameters, valueRes, sError)) { |
455 FXJS_Error(pRuntime->GetIsolate(), | 455 FXJS_Error(pRuntime->GetIsolate(), |
456 JSFormatErrorString(func_name_string, nullptr, sError)); | 456 JSFormatErrorString(func_name_string, nullptr, sError)); |
457 return; | 457 return; |
458 } | 458 } |
459 info.GetReturnValue().Set(valueRes.ToV8Value()); | 459 info.GetReturnValue().Set(valueRes.ToV8Value()); |
460 } | 460 } |
(...skipping 17 matching lines...) Expand all Loading... |
478 | 478 |
479 #define IMPLEMENT_JS_STATIC_GLOBAL_FUN(js_class_name) \ | 479 #define IMPLEMENT_JS_STATIC_GLOBAL_FUN(js_class_name) \ |
480 void js_class_name::DefineJSObjects(v8::Isolate* pIsolate) { \ | 480 void js_class_name::DefineJSObjects(v8::Isolate* pIsolate) { \ |
481 for (size_t i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \ | 481 for (size_t i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \ |
482 FXJS_DefineGlobalMethod(pIsolate, \ | 482 FXJS_DefineGlobalMethod(pIsolate, \ |
483 js_class_name::global_methods[i].pName, \ | 483 js_class_name::global_methods[i].pName, \ |
484 js_class_name::global_methods[i].pMethodCall); \ | 484 js_class_name::global_methods[i].pMethodCall); \ |
485 } \ | 485 } \ |
486 } | 486 } |
487 | 487 |
488 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p); | |
489 | |
490 #endif // FPDFSDK_JAVASCRIPT_JS_DEFINE_H_ | 488 #endif // FPDFSDK_JAVASCRIPT_JS_DEFINE_H_ |
OLD | NEW |