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 CJS_Runtime* pRuntime = | 81 CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>( |
82 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); | 82 FXJS_GetRuntimeFromV8Context(isolate->GetCurrentContext())); |
83 if (!pRuntime) | 83 if (!pRuntime) |
84 return; | 84 return; |
85 IJS_Context* pContext = pRuntime->GetCurrentContext(); | 85 IJS_Context* pContext = pRuntime->GetCurrentContext(); |
86 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); | 86 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); |
87 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); | 87 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
88 CFX_WideString sError; | 88 CFX_WideString sError; |
89 CJS_PropValue value(pRuntime); | 89 CJS_PropValue value(pRuntime); |
90 value.StartGetting(); | 90 value.StartGetting(); |
91 if (!(pObj->*M)(pContext, value, sError)) { | 91 if (!(pObj->*M)(pContext, value, sError)) { |
92 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, | 92 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, |
93 sError)); | 93 sError)); |
94 return; | 94 return; |
95 } | 95 } |
96 info.GetReturnValue().Set((v8::Local<v8::Value>)value); | 96 info.GetReturnValue().Set((v8::Local<v8::Value>)value); |
97 } | 97 } |
98 | 98 |
99 template <class C, | 99 template <class C, |
100 FX_BOOL (C::*M)(IJS_Context*, CJS_PropValue&, CFX_WideString&)> | 100 FX_BOOL (C::*M)(IJS_Context*, CJS_PropValue&, CFX_WideString&)> |
101 void JSPropSetter(const char* prop_name_string, | 101 void JSPropSetter(const char* prop_name_string, |
102 const char* class_name_string, | 102 const char* class_name_string, |
103 v8::Local<v8::String> property, | 103 v8::Local<v8::String> property, |
104 v8::Local<v8::Value> value, | 104 v8::Local<v8::Value> value, |
105 const v8::PropertyCallbackInfo<void>& info) { | 105 const v8::PropertyCallbackInfo<void>& info) { |
106 v8::Isolate* isolate = info.GetIsolate(); | 106 v8::Isolate* isolate = info.GetIsolate(); |
107 CJS_Runtime* pRuntime = | 107 CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>( |
108 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); | 108 FXJS_GetRuntimeFromV8Context(isolate->GetCurrentContext())); |
109 if (!pRuntime) | 109 if (!pRuntime) |
110 return; | 110 return; |
111 IJS_Context* pContext = pRuntime->GetCurrentContext(); | 111 IJS_Context* pContext = pRuntime->GetCurrentContext(); |
112 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); | 112 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); |
113 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); | 113 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
114 CFX_WideString sError; | 114 CFX_WideString sError; |
115 CJS_PropValue propValue(CJS_Value(pRuntime, value, CJS_Value::VT_unknown)); | 115 CJS_PropValue propValue(CJS_Value(pRuntime, value, CJS_Value::VT_unknown)); |
116 propValue.StartSetting(); | 116 propValue.StartSetting(); |
117 if (!(pObj->*M)(pContext, propValue, sError)) { | 117 if (!(pObj->*M)(pContext, propValue, sError)) { |
118 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, | 118 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, |
(...skipping 17 matching lines...) Expand all Loading... |
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 CJS_Parameters&, |
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 = static_cast<CJS_Runtime*>( |
147 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); | 147 FXJS_GetRuntimeFromV8Context(isolate->GetCurrentContext())); |
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 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()); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); | 359 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
360 FX_BOOL bRet = pObj->QueryProperty(propname.c_str()); | 360 FX_BOOL bRet = pObj->QueryProperty(propname.c_str()); |
361 info.GetReturnValue().Set(bRet ? 4 : 0); | 361 info.GetReturnValue().Set(bRet ? 4 : 0); |
362 } | 362 } |
363 | 363 |
364 template <class Alt> | 364 template <class Alt> |
365 void JSSpecialPropGet(const char* class_name, | 365 void JSSpecialPropGet(const char* class_name, |
366 v8::Local<v8::String> property, | 366 v8::Local<v8::String> property, |
367 const v8::PropertyCallbackInfo<v8::Value>& info) { | 367 const v8::PropertyCallbackInfo<v8::Value>& info) { |
368 v8::Isolate* isolate = info.GetIsolate(); | 368 v8::Isolate* isolate = info.GetIsolate(); |
369 CJS_Runtime* pRuntime = | 369 CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>( |
370 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); | 370 FXJS_GetRuntimeFromV8Context(isolate->GetCurrentContext())); |
371 if (!pRuntime) | 371 if (!pRuntime) |
372 return; | 372 return; |
373 IJS_Context* pContext = pRuntime->GetCurrentContext(); | 373 IJS_Context* pContext = pRuntime->GetCurrentContext(); |
374 CJS_Object* pJSObj = | 374 CJS_Object* pJSObj = |
375 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); | 375 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); |
376 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); | 376 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
377 v8::String::Utf8Value utf8_value(property); | 377 v8::String::Utf8Value utf8_value(property); |
378 CFX_WideString propname = | 378 CFX_WideString propname = |
379 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); | 379 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); |
380 CFX_WideString sError; | 380 CFX_WideString sError; |
381 CJS_PropValue value(pRuntime); | 381 CJS_PropValue value(pRuntime); |
382 value.StartGetting(); | 382 value.StartGetting(); |
383 if (!pObj->DoProperty(pContext, propname.c_str(), value, sError)) { | 383 if (!pObj->DoProperty(pContext, propname.c_str(), value, sError)) { |
384 FXJS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError)); | 384 FXJS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError)); |
385 return; | 385 return; |
386 } | 386 } |
387 info.GetReturnValue().Set((v8::Local<v8::Value>)value); | 387 info.GetReturnValue().Set((v8::Local<v8::Value>)value); |
388 } | 388 } |
389 | 389 |
390 template <class Alt> | 390 template <class Alt> |
391 void JSSpecialPropPut(const char* class_name, | 391 void JSSpecialPropPut(const char* class_name, |
392 v8::Local<v8::String> property, | 392 v8::Local<v8::String> property, |
393 v8::Local<v8::Value> value, | 393 v8::Local<v8::Value> value, |
394 const v8::PropertyCallbackInfo<v8::Value>& info) { | 394 const v8::PropertyCallbackInfo<v8::Value>& info) { |
395 v8::Isolate* isolate = info.GetIsolate(); | 395 v8::Isolate* isolate = info.GetIsolate(); |
396 CJS_Runtime* pRuntime = | 396 CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>( |
397 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); | 397 FXJS_GetRuntimeFromV8Context(isolate->GetCurrentContext())); |
398 if (!pRuntime) | 398 if (!pRuntime) |
399 return; | 399 return; |
400 IJS_Context* pContext = pRuntime->GetCurrentContext(); | 400 IJS_Context* pContext = pRuntime->GetCurrentContext(); |
401 CJS_Object* pJSObj = | 401 CJS_Object* pJSObj = |
402 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); | 402 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); |
403 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); | 403 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
404 v8::String::Utf8Value utf8_value(property); | 404 v8::String::Utf8Value utf8_value(property); |
405 CFX_WideString propname = | 405 CFX_WideString propname = |
406 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); | 406 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); |
407 CFX_WideString sError; | 407 CFX_WideString sError; |
408 CJS_PropValue PropValue(CJS_Value(pRuntime, value, CJS_Value::VT_unknown)); | 408 CJS_PropValue PropValue(CJS_Value(pRuntime, value, CJS_Value::VT_unknown)); |
409 PropValue.StartSetting(); | 409 PropValue.StartSetting(); |
410 if (!pObj->DoProperty(pContext, propname.c_str(), PropValue, sError)) { | 410 if (!pObj->DoProperty(pContext, propname.c_str(), PropValue, sError)) { |
411 FXJS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError)); | 411 FXJS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError)); |
412 } | 412 } |
413 } | 413 } |
414 | 414 |
415 template <class Alt> | 415 template <class Alt> |
416 void JSSpecialPropDel(const char* class_name, | 416 void JSSpecialPropDel(const char* class_name, |
417 v8::Local<v8::String> property, | 417 v8::Local<v8::String> property, |
418 const v8::PropertyCallbackInfo<v8::Boolean>& info) { | 418 const v8::PropertyCallbackInfo<v8::Boolean>& info) { |
419 v8::Isolate* isolate = info.GetIsolate(); | 419 v8::Isolate* isolate = info.GetIsolate(); |
420 IJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); | 420 IJS_Runtime* pRuntime = |
| 421 FXJS_GetRuntimeFromV8Context(isolate->GetCurrentContext()); |
421 if (!pRuntime) | 422 if (!pRuntime) |
422 return; | 423 return; |
423 IJS_Context* pContext = pRuntime->GetCurrentContext(); | 424 IJS_Context* pContext = pRuntime->GetCurrentContext(); |
424 CJS_Object* pJSObj = | 425 CJS_Object* pJSObj = |
425 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); | 426 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); |
426 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); | 427 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
427 v8::String::Utf8Value utf8_value(property); | 428 v8::String::Utf8Value utf8_value(property); |
428 CFX_WideString propname = | 429 CFX_WideString propname = |
429 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); | 430 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); |
430 CFX_WideString sError; | 431 CFX_WideString sError; |
431 if (!pObj->DelProperty(pContext, propname.c_str(), sError)) { | 432 if (!pObj->DelProperty(pContext, propname.c_str(), sError)) { |
432 CFX_ByteString cbName; | 433 CFX_ByteString cbName; |
433 cbName.Format("%s.%s", class_name, "DelProperty"); | 434 cbName.Format("%s.%s", class_name, "DelProperty"); |
434 // Probably a missing call to JSFX_Error(). | 435 // Probably a missing call to JSFX_Error(). |
435 } | 436 } |
436 } | 437 } |
437 | 438 |
438 template <FX_BOOL ( | 439 template <FX_BOOL ( |
439 *F)(IJS_Context*, const CJS_Parameters&, CJS_Value&, CFX_WideString&)> | 440 *F)(IJS_Context*, const CJS_Parameters&, CJS_Value&, CFX_WideString&)> |
440 void JSGlobalFunc(const char* func_name_string, | 441 void JSGlobalFunc(const char* func_name_string, |
441 const v8::FunctionCallbackInfo<v8::Value>& info) { | 442 const v8::FunctionCallbackInfo<v8::Value>& info) { |
442 CJS_Runtime* pRuntime = | 443 CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>( |
443 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(info.GetIsolate())); | 444 FXJS_GetRuntimeFromV8Context(info.GetIsolate()->GetCurrentContext())); |
444 if (!pRuntime) | 445 if (!pRuntime) |
445 return; | 446 return; |
446 IJS_Context* pContext = pRuntime->GetCurrentContext(); | 447 IJS_Context* pContext = pRuntime->GetCurrentContext(); |
447 CJS_Parameters parameters; | 448 CJS_Parameters parameters; |
448 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { | 449 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { |
449 parameters.push_back(CJS_Value(pRuntime, info[i], CJS_Value::VT_unknown)); | 450 parameters.push_back(CJS_Value(pRuntime, info[i], CJS_Value::VT_unknown)); |
450 } | 451 } |
451 CJS_Value valueRes(pRuntime); | 452 CJS_Value valueRes(pRuntime); |
452 CFX_WideString sError; | 453 CFX_WideString sError; |
453 if (!(*F)(pContext, parameters, valueRes, sError)) { | 454 if (!(*F)(pContext, parameters, valueRes, sError)) { |
(...skipping 26 matching lines...) Expand all Loading... |
480 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) { \ |
481 FXJS_DefineGlobalMethod(pIsolate, \ | 482 FXJS_DefineGlobalMethod(pIsolate, \ |
482 js_class_name::global_methods[i].pName, \ | 483 js_class_name::global_methods[i].pName, \ |
483 js_class_name::global_methods[i].pMethodCall); \ | 484 js_class_name::global_methods[i].pMethodCall); \ |
484 } \ | 485 } \ |
485 } | 486 } |
486 | 487 |
487 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p); | 488 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p); |
488 | 489 |
489 #endif // FPDFSDK_SRC_JAVASCRIPT_JS_DEFINE_H_ | 490 #endif // FPDFSDK_SRC_JAVASCRIPT_JS_DEFINE_H_ |
OLD | NEW |