Index: fpdfsdk/jsapi/fxjs_v8.cpp |
diff --git a/fpdfsdk/jsapi/fxjs_v8.cpp b/fpdfsdk/jsapi/fxjs_v8.cpp |
index 790d10b60201793649de1ccd3579e1496c7aa4df..f740c443cd9658f8f7f971e1f94129daf4f62e12 100644 |
--- a/fpdfsdk/jsapi/fxjs_v8.cpp |
+++ b/fpdfsdk/jsapi/fxjs_v8.cpp |
@@ -24,7 +24,6 @@ const wchar_t kFXJSValueNameUndefined[] = L"undefined"; |
// embedders of PDFIum). The value we want to use is: |
// kPerContextDataStartIndex + kEmbedderPDFium, which is 3. |
static const unsigned int kPerContextDataIndex = 3u; |
-static unsigned int g_embedderDataSlot = 1u; |
static v8::Isolate* g_isolate = nullptr; |
static size_t g_isolate_ref_count = 0; |
static FXJS_ArrayBufferAllocator* g_arrayBufferAllocator = nullptr; |
@@ -39,66 +38,6 @@ class CFXJS_PerObjectData { |
void* m_pPrivate; |
}; |
-class CFXJS_ObjDefinition { |
- public: |
- static int MaxID(v8::Isolate* pIsolate) { |
- return FXJS_PerIsolateData::Get(pIsolate)->m_ObjectDefnArray.size(); |
- } |
- |
- static CFXJS_ObjDefinition* ForID(v8::Isolate* pIsolate, int id) { |
- // Note: GetAt() halts if out-of-range even in release builds. |
- return FXJS_PerIsolateData::Get(pIsolate)->m_ObjectDefnArray[id]; |
- } |
- |
- CFXJS_ObjDefinition(v8::Isolate* isolate, |
- const wchar_t* sObjName, |
- FXJSOBJTYPE eObjType, |
- FXJS_CONSTRUCTOR pConstructor, |
- FXJS_DESTRUCTOR pDestructor) |
- : m_ObjName(sObjName), |
- m_ObjType(eObjType), |
- m_pConstructor(pConstructor), |
- m_pDestructor(pDestructor), |
- m_pIsolate(isolate) { |
- v8::Isolate::Scope isolate_scope(isolate); |
- v8::HandleScope handle_scope(isolate); |
- |
- v8::Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate); |
- fun->InstanceTemplate()->SetInternalFieldCount(2); |
- m_FunctionTemplate.Reset(isolate, fun); |
- |
- v8::Local<v8::Signature> sig = v8::Signature::New(isolate, fun); |
- m_Signature.Reset(isolate, sig); |
- } |
- |
- int AssignID() { |
- FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(m_pIsolate); |
- pData->m_ObjectDefnArray.push_back(this); |
- return pData->m_ObjectDefnArray.size() - 1; |
- } |
- |
- v8::Local<v8::ObjectTemplate> GetInstanceTemplate() { |
- v8::EscapableHandleScope scope(m_pIsolate); |
- v8::Local<v8::FunctionTemplate> function = |
- m_FunctionTemplate.Get(m_pIsolate); |
- return scope.Escape(function->InstanceTemplate()); |
- } |
- |
- v8::Local<v8::Signature> GetSignature() { |
- v8::EscapableHandleScope scope(m_pIsolate); |
- return scope.Escape(m_Signature.Get(m_pIsolate)); |
- } |
- |
- const wchar_t* const m_ObjName; |
- const FXJSOBJTYPE m_ObjType; |
- const FXJS_CONSTRUCTOR m_pConstructor; |
- const FXJS_DESTRUCTOR m_pDestructor; |
- |
- v8::Isolate* m_pIsolate; |
- v8::Global<v8::FunctionTemplate> m_FunctionTemplate; |
- v8::Global<v8::Signature> m_Signature; |
-}; |
- |
static v8::Local<v8::ObjectTemplate> GetGlobalObjectTemplate( |
v8::Isolate* pIsolate) { |
int maxID = CFXJS_ObjDefinition::MaxID(pIsolate); |
@@ -154,11 +93,11 @@ V8TemplateMapTraits::MapType* V8TemplateMapTraits::MapFromWeakCallbackInfo( |
void FXJS_Initialize(unsigned int embedderDataSlot, v8::Isolate* pIsolate) { |
if (g_isolate) { |
- ASSERT(g_embedderDataSlot == embedderDataSlot); |
+ ASSERT(FXJS_PerIsolateData::EmbedderDataSlot() == embedderDataSlot); |
ASSERT(g_isolate == pIsolate); |
return; |
} |
- g_embedderDataSlot = embedderDataSlot; |
+ FXJS_PerIsolateData::SetEmbedderDataSlot(embedderDataSlot); |
g_isolate = pIsolate; |
} |
@@ -190,18 +129,6 @@ size_t FXJS_GlobalIsolateRefCount() { |
return g_isolate_ref_count; |
} |
-// static |
-void FXJS_PerIsolateData::SetUp(v8::Isolate* pIsolate) { |
- if (!pIsolate->GetData(g_embedderDataSlot)) |
- pIsolate->SetData(g_embedderDataSlot, new FXJS_PerIsolateData()); |
-} |
- |
-// static |
-FXJS_PerIsolateData* FXJS_PerIsolateData::Get(v8::Isolate* pIsolate) { |
- return static_cast<FXJS_PerIsolateData*>( |
- pIsolate->GetData(g_embedderDataSlot)); |
-} |
- |
int FXJS_DefineObj(v8::Isolate* pIsolate, |
const wchar_t* sObjName, |
FXJSOBJTYPE eObjType, |
@@ -396,7 +323,7 @@ void FXJS_ReleaseRuntime(v8::Isolate* pIsolate, |
for (int i = 0; i < maxID; ++i) |
delete CFXJS_ObjDefinition::ForID(pIsolate, i); |
- pIsolate->SetData(g_embedderDataSlot, nullptr); |
+ pIsolate->SetData(FXJS_PerIsolateData::EmbedderDataSlot(), nullptr); |
delete pData; |
} |