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