From cc8b4d8763151f51c9fe71ce9b64b2a0d7ddcc88 Mon Sep 17 00:00:00 2001 From: Jochen Eisinger Date: Thu, 16 Jul 2015 09:37:48 +0200 Subject: Make v8 embedder data slot configurable Chrome already uses 0 and 1. BUG=none R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1235303003 . --- fpdfsdk/src/jsapi/fxjs_v8.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'fpdfsdk/src/jsapi') 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& _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; iGetSize(); i++) { @@ -246,7 +247,7 @@ void JS_InitialRuntime(IJS_Runtime* pJSRuntime,IFXJS_Runtime* pFXRuntime, IFXJS_ v8::Local 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; iGetSize(); i++) @@ -290,7 +291,7 @@ void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Global& v8Persi v8::Local context = v8::Local::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; iGetSize(); i++) @@ -306,11 +307,12 @@ void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Global& 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 JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime, IFXJS_Context* return v8::Local(); } - CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0); + CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(g_embedderDataSlot); if(!pArray) return v8::Local(); @@ -398,7 +400,7 @@ v8::Local 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(); if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return v8::Local(); @@ -417,7 +419,7 @@ v8::Local 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::Local 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; iGetSize(); i++) -- cgit v1.2.3