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

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

Issue 1395713002: Merge to XFA: Rename IFXJS_Runtime and IFXJS_Context to IJS_. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 2 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/src/javascript/util.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 "../../../core/include/fxcrt/fx_basic.h" 7 #include "../../../core/include/fxcrt/fx_basic.h"
8 #include "../../include/jsapi/fxjs_v8.h" 8 #include "../../include/jsapi/fxjs_v8.h"
9 9
10 const wchar_t kFXJSValueNameString[] = L"string"; 10 const wchar_t kFXJSValueNameString[] = L"string";
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 v8::Isolate::Scope isolate_scope(pIsolate); 253 v8::Isolate::Scope isolate_scope(pIsolate);
254 v8::HandleScope handle_scope(pIsolate); 254 v8::HandleScope handle_scope(pIsolate);
255 CFX_ByteString bsConst = CFX_WideString(sConstName).UTF8Encode(); 255 CFX_ByteString bsConst = CFX_WideString(sConstName).UTF8Encode();
256 GetGlobalObjectTemplate(pIsolate)->Set( 256 GetGlobalObjectTemplate(pIsolate)->Set(
257 v8::String::NewFromUtf8(pIsolate, bsConst.c_str(), 257 v8::String::NewFromUtf8(pIsolate, bsConst.c_str(),
258 v8::NewStringType::kNormal).ToLocalChecked(), 258 v8::NewStringType::kNormal).ToLocalChecked(),
259 pDefault, v8::ReadOnly); 259 pDefault, v8::ReadOnly);
260 } 260 }
261 261
262 void FXJS_InitializeRuntime(v8::Isolate* pIsolate, 262 void FXJS_InitializeRuntime(v8::Isolate* pIsolate,
263 IFXJS_Runtime* pFXRuntime, 263 IJS_Runtime* pFXRuntime,
264 IFXJS_Context* context, 264 IJS_Context* context,
265 v8::Global<v8::Context>& v8PersistentContext) { 265 v8::Global<v8::Context>& v8PersistentContext) {
266 v8::Isolate::Scope isolate_scope(pIsolate); 266 v8::Isolate::Scope isolate_scope(pIsolate);
267 v8::Locker locker(pIsolate); 267 v8::Locker locker(pIsolate);
268 v8::HandleScope handle_scope(pIsolate); 268 v8::HandleScope handle_scope(pIsolate);
269 v8::Local<v8::Context> v8Context = 269 v8::Local<v8::Context> v8Context =
270 v8::Context::New(pIsolate, NULL, GetGlobalObjectTemplate(pIsolate)); 270 v8::Context::New(pIsolate, NULL, GetGlobalObjectTemplate(pIsolate));
271 v8::Context::Scope context_scope(v8Context); 271 v8::Context::Scope context_scope(v8Context);
272 272
273 FXJS_PerIsolateData::SetUp(pIsolate); 273 FXJS_PerIsolateData::SetUp(pIsolate);
274 v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pFXRuntime); 274 v8Context->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pFXRuntime);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 pObjDef->m_pDestructor(pObj); 329 pObjDef->m_pDestructor(pObj);
330 FXJS_FreePrivate(pObj); 330 FXJS_FreePrivate(pObj);
331 } 331 }
332 delete pObjDef; 332 delete pObjDef;
333 } 333 }
334 334
335 pIsolate->SetData(g_embedderDataSlot, nullptr); 335 pIsolate->SetData(g_embedderDataSlot, nullptr);
336 delete pData; 336 delete pData;
337 } 337 }
338 338
339 IFXJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate) { 339 IJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate) {
340 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); 340 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
341 return static_cast<IFXJS_Runtime*>( 341 return static_cast<IJS_Runtime*>(
342 context->GetAlignedPointerFromEmbedderData(kPerContextDataIndex)); 342 context->GetAlignedPointerFromEmbedderData(kPerContextDataIndex));
343 } 343 }
344 344
345 int FXJS_Execute(v8::Isolate* pIsolate, 345 int FXJS_Execute(v8::Isolate* pIsolate,
346 IFXJS_Context* pJSContext, 346 IJS_Context* pJSContext,
347 const wchar_t* script, 347 const wchar_t* script,
348 long length, 348 long length,
349 FXJSErr* pError) { 349 FXJSErr* pError) {
350 v8::Isolate::Scope isolate_scope(pIsolate); 350 v8::Isolate::Scope isolate_scope(pIsolate);
351 v8::TryCatch try_catch(pIsolate); 351 v8::TryCatch try_catch(pIsolate);
352 CFX_ByteString bsScript = CFX_WideString(script).UTF8Encode(); 352 CFX_ByteString bsScript = CFX_WideString(script).UTF8Encode();
353 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); 353 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
354 v8::Local<v8::Script> compiled_script; 354 v8::Local<v8::Script> compiled_script;
355 if (!v8::Script::Compile( 355 if (!v8::Script::Compile(
356 context, v8::String::NewFromUtf8( 356 context, v8::String::NewFromUtf8(
357 pIsolate, bsScript.c_str(), v8::NewStringType::kNormal, 357 pIsolate, bsScript.c_str(), v8::NewStringType::kNormal,
358 bsScript.GetLength()).ToLocalChecked()) 358 bsScript.GetLength()).ToLocalChecked())
359 .ToLocal(&compiled_script)) { 359 .ToLocal(&compiled_script)) {
360 v8::String::Utf8Value error(try_catch.Exception()); 360 v8::String::Utf8Value error(try_catch.Exception());
361 // TODO(tsepez): return error via pError->message. 361 // TODO(tsepez): return error via pError->message.
362 return -1; 362 return -1;
363 } 363 }
364 364
365 v8::Local<v8::Value> result; 365 v8::Local<v8::Value> result;
366 if (!compiled_script->Run(context).ToLocal(&result)) { 366 if (!compiled_script->Run(context).ToLocal(&result)) {
367 v8::String::Utf8Value error(try_catch.Exception()); 367 v8::String::Utf8Value error(try_catch.Exception());
368 // TODO(tsepez): return error via pError->message. 368 // TODO(tsepez): return error via pError->message.
369 return -1; 369 return -1;
370 } 370 }
371 return 0; 371 return 0;
372 } 372 }
373 373
374 v8::Local<v8::Object> FXJS_NewFxDynamicObj(v8::Isolate* pIsolate, 374 v8::Local<v8::Object> FXJS_NewFxDynamicObj(v8::Isolate* pIsolate,
375 IFXJS_Context* pJSContext, 375 IJS_Context* pJSContext,
376 int nObjDefnID) { 376 int nObjDefnID) {
377 v8::Isolate::Scope isolate_scope(pIsolate); 377 v8::Isolate::Scope isolate_scope(pIsolate);
378 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); 378 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
379 if (nObjDefnID == -1) { 379 if (nObjDefnID == -1) {
380 v8::Local<v8::ObjectTemplate> objTempl = v8::ObjectTemplate::New(pIsolate); 380 v8::Local<v8::ObjectTemplate> objTempl = v8::ObjectTemplate::New(pIsolate);
381 v8::Local<v8::Object> obj; 381 v8::Local<v8::Object> obj;
382 if (!objTempl->NewInstance(context).ToLocal(&obj)) 382 if (!objTempl->NewInstance(context).ToLocal(&obj))
383 return v8::Local<v8::Object>(); 383 return v8::Local<v8::Object>();
384 return obj; 384 return obj;
385 } 385 }
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 return v8::Local<v8::Array>(); 733 return v8::Local<v8::Array>();
734 v8::Local<v8::Context> context = pIsolate->GetCurrentContext(); 734 v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
735 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked()); 735 return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked());
736 } 736 }
737 737
738 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) { 738 void FXJS_ValueCopy(v8::Local<v8::Value>& pTo, v8::Local<v8::Value> pFrom) {
739 pTo = pFrom; 739 pTo = pFrom;
740 } 740 }
741 741
742 742
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/util.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698