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

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

Issue 1370133007: Merge to XFA: Introduce kPerIsolateDataIndex and tidy JS_Define.h (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: 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
« no previous file with comments | « DEPS ('k') | fpdfsdk/include/jsapi/fxjs_v8.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ 7 #ifndef FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_
8 #define FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ 8 #define FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_
9 9
10 #include "../jsapi/fxjs_v8.h" 10 #include "../jsapi/fxjs_v8.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 /* ======================================== PROP CALLBACK 72 /* ======================================== PROP CALLBACK
73 * ============================================ */ 73 * ============================================ */
74 74
75 template <class C, 75 template <class C,
76 FX_BOOL (C::*M)(IFXJS_Context*, CJS_PropValue&, CFX_WideString&)> 76 FX_BOOL (C::*M)(IFXJS_Context*, CJS_PropValue&, CFX_WideString&)>
77 void JSPropGetter(const char* prop_name_string, 77 void JSPropGetter(const char* prop_name_string,
78 const char* class_name_string, 78 const char* class_name_string,
79 v8::Local<v8::String> property, 79 v8::Local<v8::String> property,
80 const v8::PropertyCallbackInfo<v8::Value>& info) { 80 const v8::PropertyCallbackInfo<v8::Value>& info) {
81 v8::Isolate* isolate = info.GetIsolate(); 81 v8::Isolate* isolate = info.GetIsolate();
82 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 82 IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate);
83 v8::Local<v8::Value> v = context->GetEmbedderData(1); 83 if (!pRuntime)
84 if (v.IsEmpty())
85 return; 84 return;
86 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v);
87 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();
88 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); 85 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
89 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); 86 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder());
90 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); 87 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
91 CFX_WideString sError; 88 CFX_WideString sError;
92 CJS_PropValue value(isolate); 89 CJS_PropValue value(isolate);
93 value.StartGetting(); 90 value.StartGetting();
94 if (!(pObj->*M)(pRuntimeContext, value, sError)) { 91 if (!(pObj->*M)(pRuntimeContext, value, sError)) {
95 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, 92 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string,
96 sError)); 93 sError));
97 return; 94 return;
98 } 95 }
99 info.GetReturnValue().Set((v8::Local<v8::Value>)value); 96 info.GetReturnValue().Set((v8::Local<v8::Value>)value);
100 } 97 }
101 98
102 template <class C, 99 template <class C,
103 FX_BOOL (C::*M)(IFXJS_Context*, CJS_PropValue&, CFX_WideString&)> 100 FX_BOOL (C::*M)(IFXJS_Context*, CJS_PropValue&, CFX_WideString&)>
104 void JSPropSetter(const char* prop_name_string, 101 void JSPropSetter(const char* prop_name_string,
105 const char* class_name_string, 102 const char* class_name_string,
106 v8::Local<v8::String> property, 103 v8::Local<v8::String> property,
107 v8::Local<v8::Value> value, 104 v8::Local<v8::Value> value,
108 const v8::PropertyCallbackInfo<void>& info) { 105 const v8::PropertyCallbackInfo<void>& info) {
109 v8::Isolate* isolate = info.GetIsolate(); 106 v8::Isolate* isolate = info.GetIsolate();
110 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 107 IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate);
111 v8::Local<v8::Value> v = context->GetEmbedderData(1); 108 if (!pRuntime)
112 if (v.IsEmpty())
113 return; 109 return;
114 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v);
115 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();
116 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); 110 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
117 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); 111 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder());
118 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); 112 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
119 CFX_WideString sError; 113 CFX_WideString sError;
120 CJS_PropValue propValue(CJS_Value(isolate, value, CJS_Value::VT_unknown)); 114 CJS_PropValue propValue(CJS_Value(isolate, value, CJS_Value::VT_unknown));
121 propValue.StartSetting(); 115 propValue.StartSetting();
122 if (!(pObj->*M)(pRuntimeContext, propValue, sError)) { 116 if (!(pObj->*M)(pRuntimeContext, propValue, sError)) {
123 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, 117 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string,
124 sError)); 118 sError));
125 } 119 }
(...skipping 18 matching lines...) Expand all
144 138
145 template <class C, 139 template <class C,
146 FX_BOOL (C::*M)(IFXJS_Context*, 140 FX_BOOL (C::*M)(IFXJS_Context*,
147 const CJS_Parameters&, 141 const CJS_Parameters&,
148 CJS_Value&, 142 CJS_Value&,
149 CFX_WideString&)> 143 CFX_WideString&)>
150 void JSMethod(const char* method_name_string, 144 void JSMethod(const char* method_name_string,
151 const char* class_name_string, 145 const char* class_name_string,
152 const v8::FunctionCallbackInfo<v8::Value>& info) { 146 const v8::FunctionCallbackInfo<v8::Value>& info) {
153 v8::Isolate* isolate = info.GetIsolate(); 147 v8::Isolate* isolate = info.GetIsolate();
154 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 148 IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate);
155 v8::Local<v8::Value> v = context->GetEmbedderData(1); 149 if (!pRuntime)
156 if (v.IsEmpty())
157 return; 150 return;
158 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v);
159 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();
160 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); 151 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
161 CJS_Parameters parameters; 152 CJS_Parameters parameters;
162 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { 153 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) {
163 parameters.push_back(CJS_Value(isolate, info[i], CJS_Value::VT_unknown)); 154 parameters.push_back(CJS_Value(isolate, info[i], CJS_Value::VT_unknown));
164 } 155 }
165 CJS_Value valueRes(isolate); 156 CJS_Value valueRes(isolate);
166 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); 157 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder());
167 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); 158 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
168 CFX_WideString sError; 159 CFX_WideString sError;
169 if (!(pObj->*M)(pRuntimeContext, parameters, valueRes, sError)) { 160 if (!(pObj->*M)(pRuntimeContext, parameters, valueRes, sError)) {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); 266 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
276 FX_BOOL bRet = pObj->QueryProperty(propname.c_str()); 267 FX_BOOL bRet = pObj->QueryProperty(propname.c_str());
277 info.GetReturnValue().Set(bRet ? 4 : 0); 268 info.GetReturnValue().Set(bRet ? 4 : 0);
278 } 269 }
279 270
280 template <class Alt> 271 template <class Alt>
281 void JSSpecialPropGet(const char* class_name, 272 void JSSpecialPropGet(const char* class_name,
282 v8::Local<v8::String> property, 273 v8::Local<v8::String> property,
283 const v8::PropertyCallbackInfo<v8::Value>& info) { 274 const v8::PropertyCallbackInfo<v8::Value>& info) {
284 v8::Isolate* isolate = info.GetIsolate(); 275 v8::Isolate* isolate = info.GetIsolate();
285 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 276 IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate);
286 v8::Local<v8::Value> v = context->GetEmbedderData(1); 277 if (!pRuntime)
287 if (v.IsEmpty())
288 return; 278 return;
289 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v);
290 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();
291 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); 279 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
292 CJS_Object* pJSObj = 280 CJS_Object* pJSObj =
293 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); 281 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder()));
294 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); 282 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
295 v8::String::Utf8Value utf8_value(property); 283 v8::String::Utf8Value utf8_value(property);
296 CFX_WideString propname = 284 CFX_WideString propname =
297 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); 285 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length());
298 CFX_WideString sError; 286 CFX_WideString sError;
299 CJS_PropValue value(isolate); 287 CJS_PropValue value(isolate);
300 value.StartGetting(); 288 value.StartGetting();
301 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), value, sError)) { 289 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), value, sError)) {
302 FXJS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError)); 290 FXJS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError));
303 return; 291 return;
304 } 292 }
305 info.GetReturnValue().Set((v8::Local<v8::Value>)value); 293 info.GetReturnValue().Set((v8::Local<v8::Value>)value);
306 } 294 }
307 295
308 template <class Alt> 296 template <class Alt>
309 void JSSpecialPropPut(const char* class_name, 297 void JSSpecialPropPut(const char* class_name,
310 v8::Local<v8::String> property, 298 v8::Local<v8::String> property,
311 v8::Local<v8::Value> value, 299 v8::Local<v8::Value> value,
312 const v8::PropertyCallbackInfo<v8::Value>& info) { 300 const v8::PropertyCallbackInfo<v8::Value>& info) {
313 v8::Isolate* isolate = info.GetIsolate(); 301 v8::Isolate* isolate = info.GetIsolate();
314 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 302 IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate);
315 v8::Local<v8::Value> v = context->GetEmbedderData(1); 303 if (!pRuntime)
316 if (v.IsEmpty())
317 return; 304 return;
318 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v);
319 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();
320 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); 305 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
321 CJS_Object* pJSObj = 306 CJS_Object* pJSObj =
322 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); 307 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder()));
323 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); 308 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
324 v8::String::Utf8Value utf8_value(property); 309 v8::String::Utf8Value utf8_value(property);
325 CFX_WideString propname = 310 CFX_WideString propname =
326 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); 311 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length());
327 CFX_WideString sError; 312 CFX_WideString sError;
328 CJS_PropValue PropValue(CJS_Value(isolate, value, CJS_Value::VT_unknown)); 313 CJS_PropValue PropValue(CJS_Value(isolate, value, CJS_Value::VT_unknown));
329 PropValue.StartSetting(); 314 PropValue.StartSetting();
330 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), PropValue, sError)) { 315 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), PropValue, sError)) {
331 FXJS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError)); 316 FXJS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError));
332 } 317 }
333 } 318 }
334 319
335 template <class Alt> 320 template <class Alt>
336 void JSSpecialPropDel(const char* class_name, 321 void JSSpecialPropDel(const char* class_name,
337 v8::Local<v8::String> property, 322 v8::Local<v8::String> property,
338 const v8::PropertyCallbackInfo<v8::Boolean>& info) { 323 const v8::PropertyCallbackInfo<v8::Boolean>& info) {
339 v8::Isolate* isolate = info.GetIsolate(); 324 v8::Isolate* isolate = info.GetIsolate();
340 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 325 IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate);
341 v8::Local<v8::Value> v = context->GetEmbedderData(1); 326 if (!pRuntime)
342 if (v.IsEmpty())
343 return; 327 return;
344 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v);
345 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();
346 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); 328 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
347 CJS_Object* pJSObj = 329 CJS_Object* pJSObj =
348 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); 330 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder()));
349 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); 331 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
350 v8::String::Utf8Value utf8_value(property); 332 v8::String::Utf8Value utf8_value(property);
351 CFX_WideString propname = 333 CFX_WideString propname =
352 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); 334 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length());
353 CFX_WideString sError; 335 CFX_WideString sError;
354 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) { 336 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) {
355 CFX_ByteString cbName; 337 CFX_ByteString cbName;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 } 423 }
442 424
443 /* ======================================== GLOBAL METHODS 425 /* ======================================== GLOBAL METHODS
444 * ============================================ */ 426 * ============================================ */
445 427
446 template <FX_BOOL ( 428 template <FX_BOOL (
447 *F)(IFXJS_Context*, const CJS_Parameters&, CJS_Value&, CFX_WideString&)> 429 *F)(IFXJS_Context*, const CJS_Parameters&, CJS_Value&, CFX_WideString&)>
448 void JSGlobalFunc(const char* func_name_string, 430 void JSGlobalFunc(const char* func_name_string,
449 const v8::FunctionCallbackInfo<v8::Value>& info) { 431 const v8::FunctionCallbackInfo<v8::Value>& info) {
450 v8::Isolate* isolate = info.GetIsolate(); 432 v8::Isolate* isolate = info.GetIsolate();
451 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 433 IFXJS_Runtime* pRuntime = FXJS_GetRuntimeFromIsolate(isolate);
452 v8::Local<v8::Value> v = context->GetEmbedderData(1); 434 if (!pRuntime)
453 if (v.IsEmpty())
454 return; 435 return;
455 v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v);
456 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value();
457 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); 436 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
458 CJS_Parameters parameters; 437 CJS_Parameters parameters;
459 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { 438 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) {
460 parameters.push_back(CJS_Value(isolate, info[i], CJS_Value::VT_unknown)); 439 parameters.push_back(CJS_Value(isolate, info[i], CJS_Value::VT_unknown));
461 } 440 }
462 CJS_Value valueRes(isolate); 441 CJS_Value valueRes(isolate);
463 CFX_WideString sError; 442 CFX_WideString sError;
464 if (!(*F)(pRuntimeContext, parameters, valueRes, sError)) { 443 if (!(*F)(pRuntimeContext, parameters, valueRes, sError)) {
465 FXJS_Error(isolate, JSFormatErrorString(func_name_string, nullptr, sError)); 444 FXJS_Error(isolate, JSFormatErrorString(func_name_string, nullptr, sError));
466 return; 445 return;
(...skipping 23 matching lines...) Expand all
490 for (int i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \ 469 for (int i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \
491 FXJS_DefineGlobalMethod(pIsolate, \ 470 FXJS_DefineGlobalMethod(pIsolate, \
492 js_class_name::global_methods[i].pName, \ 471 js_class_name::global_methods[i].pName, \
493 js_class_name::global_methods[i].pMethodCall); \ 472 js_class_name::global_methods[i].pMethodCall); \
494 } \ 473 } \
495 } 474 }
496 475
497 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p); 476 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p);
498 477
499 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ 478 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_
OLDNEW
« no previous file with comments | « DEPS ('k') | fpdfsdk/include/jsapi/fxjs_v8.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698