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 #include "../../../core/include/fxcrt/fx_ext.h" | 7 #include "../../../core/include/fxcrt/fx_ext.h" |
8 #include "../../include/javascript/IJavaScript.h" | 8 #include "../../include/javascript/IJavaScript.h" |
9 #include "../../include/javascript/JS_Context.h" | 9 #include "../../include/javascript/JS_Context.h" |
10 #include "../../include/javascript/JS_Define.h" | 10 #include "../../include/javascript/JS_Define.h" |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 | 237 |
238 for (int i = 0, sz = m_pGlobalData->GetSize(); i < sz; i++) { | 238 for (int i = 0, sz = m_pGlobalData->GetSize(); i < sz; i++) { |
239 CJS_GlobalData_Element* pData = m_pGlobalData->GetAt(i); | 239 CJS_GlobalData_Element* pData = m_pGlobalData->GetAt(i); |
240 ASSERT(pData != NULL); | 240 ASSERT(pData != NULL); |
241 | 241 |
242 switch (pData->data.nType) { | 242 switch (pData->data.nType) { |
243 case JS_GLOBALDATA_TYPE_NUMBER: | 243 case JS_GLOBALDATA_TYPE_NUMBER: |
244 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NUMBER, | 244 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NUMBER, |
245 pData->data.dData, false, "", | 245 pData->data.dData, false, "", |
246 v8::Local<v8::Object>(), pData->bPersistent == 1); | 246 v8::Local<v8::Object>(), pData->bPersistent == 1); |
247 FXJS_PutObjectNumber(NULL, (v8::Local<v8::Object>)(*m_pJSObject), | 247 FXJS_PutObjectNumber(NULL, m_pJSObject->ToV8Object(), |
248 pData->data.sKey.UTF8Decode().c_str(), | 248 pData->data.sKey.UTF8Decode().c_str(), |
249 pData->data.dData); | 249 pData->data.dData); |
250 break; | 250 break; |
251 case JS_GLOBALDATA_TYPE_BOOLEAN: | 251 case JS_GLOBALDATA_TYPE_BOOLEAN: |
252 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_BOOLEAN, 0, | 252 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_BOOLEAN, 0, |
253 (bool)(pData->data.bData == 1), "", | 253 (bool)(pData->data.bData == 1), "", |
254 v8::Local<v8::Object>(), pData->bPersistent == 1); | 254 v8::Local<v8::Object>(), pData->bPersistent == 1); |
255 FXJS_PutObjectBoolean(NULL, (v8::Local<v8::Object>)(*m_pJSObject), | 255 FXJS_PutObjectBoolean(NULL, m_pJSObject->ToV8Object(), |
256 pData->data.sKey.UTF8Decode().c_str(), | 256 pData->data.sKey.UTF8Decode().c_str(), |
257 (bool)(pData->data.bData == 1)); | 257 (bool)(pData->data.bData == 1)); |
258 break; | 258 break; |
259 case JS_GLOBALDATA_TYPE_STRING: | 259 case JS_GLOBALDATA_TYPE_STRING: |
260 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_STRING, 0, | 260 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_STRING, 0, |
261 false, pData->data.sData, v8::Local<v8::Object>(), | 261 false, pData->data.sData, v8::Local<v8::Object>(), |
262 pData->bPersistent == 1); | 262 pData->bPersistent == 1); |
263 FXJS_PutObjectString(NULL, (v8::Local<v8::Object>)(*m_pJSObject), | 263 FXJS_PutObjectString(NULL, m_pJSObject->ToV8Object(), |
264 pData->data.sKey.UTF8Decode().c_str(), | 264 pData->data.sKey.UTF8Decode().c_str(), |
265 pData->data.sData.UTF8Decode().c_str()); | 265 pData->data.sData.UTF8Decode().c_str()); |
266 break; | 266 break; |
267 case JS_GLOBALDATA_TYPE_OBJECT: { | 267 case JS_GLOBALDATA_TYPE_OBJECT: { |
268 v8::Isolate* pRuntime = | 268 v8::Isolate* pRuntime = FXJS_GetRuntime(m_pJSObject->ToV8Object()); |
269 FXJS_GetRuntime((v8::Local<v8::Object>)(*m_pJSObject)); | |
270 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(pRuntime, NULL, -1); | 269 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(pRuntime, NULL, -1); |
271 | 270 |
272 PutObjectProperty(pObj, &pData->data); | 271 PutObjectProperty(pObj, &pData->data); |
273 | 272 |
274 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_OBJECT, 0, | 273 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_OBJECT, 0, |
275 false, "", (v8::Local<v8::Object>)pObj, | 274 false, "", pObj, pData->bPersistent == 1); |
276 pData->bPersistent == 1); | 275 FXJS_PutObjectObject(NULL, m_pJSObject->ToV8Object(), |
277 FXJS_PutObjectObject(NULL, (v8::Local<v8::Object>)(*m_pJSObject), | 276 pData->data.sKey.UTF8Decode().c_str(), pObj); |
278 pData->data.sKey.UTF8Decode().c_str(), | 277 |
279 (v8::Local<v8::Object>)pObj); | |
280 } break; | 278 } break; |
281 case JS_GLOBALDATA_TYPE_NULL: | 279 case JS_GLOBALDATA_TYPE_NULL: |
282 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NULL, 0, false, | 280 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NULL, 0, false, |
283 "", v8::Local<v8::Object>(), | 281 "", v8::Local<v8::Object>(), |
284 pData->bPersistent == 1); | 282 pData->bPersistent == 1); |
285 FXJS_PutObjectNull(NULL, (v8::Local<v8::Object>)(*m_pJSObject), | 283 FXJS_PutObjectNull(NULL, m_pJSObject->ToV8Object(), |
286 pData->data.sKey.UTF8Decode().c_str()); | 284 pData->data.sKey.UTF8Decode().c_str()); |
287 break; | 285 break; |
288 } | 286 } |
289 } | 287 } |
290 } | 288 } |
291 | 289 |
292 void JSGlobalAlternate::CommitGlobalPersisitentVariables() { | 290 void JSGlobalAlternate::CommitGlobalPersisitentVariables() { |
293 ASSERT(m_pGlobalData); | 291 ASSERT(m_pGlobalData); |
294 for (auto it = m_mapGlobal.begin(); it != m_mapGlobal.end(); ++it) { | 292 for (auto it = m_mapGlobal.begin(); it != m_mapGlobal.end(); ++it) { |
295 CFX_ByteString name = it->first; | 293 CFX_ByteString name = it->first; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 void JSGlobalAlternate::PutObjectProperty(v8::Local<v8::Object> pObj, | 388 void JSGlobalAlternate::PutObjectProperty(v8::Local<v8::Object> pObj, |
391 CJS_KeyValue* pData) { | 389 CJS_KeyValue* pData) { |
392 ASSERT(pData != NULL); | 390 ASSERT(pData != NULL); |
393 | 391 |
394 for (int i = 0, sz = pData->objData.Count(); i < sz; i++) { | 392 for (int i = 0, sz = pData->objData.Count(); i < sz; i++) { |
395 CJS_KeyValue* pObjData = pData->objData.GetAt(i); | 393 CJS_KeyValue* pObjData = pData->objData.GetAt(i); |
396 ASSERT(pObjData != NULL); | 394 ASSERT(pObjData != NULL); |
397 | 395 |
398 switch (pObjData->nType) { | 396 switch (pObjData->nType) { |
399 case JS_GLOBALDATA_TYPE_NUMBER: | 397 case JS_GLOBALDATA_TYPE_NUMBER: |
400 FXJS_PutObjectNumber(NULL, (v8::Local<v8::Object>)pObj, | 398 FXJS_PutObjectNumber(NULL, pObj, pObjData->sKey.UTF8Decode().c_str(), |
401 pObjData->sKey.UTF8Decode().c_str(), | |
402 pObjData->dData); | 399 pObjData->dData); |
403 break; | 400 break; |
404 case JS_GLOBALDATA_TYPE_BOOLEAN: | 401 case JS_GLOBALDATA_TYPE_BOOLEAN: |
405 FXJS_PutObjectBoolean(NULL, (v8::Local<v8::Object>)pObj, | 402 FXJS_PutObjectBoolean(NULL, pObj, pObjData->sKey.UTF8Decode().c_str(), |
406 pObjData->sKey.UTF8Decode().c_str(), | 403 pObjData->bData == 1); |
407 (bool)(pObjData->bData == 1)); | |
408 break; | 404 break; |
409 case JS_GLOBALDATA_TYPE_STRING: | 405 case JS_GLOBALDATA_TYPE_STRING: |
410 FXJS_PutObjectString(NULL, (v8::Local<v8::Object>)pObj, | 406 FXJS_PutObjectString(NULL, pObj, pObjData->sKey.UTF8Decode().c_str(), |
411 pObjData->sKey.UTF8Decode().c_str(), | |
412 pObjData->sData.UTF8Decode().c_str()); | 407 pObjData->sData.UTF8Decode().c_str()); |
413 break; | 408 break; |
414 case JS_GLOBALDATA_TYPE_OBJECT: { | 409 case JS_GLOBALDATA_TYPE_OBJECT: { |
415 v8::Isolate* pRuntime = | 410 v8::Isolate* pRuntime = FXJS_GetRuntime(m_pJSObject->ToV8Object()); |
416 FXJS_GetRuntime((v8::Local<v8::Object>)(*m_pJSObject)); | |
417 v8::Local<v8::Object> pNewObj = | 411 v8::Local<v8::Object> pNewObj = |
418 FXJS_NewFxDynamicObj(pRuntime, NULL, -1); | 412 FXJS_NewFxDynamicObj(pRuntime, NULL, -1); |
419 PutObjectProperty(pNewObj, pObjData); | 413 PutObjectProperty(pNewObj, pObjData); |
420 FXJS_PutObjectObject(NULL, (v8::Local<v8::Object>)pObj, | 414 FXJS_PutObjectObject(NULL, pObj, pObjData->sKey.UTF8Decode().c_str(), |
421 pObjData->sKey.UTF8Decode().c_str(), | 415 pNewObj); |
422 (v8::Local<v8::Object>)pNewObj); | |
423 } break; | 416 } break; |
424 case JS_GLOBALDATA_TYPE_NULL: | 417 case JS_GLOBALDATA_TYPE_NULL: |
425 FXJS_PutObjectNull(NULL, (v8::Local<v8::Object>)pObj, | 418 FXJS_PutObjectNull(NULL, pObj, pObjData->sKey.UTF8Decode().c_str()); |
426 pObjData->sKey.UTF8Decode().c_str()); | |
427 break; | 419 break; |
428 } | 420 } |
429 } | 421 } |
430 } | 422 } |
431 | 423 |
432 void JSGlobalAlternate::DestroyGlobalPersisitentVariables() { | 424 void JSGlobalAlternate::DestroyGlobalPersisitentVariables() { |
433 for (const auto& pair : m_mapGlobal) { | 425 for (const auto& pair : m_mapGlobal) { |
434 delete pair.second; | 426 delete pair.second; |
435 } | 427 } |
436 m_mapGlobal.clear(); | 428 m_mapGlobal.clear(); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 return CJS_Value::VT_boolean; | 525 return CJS_Value::VT_boolean; |
534 if (nHash == JSCONST_nDateHash) | 526 if (nHash == JSCONST_nDateHash) |
535 return CJS_Value::VT_date; | 527 return CJS_Value::VT_date; |
536 if (nHash == JSCONST_nObjectHash) | 528 if (nHash == JSCONST_nObjectHash) |
537 return CJS_Value::VT_object; | 529 return CJS_Value::VT_object; |
538 if (nHash == JSCONST_nFXobjHash) | 530 if (nHash == JSCONST_nFXobjHash) |
539 return CJS_Value::VT_fxobject; | 531 return CJS_Value::VT_fxobject; |
540 | 532 |
541 return CJS_Value::VT_unknown; | 533 return CJS_Value::VT_unknown; |
542 } | 534 } |
OLD | NEW |