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

Side by Side Diff: fpdfsdk/src/jsapi/fxjs_v8.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_Runtime.cpp ('k') | no next file » | 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 "../../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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 ++g_isolate_ref_count; 280 ++g_isolate_ref_count;
281 281
282 v8::Isolate::Scope isolate_scope(pIsolate); 282 v8::Isolate::Scope isolate_scope(pIsolate);
283 v8::Locker locker(pIsolate); 283 v8::Locker locker(pIsolate);
284 v8::HandleScope handle_scope(pIsolate); 284 v8::HandleScope handle_scope(pIsolate);
285 v8::Local<v8::Context> v8Context = 285 v8::Local<v8::Context> v8Context =
286 v8::Context::New(pIsolate, NULL, GetGlobalObjectTemplate(pIsolate)); 286 v8::Context::New(pIsolate, NULL, GetGlobalObjectTemplate(pIsolate));
287 v8::Context::Scope context_scope(v8Context); 287 v8::Context::Scope context_scope(v8Context);
288 288
289 FXJS_PerIsolateData::SetUp(pIsolate); 289 FXJS_PerIsolateData::SetUp(pIsolate);
290 v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pIRuntime); 290 FXJS_SetRuntimeForV8Context(v8Context, pIRuntime);
291 291
292 int maxID = CFXJS_ObjDefinition::MaxID(pIsolate); 292 int maxID = CFXJS_ObjDefinition::MaxID(pIsolate);
293 for (int i = 0; i < maxID; ++i) { 293 for (int i = 0; i < maxID; ++i) {
294 CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i); 294 CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i);
295 CFX_ByteString bs = CFX_WideString(pObjDef->m_ObjName).UTF8Encode(); 295 CFX_ByteString bs = CFX_WideString(pObjDef->m_ObjName).UTF8Encode();
296 v8::Local<v8::String> m_ObjName = 296 v8::Local<v8::String> m_ObjName =
297 v8::String::NewFromUtf8(pIsolate, bs.c_str(), 297 v8::String::NewFromUtf8(pIsolate, bs.c_str(),
298 v8::NewStringType::kNormal, 298 v8::NewStringType::kNormal,
299 bs.GetLength()).ToLocalChecked(); 299 bs.GetLength()).ToLocalChecked();
300 300
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 pObjDef->m_pDestructor(pObj); 354 pObjDef->m_pDestructor(pObj);
355 FXJS_FreePrivate(pObj); 355 FXJS_FreePrivate(pObj);
356 } 356 }
357 delete pObjDef; 357 delete pObjDef;
358 } 358 }
359 359
360 pIsolate->SetData(g_embedderDataSlot, nullptr); 360 pIsolate->SetData(g_embedderDataSlot, nullptr);
361 delete pData; 361 delete pData;
362 } 362 }
363 363
364 IJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate) { 364 void FXJS_SetRuntimeForV8Context(v8::Local<v8::Context> v8Context,
365 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); 365 IJS_Runtime* pIRuntime) {
366 v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pIRuntime);
367 }
368
369 IJS_Runtime* FXJS_GetRuntimeFromV8Context(v8::Local<v8::Context> v8Context) {
366 return static_cast<IJS_Runtime*>( 370 return static_cast<IJS_Runtime*>(
367 context->GetAlignedPointerFromEmbedderData(kPerContextDataIndex)); 371 v8Context->GetAlignedPointerFromEmbedderData(kPerContextDataIndex));
368 } 372 }
369 373
370 int FXJS_Execute(v8::Isolate* pIsolate, 374 int FXJS_Execute(v8::Isolate* pIsolate,
371 IJS_Context* pJSContext, 375 IJS_Context* pJSContext,
372 const wchar_t* script, 376 const wchar_t* script,
373 FXJSErr* pError) { 377 FXJSErr* pError) {
374 v8::Isolate::Scope isolate_scope(pIsolate); 378 v8::Isolate::Scope isolate_scope(pIsolate);
375 v8::TryCatch try_catch(pIsolate); 379 v8::TryCatch try_catch(pIsolate);
376 CFX_ByteString bsScript = CFX_WideString(script).UTF8Encode(); 380 CFX_ByteString bsScript = CFX_WideString(script).UTF8Encode();
377 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); 381 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 return v8::Local<v8::Array>(); 753 return v8::Local<v8::Array>();
750 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); 754 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
751 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); 755 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked());
752 } 756 }
753 757
754 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) { 758 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) {
755 pTo = pFrom; 759 pTo = pFrom;
756 } 760 }
757 761
758 762
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/JS_Runtime.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698