| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); | 85 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); |
| 86 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); | 86 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); |
| 87 CFX_WideString sError; | 87 CFX_WideString sError; |
| 88 CJS_PropValue value(pRuntime); | 88 CJS_PropValue value(pRuntime); |
| 89 value.StartGetting(); | 89 value.StartGetting(); |
| 90 if (!(pObj->*M)(pContext, value, sError)) { | 90 if (!(pObj->*M)(pContext, value, sError)) { |
| 91 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, | 91 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, |
| 92 sError)); | 92 sError)); |
| 93 return; | 93 return; |
| 94 } | 94 } |
| 95 info.GetReturnValue().Set(value.ToV8Value()); | 95 info.GetReturnValue().Set(value.GetJSValue()->ToV8Value(isolate)); |
| 96 } | 96 } |
| 97 | 97 |
| 98 template <class C, | 98 template <class C, |
| 99 FX_BOOL (C::*M)(IJS_Context*, CJS_PropValue&, CFX_WideString&)> | 99 FX_BOOL (C::*M)(IJS_Context*, CJS_PropValue&, CFX_WideString&)> |
| 100 void JSPropSetter(const char* prop_name_string, | 100 void JSPropSetter(const char* prop_name_string, |
| 101 const char* class_name_string, | 101 const char* class_name_string, |
| 102 v8::Local<v8::String> property, | 102 v8::Local<v8::String> property, |
| 103 v8::Local<v8::Value> value, | 103 v8::Local<v8::Value> value, |
| 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)); | 114 CJS_PropValue propValue(pRuntime, 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 28 matching lines...) Expand all Loading... |
| 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 } |
| 163 info.GetReturnValue().Set(valueRes.ToV8Value()); | 163 info.GetReturnValue().Set(valueRes.ToV8Value(isolate)); |
| 164 } | 164 } |
| 165 | 165 |
| 166 #define JS_STATIC_METHOD(method_name, class_name) \ | 166 #define JS_STATIC_METHOD(method_name, class_name) \ |
| 167 static void method_name##_static( \ | 167 static void method_name##_static( \ |
| 168 const v8::FunctionCallbackInfo<v8::Value>& info) { \ | 168 const v8::FunctionCallbackInfo<v8::Value>& info) { \ |
| 169 JSMethod<class_name, &class_name::method_name>(#method_name, #class_name, \ | 169 JSMethod<class_name, &class_name::method_name>(#method_name, #class_name, \ |
| 170 info); \ | 170 info); \ |
| 171 } | 171 } |
| 172 | 172 |
| 173 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name) \ | 173 #define JS_SPECIAL_STATIC_METHOD(method_name, class_alternate, class_name) \ |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 v8::String::Utf8Value utf8_value(property); | 376 v8::String::Utf8Value utf8_value(property); |
| 377 CFX_WideString propname = CFX_WideString::FromUTF8( | 377 CFX_WideString propname = CFX_WideString::FromUTF8( |
| 378 CFX_ByteStringC(*utf8_value, utf8_value.length())); | 378 CFX_ByteStringC(*utf8_value, utf8_value.length())); |
| 379 CFX_WideString sError; | 379 CFX_WideString sError; |
| 380 CJS_PropValue value(pRuntime); | 380 CJS_PropValue value(pRuntime); |
| 381 value.StartGetting(); | 381 value.StartGetting(); |
| 382 if (!pObj->DoProperty(pContext, propname.c_str(), value, sError)) { | 382 if (!pObj->DoProperty(pContext, propname.c_str(), value, sError)) { |
| 383 FXJS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError)); | 383 FXJS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError)); |
| 384 return; | 384 return; |
| 385 } | 385 } |
| 386 info.GetReturnValue().Set(value.ToV8Value()); | 386 info.GetReturnValue().Set(value.GetJSValue()->ToV8Value(isolate)); |
| 387 } | 387 } |
| 388 | 388 |
| 389 template <class Alt> | 389 template <class Alt> |
| 390 void JSSpecialPropPut(const char* class_name, | 390 void JSSpecialPropPut(const char* class_name, |
| 391 v8::Local<v8::String> property, | 391 v8::Local<v8::String> property, |
| 392 v8::Local<v8::Value> value, | 392 v8::Local<v8::Value> value, |
| 393 const v8::PropertyCallbackInfo<v8::Value>& info) { | 393 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 394 v8::Isolate* isolate = info.GetIsolate(); | 394 v8::Isolate* isolate = info.GetIsolate(); |
| 395 CJS_Runtime* pRuntime = | 395 CJS_Runtime* pRuntime = |
| 396 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); | 396 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); |
| 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)); | 407 CJS_PropValue PropValue(pRuntime, 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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])); | 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(pRuntime->GetIsolate())); |
| 460 } | 460 } |
| 461 | 461 |
| 462 #define JS_STATIC_GLOBAL_FUN(fun_name) \ | 462 #define JS_STATIC_GLOBAL_FUN(fun_name) \ |
| 463 static void fun_name##_static( \ | 463 static void fun_name##_static( \ |
| 464 const v8::FunctionCallbackInfo<v8::Value>& info) { \ | 464 const v8::FunctionCallbackInfo<v8::Value>& info) { \ |
| 465 JSGlobalFunc<fun_name>(#fun_name, info); \ | 465 JSGlobalFunc<fun_name>(#fun_name, info); \ |
| 466 } | 466 } |
| 467 | 467 |
| 468 #define JS_STATIC_DECLARE_GLOBAL_FUN() \ | 468 #define JS_STATIC_DECLARE_GLOBAL_FUN() \ |
| 469 static JSMethodSpec global_methods[]; \ | 469 static JSMethodSpec global_methods[]; \ |
| 470 static void DefineJSObjects(v8::Isolate* pIsolate) | 470 static void DefineJSObjects(v8::Isolate* pIsolate) |
| 471 | 471 |
| 472 #define BEGIN_JS_STATIC_GLOBAL_FUN(js_class_name) \ | 472 #define BEGIN_JS_STATIC_GLOBAL_FUN(js_class_name) \ |
| 473 JSMethodSpec js_class_name::global_methods[] = { | 473 JSMethodSpec js_class_name::global_methods[] = { |
| 474 #define JS_STATIC_GLOBAL_FUN_ENTRY(method_name) \ | 474 #define JS_STATIC_GLOBAL_FUN_ENTRY(method_name) \ |
| 475 JS_STATIC_METHOD_ENTRY(method_name) | 475 JS_STATIC_METHOD_ENTRY(method_name) |
| 476 | 476 |
| 477 #define END_JS_STATIC_GLOBAL_FUN() END_JS_STATIC_METHOD() | 477 #define END_JS_STATIC_GLOBAL_FUN() END_JS_STATIC_METHOD() |
| 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 #endif // FPDFSDK_JAVASCRIPT_JS_DEFINE_H_ | 488 #endif // FPDFSDK_JAVASCRIPT_JS_DEFINE_H_ |
| OLD | NEW |