summaryrefslogtreecommitdiff
path: root/fpdfsdk/javascript/app.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-10-26 16:48:30 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-10-26 21:02:17 +0000
commitef299534cce8cc42f1bd13665a75947c88195ce0 (patch)
tree92e97b4f19dc7d8bdae7c0f43b549ad9d49bcdc4 /fpdfsdk/javascript/app.cpp
parent15776cf22182e74d8546849780ec0cf61b96ca95 (diff)
downloadpdfium-ef299534cce8cc42f1bd13665a75947c88195ce0.tar.xz
Cleanup statics in JS classes
This CL removes the static object IDs from each of the CJS_Object subclasses and moves them to anonymous namespaces. The Spec arrays are moved to private members of the object classes. Change-Id: I5dcdb87ef57e4b374b5431580fb55cb75023f8fb Reviewed-on: https://pdfium-review.googlesource.com/16950 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/javascript/app.cpp')
-rw-r--r--fpdfsdk/javascript/app.cpp33
1 files changed, 20 insertions, 13 deletions
diff --git a/fpdfsdk/javascript/app.cpp b/fpdfsdk/javascript/app.cpp
index ceafb8fdd8..9cc13ea21d 100644
--- a/fpdfsdk/javascript/app.cpp
+++ b/fpdfsdk/javascript/app.cpp
@@ -142,13 +142,19 @@ GlobalTimer::TimerMap* GlobalTimer::GetGlobalTimerMap() {
return s_TimerMap;
}
-int CJS_TimerObj::g_nObjDefnID = -1;
+int CJS_TimerObj::ObjDefnID = -1;
+// static
+int CJS_TimerObj::GetObjDefnID() {
+ return ObjDefnID;
+}
+
+// static
void CJS_TimerObj::DefineJSObjects(CFXJS_Engine* pEngine,
FXJSOBJTYPE eObjType) {
- g_nObjDefnID = pEngine->DefineObj("TimerObj", eObjType,
- JSConstructor<CJS_TimerObj, TimerObj>,
- JSDestructor<CJS_TimerObj>);
+ ObjDefnID = pEngine->DefineObj("TimerObj", eObjType,
+ JSConstructor<CJS_TimerObj, TimerObj>,
+ JSDestructor<CJS_TimerObj>);
}
TimerObj::TimerObj(CJS_Object* pJSObject)
@@ -210,13 +216,14 @@ JSMethodSpec CJS_App::MethodSpecs[] = {{"alert", alert_static},
{"setTimeOut", setTimeOut_static},
{0, 0}};
-int CJS_App::g_nObjDefnID = -1;
+int CJS_App::ObjDefnID = -1;
+// static
void CJS_App::DefineJSObjects(CFXJS_Engine* pEngine, FXJSOBJTYPE eObjType) {
- g_nObjDefnID = pEngine->DefineObj(
- "app", eObjType, JSConstructor<CJS_App, app>, JSDestructor<CJS_App>);
- DefineProps(pEngine, g_nObjDefnID, PropertySpecs);
- DefineMethods(pEngine, g_nObjDefnID, MethodSpecs);
+ ObjDefnID = pEngine->DefineObj("app", eObjType, JSConstructor<CJS_App, app>,
+ JSDestructor<CJS_App>);
+ DefineProps(pEngine, ObjDefnID, PropertySpecs);
+ DefineMethods(pEngine, ObjDefnID, MethodSpecs);
}
app::app(CJS_Object* pJSObject)
@@ -227,7 +234,7 @@ app::~app() {}
CJS_Return app::get_active_docs(CJS_Runtime* pRuntime) {
CJS_Document* pJSDocument = nullptr;
v8::Local<v8::Object> pObj = pRuntime->GetThisObj();
- if (CFXJS_Engine::GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID)
+ if (CFXJS_Engine::GetObjDefnID(pObj) == CJS_Document::GetObjDefnID())
pJSDocument = static_cast<CJS_Document*>(pRuntime->GetObjectPrivate(pObj));
v8::Local<v8::Array> aDocs = pRuntime->NewArray();
@@ -445,7 +452,7 @@ CJS_Return app::setInterval(CJS_Runtime* pRuntime,
m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef));
v8::Local<v8::Object> pRetObj =
- pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID);
+ pRuntime->NewFxDynamicObj(CJS_TimerObj::GetObjDefnID());
if (pRetObj.IsEmpty())
return CJS_Return(false);
@@ -473,7 +480,7 @@ CJS_Return app::setTimeOut(CJS_Runtime* pRuntime,
m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef));
v8::Local<v8::Object> pRetObj =
- pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID);
+ pRuntime->NewFxDynamicObj(CJS_TimerObj::GetObjDefnID());
if (pRetObj.IsEmpty())
return CJS_Return(false);
@@ -508,7 +515,7 @@ void app::ClearTimerCommon(CJS_Runtime* pRuntime, v8::Local<v8::Value> param) {
return;
v8::Local<v8::Object> pObj = pRuntime->ToObject(param);
- if (CFXJS_Engine::GetObjDefnID(pObj) != CJS_TimerObj::g_nObjDefnID)
+ if (CFXJS_Engine::GetObjDefnID(pObj) != CJS_TimerObj::GetObjDefnID())
return;
CJS_Object* pJSObj =