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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 ; | 72 ; |
73 | 73 |
74 template < | 74 template < |
75 class C, | 75 class C, |
76 FX_BOOL (C::*M)(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)> | 76 FX_BOOL (C::*M)(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)> |
77 void JSPropGetter(const char* prop_name_string, | 77 void JSPropGetter(const char* prop_name_string, |
78 const char* class_name_string, | 78 const char* class_name_string, |
79 v8::Local<v8::String> property, | 79 v8::Local<v8::String> property, |
80 const v8::PropertyCallbackInfo<v8::Value>& info) { | 80 const v8::PropertyCallbackInfo<v8::Value>& info) { |
81 v8::Isolate* isolate = info.GetIsolate(); | 81 v8::Isolate* isolate = info.GetIsolate(); |
82 IJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); | 82 CJS_Runtime* pRuntime = |
| 83 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); |
83 if (!pRuntime) | 84 if (!pRuntime) |
84 return; | 85 return; |
85 IJS_Context* pContext = pRuntime->GetCurrentContext(); | 86 IJS_Context* pContext = pRuntime->GetCurrentContext(); |
86 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); | 87 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); |
87 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); | 88 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
88 CFX_WideString sError; | 89 CFX_WideString sError; |
89 CJS_PropValue value(isolate); | 90 CJS_PropValue value(pRuntime); |
90 value.StartGetting(); | 91 value.StartGetting(); |
91 if (!(pObj->*M)(pContext, value, sError)) { | 92 if (!(pObj->*M)(pContext, value, sError)) { |
92 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, | 93 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, |
93 sError)); | 94 sError)); |
94 return; | 95 return; |
95 } | 96 } |
96 info.GetReturnValue().Set((v8::Local<v8::Value>)value); | 97 info.GetReturnValue().Set((v8::Local<v8::Value>)value); |
97 } | 98 } |
98 | 99 |
99 template < | 100 template < |
100 class C, | 101 class C, |
101 FX_BOOL (C::*M)(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)> | 102 FX_BOOL (C::*M)(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)> |
102 void JSPropSetter(const char* prop_name_string, | 103 void JSPropSetter(const char* prop_name_string, |
103 const char* class_name_string, | 104 const char* class_name_string, |
104 v8::Local<v8::String> property, | 105 v8::Local<v8::String> property, |
105 v8::Local<v8::Value> value, | 106 v8::Local<v8::Value> value, |
106 const v8::PropertyCallbackInfo<void>& info) { | 107 const v8::PropertyCallbackInfo<void>& info) { |
107 v8::Isolate* isolate = info.GetIsolate(); | 108 v8::Isolate* isolate = info.GetIsolate(); |
108 IJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); | 109 CJS_Runtime* pRuntime = |
| 110 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); |
109 if (!pRuntime) | 111 if (!pRuntime) |
110 return; | 112 return; |
111 IJS_Context* pContext = pRuntime->GetCurrentContext(); | 113 IJS_Context* pContext = pRuntime->GetCurrentContext(); |
112 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); | 114 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); |
113 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); | 115 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
114 CFX_WideString sError; | 116 CFX_WideString sError; |
115 CJS_PropValue propValue(CJS_Value(isolate, value, CJS_Value::VT_unknown)); | 117 CJS_PropValue propValue(CJS_Value(pRuntime, value, CJS_Value::VT_unknown)); |
116 propValue.StartSetting(); | 118 propValue.StartSetting(); |
117 if (!(pObj->*M)(pContext, propValue, sError)) { | 119 if (!(pObj->*M)(pContext, propValue, sError)) { |
118 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, | 120 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, |
119 sError)); | 121 sError)); |
120 } | 122 } |
121 } | 123 } |
122 | 124 |
123 #define JS_STATIC_PROP(prop_name, class_name) \ | 125 #define JS_STATIC_PROP(prop_name, class_name) \ |
124 static void get_##prop_name##_static( \ | 126 static void get_##prop_name##_static( \ |
125 v8::Local<v8::String> property, \ | 127 v8::Local<v8::String> property, \ |
(...skipping 10 matching lines...) Expand all Loading... |
136 | 138 |
137 template <class C, | 139 template <class C, |
138 FX_BOOL (C::*M)(IJS_Context* cc, | 140 FX_BOOL (C::*M)(IJS_Context* cc, |
139 const CJS_Parameters& params, | 141 const CJS_Parameters& params, |
140 CJS_Value& vRet, | 142 CJS_Value& vRet, |
141 CFX_WideString& sError)> | 143 CFX_WideString& sError)> |
142 void JSMethod(const char* method_name_string, | 144 void JSMethod(const char* method_name_string, |
143 const char* class_name_string, | 145 const char* class_name_string, |
144 const v8::FunctionCallbackInfo<v8::Value>& info) { | 146 const v8::FunctionCallbackInfo<v8::Value>& info) { |
145 v8::Isolate* isolate = info.GetIsolate(); | 147 v8::Isolate* isolate = info.GetIsolate(); |
146 IJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); | 148 CJS_Runtime* pRuntime = |
| 149 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); |
147 if (!pRuntime) | 150 if (!pRuntime) |
148 return; | 151 return; |
149 IJS_Context* cc = pRuntime->GetCurrentContext(); | 152 IJS_Context* cc = pRuntime->GetCurrentContext(); |
150 CJS_Parameters parameters; | 153 CJS_Parameters parameters; |
151 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { | 154 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { |
152 parameters.push_back(CJS_Value(isolate, info[i], CJS_Value::VT_unknown)); | 155 parameters.push_back(CJS_Value(pRuntime, info[i], CJS_Value::VT_unknown)); |
153 } | 156 } |
154 CJS_Value valueRes(isolate); | 157 CJS_Value valueRes(pRuntime); |
155 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); | 158 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); |
156 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); | 159 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
157 CFX_WideString sError; | 160 CFX_WideString sError; |
158 if (!(pObj->*M)(cc, parameters, valueRes, sError)) { | 161 if (!(pObj->*M)(cc, parameters, valueRes, sError)) { |
159 FXJS_Error(isolate, JSFormatErrorString(class_name_string, | 162 FXJS_Error(isolate, JSFormatErrorString(class_name_string, |
160 method_name_string, sError)); | 163 method_name_string, sError)); |
161 return; | 164 return; |
162 } | 165 } |
163 info.GetReturnValue().Set(valueRes.ToV8Value()); | 166 info.GetReturnValue().Set(valueRes.ToV8Value()); |
164 } | 167 } |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); | 361 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
359 FX_BOOL bRet = pObj->QueryProperty(propname.c_str()); | 362 FX_BOOL bRet = pObj->QueryProperty(propname.c_str()); |
360 info.GetReturnValue().Set(bRet ? 4 : 0); | 363 info.GetReturnValue().Set(bRet ? 4 : 0); |
361 } | 364 } |
362 | 365 |
363 template <class Alt> | 366 template <class Alt> |
364 void JSSpecialPropGet(const char* class_name, | 367 void JSSpecialPropGet(const char* class_name, |
365 v8::Local<v8::String> property, | 368 v8::Local<v8::String> property, |
366 const v8::PropertyCallbackInfo<v8::Value>& info) { | 369 const v8::PropertyCallbackInfo<v8::Value>& info) { |
367 v8::Isolate* isolate = info.GetIsolate(); | 370 v8::Isolate* isolate = info.GetIsolate(); |
368 IJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); | 371 CJS_Runtime* pRuntime = |
| 372 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); |
369 if (!pRuntime) | 373 if (!pRuntime) |
370 return; | 374 return; |
371 IJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); | 375 IJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); |
372 CJS_Object* pJSObj = | 376 CJS_Object* pJSObj = |
373 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); | 377 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); |
374 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); | 378 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
375 v8::String::Utf8Value utf8_value(property); | 379 v8::String::Utf8Value utf8_value(property); |
376 CFX_WideString propname = | 380 CFX_WideString propname = |
377 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); | 381 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); |
378 CFX_WideString sError; | 382 CFX_WideString sError; |
379 CJS_PropValue value(isolate); | 383 CJS_PropValue value(pRuntime); |
380 value.StartGetting(); | 384 value.StartGetting(); |
381 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), value, sError)) { | 385 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), value, sError)) { |
382 FXJS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError)); | 386 FXJS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError)); |
383 return; | 387 return; |
384 } | 388 } |
385 info.GetReturnValue().Set((v8::Local<v8::Value>)value); | 389 info.GetReturnValue().Set((v8::Local<v8::Value>)value); |
386 } | 390 } |
387 | 391 |
388 template <class Alt> | 392 template <class Alt> |
389 void JSSpecialPropPut(const char* class_name, | 393 void JSSpecialPropPut(const char* class_name, |
390 v8::Local<v8::String> property, | 394 v8::Local<v8::String> property, |
391 v8::Local<v8::Value> value, | 395 v8::Local<v8::Value> value, |
392 const v8::PropertyCallbackInfo<v8::Value>& info) { | 396 const v8::PropertyCallbackInfo<v8::Value>& info) { |
393 v8::Isolate* isolate = info.GetIsolate(); | 397 v8::Isolate* isolate = info.GetIsolate(); |
394 IJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); | 398 CJS_Runtime* pRuntime = |
| 399 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); |
395 if (!pRuntime) | 400 if (!pRuntime) |
396 return; | 401 return; |
397 IJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); | 402 IJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); |
398 CJS_Object* pJSObj = | 403 CJS_Object* pJSObj = |
399 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); | 404 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); |
400 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); | 405 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
401 v8::String::Utf8Value utf8_value(property); | 406 v8::String::Utf8Value utf8_value(property); |
402 CFX_WideString propname = | 407 CFX_WideString propname = |
403 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); | 408 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); |
404 CFX_WideString sError; | 409 CFX_WideString sError; |
405 CJS_PropValue PropValue(CJS_Value(isolate, value, CJS_Value::VT_unknown)); | 410 CJS_PropValue PropValue(CJS_Value(pRuntime, value, CJS_Value::VT_unknown)); |
406 PropValue.StartSetting(); | 411 PropValue.StartSetting(); |
407 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), PropValue, sError)) { | 412 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), PropValue, sError)) { |
408 FXJS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError)); | 413 FXJS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError)); |
409 } | 414 } |
410 } | 415 } |
411 | 416 |
412 template <class Alt> | 417 template <class Alt> |
413 void JSSpecialPropDel(const char* class_name, | 418 void JSSpecialPropDel(const char* class_name, |
414 v8::Local<v8::String> property, | 419 v8::Local<v8::String> property, |
415 const v8::PropertyCallbackInfo<v8::Boolean>& info) { | 420 const v8::PropertyCallbackInfo<v8::Boolean>& info) { |
(...skipping 15 matching lines...) Expand all Loading... |
431 // Probably a missing call to JSFX_Error(). | 436 // Probably a missing call to JSFX_Error(). |
432 } | 437 } |
433 } | 438 } |
434 | 439 |
435 template <FX_BOOL (*F)(IJS_Context* cc, | 440 template <FX_BOOL (*F)(IJS_Context* cc, |
436 const CJS_Parameters& params, | 441 const CJS_Parameters& params, |
437 CJS_Value& vRet, | 442 CJS_Value& vRet, |
438 CFX_WideString& sError)> | 443 CFX_WideString& sError)> |
439 void JSGlobalFunc(const char* func_name_string, | 444 void JSGlobalFunc(const char* func_name_string, |
440 const v8::FunctionCallbackInfo<v8::Value>& info) { | 445 const v8::FunctionCallbackInfo<v8::Value>& info) { |
441 v8::Isolate* isolate = info.GetIsolate(); | 446 CJS_Runtime* pRuntime = |
442 IJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); | 447 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(info.GetIsolate())); |
443 if (!pRuntime) | 448 if (!pRuntime) |
444 return; | 449 return; |
445 IJS_Context* cc = pRuntime->GetCurrentContext(); | 450 IJS_Context* cc = pRuntime->GetCurrentContext(); |
446 CJS_Parameters parameters; | 451 CJS_Parameters parameters; |
447 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { | 452 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { |
448 parameters.push_back(CJS_Value(isolate, info[i], CJS_Value::VT_unknown)); | 453 parameters.push_back(CJS_Value(pRuntime, info[i], CJS_Value::VT_unknown)); |
449 } | 454 } |
450 CJS_Value valueRes(isolate); | 455 CJS_Value valueRes(pRuntime); |
451 CFX_WideString sError; | 456 CFX_WideString sError; |
452 if (!(*F)(cc, parameters, valueRes, sError)) { | 457 if (!(*F)(cc, parameters, valueRes, sError)) { |
453 FXJS_Error(isolate, JSFormatErrorString(func_name_string, nullptr, sError)); | 458 FXJS_Error(pRuntime->GetIsolate(), |
| 459 JSFormatErrorString(func_name_string, nullptr, sError)); |
454 return; | 460 return; |
455 } | 461 } |
456 info.GetReturnValue().Set(valueRes.ToV8Value()); | 462 info.GetReturnValue().Set(valueRes.ToV8Value()); |
457 } | 463 } |
458 | 464 |
459 #define JS_STATIC_GLOBAL_FUN(fun_name) \ | 465 #define JS_STATIC_GLOBAL_FUN(fun_name) \ |
460 static void fun_name##_static( \ | 466 static void fun_name##_static( \ |
461 const v8::FunctionCallbackInfo<v8::Value>& info) { \ | 467 const v8::FunctionCallbackInfo<v8::Value>& info) { \ |
462 JSGlobalFunc<fun_name>(#fun_name, info); \ | 468 JSGlobalFunc<fun_name>(#fun_name, info); \ |
463 } | 469 } |
(...skipping 14 matching lines...) Expand all Loading... |
478 for (size_t i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \ | 484 for (size_t i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \ |
479 FXJS_DefineGlobalMethod(pIsolate, \ | 485 FXJS_DefineGlobalMethod(pIsolate, \ |
480 js_class_name::global_methods[i].pName, \ | 486 js_class_name::global_methods[i].pName, \ |
481 js_class_name::global_methods[i].pMethodCall); \ | 487 js_class_name::global_methods[i].pMethodCall); \ |
482 } \ | 488 } \ |
483 } | 489 } |
484 | 490 |
485 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p); | 491 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p); |
486 | 492 |
487 #endif // FPDFSDK_SRC_JAVASCRIPT_JS_DEFINE_H_ | 493 #endif // FPDFSDK_SRC_JAVASCRIPT_JS_DEFINE_H_ |
OLD | NEW |