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

Side by Side Diff: fpdfsdk/src/javascript/global.cpp

Issue 1334833003: Merge to XFA: Remove some abstractions in fxjs_v8.h. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 3 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 | « fpdfsdk/src/javascript/app.cpp ('k') | fpdfsdk/src/jsapi/fxjs_v8.cpp » ('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 #include "../../include/javascript/IJavaScript.h" 7 #include "../../include/javascript/IJavaScript.h"
8 #include "../../include/javascript/JS_Context.h" 8 #include "../../include/javascript/JS_Context.h"
9 #include "../../include/javascript/JS_Define.h" 9 #include "../../include/javascript/JS_Define.h"
10 #include "../../include/javascript/JS_EventHandler.h" 10 #include "../../include/javascript/JS_EventHandler.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_BOOLEAN, 0, 153 return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_BOOLEAN, 0,
154 bData, "", v8::Local<v8::Object>(), FALSE); 154 bData, "", v8::Local<v8::Object>(), FALSE);
155 } 155 }
156 case VT_string: { 156 case VT_string: {
157 CFX_ByteString sData; 157 CFX_ByteString sData;
158 vp >> sData; 158 vp >> sData;
159 return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_STRING, 0, 159 return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_STRING, 0,
160 false, sData, v8::Local<v8::Object>(), FALSE); 160 false, sData, v8::Local<v8::Object>(), FALSE);
161 } 161 }
162 case VT_object: { 162 case VT_object: {
163 JSObject pData; 163 v8::Local<v8::Object> pData;
164 vp >> pData; 164 vp >> pData;
165 return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_OBJECT, 0, 165 return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_OBJECT, 0,
166 false, "", pData, FALSE); 166 false, "", pData, FALSE);
167 } 167 }
168 case VT_null: { 168 case VT_null: {
169 return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_NULL, 0, false, 169 return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_NULL, 0, false,
170 "", v8::Local<v8::Object>(), FALSE); 170 "", v8::Local<v8::Object>(), FALSE);
171 } 171 }
172 case VT_undefined: { 172 case VT_undefined: {
173 DelProperty(cc, propname, sError); 173 DelProperty(cc, propname, sError);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 241
242 for (int i = 0, sz = m_pGlobalData->GetSize(); i < sz; i++) { 242 for (int i = 0, sz = m_pGlobalData->GetSize(); i < sz; i++) {
243 CJS_GlobalData_Element* pData = m_pGlobalData->GetAt(i); 243 CJS_GlobalData_Element* pData = m_pGlobalData->GetAt(i);
244 ASSERT(pData != NULL); 244 ASSERT(pData != NULL);
245 245
246 switch (pData->data.nType) { 246 switch (pData->data.nType) {
247 case JS_GLOBALDATA_TYPE_NUMBER: 247 case JS_GLOBALDATA_TYPE_NUMBER:
248 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NUMBER, 248 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NUMBER,
249 pData->data.dData, false, "", 249 pData->data.dData, false, "",
250 v8::Local<v8::Object>(), pData->bPersistent == 1); 250 v8::Local<v8::Object>(), pData->bPersistent == 1);
251 JS_PutObjectNumber(NULL, (JSFXObject)(*m_pJSObject), 251 JS_PutObjectNumber(NULL, (v8::Local<v8::Object>)(*m_pJSObject),
252 pData->data.sKey.UTF8Decode().c_str(), 252 pData->data.sKey.UTF8Decode().c_str(),
253 pData->data.dData); 253 pData->data.dData);
254 break; 254 break;
255 case JS_GLOBALDATA_TYPE_BOOLEAN: 255 case JS_GLOBALDATA_TYPE_BOOLEAN:
256 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_BOOLEAN, 0, 256 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_BOOLEAN, 0,
257 (bool)(pData->data.bData == 1), "", 257 (bool)(pData->data.bData == 1), "",
258 v8::Local<v8::Object>(), pData->bPersistent == 1); 258 v8::Local<v8::Object>(), pData->bPersistent == 1);
259 JS_PutObjectBoolean(NULL, (JSFXObject)(*m_pJSObject), 259 JS_PutObjectBoolean(NULL, (v8::Local<v8::Object>)(*m_pJSObject),
260 pData->data.sKey.UTF8Decode().c_str(), 260 pData->data.sKey.UTF8Decode().c_str(),
261 (bool)(pData->data.bData == 1)); 261 (bool)(pData->data.bData == 1));
262 break; 262 break;
263 case JS_GLOBALDATA_TYPE_STRING: 263 case JS_GLOBALDATA_TYPE_STRING:
264 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_STRING, 0, 264 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_STRING, 0,
265 false, pData->data.sData, v8::Local<v8::Object>(), 265 false, pData->data.sData, v8::Local<v8::Object>(),
266 pData->bPersistent == 1); 266 pData->bPersistent == 1);
267 JS_PutObjectString(NULL, (JSFXObject)(*m_pJSObject), 267 JS_PutObjectString(NULL, (v8::Local<v8::Object>)(*m_pJSObject),
268 pData->data.sKey.UTF8Decode().c_str(), 268 pData->data.sKey.UTF8Decode().c_str(),
269 pData->data.sData.UTF8Decode().c_str()); 269 pData->data.sData.UTF8Decode().c_str());
270 break; 270 break;
271 case JS_GLOBALDATA_TYPE_OBJECT: { 271 case JS_GLOBALDATA_TYPE_OBJECT: {
272 IJS_Runtime* pRuntime = JS_GetRuntime((JSFXObject)(*m_pJSObject)); 272 v8::Isolate* pRuntime =
273 JS_GetRuntime((v8::Local<v8::Object>)(*m_pJSObject));
273 v8::Local<v8::Object> pObj = JS_NewFxDynamicObj(pRuntime, NULL, -1); 274 v8::Local<v8::Object> pObj = JS_NewFxDynamicObj(pRuntime, NULL, -1);
274 275
275 PutObjectProperty(pObj, &pData->data); 276 PutObjectProperty(pObj, &pData->data);
276 277
277 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_OBJECT, 0, 278 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_OBJECT, 0,
278 false, "", (JSObject)pObj, pData->bPersistent == 1); 279 false, "", (v8::Local<v8::Object>)pObj,
279 JS_PutObjectObject(NULL, (JSFXObject)(*m_pJSObject), 280 pData->bPersistent == 1);
281 JS_PutObjectObject(NULL, (v8::Local<v8::Object>)(*m_pJSObject),
280 pData->data.sKey.UTF8Decode().c_str(), 282 pData->data.sKey.UTF8Decode().c_str(),
281 (JSObject)pObj); 283 (v8::Local<v8::Object>)pObj);
282 } break; 284 } break;
283 case JS_GLOBALDATA_TYPE_NULL: 285 case JS_GLOBALDATA_TYPE_NULL:
284 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NULL, 0, false, 286 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NULL, 0, false,
285 "", v8::Local<v8::Object>(), 287 "", v8::Local<v8::Object>(),
286 pData->bPersistent == 1); 288 pData->bPersistent == 1);
287 JS_PutObjectNull(NULL, (JSFXObject)(*m_pJSObject), 289 JS_PutObjectNull(NULL, (v8::Local<v8::Object>)(*m_pJSObject),
288 pData->data.sKey.UTF8Decode().c_str()); 290 pData->data.sKey.UTF8Decode().c_str());
289 break; 291 break;
290 } 292 }
291 } 293 }
292 } 294 }
293 295
294 void JSGlobalAlternate::CommitGlobalPersisitentVariables() { 296 void JSGlobalAlternate::CommitGlobalPersisitentVariables() {
295 ASSERT(m_pGlobalData); 297 ASSERT(m_pGlobalData);
296 for (auto it = m_mapGlobal.begin(); it != m_mapGlobal.end(); ++it) { 298 for (auto it = m_mapGlobal.begin(); it != m_mapGlobal.end(); ++it) {
297 CFX_ByteString name = it->first; 299 CFX_ByteString name = it->first;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 void JSGlobalAlternate::PutObjectProperty(v8::Local<v8::Object> pObj, 395 void JSGlobalAlternate::PutObjectProperty(v8::Local<v8::Object> pObj,
394 CJS_KeyValue* pData) { 396 CJS_KeyValue* pData) {
395 ASSERT(pData != NULL); 397 ASSERT(pData != NULL);
396 398
397 for (int i = 0, sz = pData->objData.Count(); i < sz; i++) { 399 for (int i = 0, sz = pData->objData.Count(); i < sz; i++) {
398 CJS_KeyValue* pObjData = pData->objData.GetAt(i); 400 CJS_KeyValue* pObjData = pData->objData.GetAt(i);
399 ASSERT(pObjData != NULL); 401 ASSERT(pObjData != NULL);
400 402
401 switch (pObjData->nType) { 403 switch (pObjData->nType) {
402 case JS_GLOBALDATA_TYPE_NUMBER: 404 case JS_GLOBALDATA_TYPE_NUMBER:
403 JS_PutObjectNumber(NULL, (JSObject)pObj, 405 JS_PutObjectNumber(NULL, (v8::Local<v8::Object>)pObj,
404 pObjData->sKey.UTF8Decode().c_str(), 406 pObjData->sKey.UTF8Decode().c_str(),
405 pObjData->dData); 407 pObjData->dData);
406 break; 408 break;
407 case JS_GLOBALDATA_TYPE_BOOLEAN: 409 case JS_GLOBALDATA_TYPE_BOOLEAN:
408 JS_PutObjectBoolean(NULL, (JSObject)pObj, 410 JS_PutObjectBoolean(NULL, (v8::Local<v8::Object>)pObj,
409 pObjData->sKey.UTF8Decode().c_str(), 411 pObjData->sKey.UTF8Decode().c_str(),
410 (bool)(pObjData->bData == 1)); 412 (bool)(pObjData->bData == 1));
411 break; 413 break;
412 case JS_GLOBALDATA_TYPE_STRING: 414 case JS_GLOBALDATA_TYPE_STRING:
413 JS_PutObjectString(NULL, (JSObject)pObj, 415 JS_PutObjectString(NULL, (v8::Local<v8::Object>)pObj,
414 pObjData->sKey.UTF8Decode().c_str(), 416 pObjData->sKey.UTF8Decode().c_str(),
415 pObjData->sData.UTF8Decode().c_str()); 417 pObjData->sData.UTF8Decode().c_str());
416 break; 418 break;
417 case JS_GLOBALDATA_TYPE_OBJECT: { 419 case JS_GLOBALDATA_TYPE_OBJECT: {
418 IJS_Runtime* pRuntime = JS_GetRuntime((JSFXObject)(*m_pJSObject)); 420 v8::Isolate* pRuntime =
421 JS_GetRuntime((v8::Local<v8::Object>)(*m_pJSObject));
419 v8::Local<v8::Object> pNewObj = JS_NewFxDynamicObj(pRuntime, NULL, -1); 422 v8::Local<v8::Object> pNewObj = JS_NewFxDynamicObj(pRuntime, NULL, -1);
420 PutObjectProperty(pNewObj, pObjData); 423 PutObjectProperty(pNewObj, pObjData);
421 JS_PutObjectObject(NULL, (JSObject)pObj, 424 JS_PutObjectObject(NULL, (v8::Local<v8::Object>)pObj,
422 pObjData->sKey.UTF8Decode().c_str(), 425 pObjData->sKey.UTF8Decode().c_str(),
423 (JSObject)pNewObj); 426 (v8::Local<v8::Object>)pNewObj);
424 } break; 427 } break;
425 case JS_GLOBALDATA_TYPE_NULL: 428 case JS_GLOBALDATA_TYPE_NULL:
426 JS_PutObjectNull(NULL, (JSObject)pObj, 429 JS_PutObjectNull(NULL, (v8::Local<v8::Object>)pObj,
427 pObjData->sKey.UTF8Decode().c_str()); 430 pObjData->sKey.UTF8Decode().c_str());
428 break; 431 break;
429 } 432 }
430 } 433 }
431 } 434 }
432 435
433 void JSGlobalAlternate::DestroyGlobalPersisitentVariables() { 436 void JSGlobalAlternate::DestroyGlobalPersisitentVariables() {
434 for (const auto& pair : m_mapGlobal) { 437 for (const auto& pair : m_mapGlobal) {
435 delete pair.second; 438 delete pair.second;
436 } 439 }
437 m_mapGlobal.clear(); 440 m_mapGlobal.clear();
438 } 441 }
439 442
440 FX_BOOL JSGlobalAlternate::SetGlobalVariables(const FX_CHAR* propname, 443 FX_BOOL JSGlobalAlternate::SetGlobalVariables(const FX_CHAR* propname,
441 int nType, 444 int nType,
442 double dData, 445 double dData,
443 bool bData, 446 bool bData,
444 const CFX_ByteString& sData, 447 const CFX_ByteString& sData,
445 JSObject pData, 448 v8::Local<v8::Object> pData,
446 bool bDefaultPersistent) { 449 bool bDefaultPersistent) {
447 if (!propname) 450 if (!propname)
448 return FALSE; 451 return FALSE;
449 452
450 auto it = m_mapGlobal.find(propname); 453 auto it = m_mapGlobal.find(propname);
451 if (it != m_mapGlobal.end()) { 454 if (it != m_mapGlobal.end()) {
452 JSGlobalData* pTemp = it->second; 455 JSGlobalData* pTemp = it->second;
453 if (pTemp->bDeleted || pTemp->nType != nType) { 456 if (pTemp->bDeleted || pTemp->nType != nType) {
454 pTemp->dData = 0; 457 pTemp->dData = 0;
455 pTemp->bData = 0; 458 pTemp->bData = 0;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 return VT_boolean; 537 return VT_boolean;
535 if (nHash == JSCONST_nDateHash) 538 if (nHash == JSCONST_nDateHash)
536 return VT_date; 539 return VT_date;
537 if (nHash == JSCONST_nObjectHash) 540 if (nHash == JSCONST_nObjectHash)
538 return VT_object; 541 return VT_object;
539 if (nHash == JSCONST_nFXobjHash) 542 if (nHash == JSCONST_nFXobjHash)
540 return VT_fxobject; 543 return VT_fxobject;
541 544
542 return VT_unknown; 545 return VT_unknown;
543 } 546 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/app.cpp ('k') | fpdfsdk/src/jsapi/fxjs_v8.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698