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 "global.h" | 7 #include "global.h" |
8 | 8 |
9 #include "../../../core/include/fxcrt/fx_ext.h" | 9 #include "../../../core/include/fxcrt/fx_ext.h" |
10 #include "../../include/fpdfxfa/fpdfxfa_app.h" | 10 #include "../../include/fpdfxfa/fpdfxfa_app.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 case JS_GLOBALDATA_TYPE_NUMBER: | 187 case JS_GLOBALDATA_TYPE_NUMBER: |
188 vp << pData->dData; | 188 vp << pData->dData; |
189 return TRUE; | 189 return TRUE; |
190 case JS_GLOBALDATA_TYPE_BOOLEAN: | 190 case JS_GLOBALDATA_TYPE_BOOLEAN: |
191 vp << pData->bData; | 191 vp << pData->bData; |
192 return TRUE; | 192 return TRUE; |
193 case JS_GLOBALDATA_TYPE_STRING: | 193 case JS_GLOBALDATA_TYPE_STRING: |
194 vp << pData->sData; | 194 vp << pData->sData; |
195 return TRUE; | 195 return TRUE; |
196 case JS_GLOBALDATA_TYPE_OBJECT: { | 196 case JS_GLOBALDATA_TYPE_OBJECT: { |
197 v8::Local<v8::Object> obj = | 197 v8::Local<v8::Object> obj = v8::Local<v8::Object>::New( |
198 v8::Local<v8::Object>::New(vp.GetIsolate(), pData->pData); | 198 vp.GetJSRuntime()->GetIsolate(), pData->pData); |
199 vp << obj; | 199 vp << obj; |
200 return TRUE; | 200 return TRUE; |
201 } | 201 } |
202 case JS_GLOBALDATA_TYPE_NULL: | 202 case JS_GLOBALDATA_TYPE_NULL: |
203 vp.SetNull(); | 203 vp.SetNull(); |
204 return TRUE; | 204 return TRUE; |
205 default: | 205 default: |
206 break; | 206 break; |
207 } | 207 } |
208 } | 208 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NULL, 0, false, | 280 SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NULL, 0, false, |
281 "", v8::Local<v8::Object>(), | 281 "", v8::Local<v8::Object>(), |
282 pData->bPersistent == 1); | 282 pData->bPersistent == 1); |
283 FXJS_PutObjectNull(NULL, m_pJSObject->ToV8Object(), | 283 FXJS_PutObjectNull(NULL, m_pJSObject->ToV8Object(), |
284 pData->data.sKey.UTF8Decode().c_str()); | 284 pData->data.sKey.UTF8Decode().c_str()); |
285 break; | 285 break; |
286 } | 286 } |
287 } | 287 } |
288 } | 288 } |
289 | 289 |
290 void JSGlobalAlternate::CommitGlobalPersisitentVariables() { | 290 void JSGlobalAlternate::CommitGlobalPersisitentVariables(IJS_Context* cc) { |
291 ASSERT(m_pGlobalData); | |
292 for (auto it = m_mapGlobal.begin(); it != m_mapGlobal.end(); ++it) { | 291 for (auto it = m_mapGlobal.begin(); it != m_mapGlobal.end(); ++it) { |
293 CFX_ByteString name = it->first; | 292 CFX_ByteString name = it->first; |
294 JSGlobalData* pData = it->second; | 293 JSGlobalData* pData = it->second; |
295 if (pData->bDeleted) { | 294 if (pData->bDeleted) { |
296 m_pGlobalData->DeleteGlobalVariable(name); | 295 m_pGlobalData->DeleteGlobalVariable(name); |
297 } else { | 296 } else { |
298 switch (pData->nType) { | 297 switch (pData->nType) { |
299 case JS_GLOBALDATA_TYPE_NUMBER: | 298 case JS_GLOBALDATA_TYPE_NUMBER: |
300 m_pGlobalData->SetGlobalVariableNumber(name, pData->dData); | 299 m_pGlobalData->SetGlobalVariableNumber(name, pData->dData); |
301 m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent); | 300 m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent); |
302 break; | 301 break; |
303 case JS_GLOBALDATA_TYPE_BOOLEAN: | 302 case JS_GLOBALDATA_TYPE_BOOLEAN: |
304 m_pGlobalData->SetGlobalVariableBoolean(name, pData->bData); | 303 m_pGlobalData->SetGlobalVariableBoolean(name, pData->bData); |
305 m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent); | 304 m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent); |
306 break; | 305 break; |
307 case JS_GLOBALDATA_TYPE_STRING: | 306 case JS_GLOBALDATA_TYPE_STRING: |
308 m_pGlobalData->SetGlobalVariableString(name, pData->sData); | 307 m_pGlobalData->SetGlobalVariableString(name, pData->sData); |
309 m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent); | 308 m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent); |
310 break; | 309 break; |
311 case JS_GLOBALDATA_TYPE_OBJECT: | 310 case JS_GLOBALDATA_TYPE_OBJECT: |
312 // if (pData->pData) | |
313 { | 311 { |
314 CJS_GlobalVariableArray array; | 312 CJS_GlobalVariableArray array; |
315 v8::Local<v8::Object> obj = v8::Local<v8::Object>::New( | 313 v8::Local<v8::Object> obj = v8::Local<v8::Object>::New( |
316 GetJSObject()->GetIsolate(), pData->pData); | 314 GetJSObject()->GetIsolate(), pData->pData); |
317 ObjectToArray(obj, array); | 315 ObjectToArray(cc, obj, array); |
318 m_pGlobalData->SetGlobalVariableObject(name, array); | 316 m_pGlobalData->SetGlobalVariableObject(name, array); |
319 m_pGlobalData->SetGlobalVariablePersistent(name, | 317 m_pGlobalData->SetGlobalVariablePersistent(name, |
320 pData->bPersistent); | 318 pData->bPersistent); |
321 } | 319 } |
322 break; | 320 break; |
323 case JS_GLOBALDATA_TYPE_NULL: | 321 case JS_GLOBALDATA_TYPE_NULL: |
324 m_pGlobalData->SetGlobalVariableNull(name); | 322 m_pGlobalData->SetGlobalVariableNull(name); |
325 m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent); | 323 m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent); |
326 break; | 324 break; |
327 } | 325 } |
328 } | 326 } |
329 } | 327 } |
330 } | 328 } |
331 | 329 |
332 void JSGlobalAlternate::ObjectToArray(v8::Local<v8::Object> pObj, | 330 void JSGlobalAlternate::ObjectToArray(IJS_Context* cc, |
| 331 v8::Local<v8::Object> pObj, |
333 CJS_GlobalVariableArray& array) { | 332 CJS_GlobalVariableArray& array) { |
334 v8::Local<v8::Context> context = pObj->CreationContext(); | 333 v8::Local<v8::Context> context = pObj->CreationContext(); |
335 v8::Isolate* isolate = context->GetIsolate(); | 334 v8::Isolate* isolate = context->GetIsolate(); |
| 335 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 336 |
336 v8::Local<v8::Array> pKeyList = FXJS_GetObjectElementNames(isolate, pObj); | 337 v8::Local<v8::Array> pKeyList = FXJS_GetObjectElementNames(isolate, pObj); |
337 int nObjElements = pKeyList->Length(); | 338 int nObjElements = pKeyList->Length(); |
338 | |
339 for (int i = 0; i < nObjElements; i++) { | 339 for (int i = 0; i < nObjElements; i++) { |
340 CFX_WideString ws = | 340 CFX_WideString ws = |
341 FXJS_ToString(isolate, FXJS_GetArrayElement(isolate, pKeyList, i)); | 341 FXJS_ToString(isolate, FXJS_GetArrayElement(isolate, pKeyList, i)); |
342 CFX_ByteString sKey = ws.UTF8Encode(); | 342 CFX_ByteString sKey = ws.UTF8Encode(); |
343 | 343 |
344 v8::Local<v8::Value> v = FXJS_GetObjectElement(isolate, pObj, ws.c_str()); | 344 v8::Local<v8::Value> v = FXJS_GetObjectElement(isolate, pObj, ws.c_str()); |
345 switch (GET_VALUE_TYPE(v)) { | 345 switch (GET_VALUE_TYPE(v)) { |
346 case CJS_Value::VT_number: { | 346 case CJS_Value::VT_number: { |
347 CJS_KeyValue* pObjElement = new CJS_KeyValue; | 347 CJS_KeyValue* pObjElement = new CJS_KeyValue; |
348 pObjElement->nType = JS_GLOBALDATA_TYPE_NUMBER; | 348 pObjElement->nType = JS_GLOBALDATA_TYPE_NUMBER; |
349 pObjElement->sKey = sKey; | 349 pObjElement->sKey = sKey; |
350 pObjElement->dData = FXJS_ToNumber(isolate, v); | 350 pObjElement->dData = FXJS_ToNumber(isolate, v); |
351 array.Add(pObjElement); | 351 array.Add(pObjElement); |
352 } break; | 352 } break; |
353 case CJS_Value::VT_boolean: { | 353 case CJS_Value::VT_boolean: { |
354 CJS_KeyValue* pObjElement = new CJS_KeyValue; | 354 CJS_KeyValue* pObjElement = new CJS_KeyValue; |
355 pObjElement->nType = JS_GLOBALDATA_TYPE_BOOLEAN; | 355 pObjElement->nType = JS_GLOBALDATA_TYPE_BOOLEAN; |
356 pObjElement->sKey = sKey; | 356 pObjElement->sKey = sKey; |
357 pObjElement->dData = FXJS_ToBoolean(isolate, v); | 357 pObjElement->dData = FXJS_ToBoolean(isolate, v); |
358 array.Add(pObjElement); | 358 array.Add(pObjElement); |
359 } break; | 359 } break; |
360 case CJS_Value::VT_string: { | 360 case CJS_Value::VT_string: { |
361 CFX_ByteString sValue = | 361 CFX_ByteString sValue = |
362 CJS_Value(isolate, v, CJS_Value::VT_string).ToCFXByteString(); | 362 CJS_Value(pRuntime, v, CJS_Value::VT_string).ToCFXByteString(); |
363 CJS_KeyValue* pObjElement = new CJS_KeyValue; | 363 CJS_KeyValue* pObjElement = new CJS_KeyValue; |
364 pObjElement->nType = JS_GLOBALDATA_TYPE_STRING; | 364 pObjElement->nType = JS_GLOBALDATA_TYPE_STRING; |
365 pObjElement->sKey = sKey; | 365 pObjElement->sKey = sKey; |
366 pObjElement->sData = sValue; | 366 pObjElement->sData = sValue; |
367 array.Add(pObjElement); | 367 array.Add(pObjElement); |
368 } break; | 368 } break; |
369 case CJS_Value::VT_object: { | 369 case CJS_Value::VT_object: { |
370 CJS_KeyValue* pObjElement = new CJS_KeyValue; | 370 CJS_KeyValue* pObjElement = new CJS_KeyValue; |
371 pObjElement->nType = JS_GLOBALDATA_TYPE_OBJECT; | 371 pObjElement->nType = JS_GLOBALDATA_TYPE_OBJECT; |
372 pObjElement->sKey = sKey; | 372 pObjElement->sKey = sKey; |
373 ObjectToArray(FXJS_ToObject(isolate, v), pObjElement->objData); | 373 ObjectToArray(cc, FXJS_ToObject(isolate, v), pObjElement->objData); |
374 array.Add(pObjElement); | 374 array.Add(pObjElement); |
375 } break; | 375 } break; |
376 case CJS_Value::VT_null: { | 376 case CJS_Value::VT_null: { |
377 CJS_KeyValue* pObjElement = new CJS_KeyValue; | 377 CJS_KeyValue* pObjElement = new CJS_KeyValue; |
378 pObjElement->nType = JS_GLOBALDATA_TYPE_NULL; | 378 pObjElement->nType = JS_GLOBALDATA_TYPE_NULL; |
379 pObjElement->sKey = sKey; | 379 pObjElement->sKey = sKey; |
380 array.Add(pObjElement); | 380 array.Add(pObjElement); |
381 } break; | 381 } break; |
382 default: | 382 default: |
383 break; | 383 break; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 return CJS_Value::VT_boolean; | 525 return CJS_Value::VT_boolean; |
526 if (nHash == JSCONST_nDateHash) | 526 if (nHash == JSCONST_nDateHash) |
527 return CJS_Value::VT_date; | 527 return CJS_Value::VT_date; |
528 if (nHash == JSCONST_nObjectHash) | 528 if (nHash == JSCONST_nObjectHash) |
529 return CJS_Value::VT_object; | 529 return CJS_Value::VT_object; |
530 if (nHash == JSCONST_nFXobjHash) | 530 if (nHash == JSCONST_nFXobjHash) |
531 return CJS_Value::VT_fxobject; | 531 return CJS_Value::VT_fxobject; |
532 | 532 |
533 return CJS_Value::VT_unknown; | 533 return CJS_Value::VT_unknown; |
534 } | 534 } |
OLD | NEW |