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 "JS_Object.h" | 10 #include "JS_Object.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 = static_cast<CJS_Runtime*>( | 81 CJS_Runtime* pRuntime = |
82 FXJS_GetRuntimeFromV8Context(isolate->GetCurrentContext())); | 82 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); |
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 = static_cast<CJS_Runtime*>( | 107 CJS_Runtime* pRuntime = |
108 FXJS_GetRuntimeFromV8Context(isolate->GetCurrentContext())); | 108 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); |
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 std::vector<CJS_Value>&, | 139 const std::vector<CJS_Value>&, |
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 = static_cast<CJS_Runtime*>( | 146 CJS_Runtime* pRuntime = |
147 FXJS_GetRuntimeFromV8Context(isolate->GetCurrentContext())); | 147 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); |
148 if (!pRuntime) | 148 if (!pRuntime) |
149 return; | 149 return; |
150 IJS_Context* pContext = pRuntime->GetCurrentContext(); | 150 IJS_Context* pContext = pRuntime->GetCurrentContext(); |
151 std::vector<CJS_Value> parameters; | 151 std::vector<CJS_Value> 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 = static_cast<CJS_Runtime*>( | 369 CJS_Runtime* pRuntime = |
370 FXJS_GetRuntimeFromV8Context(isolate->GetCurrentContext())); | 370 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); |
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 = static_cast<CJS_Runtime*>( | 396 CJS_Runtime* pRuntime = |
397 FXJS_GetRuntimeFromV8Context(isolate->GetCurrentContext())); | 397 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); |
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 = | 420 IJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate); |
421 FXJS_GetRuntimeFromV8Context(isolate->GetCurrentContext()); | |
422 if (!pRuntime) | 421 if (!pRuntime) |
423 return; | 422 return; |
424 IJS_Context* pContext = pRuntime->GetCurrentContext(); | 423 IJS_Context* pContext = pRuntime->GetCurrentContext(); |
425 CJS_Object* pJSObj = | 424 CJS_Object* pJSObj = |
426 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); | 425 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); |
427 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); | 426 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); |
428 v8::String::Utf8Value utf8_value(property); | 427 v8::String::Utf8Value utf8_value(property); |
429 CFX_WideString propname = | 428 CFX_WideString propname = |
430 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); | 429 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); |
431 CFX_WideString sError; | 430 CFX_WideString sError; |
432 if (!pObj->DelProperty(pContext, propname.c_str(), sError)) { | 431 if (!pObj->DelProperty(pContext, propname.c_str(), sError)) { |
433 CFX_ByteString cbName; | 432 CFX_ByteString cbName; |
434 cbName.Format("%s.%s", class_name, "DelProperty"); | 433 cbName.Format("%s.%s", class_name, "DelProperty"); |
435 // Probably a missing call to JSFX_Error(). | 434 // Probably a missing call to JSFX_Error(). |
436 } | 435 } |
437 } | 436 } |
438 | 437 |
439 template <FX_BOOL (*F)(IJS_Context*, | 438 template <FX_BOOL (*F)(IJS_Context*, |
440 const std::vector<CJS_Value>&, | 439 const std::vector<CJS_Value>&, |
441 CJS_Value&, | 440 CJS_Value&, |
442 CFX_WideString&)> | 441 CFX_WideString&)> |
443 void JSGlobalFunc(const char* func_name_string, | 442 void JSGlobalFunc(const char* func_name_string, |
444 const v8::FunctionCallbackInfo<v8::Value>& info) { | 443 const v8::FunctionCallbackInfo<v8::Value>& info) { |
445 CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>( | 444 CJS_Runtime* pRuntime = |
446 FXJS_GetRuntimeFromV8Context(info.GetIsolate()->GetCurrentContext())); | 445 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(info.GetIsolate())); |
447 if (!pRuntime) | 446 if (!pRuntime) |
448 return; | 447 return; |
449 IJS_Context* pContext = pRuntime->GetCurrentContext(); | 448 IJS_Context* pContext = pRuntime->GetCurrentContext(); |
450 std::vector<CJS_Value> parameters; | 449 std::vector<CJS_Value> parameters; |
451 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { | 450 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { |
452 parameters.push_back(CJS_Value(pRuntime, info[i], CJS_Value::VT_unknown)); | 451 parameters.push_back(CJS_Value(pRuntime, info[i], CJS_Value::VT_unknown)); |
453 } | 452 } |
454 CJS_Value valueRes(pRuntime); | 453 CJS_Value valueRes(pRuntime); |
455 CFX_WideString sError; | 454 CFX_WideString sError; |
456 if (!(*F)(pContext, parameters, valueRes, sError)) { | 455 if (!(*F)(pContext, parameters, valueRes, sError)) { |
(...skipping 26 matching lines...) Expand all Loading... |
483 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) { \ |
484 FXJS_DefineGlobalMethod(pIsolate, \ | 483 FXJS_DefineGlobalMethod(pIsolate, \ |
485 js_class_name::global_methods[i].pName, \ | 484 js_class_name::global_methods[i].pName, \ |
486 js_class_name::global_methods[i].pMethodCall); \ | 485 js_class_name::global_methods[i].pMethodCall); \ |
487 } \ | 486 } \ |
488 } | 487 } |
489 | 488 |
490 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p); | 489 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p); |
491 | 490 |
492 #endif // FPDFSDK_SRC_JAVASCRIPT_JS_DEFINE_H_ | 491 #endif // FPDFSDK_SRC_JAVASCRIPT_JS_DEFINE_H_ |
OLD | NEW |