diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-10-26 16:48:30 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-10-26 21:02:17 +0000 |
commit | ef299534cce8cc42f1bd13665a75947c88195ce0 (patch) | |
tree | 92e97b4f19dc7d8bdae7c0f43b549ad9d49bcdc4 /fpdfsdk/javascript/Document.cpp | |
parent | 15776cf22182e74d8546849780ec0cf61b96ca95 (diff) | |
download | pdfium-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/Document.cpp')
-rw-r--r-- | fpdfsdk/javascript/Document.cpp | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp index 232f6dd380..5ff66e9c8d 100644 --- a/fpdfsdk/javascript/Document.cpp +++ b/fpdfsdk/javascript/Document.cpp @@ -38,11 +38,17 @@ #include "third_party/base/numerics/safe_math.h" #include "third_party/base/ptr_util.h" -int CJS_PrintParamsObj::g_nObjDefnID = -1; +int CJS_PrintParamsObj::ObjDefnID = -1; +// static +int CJS_PrintParamsObj::GetObjDefnID() { + return ObjDefnID; +} + +// static void CJS_PrintParamsObj::DefineJSObjects(CFXJS_Engine* pEngine, FXJSOBJTYPE eObjType) { - g_nObjDefnID = + ObjDefnID = pEngine->DefineObj("PrintParamsObj", eObjType, JSConstructor<CJS_PrintParamsObj, PrintParamsObj>, JSDestructor<CJS_PrintParamsObj>); @@ -145,15 +151,21 @@ JSMethodSpec CJS_Document::MethodSpecs[] = { {"mailDoc", mailDoc_static}, {0, 0}}; -int CJS_Document::g_nObjDefnID = -1; +int CJS_Document::ObjDefnID = -1; + +// static +int CJS_Document::GetObjDefnID() { + return ObjDefnID; +} +// static void CJS_Document::DefineJSObjects(CFXJS_Engine* pEngine, FXJSOBJTYPE eObjType) { - g_nObjDefnID = pEngine->DefineObj("Document", eObjType, - JSConstructor<CJS_Document, Document>, - JSDestructor<CJS_Document>); - DefineProps(pEngine, g_nObjDefnID, PropertySpecs); - DefineMethods(pEngine, g_nObjDefnID, MethodSpecs); + ObjDefnID = pEngine->DefineObj("Document", eObjType, + JSConstructor<CJS_Document, Document>, + JSDestructor<CJS_Document>); + DefineProps(pEngine, ObjDefnID, PropertySpecs); + DefineMethods(pEngine, ObjDefnID, MethodSpecs); } void CJS_Document::InitInstance(IJS_Runtime* pIRuntime) { @@ -283,7 +295,7 @@ CJS_Return Document::getField(CJS_Runtime* pRuntime, return CJS_Return(pRuntime->NewUndefined()); v8::Local<v8::Object> pFieldObj = - pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID); + pRuntime->NewFxDynamicObj(CJS_Field::GetObjDefnID()); if (pFieldObj.IsEmpty()) return CJS_Return(false); @@ -393,7 +405,7 @@ CJS_Return Document::print(CJS_Runtime* pRuntime, if (params[8]->IsObject()) { v8::Local<v8::Object> pObj = pRuntime->ToObject(params[8]); if (CFXJS_Engine::GetObjDefnID(pObj) == - CJS_PrintParamsObj::g_nObjDefnID) { + CJS_PrintParamsObj::GetObjDefnID()) { v8::Local<v8::Object> pObj = pRuntime->ToObject(params[8]); CJS_Object* pJSObj = static_cast<CJS_Object*>(pRuntime->GetObjectPrivate(pObj)); @@ -1051,7 +1063,7 @@ CJS_Return Document::getAnnot(CJS_Runtime* pRuntime, return CJS_Return(false); v8::Local<v8::Object> pObj = - pRuntime->NewFxDynamicObj(CJS_Annot::g_nObjDefnID); + pRuntime->NewFxDynamicObj(CJS_Annot::GetObjDefnID()); if (pObj.IsEmpty()) return CJS_Return(false); @@ -1088,7 +1100,7 @@ CJS_Return Document::getAnnots( return CJS_Return(JSGetStringFromID(IDS_STRING_JSBADOBJECT)); v8::Local<v8::Object> pObj = - pRuntime->NewFxDynamicObj(CJS_Annot::g_nObjDefnID); + pRuntime->NewFxDynamicObj(CJS_Annot::GetObjDefnID()); if (pObj.IsEmpty()) return CJS_Return(false); @@ -1142,7 +1154,7 @@ CJS_Return Document::addIcon(CJS_Runtime* pRuntime, return CJS_Return(JSGetStringFromID(IDS_STRING_JSTYPEERROR)); v8::Local<v8::Object> pJSIcon = pRuntime->ToObject(params[1]); - if (CFXJS_Engine::GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) + if (CFXJS_Engine::GetObjDefnID(pJSIcon) != CJS_Icon::GetObjDefnID()) return CJS_Return(JSGetStringFromID(IDS_STRING_JSTYPEERROR)); v8::Local<v8::Object> pObj = pRuntime->ToObject(params[1]); @@ -1162,7 +1174,7 @@ CJS_Return Document::get_icons(CJS_Runtime* pRuntime) { int i = 0; for (const auto& name : m_IconNames) { v8::Local<v8::Object> pObj = - pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); + pRuntime->NewFxDynamicObj(CJS_Icon::GetObjDefnID()); if (pObj.IsEmpty()) return CJS_Return(false); @@ -1193,7 +1205,7 @@ CJS_Return Document::getIcon(CJS_Runtime* pRuntime, return CJS_Return(false); v8::Local<v8::Object> pObj = - pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); + pRuntime->NewFxDynamicObj(CJS_Icon::GetObjDefnID()); if (pObj.IsEmpty()) return CJS_Return(false); @@ -1345,7 +1357,7 @@ CJS_Return Document::getPrintParams( CJS_Runtime* pRuntime, const std::vector<v8::Local<v8::Value>>& params) { v8::Local<v8::Object> pRetObj = - pRuntime->NewFxDynamicObj(CJS_PrintParamsObj::g_nObjDefnID); + pRuntime->NewFxDynamicObj(CJS_PrintParamsObj::GetObjDefnID()); if (pRetObj.IsEmpty()) return CJS_Return(false); |