summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorJochen Eisinger <jochen@chromium.org>2015-07-16 09:37:48 +0200
committerJochen Eisinger <jochen@chromium.org>2015-07-16 09:37:48 +0200
commitcc8b4d8763151f51c9fe71ce9b64b2a0d7ddcc88 (patch)
treefbb16c6ff6d7386dd4c532956d54232a9851a75a /fpdfsdk
parent281d1d293dab54cadd214e5a1c098583fbbe0788 (diff)
downloadpdfium-cc8b4d8763151f51c9fe71ce9b64b2a0d7ddcc88.tar.xz
Make v8 embedder data slot configurablechromium/2460chromium/2459chromium/2458
Chrome already uses 0 and 1. BUG=none R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1235303003 .
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/include/jsapi/fxjs_v8.h2
-rw-r--r--fpdfsdk/src/javascript/JS_Runtime.cpp6
-rw-r--r--fpdfsdk/src/jsapi/fxjs_v8.cpp32
3 files changed, 23 insertions, 17 deletions
diff --git a/fpdfsdk/include/jsapi/fxjs_v8.h b/fpdfsdk/include/jsapi/fxjs_v8.h
index f5d699287d..b4dac71561 100644
--- a/fpdfsdk/include/jsapi/fxjs_v8.h
+++ b/fpdfsdk/include/jsapi/fxjs_v8.h
@@ -63,7 +63,7 @@ int JS_DefineGlobalConst(IJS_Runtime* pJSRuntime, const wchar_t* sConstNa
void JS_InitialRuntime(IJS_Runtime* pJSRuntime,IFXJS_Runtime* pFXRuntime, IFXJS_Context* context, v8::Global<v8::Context>& v8PersistentContext);
void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Global<v8::Context>& v8PersistentContext);
-void JS_Initial();
+void JS_Initial(unsigned int embedderDataSlot);
void JS_Release();
int JS_Parse(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t* script, long length, FXJSErr* perror);
int JS_Execute(IJS_Runtime* pJSRuntime, IFXJS_Context* pJSContext, const wchar_t* script, long length, FXJSErr* perror);
diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp
index b26f5a2e62..f21819ac17 100644
--- a/fpdfsdk/src/javascript/JS_Runtime.cpp
+++ b/fpdfsdk/src/javascript/JS_Runtime.cpp
@@ -35,7 +35,11 @@ IFXJS_Runtime* CJS_RuntimeFactory::NewJSRuntime(CPDFDoc_Environment* pApp)
{
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);
diff --git a/fpdfsdk/src/jsapi/fxjs_v8.cpp b/fpdfsdk/src/jsapi/fxjs_v8.cpp
index 7adfc2696d..feed779f17 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
@@ -79,11 +80,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(0);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray)
{
pArray = new CFX_PtrArray();
- isolate->SetData(0, pArray);
+ isolate->SetData(g_embedderDataSlot, pArray);
}
CJS_ObjDefintion* pObjDef = new CJS_ObjDefintion(isolate, sObjName, eObjType, pConstructor, pDestructor, bApplyNew);
pArray->Add(pObjDef);
@@ -99,7 +100,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(0);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return 0;
if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0;
@@ -119,7 +120,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(0);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return 0;
if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0;
@@ -136,7 +137,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(0);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return 0;
if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0;
@@ -153,7 +154,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(0);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return 0;
CFX_WideString ws = CFX_WideString(sConstName);
@@ -173,7 +174,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(0);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
ASSERT(pArray != NULL);
for(int i=0; i<pArray->GetSize(); i++)
{
@@ -246,7 +247,7 @@ void JS_InitialRuntime(IJS_Runtime* pJSRuntime,IFXJS_Runtime* pFXRuntime, IFXJS_
v8::Local<v8::External> ptr = v8::External::New(isolate, pFXRuntime);
v8Context->SetEmbedderData(1, ptr);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return;
for(int i=0; i<pArray->GetSize(); i++)
@@ -290,7 +291,7 @@ void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Global<v8::Context>& v8Persi
v8::Local<v8::Context> context = v8::Local<v8::Context>::New(isolate, v8PersistentContext);
v8::Context::Scope context_scope(context);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return ;
for(int i=0; i<pArray->GetSize(); i++)
@@ -306,11 +307,12 @@ void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Global<v8::Context>& v8Persi
delete pObjDef;
}
delete pArray;
- isolate->SetData(0,NULL);
+ isolate->SetData(g_embedderDataSlot,NULL);
}
-void JS_Initial()
+void JS_Initial(unsigned int embedderDataSlot)
{
+ g_embedderDataSlot = embedderDataSlot;
}
void JS_Release()
{
@@ -372,7 +374,7 @@ v8::Local<v8::Object> JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime, IFXJS_Context*
return v8::Local<v8::Object>();
}
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return v8::Local<v8::Object>();
@@ -398,7 +400,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(0);
+ 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>();
@@ -417,7 +419,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(0);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return v8::Local<v8::Object>();
v8::Local<v8::Context> context = isolate->GetCurrentContext();
@@ -446,7 +448,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(0);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot);
if(!pArray) return -1;
for(int i=0; i<pArray->GetSize(); i++)