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 "../../include/jsapi/fxjs_v8.h" | 7 #include "../../include/jsapi/fxjs_v8.h" |
8 | 8 |
9 #include "../../../core/include/fxcrt/fx_basic.h" | 9 #include "../../../core/include/fxcrt/fx_basic.h" |
10 | 10 |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 ++g_isolate_ref_count; | 279 ++g_isolate_ref_count; |
280 | 280 |
281 v8::Isolate::Scope isolate_scope(pIsolate); | 281 v8::Isolate::Scope isolate_scope(pIsolate); |
282 v8::Locker locker(pIsolate); | 282 v8::Locker locker(pIsolate); |
283 v8::HandleScope handle_scope(pIsolate); | 283 v8::HandleScope handle_scope(pIsolate); |
284 v8::Local<v8::Context> v8Context = | 284 v8::Local<v8::Context> v8Context = |
285 v8::Context::New(pIsolate, NULL, GetGlobalObjectTemplate(pIsolate)); | 285 v8::Context::New(pIsolate, NULL, GetGlobalObjectTemplate(pIsolate)); |
286 v8::Context::Scope context_scope(v8Context); | 286 v8::Context::Scope context_scope(v8Context); |
287 | 287 |
288 FXJS_PerIsolateData::SetUp(pIsolate); | 288 FXJS_PerIsolateData::SetUp(pIsolate); |
289 v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pIRuntime); | 289 FXJS_SetRuntimeForV8Context(v8Context, pIRuntime); |
290 | 290 |
291 int maxID = CFXJS_ObjDefinition::MaxID(pIsolate); | 291 int maxID = CFXJS_ObjDefinition::MaxID(pIsolate); |
292 for (int i = 0; i < maxID; ++i) { | 292 for (int i = 0; i < maxID; ++i) { |
293 CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i); | 293 CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i); |
294 CFX_ByteString bs = CFX_WideString(pObjDef->m_ObjName).UTF8Encode(); | 294 CFX_ByteString bs = CFX_WideString(pObjDef->m_ObjName).UTF8Encode(); |
295 v8::Local<v8::String> m_ObjName = | 295 v8::Local<v8::String> m_ObjName = |
296 v8::String::NewFromUtf8(pIsolate, bs.c_str(), | 296 v8::String::NewFromUtf8(pIsolate, bs.c_str(), |
297 v8::NewStringType::kNormal, | 297 v8::NewStringType::kNormal, |
298 bs.GetLength()).ToLocalChecked(); | 298 bs.GetLength()).ToLocalChecked(); |
299 | 299 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 pObjDef->m_pDestructor(pObj); | 353 pObjDef->m_pDestructor(pObj); |
354 FXJS_FreePrivate(pObj); | 354 FXJS_FreePrivate(pObj); |
355 } | 355 } |
356 delete pObjDef; | 356 delete pObjDef; |
357 } | 357 } |
358 | 358 |
359 pIsolate->SetData(g_embedderDataSlot, nullptr); | 359 pIsolate->SetData(g_embedderDataSlot, nullptr); |
360 delete pData; | 360 delete pData; |
361 } | 361 } |
362 | 362 |
363 IJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate) { | 363 void FXJS_SetRuntimeForV8Context(v8::Local<v8::Context> v8Context, |
364 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); | 364 IJS_Runtime* pIRuntime) { |
| 365 v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pIRuntime); |
| 366 } |
| 367 |
| 368 IJS_Runtime* FXJS_GetRuntimeFromV8Context(v8::Local<v8::Context> v8Context) { |
365 return static_cast<IJS_Runtime*>( | 369 return static_cast<IJS_Runtime*>( |
366 context->GetAlignedPointerFromEmbedderData(kPerContextDataIndex)); | 370 v8Context->GetAlignedPointerFromEmbedderData(kPerContextDataIndex)); |
367 } | 371 } |
368 | 372 |
369 int FXJS_Execute(v8::Isolate* pIsolate, | 373 int FXJS_Execute(v8::Isolate* pIsolate, |
370 IJS_Context* pJSContext, | 374 IJS_Context* pJSContext, |
371 const wchar_t* script, | 375 const wchar_t* script, |
372 FXJSErr* pError) { | 376 FXJSErr* pError) { |
373 v8::Isolate::Scope isolate_scope(pIsolate); | 377 v8::Isolate::Scope isolate_scope(pIsolate); |
374 v8::TryCatch try_catch(pIsolate); | 378 v8::TryCatch try_catch(pIsolate); |
375 CFX_ByteString bsScript = CFX_WideString(script).UTF8Encode(); | 379 CFX_ByteString bsScript = CFX_WideString(script).UTF8Encode(); |
376 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); | 380 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 return v8::Local<v8::Array>(); | 761 return v8::Local<v8::Array>(); |
758 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); | 762 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); |
759 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); | 763 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); |
760 } | 764 } |
761 | 765 |
762 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) { | 766 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) { |
763 pTo = pFrom; | 767 pTo = pFrom; |
764 } | 768 } |
765 | 769 |
766 | 770 |
OLD | NEW |