Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: fpdfsdk/src/javascript/JS_Define.h

Issue 1398703009: Next round of XFA changes to match master (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: remove arg Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 =
82 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); 82 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate));
83 if (!pRuntime) 83 if (!pRuntime)
84 return; 84 return;
85 IJS_Context* pRuntimeContext = 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)(pRuntimeContext, 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 =
108 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); 108 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate));
109 if (!pRuntime) 109 if (!pRuntime)
110 return; 110 return;
111 IJS_Context* pRuntimeContext = 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)(pRuntimeContext, 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,
119 sError)); 119 sError));
120 } 120 }
121 } 121 }
122 122
123 #define JS_STATIC_PROP(prop_name, class_name) \ 123 #define JS_STATIC_PROP(prop_name, class_name) \
124 static void get_##prop_name##_static( \ 124 static void get_##prop_name##_static( \
125 v8::Local<v8::String> property, \ 125 v8::Local<v8::String> property, \
126 const v8::PropertyCallbackInfo<v8::Value>& info) { \ 126 const v8::PropertyCallbackInfo<v8::Value>& info) { \
127 JSPropGetter<class_name, &class_name::prop_name>(#prop_name, #class_name, \ 127 JSPropGetter<class_name, &class_name::prop_name>(#prop_name, #class_name, \
(...skipping 12 matching lines...) Expand all
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 =
147 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); 147 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate));
148 if (!pRuntime) 148 if (!pRuntime)
149 return; 149 return;
150 IJS_Context* pRuntimeContext = 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());
158 CFX_WideString sError; 158 CFX_WideString sError;
159 if (!(pObj->*M)(pRuntimeContext, parameters, valueRes, sError)) { 159 if (!(pObj->*M)(pContext, parameters, valueRes, sError)) {
160 FXJS_Error(isolate, JSFormatErrorString(class_name_string, 160 FXJS_Error(isolate, JSFormatErrorString(class_name_string,
161 method_name_string, sError)); 161 method_name_string, sError));
162 return; 162 return;
163 } 163 }
164 info.GetReturnValue().Set(valueRes.ToV8Value()); 164 info.GetReturnValue().Set(valueRes.ToV8Value());
165 } 165 }
166 166
167 #define JS_STATIC_METHOD(method_name, class_name) \ 167 #define JS_STATIC_METHOD(method_name, class_name) \
168 static void method_name##_static( \ 168 static void method_name##_static( \
169 const v8::FunctionCallbackInfo<v8::Value>& info) { \ 169 const v8::FunctionCallbackInfo<v8::Value>& info) { \
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 =
370 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); 370 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate));
371 if (!pRuntime) 371 if (!pRuntime)
372 return; 372 return;
373 IJS_Context* pRuntimeContext = 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(pRuntimeContext, 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 =
397 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate)); 397 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(isolate));
398 if (!pRuntime) 398 if (!pRuntime)
399 return; 399 return;
400 IJS_Context* pRuntimeContext = 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(pRuntimeContext, 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 = FXJS_GetRuntimeFromIsolate(isolate);
421 if (!pRuntime) 421 if (!pRuntime)
422 return; 422 return;
423 IJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); 423 IJS_Context* pContext = pRuntime->GetCurrentContext();
424 CJS_Object* pJSObj = 424 CJS_Object* pJSObj =
425 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); 425 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder()));
426 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); 426 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
427 v8::String::Utf8Value utf8_value(property); 427 v8::String::Utf8Value utf8_value(property);
428 CFX_WideString propname = 428 CFX_WideString propname =
429 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); 429 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length());
430 CFX_WideString sError; 430 CFX_WideString sError;
431 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) { 431 if (!pObj->DelProperty(pContext, propname.c_str(), sError)) {
432 CFX_ByteString cbName; 432 CFX_ByteString cbName;
433 cbName.Format("%s.%s", class_name, "DelProperty"); 433 cbName.Format("%s.%s", class_name, "DelProperty");
434 // Probably a missing call to JSFX_Error(). 434 // Probably a missing call to JSFX_Error().
435 } 435 }
436 } 436 }
437 437
438 template <FX_BOOL (*F)(IJS_Context* cc, 438 template <FX_BOOL (*F)(IJS_Context* cc,
439 const CJS_Parameters& params, 439 const CJS_Parameters& params,
440 CJS_Value& vRet, 440 CJS_Value& vRet,
441 CFX_WideString& sError)> 441 CFX_WideString& sError)>
442 void JSGlobalFunc(const char* func_name_string, 442 void JSGlobalFunc(const char* func_name_string,
443 const v8::FunctionCallbackInfo<v8::Value>& info) { 443 const v8::FunctionCallbackInfo<v8::Value>& info) {
444 CJS_Runtime* pRuntime = 444 CJS_Runtime* pRuntime =
445 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(info.GetIsolate())); 445 static_cast<CJS_Runtime*>(FXJS_GetRuntimeFromIsolate(info.GetIsolate()));
446 if (!pRuntime) 446 if (!pRuntime)
447 return; 447 return;
448 IJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); 448 IJS_Context* pContext = pRuntime->GetCurrentContext();
449 CJS_Parameters parameters; 449 CJS_Parameters parameters;
450 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { 450 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) {
451 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));
452 } 452 }
453 CJS_Value valueRes(pRuntime); 453 CJS_Value valueRes(pRuntime);
454 CFX_WideString sError; 454 CFX_WideString sError;
455 if (!(*F)(pRuntimeContext, parameters, valueRes, sError)) { 455 if (!(*F)(pContext, parameters, valueRes, sError)) {
456 FXJS_Error(pRuntime->GetIsolate(), 456 FXJS_Error(pRuntime->GetIsolate(),
457 JSFormatErrorString(func_name_string, nullptr, sError)); 457 JSFormatErrorString(func_name_string, nullptr, sError));
458 return; 458 return;
459 } 459 }
460 info.GetReturnValue().Set(valueRes.ToV8Value()); 460 info.GetReturnValue().Set(valueRes.ToV8Value());
461 } 461 }
462 462
463 #define JS_STATIC_GLOBAL_FUN(fun_name) \ 463 #define JS_STATIC_GLOBAL_FUN(fun_name) \
464 static void fun_name##_static( \ 464 static void fun_name##_static( \
465 const v8::FunctionCallbackInfo<v8::Value>& info) { \ 465 const v8::FunctionCallbackInfo<v8::Value>& info) { \
(...skipping 16 matching lines...) Expand all
482 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) { \
483 FXJS_DefineGlobalMethod(pIsolate, \ 483 FXJS_DefineGlobalMethod(pIsolate, \
484 js_class_name::global_methods[i].pName, \ 484 js_class_name::global_methods[i].pName, \
485 js_class_name::global_methods[i].pMethodCall); \ 485 js_class_name::global_methods[i].pMethodCall); \
486 } \ 486 } \
487 } 487 }
488 488
489 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p); 489 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p);
490 490
491 #endif // FPDFSDK_SRC_JAVASCRIPT_JS_DEFINE_H_ 491 #endif // FPDFSDK_SRC_JAVASCRIPT_JS_DEFINE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698