js_global_data and global_alternate violate naming rules.
authorTom Sepez <tsepez@chromium.org>
Mon, 17 Aug 2015 18:58:34 +0000 (11:58 -0700)
committerTom Sepez <tsepez@chromium.org>
Mon, 17 Aug 2015 18:58:34 +0000 (11:58 -0700)
They look too much like locals; use JSGlobalData and JSGlobalAlternate
instead.  Kill some commented out code.

R=thestig@chromium.org

Review URL: https://codereview.chromium.org/1289903004 .

fpdfsdk/include/javascript/global.h
fpdfsdk/src/javascript/JS_GlobalData.cpp
fpdfsdk/src/javascript/global.cpp

index 3699567..e881625 100644 (file)
@@ -13,8 +13,8 @@ class CJS_GlobalData;
 class CJS_GlobalVariableArray;
 class CJS_KeyValue;
 
-struct js_global_data {
-  js_global_data() {
+struct JSGlobalData {
+  JSGlobalData() {
     nType = 0;
     dData = 0;
     bData = FALSE;
@@ -23,7 +23,7 @@ struct js_global_data {
     bDeleted = FALSE;
   }
 
-  ~js_global_data() { pData.Reset(); }
+  ~JSGlobalData() { pData.Reset(); }
   int nType;  // 0:int 1:bool 2:string 3:obj
   double dData;
   bool bData;
@@ -33,18 +33,15 @@ struct js_global_data {
   bool bDeleted;
 };
 
-class global_alternate : public CJS_EmbedObj {
+class JSGlobalAlternate : public CJS_EmbedObj {
  public:
-  global_alternate(CJS_Object* pJSObject);
-  ~global_alternate() override;
+  JSGlobalAlternate(CJS_Object* pJSObject);
+  ~JSGlobalAlternate() override;
 
- public:
   FX_BOOL setPersistent(IFXJS_Context* cc,
                         const CJS_Parameters& params,
                         CJS_Value& vRet,
                         CFX_WideString& sError);
-
- public:
   FX_BOOL QueryProperty(const FX_WCHAR* propname);
   FX_BOOL DoProperty(IFXJS_Context* cc,
                      const FX_WCHAR* propname,
@@ -53,7 +50,6 @@ class global_alternate : public CJS_EmbedObj {
   FX_BOOL DelProperty(IFXJS_Context* cc,
                       const FX_WCHAR* propname,
                       CFX_WideString& sError);
-
   void Initial(CPDFDoc_Environment* pApp);
 
  private:
@@ -89,7 +85,7 @@ class CJS_Global : public CJS_Object {
 
   DECLARE_SPECIAL_JS_CLASS(CJS_Global);
 
-  JS_SPECIAL_STATIC_METHOD(setPersistent, global_alternate, global);
+  JS_SPECIAL_STATIC_METHOD(setPersistent, JSGlobalAlternate, global);
 };
 
 #endif  // FPDFSDK_INCLUDE_JAVASCRIPT_GLOBAL_H_
index 9f954ac..0a21a92 100644 (file)
@@ -398,23 +398,6 @@ void CJS_GlobalData::LoadGlobalPersistentVariables() {
   }
 }
 
-/*
-struct js_global_datafile_header
-{
-    FX_WORD type; //FX ('X' << 8) | 'F'
-    FX_WORD version; //1.0
-    FX_DWORD datacount;
-};
-struct js_global_datafile_data
-{
-    FX_WORD type;
-    FX_DWORD nData;
-    FX_WORD bData;
-    FX_DWORD nStrLen;
-    char* pStr;
-};
-*/
-
 void CJS_GlobalData::SaveGlobalPersisitentVariables() {
   FX_DWORD nCount = 0;
   CFX_BinaryBuf sData;
index 17aa00e..aa3bfa0 100644 (file)
@@ -89,13 +89,13 @@ BEGIN_JS_STATIC_METHOD(CJS_Global)
 JS_STATIC_METHOD_ENTRY(setPersistent)
 END_JS_STATIC_METHOD()
 
-IMPLEMENT_SPECIAL_JS_CLASS(CJS_Global, global_alternate, global);
+IMPLEMENT_SPECIAL_JS_CLASS(CJS_Global, JSGlobalAlternate, global);
 
 FX_BOOL CJS_Global::InitInstance(IFXJS_Context* cc) {
   CJS_Context* pContext = (CJS_Context*)cc;
   ASSERT(pContext != NULL);
 
-  global_alternate* pGlobal = (global_alternate*)GetEmbedObject();
+  JSGlobalAlternate* pGlobal = (JSGlobalAlternate*)GetEmbedObject();
   ASSERT(pGlobal != NULL);
 
   pGlobal->Initial(pContext->GetReaderApp());
@@ -103,28 +103,29 @@ FX_BOOL CJS_Global::InitInstance(IFXJS_Context* cc) {
   return TRUE;
 };
 
-global_alternate::global_alternate(CJS_Object* pJSObject)
-    : CJS_EmbedObj(pJSObject), m_pApp(NULL) {}
+JSGlobalAlternate::JSGlobalAlternate(CJS_Object* pJSObject)
+    : CJS_EmbedObj(pJSObject), m_pApp(NULL) {
+}
 
-global_alternate::~global_alternate() {
+JSGlobalAlternate::~JSGlobalAlternate() {
   DestroyGlobalPersisitentVariables();
   m_pApp->GetRuntimeFactory()->ReleaseGlobalData();
 }
 
-void global_alternate::Initial(CPDFDoc_Environment* pApp) {
+void JSGlobalAlternate::Initial(CPDFDoc_Environment* pApp) {
   m_pApp = pApp;
   m_pGlobalData = pApp->GetRuntimeFactory()->NewGlobalData(pApp);
   UpdateGlobalPersistentVariables();
 }
 
-FX_BOOL global_alternate::QueryProperty(const FX_WCHAR* propname) {
+FX_BOOL JSGlobalAlternate::QueryProperty(const FX_WCHAR* propname) {
   return CFX_WideString(propname) != L"setPersistent";
 }
 
-FX_BOOL global_alternate::DelProperty(IFXJS_Context* cc,
-                                      const FX_WCHAR* propname,
-                                      CFX_WideString& sError) {
-  js_global_data* pData = NULL;
+FX_BOOL JSGlobalAlternate::DelProperty(IFXJS_Context* cc,
+                                       const FX_WCHAR* propname,
+                                       CFX_WideString& sError) {
+  JSGlobalData* pData = NULL;
   CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname);
 
   if (m_mapGlobal.Lookup(sPropName, (void*&)pData)) {
@@ -135,10 +136,10 @@ FX_BOOL global_alternate::DelProperty(IFXJS_Context* cc,
   return FALSE;
 }
 
-FX_BOOL global_alternate::DoProperty(IFXJS_Context* cc,
-                                     const FX_WCHAR* propname,
-                                     CJS_PropValue& vp,
-                                     CFX_WideString& sError) {
+FX_BOOL JSGlobalAlternate::DoProperty(IFXJS_Context* cc,
+                                      const FX_WCHAR* propname,
+                                      CJS_PropValue& vp,
+                                      CFX_WideString& sError) {
   if (vp.IsSetting()) {
     CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname);
     switch (vp.GetType()) {
@@ -187,7 +188,7 @@ FX_BOOL global_alternate::DoProperty(IFXJS_Context* cc,
       vp.SetNull();
       return TRUE;
     }
-    js_global_data* pData = (js_global_data*)pVoid;
+    JSGlobalData* pData = (JSGlobalData*)pVoid;
     if (pData->bDeleted)
       return TRUE;
 
@@ -217,10 +218,10 @@ FX_BOOL global_alternate::DoProperty(IFXJS_Context* cc,
   return FALSE;
 }
 
-FX_BOOL global_alternate::setPersistent(IFXJS_Context* cc,
-                                        const CJS_Parameters& params,
-                                        CJS_Value& vRet,
-                                        CFX_WideString& sError) {
+FX_BOOL JSGlobalAlternate::setPersistent(IFXJS_Context* cc,
+                                         const CJS_Parameters& params,
+                                         CJS_Value& vRet,
+                                         CFX_WideString& sError) {
   CJS_Context* pContext = static_cast<CJS_Context*>(cc);
   if (params.size() != 2) {
     sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
@@ -229,7 +230,7 @@ FX_BOOL global_alternate::setPersistent(IFXJS_Context* cc,
 
   CFX_ByteString sName = params[0].ToCFXByteString();
 
-  js_global_data* pData = NULL;
+  JSGlobalData* pData = NULL;
   if (m_mapGlobal.Lookup(sName, (void*&)pData)) {
     if (pData && !pData->bDeleted) {
       pData->bPersistent = params[1].ToBool();
@@ -241,7 +242,7 @@ FX_BOOL global_alternate::setPersistent(IFXJS_Context* cc,
   return FALSE;
 }
 
-void global_alternate::UpdateGlobalPersistentVariables() {
+void JSGlobalAlternate::UpdateGlobalPersistentVariables() {
   ASSERT(m_pGlobalData != NULL);
 
   for (int i = 0, sz = m_pGlobalData->GetSize(); i < sz; i++) {
@@ -296,13 +297,13 @@ void global_alternate::UpdateGlobalPersistentVariables() {
   }
 }
 
-void global_alternate::CommitGlobalPersisitentVariables() {
+void JSGlobalAlternate::CommitGlobalPersisitentVariables() {
   ASSERT(m_pGlobalData != NULL);
 
   FX_POSITION pos = m_mapGlobal.GetStartPosition();
   while (pos) {
     CFX_ByteString name;
-    js_global_data* pData = NULL;
+    JSGlobalData* pData = NULL;
     m_mapGlobal.GetNextAssoc(pos, name, (void*&)pData);
 
     if (pData) {
@@ -348,8 +349,8 @@ void global_alternate::CommitGlobalPersisitentVariables() {
   }
 }
 
-void global_alternate::ObjectToArray(v8::Local<v8::Object> pObj,
-                                     CJS_GlobalVariableArray& array) {
+void JSGlobalAlternate::ObjectToArray(v8::Local<v8::Object> pObj,
+                                      CJS_GlobalVariableArray& array) {
   v8::Local<v8::Context> context = pObj->CreationContext();
   v8::Isolate* isolate = context->GetIsolate();
   v8::Local<v8::Array> pKeyList = JS_GetObjectElementNames(isolate, pObj);
@@ -405,8 +406,8 @@ void global_alternate::ObjectToArray(v8::Local<v8::Object> pObj,
   }
 }
 
-void global_alternate::PutObjectProperty(v8::Local<v8::Object> pObj,
-                                         CJS_KeyValue* pData) {
+void JSGlobalAlternate::PutObjectProperty(v8::Local<v8::Object> pObj,
+                                          CJS_KeyValue* pData) {
   ASSERT(pData != NULL);
 
   for (int i = 0, sz = pData->objData.Count(); i < sz; i++) {
@@ -445,11 +446,11 @@ void global_alternate::PutObjectProperty(v8::Local<v8::Object> pObj,
   }
 }
 
-void global_alternate::DestroyGlobalPersisitentVariables() {
+void JSGlobalAlternate::DestroyGlobalPersisitentVariables() {
   FX_POSITION pos = m_mapGlobal.GetStartPosition();
   while (pos) {
     CFX_ByteString name;
-    js_global_data* pData = NULL;
+    JSGlobalData* pData = NULL;
     m_mapGlobal.GetNextAssoc(pos, name, (void*&)pData);
     delete pData;
   }
@@ -457,17 +458,17 @@ void global_alternate::DestroyGlobalPersisitentVariables() {
   m_mapGlobal.RemoveAll();
 }
 
-FX_BOOL global_alternate::SetGlobalVariables(const FX_CHAR* propname,
-                                             int nType,
-                                             double dData,
-                                             bool bData,
-                                             const CFX_ByteString& sData,
-                                             JSObject pData,
-                                             bool bDefaultPersistent) {
+FX_BOOL JSGlobalAlternate::SetGlobalVariables(const FX_CHAR* propname,
+                                              int nType,
+                                              double dData,
+                                              bool bData,
+                                              const CFX_ByteString& sData,
+                                              JSObject pData,
+                                              bool bDefaultPersistent) {
   if (propname == NULL)
     return FALSE;
 
-  js_global_data* pTemp = NULL;
+  JSGlobalData* pTemp = NULL;
   m_mapGlobal.Lookup(propname, (void*&)pTemp);
 
   if (pTemp) {
@@ -502,35 +503,35 @@ FX_BOOL global_alternate::SetGlobalVariables(const FX_CHAR* propname,
     return TRUE;
   }
 
-  js_global_data* pNewData = NULL;
+  JSGlobalData* pNewData = NULL;
 
   switch (nType) {
     case JS_GLOBALDATA_TYPE_NUMBER: {
-      pNewData = new js_global_data;
+      pNewData = new JSGlobalData;
       pNewData->nType = JS_GLOBALDATA_TYPE_NUMBER;
       pNewData->dData = dData;
       pNewData->bPersistent = bDefaultPersistent;
     } break;
     case JS_GLOBALDATA_TYPE_BOOLEAN: {
-      pNewData = new js_global_data;
+      pNewData = new JSGlobalData;
       pNewData->nType = JS_GLOBALDATA_TYPE_BOOLEAN;
       pNewData->bData = bData;
       pNewData->bPersistent = bDefaultPersistent;
     } break;
     case JS_GLOBALDATA_TYPE_STRING: {
-      pNewData = new js_global_data;
+      pNewData = new JSGlobalData;
       pNewData->nType = JS_GLOBALDATA_TYPE_STRING;
       pNewData->sData = sData;
       pNewData->bPersistent = bDefaultPersistent;
     } break;
     case JS_GLOBALDATA_TYPE_OBJECT: {
-      pNewData = new js_global_data;
+      pNewData = new JSGlobalData;
       pNewData->nType = JS_GLOBALDATA_TYPE_OBJECT;
       pNewData->pData.Reset(JS_GetRuntime(pData), pData);
       pNewData->bPersistent = bDefaultPersistent;
     } break;
     case JS_GLOBALDATA_TYPE_NULL: {
-      pNewData = new js_global_data;
+      pNewData = new JSGlobalData;
       pNewData->nType = JS_GLOBALDATA_TYPE_NULL;
       pNewData->bPersistent = bDefaultPersistent;
     } break;