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

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

Issue 1351173002: XFA: contention between FXJSE and FXJS over isolate data slots (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: rebase 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_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 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); 82 FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(isolate);
83 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); 83 IFXJS_Context* pRuntimeContext = pData->m_pFXJSRuntime->GetCurrentContext();
84 CJS_PropValue value(isolate); 84 CJS_PropValue value(isolate);
85 value.StartGetting(); 85 value.StartGetting();
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 if (!(pObj->*M)(pRuntimeContext, value, sError)) { 89 if (!(pObj->*M)(pRuntimeContext, value, sError)) {
90 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, 90 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string,
91 sError)); 91 sError));
92 return; 92 return;
93 } 93 }
94 info.GetReturnValue().Set((v8::Local<v8::Value>)value); 94 info.GetReturnValue().Set((v8::Local<v8::Value>)value);
95 } 95 }
96 96
97 template <class C, 97 template <class C,
98 FX_BOOL (C::*M)(IFXJS_Context*, CJS_PropValue&, CFX_WideString&)> 98 FX_BOOL (C::*M)(IFXJS_Context*, CJS_PropValue&, CFX_WideString&)>
99 void JSPropSetter(const char* prop_name_string, 99 void JSPropSetter(const char* prop_name_string,
100 const char* class_name_string, 100 const char* class_name_string,
101 v8::Local<v8::String> property, 101 v8::Local<v8::String> property,
102 v8::Local<v8::Value> value, 102 v8::Local<v8::Value> value,
103 const v8::PropertyCallbackInfo<void>& info) { 103 const v8::PropertyCallbackInfo<void>& info) {
104 v8::Isolate* isolate = info.GetIsolate(); 104 v8::Isolate* isolate = info.GetIsolate();
105 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); 105 FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(isolate);
106 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); 106 IFXJS_Context* pRuntimeContext = pData->m_pFXJSRuntime->GetCurrentContext();
107 CJS_PropValue propValue(CJS_Value(isolate, value, CJS_Value::VT_unknown)); 107 CJS_PropValue propValue(CJS_Value(isolate, value, CJS_Value::VT_unknown));
108 propValue.StartSetting(); 108 propValue.StartSetting();
109 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); 109 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder());
110 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); 110 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
111 CFX_WideString sError; 111 CFX_WideString sError;
112 if (!(pObj->*M)(pRuntimeContext, propValue, sError)) { 112 if (!(pObj->*M)(pRuntimeContext, propValue, sError)) {
113 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, 113 FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string,
114 sError)); 114 sError));
115 } 115 }
116 } 116 }
(...skipping 17 matching lines...) Expand all
134 134
135 template <class C, 135 template <class C,
136 FX_BOOL (C::*M)(IFXJS_Context*, 136 FX_BOOL (C::*M)(IFXJS_Context*,
137 const CJS_Parameters&, 137 const CJS_Parameters&,
138 CJS_Value&, 138 CJS_Value&,
139 CFX_WideString&)> 139 CFX_WideString&)>
140 void JSMethod(const char* method_name_string, 140 void JSMethod(const char* method_name_string,
141 const char* class_name_string, 141 const char* class_name_string,
142 const v8::FunctionCallbackInfo<v8::Value>& info) { 142 const v8::FunctionCallbackInfo<v8::Value>& info) {
143 v8::Isolate* isolate = info.GetIsolate(); 143 v8::Isolate* isolate = info.GetIsolate();
144 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); 144 FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(isolate);
145 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); 145 IFXJS_Context* pRuntimeContext = pData->m_pFXJSRuntime->GetCurrentContext();
146 CJS_Parameters parameters; 146 CJS_Parameters parameters;
147 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { 147 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) {
148 parameters.push_back(CJS_Value(isolate, info[i], CJS_Value::VT_unknown)); 148 parameters.push_back(CJS_Value(isolate, info[i], CJS_Value::VT_unknown));
149 } 149 }
150 CJS_Value valueRes(isolate); 150 CJS_Value valueRes(isolate);
151 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder()); 151 CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder());
152 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject()); 152 C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
153 CFX_WideString sError; 153 CFX_WideString sError;
154 if (!(pObj->*M)(pRuntimeContext, parameters, valueRes, sError)) { 154 if (!(pObj->*M)(pRuntimeContext, parameters, valueRes, sError)) {
155 FXJS_Error(isolate, JSFormatErrorString(class_name_string, 155 FXJS_Error(isolate, JSFormatErrorString(class_name_string,
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 FX_BOOL bRet = pObj->QueryProperty(propname.c_str()); 261 FX_BOOL bRet = pObj->QueryProperty(propname.c_str());
262 info.GetReturnValue().Set(bRet ? 4 : 0); 262 info.GetReturnValue().Set(bRet ? 4 : 0);
263 } 263 }
264 264
265 template <class Alt> 265 template <class Alt>
266 void JSSpecialPropGet(const char* class_name, 266 void JSSpecialPropGet(const char* class_name,
267 v8::Local<v8::String> property, 267 v8::Local<v8::String> property,
268 const v8::PropertyCallbackInfo<v8::Value>& info) { 268 const v8::PropertyCallbackInfo<v8::Value>& info) {
269 v8::Isolate* isolate = info.GetIsolate(); 269 v8::Isolate* isolate = info.GetIsolate();
270 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 270 v8::Local<v8::Context> context = isolate->GetCurrentContext();
271 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); 271 FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(isolate);
272 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); 272 IFXJS_Context* pRuntimeContext = pData->m_pFXJSRuntime->GetCurrentContext();
273 CJS_Object* pJSObj = 273 CJS_Object* pJSObj =
274 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); 274 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder()));
275 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); 275 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
276 v8::String::Utf8Value utf8_value(property); 276 v8::String::Utf8Value utf8_value(property);
277 CFX_WideString propname = 277 CFX_WideString propname =
278 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); 278 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length());
279 CFX_WideString sError; 279 CFX_WideString sError;
280 CJS_PropValue value(isolate); 280 CJS_PropValue value(isolate);
281 value.StartGetting(); 281 value.StartGetting();
282 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), value, sError)) { 282 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), value, sError)) {
283 FXJS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError)); 283 FXJS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError));
284 return; 284 return;
285 } 285 }
286 info.GetReturnValue().Set((v8::Local<v8::Value>)value); 286 info.GetReturnValue().Set((v8::Local<v8::Value>)value);
287 } 287 }
288 288
289 template <class Alt> 289 template <class Alt>
290 void JSSpecialPropPut(const char* class_name, 290 void JSSpecialPropPut(const char* class_name,
291 v8::Local<v8::String> property, 291 v8::Local<v8::String> property,
292 v8::Local<v8::Value> value, 292 v8::Local<v8::Value> value,
293 const v8::PropertyCallbackInfo<v8::Value>& info) { 293 const v8::PropertyCallbackInfo<v8::Value>& info) {
294 v8::Isolate* isolate = info.GetIsolate(); 294 v8::Isolate* isolate = info.GetIsolate();
295 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 295 v8::Local<v8::Context> context = isolate->GetCurrentContext();
296 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); 296 FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(isolate);
297 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); 297 IFXJS_Context* pRuntimeContext = pData->m_pFXJSRuntime->GetCurrentContext();
298 CJS_Object* pJSObj = 298 CJS_Object* pJSObj =
299 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); 299 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder()));
300 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); 300 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
301 v8::String::Utf8Value utf8_value(property); 301 v8::String::Utf8Value utf8_value(property);
302 CFX_WideString propname = 302 CFX_WideString propname =
303 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); 303 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length());
304 CFX_WideString sError; 304 CFX_WideString sError;
305 CJS_PropValue PropValue(CJS_Value(isolate, value, CJS_Value::VT_unknown)); 305 CJS_PropValue PropValue(CJS_Value(isolate, value, CJS_Value::VT_unknown));
306 PropValue.StartSetting(); 306 PropValue.StartSetting();
307 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), PropValue, sError)) { 307 if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), PropValue, sError)) {
308 FXJS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError)); 308 FXJS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError));
309 } 309 }
310 } 310 }
311 311
312 template <class Alt> 312 template <class Alt>
313 void JSSpecialPropDel(const char* class_name, 313 void JSSpecialPropDel(const char* class_name,
314 v8::Local<v8::String> property, 314 v8::Local<v8::String> property,
315 const v8::PropertyCallbackInfo<v8::Boolean>& info) { 315 const v8::PropertyCallbackInfo<v8::Boolean>& info) {
316 v8::Isolate* isolate = info.GetIsolate(); 316 v8::Isolate* isolate = info.GetIsolate();
317 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 317 v8::Local<v8::Context> context = isolate->GetCurrentContext();
318 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); 318 FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(isolate);
319 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); 319 IFXJS_Context* pRuntimeContext = pData->m_pFXJSRuntime->GetCurrentContext();
320 CJS_Object* pJSObj = 320 CJS_Object* pJSObj =
321 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder())); 321 reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder()));
322 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject()); 322 Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
323 v8::String::Utf8Value utf8_value(property); 323 v8::String::Utf8Value utf8_value(property);
324 CFX_WideString propname = 324 CFX_WideString propname =
325 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length()); 325 CFX_WideString::FromUTF8(*utf8_value, utf8_value.length());
326 CFX_WideString sError; 326 CFX_WideString sError;
327 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) { 327 if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) {
328 CFX_ByteString cbName; 328 CFX_ByteString cbName;
329 cbName.Format("%s.%s", class_name, "DelProperty"); 329 cbName.Format("%s.%s", class_name, "DelProperty");
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 } 414 }
415 415
416 /* ======================================== GLOBAL METHODS 416 /* ======================================== GLOBAL METHODS
417 * ============================================ */ 417 * ============================================ */
418 418
419 template <FX_BOOL ( 419 template <FX_BOOL (
420 *F)(IFXJS_Context*, const CJS_Parameters&, CJS_Value&, CFX_WideString&)> 420 *F)(IFXJS_Context*, const CJS_Parameters&, CJS_Value&, CFX_WideString&)>
421 void JSGlobalFunc(const char* func_name_string, 421 void JSGlobalFunc(const char* func_name_string,
422 const v8::FunctionCallbackInfo<v8::Value>& info) { 422 const v8::FunctionCallbackInfo<v8::Value>& info) {
423 v8::Isolate* isolate = info.GetIsolate(); 423 v8::Isolate* isolate = info.GetIsolate();
424 IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2); 424 FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(isolate);
425 IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext(); 425 IFXJS_Context* pRuntimeContext = pData->m_pFXJSRuntime->GetCurrentContext();
426 CJS_Parameters parameters; 426 CJS_Parameters parameters;
427 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { 427 for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) {
428 parameters.push_back(CJS_Value(isolate, info[i], CJS_Value::VT_unknown)); 428 parameters.push_back(CJS_Value(isolate, info[i], CJS_Value::VT_unknown));
429 } 429 }
430 CJS_Value valueRes(isolate); 430 CJS_Value valueRes(isolate);
431 CFX_WideString sError; 431 CFX_WideString sError;
432 if (!(*F)(pRuntimeContext, parameters, valueRes, sError)) { 432 if (!(*F)(pRuntimeContext, parameters, valueRes, sError)) {
433 FXJS_Error(isolate, JSFormatErrorString(func_name_string, nullptr, sError)); 433 FXJS_Error(isolate, JSFormatErrorString(func_name_string, nullptr, sError));
434 return; 434 return;
435 } 435 }
(...skipping 22 matching lines...) Expand all
458 for (int i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \ 458 for (int i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \
459 FXJS_DefineGlobalMethod(pIsolate, \ 459 FXJS_DefineGlobalMethod(pIsolate, \
460 js_class_name::global_methods[i].pName, \ 460 js_class_name::global_methods[i].pName, \
461 js_class_name::global_methods[i].pMethodCall); \ 461 js_class_name::global_methods[i].pMethodCall); \
462 } \ 462 } \
463 } 463 }
464 464
465 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p); 465 CJS_Value::Type GET_VALUE_TYPE(v8::Local<v8::Value> p);
466 466
467 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_ 467 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698