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