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

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: Make members private 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
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();
122 FXJS_ReleaseEngine(GetIsolate(), &m_context, &m_StaticObjects);
123 m_context.Reset();
124 if (m_isolateManaged) 130 if (m_isolateManaged)
125 m_isolate->Dispose(); 131 GetIsolate()->Dispose();
126 } 132 }
127 133
128 void CJS_Runtime::DefineJSObjects() { 134 void CJS_Runtime::DefineJSObjects() {
129 v8::Isolate::Scope isolate_scope(GetIsolate()); 135 v8::Isolate::Scope isolate_scope(GetIsolate());
130 v8::HandleScope handle_scope(GetIsolate()); 136 v8::HandleScope handle_scope(GetIsolate());
131 v8::Local<v8::Context> context = v8::Context::New(GetIsolate()); 137 v8::Local<v8::Context> context = v8::Context::New(GetIsolate());
132 v8::Context::Scope context_scope(context); 138 v8::Context::Scope context_scope(context);
133 139
134 // The call order determines the "ObjDefID" assigned to each class. 140 // The call order determines the "ObjDefID" assigned to each class.
135 // ObjDefIDs 0 - 2 141 // ObjDefIDs 0 - 2
136 CJS_Border::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 142 CJS_Border::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
137 CJS_Display::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 143 CJS_Display::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
138 CJS_Font::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 144 CJS_Font::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
139 145
140 // ObjDefIDs 3 - 5 146 // ObjDefIDs 3 - 5
141 CJS_Highlight::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 147 CJS_Highlight::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
142 CJS_Position::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 148 CJS_Position::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
143 CJS_ScaleHow::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 149 CJS_ScaleHow::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
144 150
145 // ObjDefIDs 6 - 8 151 // ObjDefIDs 6 - 8
146 CJS_ScaleWhen::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 152 CJS_ScaleWhen::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
147 CJS_Style::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 153 CJS_Style::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
148 CJS_Zoomtype::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 154 CJS_Zoomtype::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
149 155
150 // ObjDefIDs 9 - 11 156 // ObjDefIDs 9 - 11
151 CJS_App::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 157 CJS_App::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
152 CJS_Color::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 158 CJS_Color::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
153 CJS_Console::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 159 CJS_Console::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
154 160
155 // ObjDefIDs 12 - 14 161 // ObjDefIDs 12 - 14
156 CJS_Document::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_GLOBAL); 162 CJS_Document::DefineJSObjects(this, FXJSOBJTYPE_GLOBAL);
157 CJS_Event::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 163 CJS_Event::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
158 CJS_Field::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC); 164 CJS_Field::DefineJSObjects(this, FXJSOBJTYPE_DYNAMIC);
159 165
160 // ObjDefIDs 15 - 17 166 // ObjDefIDs 15 - 17
161 CJS_Global::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 167 CJS_Global::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
162 CJS_Icon::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC); 168 CJS_Icon::DefineJSObjects(this, FXJSOBJTYPE_DYNAMIC);
163 CJS_Util::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC); 169 CJS_Util::DefineJSObjects(this, FXJSOBJTYPE_STATIC);
164 170
165 // ObjDefIDs 18 - 20 (these can't fail, return void). 171 // ObjDefIDs 18 - 20 (these can't fail, return void).
166 CJS_PublicMethods::DefineJSObjects(GetIsolate()); 172 CJS_PublicMethods::DefineJSObjects(this);
167 CJS_GlobalConsts::DefineJSObjects(this); 173 CJS_GlobalConsts::DefineJSObjects(this);
168 CJS_GlobalArrays::DefineJSObjects(this); 174 CJS_GlobalArrays::DefineJSObjects(this);
169 175
170 // ObjDefIDs 21 - 22. 176 // ObjDefIDs 21 - 22.
171 CJS_TimerObj::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC); 177 CJS_TimerObj::DefineJSObjects(this, FXJSOBJTYPE_DYNAMIC);
172 CJS_PrintParamsObj::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC); 178 CJS_PrintParamsObj::DefineJSObjects(this, FXJSOBJTYPE_DYNAMIC);
173 } 179 }
174 180
175 IJS_Context* CJS_Runtime::NewContext() { 181 IJS_Context* CJS_Runtime::NewContext() {
176 m_ContextArray.push_back(std::unique_ptr<CJS_Context>(new CJS_Context(this))); 182 m_ContextArray.push_back(std::unique_ptr<CJS_Context>(new CJS_Context(this)));
177 return m_ContextArray.back().get(); 183 return m_ContextArray.back().get();
178 } 184 }
179 185
180 void CJS_Runtime::ReleaseContext(IJS_Context* pContext) { 186 void CJS_Runtime::ReleaseContext(IJS_Context* pContext) {
181 for (auto it = m_ContextArray.begin(); it != m_ContextArray.end(); ++it) { 187 for (auto it = m_ContextArray.begin(); it != m_ContextArray.end(); ++it) {
182 if (it->get() == static_cast<CJS_Context*>(pContext)) { 188 if (it->get() == static_cast<CJS_Context*>(pContext)) {
183 m_ContextArray.erase(it); 189 m_ContextArray.erase(it);
184 return; 190 return;
185 } 191 }
186 } 192 }
187 } 193 }
188 194
189 IJS_Context* CJS_Runtime::GetCurrentContext() { 195 IJS_Context* CJS_Runtime::GetCurrentContext() {
190 return m_ContextArray.empty() ? nullptr : m_ContextArray.back().get(); 196 return m_ContextArray.empty() ? nullptr : m_ContextArray.back().get();
191 } 197 }
192 198
193 void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) { 199 void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) {
194 if (m_pDocument != pReaderDoc) { 200 if (m_pDocument == pReaderDoc)
195 v8::Isolate::Scope isolate_scope(m_isolate); 201 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 202
201 m_pDocument = pReaderDoc; 203 v8::Isolate::Scope isolate_scope(GetIsolate());
202 if (pReaderDoc) { 204 v8::HandleScope handle_scope(GetIsolate());
203 v8::Local<v8::Object> pThis = FXJS_GetThisObj(GetIsolate()); 205 v8::Local<v8::Context> context = NewLocalContext();
204 if (!pThis.IsEmpty()) { 206 v8::Context::Scope context_scope(context);
205 if (FXJS_GetObjDefnID(pThis) == CJS_Document::g_nObjDefnID) { 207
206 if (CJS_Document* pJSDocument = 208 m_pDocument = pReaderDoc;
207 (CJS_Document*)FXJS_GetPrivate(GetIsolate(), pThis)) { 209 if (!pReaderDoc)
208 if (Document* pDocument = (Document*)pJSDocument->GetEmbedObject()) 210 return;
209 pDocument->AttachDoc(pReaderDoc); 211
210 } 212 v8::Local<v8::Object> pThis = GetThisObj();
211 } 213 if (pThis.IsEmpty())
212 } 214 return;
213 } 215
214 } 216 if (CFXJS_Engine::GetObjDefnID(pThis) != CJS_Document::g_nObjDefnID)
217 return;
218
219 CJS_Document* pJSDocument =
220 static_cast<CJS_Document*>(GetObjectPrivate(pThis));
221 if (!pJSDocument)
222 return;
223
224 Document* pDocument = static_cast<Document*>(pJSDocument->GetEmbedObject());
225 if (!pDocument)
226 return;
227
228 pDocument->AttachDoc(pReaderDoc);
215 } 229 }
216 230
217 CPDFSDK_Document* CJS_Runtime::GetReaderDocument() { 231 CPDFSDK_Document* CJS_Runtime::GetReaderDocument() {
218 return m_pDocument; 232 return m_pDocument;
219 } 233 }
220 234
221 int CJS_Runtime::Execute(const CFX_WideString& script, CFX_WideString* info) { 235 int CJS_Runtime::ExecuteScript(const CFX_WideString& script,
236 CFX_WideString* info) {
222 FXJSErr error = {}; 237 FXJSErr error = {};
223 int nRet = FXJS_Execute(m_isolate, script, &error); 238 int nRet = Execute(script, &error);
224 if (nRet < 0) { 239 if (nRet < 0) {
225 info->Format(L"[ Line: %05d { %s } ] : %s", error.linnum - 1, error.srcline, 240 info->Format(L"[ Line: %05d { %s } ] : %s", error.linnum - 1, error.srcline,
226 error.message); 241 error.message);
227 } 242 }
228 return nRet; 243 return nRet;
229 } 244 }
230 245
231 bool CJS_Runtime::AddEventToSet(const FieldEvent& event) { 246 bool CJS_Runtime::AddEventToSet(const FieldEvent& event) {
232 return m_FieldEventSet.insert(event).second; 247 return m_FieldEventSet.insert(event).second;
233 } 248 }
234 249
235 void CJS_Runtime::RemoveEventFromSet(const FieldEvent& event) { 250 void CJS_Runtime::RemoveEventFromSet(const FieldEvent& event) {
236 m_FieldEventSet.erase(event); 251 m_FieldEventSet.erase(event);
237 } 252 }
238 253
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) { 254 void CJS_Runtime::AddObserver(Observer* observer) {
253 ASSERT(!pdfium::ContainsKey(m_observers, observer)); 255 ASSERT(!pdfium::ContainsKey(m_observers, observer));
254 m_observers.insert(observer); 256 m_observers.insert(observer);
255 } 257 }
256 258
257 void CJS_Runtime::RemoveObserver(Observer* observer) { 259 void CJS_Runtime::RemoveObserver(Observer* observer) {
258 ASSERT(pdfium::ContainsKey(m_observers, observer)); 260 ASSERT(pdfium::ContainsKey(m_observers, observer));
259 m_observers.erase(observer); 261 m_observers.erase(observer);
260 } 262 }
261 263
262 #ifdef PDF_ENABLE_XFA 264 #ifdef PDF_ENABLE_XFA
263 CFX_WideString ChangeObjName(const CFX_WideString& str) { 265 CFX_WideString ChangeObjName(const CFX_WideString& str) {
264 CFX_WideString sRet = str; 266 CFX_WideString sRet = str;
265 sRet.Replace(L"_", L"."); 267 sRet.Replace(L"_", L".");
266 return sRet; 268 return sRet;
267 } 269 }
268 FX_BOOL CJS_Runtime::GetValueByName(const CFX_ByteStringC& utf8Name, 270 FX_BOOL CJS_Runtime::GetValueByName(const CFX_ByteStringC& utf8Name,
269 CFXJSE_Value* pValue) { 271 CFXJSE_Value* pValue) {
270 const FX_CHAR* name = utf8Name.c_str(); 272 const FX_CHAR* name = utf8Name.c_str();
271 273
272 v8::Isolate::Scope isolate_scope(GetIsolate()); 274 v8::Isolate::Scope isolate_scope(GetIsolate());
273 v8::HandleScope handle_scope(GetIsolate()); 275 v8::HandleScope handle_scope(GetIsolate());
274 v8::Local<v8::Context> old_context = GetIsolate()->GetCurrentContext(); 276 v8::Local<v8::Context> old_context = GetIsolate()->GetCurrentContext();
275 v8::Local<v8::Context> context = 277 v8::Local<v8::Context> context = NewLocalContext();
276 v8::Local<v8::Context>::New(GetIsolate(), m_context);
277 v8::Context::Scope context_scope(context); 278 v8::Context::Scope context_scope(context);
278 279
279 // Caution: We're about to hand to XFA an object that in order to invoke 280 // 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 281 // 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 282 // 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. 283 // its own v8::Context which has not initialized the embedder data slot.
283 // Do so now. 284 // Do so now.
284 // TODO(tsepez): redesign PDF-side objects to not rely on v8::Context's 285 // 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. 286 // embedder data slots, and/or to always use the right context.
286 FXJS_SetEngineForV8Context(old_context, this); 287 CFXJS_Engine::SetForV8Context(old_context, this);
287 288
288 v8::Local<v8::Value> propvalue = 289 v8::Local<v8::Value> propvalue =
289 context->Global()->Get(v8::String::NewFromUtf8( 290 context->Global()->Get(v8::String::NewFromUtf8(
290 GetIsolate(), name, v8::String::kNormalString, utf8Name.GetLength())); 291 GetIsolate(), name, v8::String::kNormalString, utf8Name.GetLength()));
291 292
292 if (propvalue.IsEmpty()) { 293 if (propvalue.IsEmpty()) {
293 pValue->SetUndefined(); 294 pValue->SetUndefined();
294 return FALSE; 295 return FALSE;
295 } 296 }
296 pValue->ForceSetValue(propvalue); 297 pValue->ForceSetValue(propvalue);
297 return TRUE; 298 return TRUE;
298 } 299 }
299 FX_BOOL CJS_Runtime::SetValueByName(const CFX_ByteStringC& utf8Name, 300 FX_BOOL CJS_Runtime::SetValueByName(const CFX_ByteStringC& utf8Name,
300 CFXJSE_Value* pValue) { 301 CFXJSE_Value* pValue) {
301 if (utf8Name.IsEmpty() || !pValue) 302 if (utf8Name.IsEmpty() || !pValue)
302 return FALSE; 303 return FALSE;
303 const FX_CHAR* name = utf8Name.c_str(); 304 const FX_CHAR* name = utf8Name.c_str();
304 v8::Isolate* pIsolate = GetIsolate(); 305 v8::Isolate* pIsolate = GetIsolate();
305 v8::Isolate::Scope isolate_scope(pIsolate); 306 v8::Isolate::Scope isolate_scope(pIsolate);
306 v8::HandleScope handle_scope(pIsolate); 307 v8::HandleScope handle_scope(pIsolate);
307 v8::Local<v8::Context> context = 308 v8::Local<v8::Context> context = NewLocalContext();
308 v8::Local<v8::Context>::New(pIsolate, m_context);
309 v8::Context::Scope context_scope(context); 309 v8::Context::Scope context_scope(context);
310 310
311 // v8::Local<v8::Context> tmpCotext = 311 // v8::Local<v8::Context> tmpCotext =
312 // v8::Local<v8::Context>::New(GetIsolate(), m_context); 312 // v8::Local<v8::Context>::New(GetIsolate(), m_context);
313 v8::Local<v8::Value> propvalue = 313 v8::Local<v8::Value> propvalue =
314 v8::Local<v8::Value>::New(GetIsolate(), pValue->DirectGetValue()); 314 v8::Local<v8::Value>::New(GetIsolate(), pValue->DirectGetValue());
315 context->Global()->Set( 315 context->Global()->Set(
316 v8::String::NewFromUtf8(pIsolate, name, v8::String::kNormalString, 316 v8::String::NewFromUtf8(pIsolate, name, v8::String::kNormalString,
317 utf8Name.GetLength()), 317 utf8Name.GetLength()),
318 propvalue); 318 propvalue);
319 return TRUE; 319 return TRUE;
320 } 320 }
321 #endif 321 #endif
OLDNEW
« no previous file with comments | « fpdfsdk/javascript/cjs_runtime.h ('k') | fpdfsdk/javascript/color.cpp » ('j') | fxjs/fxjs_v8.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698