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

Side by Side Diff: fpdfsdk/src/javascript/JS_Runtime.cpp

Issue 1412103010: Segv when PDF-side JS object property getter invoked from XFA. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Comment about using right context. Created 5 years, 1 month 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/src/javascript/JS_Define.h ('k') | fpdfsdk/src/jsapi/fxjs_v8.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 "JS_Runtime.h" 7 #include "JS_Runtime.h"
8 8
9 #include "../../../xfa/src/fxjse/src/value.h" 9 #include "../../../xfa/src/fxjse/src/value.h"
10 #include "../../include/fpdfxfa/fpdfxfa_app.h" 10 #include "../../include/fpdfxfa/fpdfxfa_app.h"
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 return sRet; 238 return sRet;
239 } 239 }
240 FX_BOOL CJS_Runtime::GetHValueByName(const CFX_ByteStringC& utf8Name, 240 FX_BOOL CJS_Runtime::GetHValueByName(const CFX_ByteStringC& utf8Name,
241 FXJSE_HVALUE hValue) { 241 FXJSE_HVALUE hValue) {
242 #ifdef PDF_ENABLE_XFA 242 #ifdef PDF_ENABLE_XFA
243 const FX_CHAR* name = utf8Name.GetCStr(); 243 const FX_CHAR* name = utf8Name.GetCStr();
244 244
245 v8::Locker lock(GetIsolate()); 245 v8::Locker lock(GetIsolate());
246 v8::Isolate::Scope isolate_scope(GetIsolate()); 246 v8::Isolate::Scope isolate_scope(GetIsolate());
247 v8::HandleScope handle_scope(GetIsolate()); 247 v8::HandleScope handle_scope(GetIsolate());
248 v8::Local<v8::Context> old_context = GetIsolate()->GetCurrentContext();
248 v8::Local<v8::Context> context = 249 v8::Local<v8::Context> context =
249 v8::Local<v8::Context>::New(GetIsolate(), m_context); 250 v8::Local<v8::Context>::New(GetIsolate(), m_context);
250 v8::Context::Scope context_scope(context); 251 v8::Context::Scope context_scope(context);
251 252
252 // v8::Local<v8::Context> tmpCotext = 253 // Caution: We're about to hand to XFA an object that in order to invoke
253 // v8::Local<v8::Context>::New(GetIsolate(), m_context); 254 // methods will require that the current v8::Context always has a pointer
255 // to a CJS_Runtime in its embedder data slot. Unfortunately, XFA creates
256 // its own v8::Context which has not initialized the embedder data slot.
257 // Do so now.
258 // TODO(tsepez): redesign PDF-side objects to not rely on v8::Context's
259 // embedder data slots, and/or to always use the right context.
260 FXJS_SetRuntimeForV8Context(old_context, this);
261
254 v8::Local<v8::Value> propvalue = 262 v8::Local<v8::Value> propvalue =
255 context->Global()->Get(v8::String::NewFromUtf8( 263 context->Global()->Get(v8::String::NewFromUtf8(
256 GetIsolate(), name, v8::String::kNormalString, utf8Name.GetLength())); 264 GetIsolate(), name, v8::String::kNormalString, utf8Name.GetLength()));
257 265
258 if (propvalue.IsEmpty()) { 266 if (propvalue.IsEmpty()) {
259 FXJSE_Value_SetUndefined(hValue); 267 FXJSE_Value_SetUndefined(hValue);
260 return FALSE; 268 return FALSE;
261 } 269 }
262 ((CFXJSE_Value*)hValue)->ForceSetValue(propvalue); 270 ((CFXJSE_Value*)hValue)->ForceSetValue(propvalue);
263 #endif 271 #endif
(...skipping 28 matching lines...) Expand all
292 300
293 void CJS_Runtime::AddObserver(Observer* observer) { 301 void CJS_Runtime::AddObserver(Observer* observer) {
294 ASSERT(m_observers.find(observer) == m_observers.end()); 302 ASSERT(m_observers.find(observer) == m_observers.end());
295 m_observers.insert(observer); 303 m_observers.insert(observer);
296 } 304 }
297 305
298 void CJS_Runtime::RemoveObserver(Observer* observer) { 306 void CJS_Runtime::RemoveObserver(Observer* observer) {
299 ASSERT(m_observers.find(observer) != m_observers.end()); 307 ASSERT(m_observers.find(observer) != m_observers.end());
300 m_observers.erase(observer); 308 m_observers.erase(observer);
301 } 309 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/JS_Define.h ('k') | fpdfsdk/src/jsapi/fxjs_v8.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698