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 "fpdfsdk/javascript/cjs_runtime.h" | 7 #include "fpdfsdk/javascript/cjs_runtime.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 const CJS_Context* pContext = static_cast<const CJS_Context*>(cc); | 56 const CJS_Context* pContext = static_cast<const CJS_Context*>(cc); |
57 return pContext->GetJSRuntime(); | 57 return pContext->GetJSRuntime(); |
58 } | 58 } |
59 | 59 |
60 // static | 60 // static |
61 CJS_Runtime* CJS_Runtime::CurrentRuntimeFromIsolate(v8::Isolate* pIsolate) { | 61 CJS_Runtime* CJS_Runtime::CurrentRuntimeFromIsolate(v8::Isolate* pIsolate) { |
62 return static_cast<CJS_Runtime*>( | 62 return static_cast<CJS_Runtime*>( |
63 CFXJS_Engine::CurrentEngineFromIsolate(pIsolate)); | 63 CFXJS_Engine::CurrentEngineFromIsolate(pIsolate)); |
64 } | 64 } |
65 | 65 |
66 CJS_Runtime::CJS_Runtime(CPDFSDK_Environment* pApp) | 66 CJS_Runtime::CJS_Runtime(CPDFSDK_Environment* pEnv) |
67 : m_pApp(pApp), | 67 : m_pEnv(pEnv), |
68 m_pDocument(nullptr), | 68 m_pDocument(nullptr), |
69 m_bBlocking(false), | 69 m_bBlocking(false), |
70 m_isolateManaged(false) { | 70 m_isolateManaged(false) { |
71 v8::Isolate* pIsolate = nullptr; | 71 v8::Isolate* pIsolate = nullptr; |
72 #ifndef PDF_ENABLE_XFA | 72 #ifndef PDF_ENABLE_XFA |
73 IPDF_JSPLATFORM* pPlatform = m_pApp->GetFormFillInfo()->m_pJsPlatform; | 73 IPDF_JSPLATFORM* pPlatform = m_pEnv->GetFormFillInfo()->m_pJsPlatform; |
74 if (pPlatform->version <= 2) { | 74 if (pPlatform->version <= 2) { |
75 unsigned int embedderDataSlot = 0; | 75 unsigned int embedderDataSlot = 0; |
76 v8::Isolate* pExternalIsolate = nullptr; | 76 v8::Isolate* pExternalIsolate = nullptr; |
77 if (pPlatform->version == 2) { | 77 if (pPlatform->version == 2) { |
78 pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate); | 78 pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate); |
79 embedderDataSlot = pPlatform->m_v8EmbedderSlot; | 79 embedderDataSlot = pPlatform->m_v8EmbedderSlot; |
80 } | 80 } |
81 FXJS_Initialize(embedderDataSlot, pExternalIsolate); | 81 FXJS_Initialize(embedderDataSlot, pExternalIsolate); |
82 } | 82 } |
83 m_isolateManaged = FXJS_GetIsolate(&pIsolate); | 83 m_isolateManaged = FXJS_GetIsolate(&pIsolate); |
84 SetIsolate(pIsolate); | 84 SetIsolate(pIsolate); |
85 #else | 85 #else |
86 if (CPDFXFA_App::GetInstance()->GetJSERuntime()) { | 86 if (CPDFXFA_App::GetInstance()->GetJSERuntime()) { |
87 // TODO(tsepez): CPDFXFA_App should also use the embedder provided isolate. | 87 // TODO(tsepez): CPDFXFA_App should also use the embedder provided isolate. |
88 pIsolate = CPDFXFA_App::GetInstance()->GetJSERuntime(); | 88 pIsolate = CPDFXFA_App::GetInstance()->GetJSERuntime(); |
89 SetIsolate(pIsolate); | 89 SetIsolate(pIsolate); |
90 } else { | 90 } else { |
91 IPDF_JSPLATFORM* pPlatform = m_pApp->GetFormFillInfo()->m_pJsPlatform; | 91 IPDF_JSPLATFORM* pPlatform = m_pEnv->GetFormFillInfo()->m_pJsPlatform; |
92 if (pPlatform->version <= 2) { | 92 if (pPlatform->version <= 2) { |
93 unsigned int embedderDataSlot = 0; | 93 unsigned int embedderDataSlot = 0; |
94 v8::Isolate* pExternalIsolate = nullptr; | 94 v8::Isolate* pExternalIsolate = nullptr; |
95 if (pPlatform->version == 2) { | 95 if (pPlatform->version == 2) { |
96 pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate); | 96 pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate); |
97 embedderDataSlot = pPlatform->m_v8EmbedderSlot; | 97 embedderDataSlot = pPlatform->m_v8EmbedderSlot; |
98 } | 98 } |
99 FXJS_Initialize(embedderDataSlot, pExternalIsolate); | 99 FXJS_Initialize(embedderDataSlot, pExternalIsolate); |
100 } | 100 } |
101 m_isolateManaged = FXJS_GetIsolate(&pIsolate); | 101 m_isolateManaged = FXJS_GetIsolate(&pIsolate); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 // v8::Local<v8::Context>::New(GetIsolate(), m_context); | 305 // v8::Local<v8::Context>::New(GetIsolate(), m_context); |
306 v8::Local<v8::Value> propvalue = | 306 v8::Local<v8::Value> propvalue = |
307 v8::Local<v8::Value>::New(GetIsolate(), pValue->DirectGetValue()); | 307 v8::Local<v8::Value>::New(GetIsolate(), pValue->DirectGetValue()); |
308 context->Global()->Set( | 308 context->Global()->Set( |
309 v8::String::NewFromUtf8(pIsolate, name, v8::String::kNormalString, | 309 v8::String::NewFromUtf8(pIsolate, name, v8::String::kNormalString, |
310 utf8Name.GetLength()), | 310 utf8Name.GetLength()), |
311 propvalue); | 311 propvalue); |
312 return TRUE; | 312 return TRUE; |
313 } | 313 } |
314 #endif | 314 #endif |
OLD | NEW |