Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: fpdfsdk/javascript/cjs_runtime.cpp

Issue 2245863002: Push v8::Isolate into CFXJS_Engine class (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Null isolate before letting CFXJS_Engine dtor invoked Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/javascript/cjs_runtime.h ('k') | fpdfsdk/javascript/color.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 IJS_Runtime* IJS_Runtime::Create(CPDFDoc_Environment* pEnv) { 48 IJS_Runtime* IJS_Runtime::Create(CPDFDoc_Environment* pEnv) {
49 return new CJS_Runtime(pEnv); 49 return new CJS_Runtime(pEnv);
50 } 50 }
51 51
52 // static 52 // static
53 CJS_Runtime* CJS_Runtime::FromContext(const IJS_Context* cc) { 53 CJS_Runtime* CJS_Runtime::FromContext(const IJS_Context* cc) {
54 const CJS_Context* pContext = static_cast<const CJS_Context*>(cc); 54 const CJS_Context* pContext = static_cast<const CJS_Context*>(cc);
55 return pContext->GetJSRuntime(); 55 return pContext->GetJSRuntime();
56 } 56 }
57 57
58 // static
59 CJS_Runtime* CJS_Runtime::CurrentRuntimeFromIsolate(v8::Isolate* pIsolate) {
60 return static_cast<CJS_Runtime*>(
61 CFXJS_Engine::CurrentEngineFromIsolate(pIsolate));
62 }
63
58 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) 64 CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp)
59 : m_pApp(pApp), 65 : m_pApp(pApp),
60 m_pDocument(nullptr), 66 m_pDocument(nullptr),
61 m_bBlocking(false), 67 m_bBlocking(false),
62 m_isolateManaged(false) { 68 m_isolateManaged(false) {
69 v8::Isolate* pIsolate = nullptr;
63 #ifndef PDF_ENABLE_XFA 70 #ifndef PDF_ENABLE_XFA
64 IPDF_JSPLATFORM* pPlatform = m_pApp->GetFormFillInfo()->m_pJsPlatform; 71 IPDF_JSPLATFORM* pPlatform = m_pApp->GetFormFillInfo()->m_pJsPlatform;
65 if (pPlatform->version <= 2) { 72 if (pPlatform->version <= 2) {
66 unsigned int embedderDataSlot = 0; 73 unsigned int embedderDataSlot = 0;
67 v8::Isolate* pExternalIsolate = nullptr; 74 v8::Isolate* pExternalIsolate = nullptr;
68 if (pPlatform->version == 2) { 75 if (pPlatform->version == 2) {
69 pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate); 76 pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate);
70 embedderDataSlot = pPlatform->m_v8EmbedderSlot; 77 embedderDataSlot = pPlatform->m_v8EmbedderSlot;
71 } 78 }
72 FXJS_Initialize(embedderDataSlot, pExternalIsolate); 79 FXJS_Initialize(embedderDataSlot, pExternalIsolate);
73 } 80 }
74 m_isolateManaged = FXJS_GetIsolate(&m_isolate); 81 m_isolateManaged = FXJS_GetIsolate(&pIsolate);
82 SetIsolate(pIsolate);
75 #else 83 #else
76 if (CPDFXFA_App::GetInstance()->GetJSERuntime()) { 84 if (CPDFXFA_App::GetInstance()->GetJSERuntime()) {
77 // TODO(tsepez): CPDFXFA_App should also use the embedder provided isolate. 85 // TODO(tsepez): CPDFXFA_App should also use the embedder provided isolate.
78 m_isolate = (v8::Isolate*)CPDFXFA_App::GetInstance()->GetJSERuntime(); 86 pIsolate = CPDFXFA_App::GetInstance()->GetJSERuntime();
87 SetIsolate(pIsolate);
79 } else { 88 } else {
80 IPDF_JSPLATFORM* pPlatform = m_pApp->GetFormFillInfo()->m_pJsPlatform; 89 IPDF_JSPLATFORM* pPlatform = m_pApp->GetFormFillInfo()->m_pJsPlatform;
81 if (pPlatform->version <= 2) { 90 if (pPlatform->version <= 2) {
82 unsigned int embedderDataSlot = 0; 91 unsigned int embedderDataSlot = 0;
83 v8::Isolate* pExternalIsolate = nullptr; 92 v8::Isolate* pExternalIsolate = nullptr;
84 if (pPlatform->version == 2) { 93 if (pPlatform->version == 2) {
85 pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate); 94 pExternalIsolate = reinterpret_cast<v8::Isolate*>(pPlatform->m_isolate);
86 embedderDataSlot = pPlatform->m_v8EmbedderSlot; 95 embedderDataSlot = pPlatform->m_v8EmbedderSlot;
87 } 96 }
88 FXJS_Initialize(embedderDataSlot, pExternalIsolate); 97 FXJS_Initialize(embedderDataSlot, pExternalIsolate);
89 } 98 }
90 m_isolateManaged = FXJS_GetIsolate(&m_isolate); 99 m_isolateManaged = FXJS_GetIsolate(&pIsolate);
100 SetIsolate(pIsolate);
91 } 101 }
92 102
93 v8::Isolate* isolate = m_isolate; 103 v8::Isolate::Scope isolate_scope(pIsolate);
94 v8::Isolate::Scope isolate_scope(isolate); 104 v8::HandleScope handle_scope(pIsolate);
95 v8::HandleScope handle_scope(isolate);
96 if (CPDFXFA_App::GetInstance()->IsJavaScriptInitialized()) { 105 if (CPDFXFA_App::GetInstance()->IsJavaScriptInitialized()) {
97 CJS_Context* pContext = (CJS_Context*)NewContext(); 106 CJS_Context* pContext = (CJS_Context*)NewContext();
98 FXJS_InitializeEngine(GetIsolate(), this, &m_context, &m_StaticObjects); 107 InitializeEngine();
99 ReleaseContext(pContext); 108 ReleaseContext(pContext);
100 return; 109 return;
101 } 110 }
102 #endif 111 #endif
103 112
104 if (m_isolateManaged || FXJS_GlobalIsolateRefCount() == 0) 113 if (m_isolateManaged || FXJS_GlobalIsolateRefCount() == 0)
105 DefineJSObjects(); 114 DefineJSObjects();
106 115
107 #ifdef PDF_ENABLE_XFA 116 #ifdef PDF_ENABLE_XFA
108 CPDFXFA_App::GetInstance()->SetJavaScriptInitialized(TRUE); 117 CPDFXFA_App::GetInstance()->SetJavaScriptInitialized(TRUE);
109 #endif 118 #endif
110 119
111 CJS_Context* pContext = (CJS_Context*)NewContext(); 120 CJS_Context* pContext = (CJS_Context*)NewContext();
112 FXJS_InitializeEngine(GetIsolate(), this, &m_context, &m_StaticObjects); 121 InitializeEngine();
113 ReleaseContext(pContext); 122 ReleaseContext(pContext);
114 } 123 }
115 124
116 CJS_Runtime::~CJS_Runtime() { 125 CJS_Runtime::~CJS_Runtime() {
117 for (auto* obs : m_observers) 126 for (auto* obs : m_observers)
118 obs->OnDestroyed(); 127 obs->OnDestroyed();
119 128
120 m_ContextArray.clear(); 129 ReleaseEngine();
121 m_ConstArrays.clear(); 130 if (m_isolateManaged) {
122 FXJS_ReleaseEngine(GetIsolate(), &m_context, &m_StaticObjects); 131 GetIsolate()->Dispose();
123 m_context.Reset(); 132 SetIsolate(nullptr);
124 if (m_isolateManaged) 133 }
125 m_isolate->Dispose();
126 } 134 }
127 135
128 void CJS_Runtime::DefineJSObjects() { 136 void CJS_Runtime::DefineJSObjects() {
129 v8::Isolate::Scope isolate_scope(GetIsolate()); 137 v8::Isolate::Scope isolate_scope(GetIsolate());
130 v8::HandleScope handle_scope(GetIsolate()); 138 v8::HandleScope handle_scope(GetIsolate());
131 v8::Local<v8::Context> context = v8::Context::New(GetIsolate()); 139 v8::Local<v8::Context> context = v8::Context::New(GetIsolate());
132 v8::Context::Scope context_scope(context); 140 v8::Context::Scope context_scope(context);
133 141
134 // The call order determines the "ObjDefID" assigned to each class. 142 // The call order determines the "ObjDefID" assigned to each class.
135 // ObjDefIDs 0 - 2 143 // ObjDefIDs 0 - 2
136 CJS_Border::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 144 CJS_Border::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
137 CJS_Display::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 145 CJS_Display::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
138 CJS_Font::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 146 CJS_Font::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
139 147
140 // ObjDefIDs 3 - 5 148 // ObjDefIDs 3 - 5
141 CJS_Highlight::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 149 CJS_Highlight::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
142 CJS_Position::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 150 CJS_Position::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
143 CJS_ScaleHow::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 151 CJS_ScaleHow::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
144 152
145 // ObjDefIDs 6 - 8 153 // ObjDefIDs 6 - 8
146 CJS_ScaleWhen::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 154 CJS_ScaleWhen::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
147 CJS_Style::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 155 CJS_Style::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
148 CJS_Zoomtype::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 156 CJS_Zoomtype::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
149 157
150 // ObjDefIDs 9 - 11 158 // ObjDefIDs 9 - 11
151 CJS_App::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 159 CJS_App::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
152 CJS_Color::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 160 CJS_Color::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
153 CJS_Console::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 161 CJS_Console::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
154 162
155 // ObjDefIDs 12 - 14 163 // ObjDefIDs 12 - 14
156 CJS_Document::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_GLOBAL); 164 CJS_Document::DefineJSObjects(this, FXJSOBJTYPE_GLOBAL);
157 CJS_Event::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 165 CJS_Event::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
158 CJS_Field::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC); 166 CJS_Field::DefineJSObjects(this, FXJSOBJTYPE_DYNAMIC);
159 167
160 // ObjDefIDs 15 - 17 168 // ObjDefIDs 15 - 17
161 CJS_Global::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 169 CJS_Global::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
162 CJS_Icon::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC); 170 CJS_Icon::DefineJSObjects(this, FXJSOBJTYPE_DYNAMIC);
163 CJS_Util::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 171 CJS_Util::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
164 172
165 // ObjDefIDs 18 - 20 (these can't fail, return void). 173 // ObjDefIDs 18 - 20 (these can't fail, return void).
166 CJS_PublicMethods::DefineJSObjects(GetIsolate()); 174 CJS_PublicMethods::DefineJSObjects(this);
167 CJS_GlobalConsts::DefineJSObjects(this); 175 CJS_GlobalConsts::DefineJSObjects(this);
168 CJS_GlobalArrays::DefineJSObjects(this); 176 CJS_GlobalArrays::DefineJSObjects(this);
169 177
170 // ObjDefIDs 21 - 22. 178 // ObjDefIDs 21 - 22.
171 CJS_TimerObj::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC); 179 CJS_TimerObj::DefineJSObjects(this, FXJSOBJTYPE_DYNAMIC);
172 CJS_PrintParamsObj::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC); 180 CJS_PrintParamsObj::DefineJSObjects(this, FXJSOBJTYPE_DYNAMIC);
173 } 181 }
174 182
175 IJS_Context* CJS_Runtime::NewContext() { 183 IJS_Context* CJS_Runtime::NewContext() {
176 m_ContextArray.push_back(std::unique_ptr<CJS_Context>(new CJS_Context(this))); 184 m_ContextArray.push_back(std::unique_ptr<CJS_Context>(new CJS_Context(this)));
177 return m_ContextArray.back().get(); 185 return m_ContextArray.back().get();
178 } 186 }
179 187
180 void CJS_Runtime::ReleaseContext(IJS_Context* pContext) { 188 void CJS_Runtime::ReleaseContext(IJS_Context* pContext) {
181 for (auto it = m_ContextArray.begin(); it != m_ContextArray.end(); ++it) { 189 for (auto it = m_ContextArray.begin(); it != m_ContextArray.end(); ++it) {
182 if (it->get() == static_cast<CJS_Context*>(pContext)) { 190 if (it->get() == static_cast<CJS_Context*>(pContext)) {
183 m_ContextArray.erase(it); 191 m_ContextArray.erase(it);
184 return; 192 return;
185 } 193 }
186 } 194 }
187 } 195 }
188 196
189 IJS_Context* CJS_Runtime::GetCurrentContext() { 197 IJS_Context* CJS_Runtime::GetCurrentContext() {
190 return m_ContextArray.empty() ? nullptr : m_ContextArray.back().get(); 198 return m_ContextArray.empty() ? nullptr : m_ContextArray.back().get();
191 } 199 }
192 200
193 void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) { 201 void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) {
194 if (m_pDocument != pReaderDoc) { 202 if (m_pDocument == pReaderDoc)
195 v8::Isolate::Scope isolate_scope(m_isolate); 203 return;
196 v8::HandleScope handle_scope(m_isolate);
197 v8::Local<v8::Context> context =
198 v8::Local<v8::Context>::New(m_isolate, m_context);
199 v8::Context::Scope context_scope(context);
200 204
201 m_pDocument = pReaderDoc; 205 v8::Isolate::Scope isolate_scope(GetIsolate());
202 if (pReaderDoc) { 206 v8::HandleScope handle_scope(GetIsolate());
203 v8::Local<v8::Object> pThis = FXJS_GetThisObj(GetIsolate()); 207 v8::Local<v8::Context> context = NewLocalContext();
204 if (!pThis.IsEmpty()) { 208 v8::Context::Scope context_scope(context);
205 if (FXJS_GetObjDefnID(pThis) == CJS_Document::g_nObjDefnID) { 209
206 if (CJS_Document* pJSDocument = 210 m_pDocument = pReaderDoc;
207 (CJS_Document*)FXJS_GetPrivate(GetIsolate(), pThis)) { 211 if (!pReaderDoc)
208 if (Document* pDocument = (Document*)pJSDocument->GetEmbedObject()) 212 return;
209 pDocument->AttachDoc(pReaderDoc); 213
210 } 214 v8::Local<v8::Object> pThis = GetThisObj();
211 } 215 if (pThis.IsEmpty())
212 } 216 return;
213 } 217
214 } 218 if (CFXJS_Engine::GetObjDefnID(pThis) != CJS_Document::g_nObjDefnID)
219 return;
220
221 CJS_Document* pJSDocument =
222 static_cast<CJS_Document*>(GetObjectPrivate(pThis));
223 if (!pJSDocument)
224 return;
225
226 Document* pDocument = static_cast<Document*>(pJSDocument->GetEmbedObject());
227 if (!pDocument)
228 return;
229
230 pDocument->AttachDoc(pReaderDoc);
215 } 231 }
216 232
217 CPDFSDK_Document* CJS_Runtime::GetReaderDocument() { 233 CPDFSDK_Document* CJS_Runtime::GetReaderDocument() {
218 return m_pDocument; 234 return m_pDocument;
219 } 235 }
220 236
221 int CJS_Runtime::Execute(const CFX_WideString& script, CFX_WideString* info) { 237 int CJS_Runtime::ExecuteScript(const CFX_WideString& script,
238 CFX_WideString* info) {
222 FXJSErr error = {}; 239 FXJSErr error = {};
223 int nRet = FXJS_Execute(m_isolate, script, &error); 240 int nRet = Execute(script, &error);
224 if (nRet < 0) { 241 if (nRet < 0) {
225 info->Format(L"[ Line: %05d { %s } ] : %s", error.linnum - 1, error.srcline, 242 info->Format(L"[ Line: %05d { %s } ] : %s", error.linnum - 1, error.srcline,
226 error.message); 243 error.message);
227 } 244 }
228 return nRet; 245 return nRet;
229 } 246 }
230 247
231 bool CJS_Runtime::AddEventToSet(const FieldEvent& event) { 248 bool CJS_Runtime::AddEventToSet(const FieldEvent& event) {
232 return m_FieldEventSet.insert(event).second; 249 return m_FieldEventSet.insert(event).second;
233 } 250 }
234 251
235 void CJS_Runtime::RemoveEventFromSet(const FieldEvent& event) { 252 void CJS_Runtime::RemoveEventFromSet(const FieldEvent& event) {
236 m_FieldEventSet.erase(event); 253 m_FieldEventSet.erase(event);
237 } 254 }
238 255
239 v8::Local<v8::Context> CJS_Runtime::NewJSContext() {
240 return v8::Local<v8::Context>::New(m_isolate, m_context);
241 }
242
243 void CJS_Runtime::SetConstArray(const CFX_WideString& name,
244 v8::Local<v8::Array> array) {
245 m_ConstArrays[name] = v8::Global<v8::Array>(m_isolate, array);
246 }
247
248 v8::Local<v8::Array> CJS_Runtime::GetConstArray(const CFX_WideString& name) {
249 return v8::Local<v8::Array>::New(m_isolate, m_ConstArrays[name]);
250 }
251
252 void CJS_Runtime::AddObserver(Observer* observer) { 256 void CJS_Runtime::AddObserver(Observer* observer) {
253 ASSERT(!pdfium::ContainsKey(m_observers, observer)); 257 ASSERT(!pdfium::ContainsKey(m_observers, observer));
254 m_observers.insert(observer); 258 m_observers.insert(observer);
255 } 259 }
256 260
257 void CJS_Runtime::RemoveObserver(Observer* observer) { 261 void CJS_Runtime::RemoveObserver(Observer* observer) {
258 ASSERT(pdfium::ContainsKey(m_observers, observer)); 262 ASSERT(pdfium::ContainsKey(m_observers, observer));
259 m_observers.erase(observer); 263 m_observers.erase(observer);
260 } 264 }
261 265
262 #ifdef PDF_ENABLE_XFA 266 #ifdef PDF_ENABLE_XFA
263 CFX_WideString ChangeObjName(const CFX_WideString& str) { 267 CFX_WideString ChangeObjName(const CFX_WideString& str) {
264 CFX_WideString sRet = str; 268 CFX_WideString sRet = str;
265 sRet.Replace(L"_", L"."); 269 sRet.Replace(L"_", L".");
266 return sRet; 270 return sRet;
267 } 271 }
268 FX_BOOL CJS_Runtime::GetValueByName(const CFX_ByteStringC& utf8Name, 272 FX_BOOL CJS_Runtime::GetValueByName(const CFX_ByteStringC& utf8Name,
269 CFXJSE_Value* pValue) { 273 CFXJSE_Value* pValue) {
270 const FX_CHAR* name = utf8Name.c_str(); 274 const FX_CHAR* name = utf8Name.c_str();
271 275
272 v8::Isolate::Scope isolate_scope(GetIsolate()); 276 v8::Isolate::Scope isolate_scope(GetIsolate());
273 v8::HandleScope handle_scope(GetIsolate()); 277 v8::HandleScope handle_scope(GetIsolate());
274 v8::Local<v8::Context> old_context = GetIsolate()->GetCurrentContext(); 278 v8::Local<v8::Context> old_context = GetIsolate()->GetCurrentContext();
275 v8::Local<v8::Context> context = 279 v8::Local<v8::Context> context = NewLocalContext();
276 v8::Local<v8::Context>::New(GetIsolate(), m_context);
277 v8::Context::Scope context_scope(context); 280 v8::Context::Scope context_scope(context);
278 281
279 // Caution: We're about to hand to XFA an object that in order to invoke 282 // Caution: We're about to hand to XFA an object that in order to invoke
280 // methods will require that the current v8::Context always has a pointer 283 // methods will require that the current v8::Context always has a pointer
281 // to a CJS_Runtime in its embedder data slot. Unfortunately, XFA creates 284 // to a CJS_Runtime in its embedder data slot. Unfortunately, XFA creates
282 // its own v8::Context which has not initialized the embedder data slot. 285 // its own v8::Context which has not initialized the embedder data slot.
283 // Do so now. 286 // Do so now.
284 // TODO(tsepez): redesign PDF-side objects to not rely on v8::Context's 287 // TODO(tsepez): redesign PDF-side objects to not rely on v8::Context's
285 // embedder data slots, and/or to always use the right context. 288 // embedder data slots, and/or to always use the right context.
286 FXJS_SetEngineForV8Context(old_context, this); 289 CFXJS_Engine::SetForV8Context(old_context, this);
287 290
288 v8::Local<v8::Value> propvalue = 291 v8::Local<v8::Value> propvalue =
289 context->Global()->Get(v8::String::NewFromUtf8( 292 context->Global()->Get(v8::String::NewFromUtf8(
290 GetIsolate(), name, v8::String::kNormalString, utf8Name.GetLength())); 293 GetIsolate(), name, v8::String::kNormalString, utf8Name.GetLength()));
291 294
292 if (propvalue.IsEmpty()) { 295 if (propvalue.IsEmpty()) {
293 pValue->SetUndefined(); 296 pValue->SetUndefined();
294 return FALSE; 297 return FALSE;
295 } 298 }
296 pValue->ForceSetValue(propvalue); 299 pValue->ForceSetValue(propvalue);
297 return TRUE; 300 return TRUE;
298 } 301 }
299 FX_BOOL CJS_Runtime::SetValueByName(const CFX_ByteStringC& utf8Name, 302 FX_BOOL CJS_Runtime::SetValueByName(const CFX_ByteStringC& utf8Name,
300 CFXJSE_Value* pValue) { 303 CFXJSE_Value* pValue) {
301 if (utf8Name.IsEmpty() || !pValue) 304 if (utf8Name.IsEmpty() || !pValue)
302 return FALSE; 305 return FALSE;
303 const FX_CHAR* name = utf8Name.c_str(); 306 const FX_CHAR* name = utf8Name.c_str();
304 v8::Isolate* pIsolate = GetIsolate(); 307 v8::Isolate* pIsolate = GetIsolate();
305 v8::Isolate::Scope isolate_scope(pIsolate); 308 v8::Isolate::Scope isolate_scope(pIsolate);
306 v8::HandleScope handle_scope(pIsolate); 309 v8::HandleScope handle_scope(pIsolate);
307 v8::Local<v8::Context> context = 310 v8::Local<v8::Context> context = NewLocalContext();
308 v8::Local<v8::Context>::New(pIsolate, m_context);
309 v8::Context::Scope context_scope(context); 311 v8::Context::Scope context_scope(context);
310 312
311 // v8::Local<v8::Context> tmpCotext = 313 // v8::Local<v8::Context> tmpCotext =
312 // v8::Local<v8::Context>::New(GetIsolate(), m_context); 314 // v8::Local<v8::Context>::New(GetIsolate(), m_context);
313 v8::Local<v8::Value> propvalue = 315 v8::Local<v8::Value> propvalue =
314 v8::Local<v8::Value>::New(GetIsolate(), pValue->DirectGetValue()); 316 v8::Local<v8::Value>::New(GetIsolate(), pValue->DirectGetValue());
315 context->Global()->Set( 317 context->Global()->Set(
316 v8::String::NewFromUtf8(pIsolate, name, v8::String::kNormalString, 318 v8::String::NewFromUtf8(pIsolate, name, v8::String::kNormalString,
317 utf8Name.GetLength()), 319 utf8Name.GetLength()),
318 propvalue); 320 propvalue);
319 return TRUE; 321 return TRUE;
320 } 322 }
321 #endif 323 #endif
OLDNEW
« no previous file with comments | « fpdfsdk/javascript/cjs_runtime.h ('k') | fpdfsdk/javascript/color.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698