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

Side by Side Diff: fpdfsdk/src/jsapi/fxjs_v8.cpp

Issue 1463973002: Mising JS refactoring in XFA. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: 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') | 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 "fpdfsdk/include/jsapi/fxjs_v8.h" 7 #include "fpdfsdk/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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 ++g_isolate_ref_count; 281 ++g_isolate_ref_count;
282 282
283 v8::Isolate::Scope isolate_scope(pIsolate); 283 v8::Isolate::Scope isolate_scope(pIsolate);
284 v8::Locker locker(pIsolate); 284 v8::Locker locker(pIsolate);
285 v8::HandleScope handle_scope(pIsolate); 285 v8::HandleScope handle_scope(pIsolate);
286 v8::Local<v8::Context> v8Context = 286 v8::Local<v8::Context> v8Context =
287 v8::Context::New(pIsolate, NULL, GetGlobalObjectTemplate(pIsolate)); 287 v8::Context::New(pIsolate, NULL, GetGlobalObjectTemplate(pIsolate));
288 v8::Context::Scope context_scope(v8Context); 288 v8::Context::Scope context_scope(v8Context);
289 289
290 FXJS_PerIsolateData::SetUp(pIsolate); 290 FXJS_PerIsolateData::SetUp(pIsolate);
291 FXJS_SetRuntimeForV8Context(v8Context, pIRuntime); 291 v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pIRuntime);
292 292
293 int maxID = CFXJS_ObjDefinition::MaxID(pIsolate); 293 int maxID = CFXJS_ObjDefinition::MaxID(pIsolate);
294 pStaticObjects->resize(maxID + 1); 294 pStaticObjects->resize(maxID + 1);
295 for (int i = 0; i < maxID; ++i) { 295 for (int i = 0; i < maxID; ++i) {
296 CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i); 296 CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i);
297 if (pObjDef->m_ObjType == FXJSOBJTYPE_GLOBAL) { 297 if (pObjDef->m_ObjType == FXJSOBJTYPE_GLOBAL) {
298 v8Context->Global() 298 v8Context->Global()
299 ->GetPrototype() 299 ->GetPrototype()
300 ->ToObject(v8Context) 300 ->ToObject(v8Context)
301 .ToLocalChecked() 301 .ToLocalChecked()
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 delete pObjDef; 359 delete pObjDef;
360 } 360 }
361 361
362 if (pIsolate == g_isolate && --g_isolate_ref_count > 0) 362 if (pIsolate == g_isolate && --g_isolate_ref_count > 0)
363 return; 363 return;
364 364
365 pIsolate->SetData(g_embedderDataSlot, nullptr); 365 pIsolate->SetData(g_embedderDataSlot, nullptr);
366 delete pData; 366 delete pData;
367 } 367 }
368 368
369 IJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate) {
370 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
371 return static_cast<IJS_Runtime*>(
372 context->GetAlignedPointerFromEmbedderData(kPerContextDataIndex));
373 }
374
369 void FXJS_SetRuntimeForV8Context(v8::Local<v8::Context> v8Context, 375 void FXJS_SetRuntimeForV8Context(v8::Local<v8::Context> v8Context,
370 IJS_Runtime* pIRuntime) { 376 IJS_Runtime* pIRuntime) {
371 v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pIRuntime); 377 v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pIRuntime);
372 } 378 }
373 379
374 IJS_Runtime* FXJS_GetRuntimeFromV8Context(v8::Local<v8::Context> v8Context) {
375 return static_cast<IJS_Runtime*>(
376 v8Context->GetAlignedPointerFromEmbedderData(kPerContextDataIndex));
377 }
378
379 int FXJS_Execute(v8::Isolate* pIsolate, 380 int FXJS_Execute(v8::Isolate* pIsolate,
380 IJS_Context* pJSContext, 381 IJS_Context* pJSContext,
381 const wchar_t* script, 382 const wchar_t* script,
382 FXJSErr* pError) { 383 FXJSErr* pError) {
383 v8::Isolate::Scope isolate_scope(pIsolate); 384 v8::Isolate::Scope isolate_scope(pIsolate);
384 v8::TryCatch try_catch(pIsolate); 385 v8::TryCatch try_catch(pIsolate);
385 CFX_ByteString bsScript = CFX_WideString(script).UTF8Encode(); 386 CFX_ByteString bsScript = CFX_WideString(script).UTF8Encode();
386 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); 387 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
387 v8::Local<v8::Script> compiled_script; 388 v8::Local<v8::Script> compiled_script;
388 if (!v8::Script::Compile( 389 if (!v8::Script::Compile(
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 return v8::Local<v8::Array>(); 759 return v8::Local<v8::Array>();
759 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); 760 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
760 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); 761 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked());
761 } 762 }
762 763
763 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) { 764 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) {
764 pTo = pFrom; 765 pTo = pFrom;
765 } 766 }
766 767
767 768
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/JS_Define.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698