summaryrefslogtreecommitdiff
path: root/fxjs/fxjs_v8.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-02-08 20:16:09 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-02-08 20:16:09 +0000
commitb3f1046cb2c9bb7fc2a2579b76c8e65b24323002 (patch)
treec687a105ebece091f5a2386f88855c163ba7e6cc /fxjs/fxjs_v8.cpp
parentf0e386de64e030f6d692acfa27e2bc0a50018710 (diff)
downloadpdfium-b3f1046cb2c9bb7fc2a2579b76c8e65b24323002.tar.xz
Make CFXJS_Engine::SetObjectPrivate() static.
Avoids call to CFXJS_Engine::EngineFromIsolateCurrentContext() during the Dispose() path, which feels scary because there aren't guarantees about it having an engine at isolate "dispose" time. Fortunately, |this| is not used, so make that fact clear. Replace some c-style callbacks with std::function while we're at it. Change-Id: Ia1a1a1fcc085d8657939e6f8c8d34fc511afddfe Reviewed-on: https://pdfium-review.googlesource.com/25970 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fxjs/fxjs_v8.cpp')
-rw-r--r--fxjs/fxjs_v8.cpp39
1 files changed, 19 insertions, 20 deletions
diff --git a/fxjs/fxjs_v8.cpp b/fxjs/fxjs_v8.cpp
index 8a04a0680e..3d82848a6e 100644
--- a/fxjs/fxjs_v8.cpp
+++ b/fxjs/fxjs_v8.cpp
@@ -181,10 +181,8 @@ void V8TemplateMapTraits::Dispose(v8::Isolate* isolate,
CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(isolate, id);
if (!pObjDef)
return;
- if (pObjDef->m_pDestructor) {
- pObjDef->m_pDestructor(
- CFXJS_Engine::EngineFromIsolateCurrentContext(isolate), obj);
- }
+ if (pObjDef->m_pDestructor)
+ pObjDef->m_pDestructor(obj);
CFXJS_Engine::FreeObjectPrivate(obj);
}
@@ -271,16 +269,12 @@ CFXJS_Engine* CFXJS_Engine::EngineFromIsolateCurrentContext(
return EngineFromContext(pIsolate->GetCurrentContext());
}
+// static
CFXJS_Engine* CFXJS_Engine::EngineFromContext(v8::Local<v8::Context> pContext) {
return static_cast<CFXJS_Engine*>(
pContext->GetAlignedPointerFromEmbedderData(kPerContextDataIndex));
}
-void CFXJS_Engine::SetEngineInContext(CFXJS_Engine* pEngine,
- v8::Local<v8::Context> pContext) {
- pContext->SetAlignedPointerInEmbedderData(kPerContextDataIndex, pEngine);
-}
-
// static
int CFXJS_Engine::GetObjDefnID(v8::Local<v8::Object> pObj) {
CFXJS_PerObjectData* pData = CFXJS_PerObjectData::GetFromObject(pObj);
@@ -288,6 +282,16 @@ int CFXJS_Engine::GetObjDefnID(v8::Local<v8::Object> pObj) {
}
// static
+void CFXJS_Engine::SetObjectPrivate(v8::Local<v8::Object> pObj,
+ std::unique_ptr<CJS_Object> p) {
+ CFXJS_PerObjectData* pPerObjectData =
+ CFXJS_PerObjectData::GetFromObject(pObj);
+ if (!pPerObjectData)
+ return;
+ pPerObjectData->m_pPrivate = std::move(p);
+}
+
+// static
void CFXJS_Engine::FreeObjectPrivate(v8::Local<v8::Object> pObj) {
CFXJS_PerObjectData* pData = CFXJS_PerObjectData::GetFromObject(pObj);
pObj->SetAlignedPointerInInternalField(0, nullptr);
@@ -295,6 +299,10 @@ void CFXJS_Engine::FreeObjectPrivate(v8::Local<v8::Object> pObj) {
delete pData;
}
+void CFXJS_Engine::SetIntoContext(v8::Local<v8::Context> pContext) {
+ pContext->SetAlignedPointerInEmbedderData(kPerContextDataIndex, this);
+}
+
int CFXJS_Engine::DefineObj(const char* sObjName,
FXJSOBJTYPE eObjType,
CFXJS_Engine::Constructor pConstructor,
@@ -394,7 +402,7 @@ void CFXJS_Engine::InitializeEngine() {
v8::Local<v8::Context> v8Context = v8::Context::New(
GetIsolate(), nullptr, GetGlobalObjectTemplate(GetIsolate()));
v8::Context::Scope context_scope(v8Context);
- SetEngineInContext(this, v8Context);
+ SetIntoContext(v8Context);
int maxID = CFXJS_ObjDefinition::MaxID(GetIsolate());
m_StaticObjects.resize(maxID + 1);
@@ -449,7 +457,7 @@ void CFXJS_Engine::ReleaseEngine() {
if (!pObj.IsEmpty()) {
if (pObjDef->m_pDestructor)
- pObjDef->m_pDestructor(this, pObj);
+ pObjDef->m_pDestructor(pObj);
FreeObjectPrivate(pObj);
}
}
@@ -527,15 +535,6 @@ void CFXJS_Engine::Error(const WideString& message) {
GetIsolate()->ThrowException(NewString(message.AsStringView()));
}
-void CFXJS_Engine::SetObjectPrivate(v8::Local<v8::Object> pObj,
- std::unique_ptr<CJS_Object> p) {
- CFXJS_PerObjectData* pPerObjectData =
- CFXJS_PerObjectData::GetFromObject(pObj);
- if (!pPerObjectData)
- return;
- pPerObjectData->m_pPrivate = std::move(p);
-}
-
CJS_Object* CFXJS_Engine::GetObjectPrivate(v8::Local<v8::Object> pObj) {
CFXJS_PerObjectData* pData = CFXJS_PerObjectData::GetFromObject(pObj);
if (!pData && !pObj.IsEmpty()) {