summaryrefslogtreecommitdiff
path: root/fpdfsdk/src
diff options
context:
space:
mode:
authorJochen Eisinger <jochen@chromium.org>2015-07-30 17:44:35 +0200
committerJochen Eisinger <jochen@chromium.org>2015-07-30 17:44:35 +0200
commit06b60021edacf7e4f2d1b1468a3aa898bab10301 (patch)
tree6c0177fefc0d839594abe81224fde3aae9951352 /fpdfsdk/src
parent4e57057c361897834b77b4c84b412f949427f974 (diff)
downloadpdfium-06b60021edacf7e4f2d1b1468a3aa898bab10301.tar.xz
Merge to XFA: Plumb in an externally created v8::Isolate
Origin Review URL: - https://codereview.chromium.org/1234053003 - https://codereview.chromium.org/1241863004 - https://codereview.chromium.org/1235303003 R=tsepez@chromium.org BUG= Review URL: https://codereview.chromium.org/1263963002 .
Diffstat (limited to 'fpdfsdk/src')
-rw-r--r--fpdfsdk/src/javascript/JS_Runtime.cpp18
-rw-r--r--fpdfsdk/src/jsapi/fxjs_v8.cpp33
2 files changed, 33 insertions, 18 deletions
diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp
index 346b642913..d68b268591 100644
--- a/fpdfsdk/src/javascript/JS_Runtime.cpp
+++ b/fpdfsdk/src/javascript/JS_Runtime.cpp
@@ -37,7 +37,11 @@ IFXJS_Runtime* CJS_RuntimeFactory::NewJSRuntime(CPDFDoc_Environ
{
if (!m_bInit)
{
- JS_Initial();
+ unsigned int embedderDataSlot = 0;
+ if (pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) {
+ embedderDataSlot = pApp->GetFormFillInfo()->m_pJsPlatform->m_v8EmbedderSlot;
+ }
+ JS_Initial(embedderDataSlot);
m_bInit = TRUE;
}
return new CJS_Runtime(pApp);
@@ -107,16 +111,22 @@ CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) :
m_pApp(pApp),
m_pDocument(NULL),
m_bBlocking(FALSE),
- m_pFieldEventPath(NULL)
+ m_pFieldEventPath(NULL),
+ m_isolate(NULL)
{
if (CPDFXFA_App::GetInstance()->GetJSERuntime()) {
+ // TODO(tsepez): CPDFXFA_App should also use the embedder provided isolate.
m_isolate = (v8::Isolate*)CPDFXFA_App::GetInstance()->GetJSERuntime();
- } else {
+ } else if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) {
+ m_isolate = reinterpret_cast<v8::Isolate*>(m_pApp->GetFormFillInfo()->m_pJsPlatform->m_isolate);
+ }
+ if (!m_isolate) {
m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator());
+
v8::Isolate::CreateParams params;
params.array_buffer_allocator = m_pArrayBufferAllocator.get();
m_isolate = v8::Isolate::New(params);
- }
+ }
v8::Isolate* isolate = m_isolate;
v8::Isolate::Scope isolate_scope(isolate);
diff --git a/fpdfsdk/src/jsapi/fxjs_v8.cpp b/fpdfsdk/src/jsapi/fxjs_v8.cpp
index 24d7bcc50a..c3b1b925fa 100644
--- a/fpdfsdk/src/jsapi/fxjs_v8.cpp
+++ b/fpdfsdk/src/jsapi/fxjs_v8.cpp
@@ -26,6 +26,7 @@ static double GetNan()
{
return *(double*)g_nan;
}
+static unsigned int g_embedderDataSlot = 0u;
class CJS_PrivateData
@@ -78,11 +79,11 @@ int JS_DefineObj(IJS_Runtime* pJSRuntime, const wchar_t* sObjName, FXJSOBJTYPE e
v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray)
{
pArray = FX_NEW CFX_PtrArray();
- isolate->SetData(1, pArray);
+ isolate->SetData(g_embedderDataSlot, pArray);
}
CJS_ObjDefintion* pObjDef = FX_NEW CJS_ObjDefintion(isolate, sObjName, eObjType, pConstructor, pDestructor);
pArray->Add(pObjDef);
@@ -98,7 +99,7 @@ int JS_DefineObjMethod(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* s
CFX_WideString ws = CFX_WideString(sMethodName);
CFX_ByteString bsMethodName = ws.UTF8Encode();
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return 0;
if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0;
@@ -118,7 +119,7 @@ int JS_DefineObjProperty(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t*
CFX_WideString ws = CFX_WideString(sPropName);
CFX_ByteString bsPropertyName = ws.UTF8Encode();
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return 0;
if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0;
@@ -135,7 +136,7 @@ int JS_DefineObjAllProperties(IJS_Runtime* pJSRuntime, int nObjDefnID, v8::Named
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return 0;
if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0;
@@ -152,7 +153,7 @@ int JS_DefineObjConst(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sC
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return 0;
CFX_WideString ws = CFX_WideString(sConstName);
@@ -172,7 +173,7 @@ static v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate(IJS_Runtime* pJS
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
ASSERT(pArray != NULL);
for(int i=0; i<pArray->GetSize(); i++)
{
@@ -245,9 +246,10 @@ void JS_InitialRuntime(IJS_Runtime* pJSRuntime,IFXJS_Runtime* pFXRuntime, IFXJS_
//v8::Local<External> ptr = External::New(isolate, pFXRuntime);
//v8Context->SetEmbedderData(1, ptr);
+ // TODO(tsepez): Don't use more than one embedder data slot.
isolate->SetData(2, pFXRuntime);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return;
for(int i=0; i<pArray->GetSize(); i++)
@@ -291,7 +293,7 @@ void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Global<v8::Context>& v8Persi
v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return ;
for(int i=0; i<pArray->GetSize(); i++)
@@ -308,11 +310,14 @@ void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Global<v8::Context>& v8Persi
}
delete pArray;
isolate->SetData(1,NULL);
+ isolate->SetData(g_embedderDataSlot,NULL);
+ // TODO(tsepez): Don't use more than one embedder data slot.
isolate->SetData(2,NULL);
}
-void JS_Initial()
+void JS_Initial(unsigned int embedderDataSlot)
{
+ g_embedderDataSlot = embedderDataSlot;
}
void JS_Release()
{
@@ -374,7 +379,7 @@ v8::Local<v8::Object> JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime, IFXJS_Context*
return v8::Local<v8::Object>();
}
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return v8::Local<v8::Object>();
@@ -399,7 +404,7 @@ v8::Local<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID)
v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
v8::Isolate::Scope isolate_scope(isolate);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return v8::Local<v8::Object>();
if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return v8::Local<v8::Object>();
@@ -418,7 +423,7 @@ v8::Local<v8::Object> JS_GetThisObj(IJS_Runtime * pJSRuntime)
v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
v8::Isolate::Scope isolate_scope(isolate);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return v8::Local<v8::Object>();
v8::Local<v8::Context> context = isolate->GetCurrentContext();
@@ -447,7 +452,7 @@ int JS_GetObjDefnID(IJS_Runtime * pJSRuntime, const wchar_t* pObjName)
v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
v8::Isolate::Scope isolate_scope(isolate);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return -1;
for(int i=0; i<pArray->GetSize(); i++)