Store object definition ID in each js_class.
authorTom Sepez <tsepez@chromium.org>
Tue, 6 Oct 2015 18:10:52 +0000 (11:10 -0700)
committerTom Sepez <tsepez@chromium.org>
Tue, 6 Oct 2015 18:10:52 +0000 (11:10 -0700)
Avoids doing a lookup via FXJS_V8 for something already
known in CJS layer.

Also:
Consolidate repeated code in JS macros.
Remove knowledge that Document is global from FXJS layer

R=thestig@chromium.org

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

18 files changed:
fpdfsdk/include/jsapi/fxjs_v8.h
fpdfsdk/src/javascript/Document.cpp
fpdfsdk/src/javascript/Document.h
fpdfsdk/src/javascript/Field.cpp
fpdfsdk/src/javascript/Field.h
fpdfsdk/src/javascript/Icon.h
fpdfsdk/src/javascript/JS_Define.h
fpdfsdk/src/javascript/JS_EventHandler.cpp
fpdfsdk/src/javascript/JS_Runtime.cpp
fpdfsdk/src/javascript/app.cpp
fpdfsdk/src/javascript/app.h
fpdfsdk/src/javascript/color.h
fpdfsdk/src/javascript/console.h
fpdfsdk/src/javascript/event.h
fpdfsdk/src/javascript/global.h
fpdfsdk/src/javascript/report.h
fpdfsdk/src/javascript/util.h
fpdfsdk/src/jsapi/fxjs_v8.cpp

index 8b5c0b2..289a73e 100644 (file)
@@ -19,8 +19,9 @@ class IFXJS_Context;
 class IFXJS_Runtime;
 
 enum FXJSOBJTYPE {
-  FXJS_DYNAMIC = 0,
-  FXJS_STATIC = 1,
+  FXJSOBJTYPE_DYNAMIC = 0,  // Created by native method and returned to JS.
+  FXJSOBJTYPE_STATIC,       // Created by init and hung off of global object.
+  FXJSOBJTYPE_GLOBAL,       // The global object itself (may only appear once).
 };
 
 struct FXJSErr {
@@ -135,7 +136,6 @@ v8::Local<v8::Object> FXJS_NewFxDynamicObj(v8::Isolate* pIsolate,
                                            int nObjDefnID);
 v8::Local<v8::Object> FXJS_GetThisObj(v8::Isolate* pIsolate);
 int FXJS_GetObjDefnID(v8::Local<v8::Object> pObj);
-int FXJS_GetObjDefnID(v8::Isolate* pIsolate, const wchar_t* pObjName);
 v8::Isolate* FXJS_GetRuntime(v8::Local<v8::Object> pObj);
 const wchar_t* FXJS_GetTypeof(v8::Local<v8::Value> pObj);
 
index 748aad3..d31bdc4 100644 (file)
@@ -325,9 +325,8 @@ FX_BOOL Document::getField(IFXJS_Context* cc,
   }
 
   CJS_Runtime* pRuntime = pContext->GetJSRuntime();
-  v8::Local<v8::Object> pFieldObj =
-      FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext,
-                           FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Field"));
+  v8::Local<v8::Object> pFieldObj = FXJS_NewFxDynamicObj(
+      pRuntime->GetIsolate(), pContext, CJS_Field::g_nObjDefnID);
 
   v8::Isolate* isolate = GetIsolate(cc);
   CJS_Field* pJSField = (CJS_Field*)FXJS_GetPrivate(isolate, pFieldObj);
@@ -441,11 +440,6 @@ FX_BOOL Document::print(IFXJS_Context* cc,
                         const CJS_Parameters& params,
                         CJS_Value& vRet,
                         CFX_WideString& sError) {
-  CJS_Context* pContext = (CJS_Context*)cc;
-  ASSERT(pContext != NULL);
-  CJS_Runtime* pRuntime = pContext->GetJSRuntime();
-  ASSERT(pRuntime != NULL);
-
   FX_BOOL bUI = TRUE;
   int nStart = 0;
   int nEnd = 0;
@@ -460,8 +454,7 @@ FX_BOOL Document::print(IFXJS_Context* cc,
     if (params[8].GetType() == CJS_Value::VT_fxobject) {
       v8::Local<v8::Object> pObj = params[8].ToV8Object();
       {
-        if (FXJS_GetObjDefnID(pObj) ==
-            FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"PrintParamsObj")) {
+        if (FXJS_GetObjDefnID(pObj) == CJS_PrintParamsObj::g_nObjDefnID) {
           if (CJS_Object* pJSObj = params[8].ToCJSObject()) {
             if (PrintParamsObj* pprintparamsObj =
                     (PrintParamsObj*)pJSObj->GetEmbedObject()) {
@@ -1371,11 +1364,9 @@ FX_BOOL Document::addIcon(IFXJS_Context* cc,
     sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
     return FALSE;
   }
-  v8::Local<v8::Object> pJSIcon = params[1].ToV8Object();
 
-  CJS_Runtime* pRuntime = pContext->GetJSRuntime();
-  if (FXJS_GetObjDefnID(pJSIcon) !=
-      FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Icon")) {
+  v8::Local<v8::Object> pJSIcon = params[1].ToV8Object();
+  if (FXJS_GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) {
     sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
     return FALSE;
   }
@@ -1423,8 +1414,7 @@ FX_BOOL Document::icons(IFXJS_Context* cc,
     pIconElement = (*m_pIconTree)[i];
 
     v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
-        pRuntime->GetIsolate(), pContext,
-        FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Icon"));
+        pRuntime->GetIsolate(), pContext, CJS_Icon::g_nObjDefnID);
     if (pObj.IsEmpty())
       return FALSE;
 
@@ -1467,8 +1457,7 @@ FX_BOOL Document::getIcon(IFXJS_Context* cc,
       Icon* pRetIcon = (*m_pIconTree)[i]->IconStream;
 
       v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
-          pRuntime->GetIsolate(), pContext,
-          FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Icon"));
+          pRuntime->GetIsolate(), pContext, CJS_Icon::g_nObjDefnID);
       if (pObj.IsEmpty())
         return FALSE;
 
@@ -1664,8 +1653,7 @@ FX_BOOL Document::getPrintParams(IFXJS_Context* cc,
   CJS_Context* pContext = (CJS_Context*)cc;
   CJS_Runtime* pRuntime = pContext->GetJSRuntime();
   v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj(
-      pRuntime->GetIsolate(), pContext,
-      FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"PrintParamsObj"));
+      pRuntime->GetIsolate(), pContext, CJS_PrintParamsObj::g_nObjDefnID);
 
   // Not implemented yet.
 
index 6c403e3..42ba9d7 100644 (file)
@@ -30,7 +30,7 @@ class CJS_PrintParamsObj : public CJS_Object {
   CJS_PrintParamsObj(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {}
   ~CJS_PrintParamsObj() override {}
 
-  DECLARE_JS_CLASS(CJS_PrintParamsObj);
+  DECLARE_JS_CLASS();
 };
 
 class Icon;
@@ -327,7 +327,7 @@ class CJS_Document : public CJS_Object {
   // CJS_Object
   FX_BOOL InitInstance(IFXJS_Context* cc) override;
 
-  DECLARE_JS_CLASS(CJS_Document);
+  DECLARE_JS_CLASS();
 
   JS_STATIC_PROP(ADBE, Document);
   JS_STATIC_PROP(author, Document);
index 7026530..973d912 100644 (file)
@@ -3310,9 +3310,8 @@ FX_BOOL Field::buttonGetIcon(IFXJS_Context* cc,
 
   CJS_Context* pContext = (CJS_Context*)cc;
   CJS_Runtime* pRuntime = pContext->GetJSRuntime();
-  v8::Local<v8::Object> pObj =
-      FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), pContext,
-                           FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Icon"));
+  v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
+      pRuntime->GetIsolate(), pContext, CJS_Icon::g_nObjDefnID);
   ASSERT(pObj.IsEmpty() == FALSE);
 
   CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
@@ -3521,9 +3520,8 @@ FX_BOOL Field::getArray(IFXJS_Context* cc,
   for (int j = 0, jsz = swSort.GetSize(); j < jsz; j++) {
     nonstd::unique_ptr<CFX_WideString> pStr(swSort.GetAt(j));
     v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
-        pRuntime->GetIsolate(), pContext,
-        FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Field"));
-    ASSERT(pObj.IsEmpty() == FALSE);
+        pRuntime->GetIsolate(), pContext, CJS_Field::g_nObjDefnID);
+    ASSERT(!pObj.IsEmpty());
 
     CJS_Field* pJSField =
         (CJS_Field*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
index a62bf39..daf47d5 100644 (file)
@@ -539,8 +539,7 @@ class CJS_Field : public CJS_Object {
 
   FX_BOOL InitInstance(IFXJS_Context* cc) override;
 
-  DECLARE_JS_CLASS(CJS_Field);
-
+  DECLARE_JS_CLASS();
   JS_STATIC_PROP(alignment, Field);
   JS_STATIC_PROP(borderStyle, Field);
   JS_STATIC_PROP(buttonAlignX, Field);
index b03048b..c188060 100644 (file)
@@ -30,9 +30,7 @@ class CJS_Icon : public CJS_Object {
   CJS_Icon(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {}
   ~CJS_Icon() override {}
 
- public:
-  DECLARE_JS_CLASS(CJS_Icon);
-
+  DECLARE_JS_CLASS();
   JS_STATIC_PROP(name, Icon);
 };
 
index 5e98b4f..3881951 100644 (file)
@@ -30,18 +30,17 @@ struct JSMethodSpec {
   v8::FunctionCallback pMethodCall;
 };
 
-/* ====================================== PUBLIC DEFINE SPEC
- * ============================================== */
 #define JS_WIDESTRING(widestring) L## #widestring
-
 #define BEGIN_JS_STATIC_CONST(js_class_name) \
   JSConstSpec js_class_name::JS_Class_Consts[] = {
 #define JS_STATIC_CONST_ENTRY_NUMBER(const_name, pValue) \
   { const_name, pValue, L"", 0 }                         \
   ,
+
 #define JS_STATIC_CONST_ENTRY_STRING(const_name, pValue) \
   { const_name, 0, pValue, 1 }                           \
   ,
+
 #define END_JS_STATIC_CONST() \
   { 0, 0, 0, 0 }              \
   }                           \
@@ -55,6 +54,7 @@ struct JSMethodSpec {
         set_##prop_name##_static                        \
   }                                                     \
   ,
+
 #define END_JS_STATIC_PROP() \
   { 0, 0, 0 }                \
   }                          \
@@ -65,14 +65,12 @@ struct JSMethodSpec {
 #define JS_STATIC_METHOD_ENTRY(method_name)            \
   { JS_WIDESTRING(method_name), method_name##_static } \
   ,
+
 #define END_JS_STATIC_METHOD() \
   { 0, 0 }                     \
   }                            \
   ;
 
-/* ======================================== PROP CALLBACK
- * ============================================ */
-
 template <class C,
           FX_BOOL (C::*M)(IFXJS_Context* cc,
                           CJS_PropValue& vp,
@@ -138,9 +136,6 @@ void JSPropSetter(const char* prop_name_string,
                                                      property, value, info);  \
   }
 
-/* ========================================= METHOD CALLBACK
- * =========================================== */
-
 template <class C,
           FX_BOOL (C::*M)(IFXJS_Context* cc,
                           const CJS_Parameters& params,
@@ -184,79 +179,175 @@ void JSMethod(const char* method_name_string,
         #method_name, #class_name, info);                                  \
   }
 
-/* ===================================== JS CLASS
- * =============================================== */
-
-#define DECLARE_JS_CLASS(js_class_name)                                     \
-  static void JSConstructor(IFXJS_Context* cc, v8::Local<v8::Object> obj,   \
-                            v8::Local<v8::Object> global);                  \
-  static void JSDestructor(v8::Local<v8::Object> obj);                      \
-  static void DefineJSObjects(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); \
-  static JSConstSpec JS_Class_Consts[];                                     \
-  static JSPropertySpec JS_Class_Properties[];                              \
-  static JSMethodSpec JS_Class_Methods[];                                   \
-  static const wchar_t* m_pClassName
-
-#define IMPLEMENT_JS_CLASS_RICH(js_class_name, class_alternate, class_name)  \
-  const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name);    \
-  void js_class_name::JSConstructor(IFXJS_Context* cc,                       \
-                                    v8::Local<v8::Object> obj,               \
-                                    v8::Local<v8::Object> global) {          \
-    CJS_Object* pObj = new js_class_name(obj);                               \
-    pObj->SetEmbedObject(new class_alternate(pObj));                         \
-    FXJS_SetPrivate(NULL, obj, (void*)pObj);                                 \
-    pObj->InitInstance(cc);                                                  \
-  }                                                                          \
-                                                                             \
-  void js_class_name::JSDestructor(v8::Local<v8::Object> obj) {              \
-    js_class_name* pObj = (js_class_name*)FXJS_GetPrivate(NULL, obj);        \
-    pObj->ExitInstance();                                                    \
-    delete pObj;                                                             \
-  }                                                                          \
-                                                                             \
-  void js_class_name::DefineJSObjects(v8::Isolate* pIsolate,                 \
-                                      FXJSOBJTYPE eObjType) {                \
-    int nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::m_pClassName,   \
-                                    eObjType, JSConstructor, JSDestructor);  \
-    for (int i = 0; i < FX_ArraySize(JS_Class_Properties) - 1; ++i) {        \
-      FXJS_DefineObjProperty(                                                \
-          pIsolate, nObjDefnID, JS_Class_Properties[i].pName,                \
-          JS_Class_Properties[i].pPropGet, JS_Class_Properties[i].pPropPut); \
-    }                                                                        \
-    for (int i = 0; i < FX_ArraySize(JS_Class_Methods) - 1; ++i) {           \
-      FXJS_DefineObjMethod(pIsolate, nObjDefnID, JS_Class_Methods[i].pName,  \
-                           JS_Class_Methods[i].pMethodCall);                 \
-    }                                                                        \
+// All JS classes have a name, an object defintion ID, and the ability to
+// register themselves with FXJS_V8. We never make a BASE class on its own
+// because it can't really do anything.
+#define DECLARE_JS_CLASS_BASE_PART()  \
+  static const wchar_t* g_pClassName; \
+  static int g_nObjDefnID;            \
+  static void DefineJSObjects(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType);
+
+#define IMPLEMENT_JS_CLASS_BASE_PART(js_class_name, class_name)           \
+  const wchar_t* js_class_name::g_pClassName = JS_WIDESTRING(class_name); \
+  int js_class_name::g_nObjDefnID = -1;
+
+// CONST classes provide constants, but not constructors, methods, or props.
+#define DECLARE_JS_CLASS_CONST() \
+  DECLARE_JS_CLASS_BASE_PART()   \
+  DECLARE_JS_CLASS_CONST_PART()
+
+#define IMPLEMENT_JS_CLASS_CONST(js_class_name, class_name)              \
+  IMPLEMENT_JS_CLASS_BASE_PART(js_class_name, class_name)                \
+  IMPLEMENT_JS_CLASS_CONST_PART(js_class_name, class_name)               \
+  void js_class_name::DefineJSObjects(v8::Isolate* pIsolate,             \
+                                      FXJSOBJTYPE eObjType) {            \
+    g_nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::g_pClassName, \
+                                  eObjType, nullptr, nullptr);           \
+    DefineConsts(pIsolate);                                              \
   }
 
+#define DECLARE_JS_CLASS_CONST_PART()   \
+  static JSConstSpec JS_Class_Consts[]; \
+  static void DefineConsts(v8::Isolate* pIsolate);
+
+#define IMPLEMENT_JS_CLASS_CONST_PART(js_class_name, class_name)      \
+  void js_class_name::DefineConsts(v8::Isolate* pIsolate) {           \
+    for (size_t i = 0; i < FX_ArraySize(JS_Class_Consts) - 1; ++i) {  \
+      FXJS_DefineObjConst(                                            \
+          pIsolate, g_nObjDefnID, JS_Class_Consts[i].pName,           \
+          JS_Class_Consts[i].t == 0                                   \
+              ? FXJS_NewNumber(pIsolate, JS_Class_Consts[i].number)   \
+              : FXJS_NewString(pIsolate, JS_Class_Consts[i].string)); \
+    }                                                                 \
+  }
+
+// Convenience macros for declaring classes without an alternate.
+#define DECLARE_JS_CLASS() DECLARE_JS_CLASS_RICH()
 #define IMPLEMENT_JS_CLASS(js_class_name, class_name) \
   IMPLEMENT_JS_CLASS_RICH(js_class_name, class_name, class_name)
 
-/* ======================================== CONST CLASS
- * ============================================ */
-
-#define DECLARE_JS_CLASS_CONST()                                            \
-  static void DefineJSObjects(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); \
-  static JSConstSpec JS_Class_Consts[];                                     \
-  static const wchar_t* m_pClassName
-
-#define IMPLEMENT_JS_CLASS_CONST(js_class_name, class_name)                \
-  const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name);  \
-  void js_class_name::DefineJSObjects(v8::Isolate* pIsolate,               \
-                                      FXJSOBJTYPE eObjType) {              \
-    int nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::m_pClassName, \
-                                    eObjType, NULL, NULL);                 \
-    for (int i = 0; i < FX_ArraySize(JS_Class_Consts) - 1; ++i) {          \
-      FXJS_DefineObjConst(                                                 \
-          pIsolate, nObjDefnID, JS_Class_Consts[i].pName,                  \
-          JS_Class_Consts[i].t == 0                                        \
-              ? FXJS_NewNumber(pIsolate, JS_Class_Consts[i].number)        \
-              : FXJS_NewString(pIsolate, JS_Class_Consts[i].string));      \
-    }                                                                      \
+// Rich JS classes provide constants, methods, properties, and the ability
+// to construct native object state.
+#define DECLARE_JS_CLASS_RICH() \
+  DECLARE_JS_CLASS_BASE_PART()  \
+  DECLARE_JS_CLASS_CONST_PART() \
+  DECLARE_JS_CLASS_RICH_PART()
+
+#define IMPLEMENT_JS_CLASS_RICH(js_class_name, class_alternate, class_name) \
+  IMPLEMENT_JS_CLASS_BASE_PART(js_class_name, class_name)                   \
+  IMPLEMENT_JS_CLASS_CONST_PART(js_class_name, class_name)                  \
+  IMPLEMENT_JS_CLASS_RICH_PART(js_class_name, class_alternate, class_name)  \
+  void js_class_name::DefineJSObjects(v8::Isolate* pIsolate,                \
+                                      FXJSOBJTYPE eObjType) {               \
+    g_nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::g_pClassName,    \
+                                  eObjType, JSConstructor, JSDestructor);   \
+    DefineConsts(pIsolate);                                                 \
+    DefineProps(pIsolate);                                                  \
+    DefineMethods(pIsolate);                                                \
   }
 
-/* ===================================== SPECIAL JS CLASS
- * =============================================== */
+#define DECLARE_JS_CLASS_RICH_PART()                                      \
+  static void JSConstructor(IFXJS_Context* cc, v8::Local<v8::Object> obj, \
+                            v8::Local<v8::Object> global);                \
+  static void JSDestructor(v8::Local<v8::Object> obj);                    \
+  static void DefineProps(v8::Isolate* pIsoalte);                         \
+  static void DefineMethods(v8::Isolate* pIsoalte);                       \
+  static JSPropertySpec JS_Class_Properties[];                            \
+  static JSMethodSpec JS_Class_Methods[];
+
+#define IMPLEMENT_JS_CLASS_RICH_PART(js_class_name, class_alternate,          \
+                                     class_name)                              \
+  void js_class_name::JSConstructor(IFXJS_Context* cc,                        \
+                                    v8::Local<v8::Object> obj,                \
+                                    v8::Local<v8::Object> global) {           \
+    CJS_Object* pObj = new js_class_name(obj);                                \
+    pObj->SetEmbedObject(new class_alternate(pObj));                          \
+    FXJS_SetPrivate(nullptr, obj, (void*)pObj);                               \
+    pObj->InitInstance(cc);                                                   \
+  }                                                                           \
+  void js_class_name::JSDestructor(v8::Local<v8::Object> obj) {               \
+    js_class_name* pObj = (js_class_name*)FXJS_GetPrivate(nullptr, obj);      \
+    pObj->ExitInstance();                                                     \
+    delete pObj;                                                              \
+  }                                                                           \
+  void js_class_name::DefineProps(v8::Isolate* pIsolate) {                    \
+    for (size_t i = 0; i < FX_ArraySize(JS_Class_Properties) - 1; ++i) {      \
+      FXJS_DefineObjProperty(                                                 \
+          pIsolate, g_nObjDefnID, JS_Class_Properties[i].pName,               \
+          JS_Class_Properties[i].pPropGet, JS_Class_Properties[i].pPropPut);  \
+    }                                                                         \
+  }                                                                           \
+  void js_class_name::DefineMethods(v8::Isolate* pIsolate) {                  \
+    for (size_t i = 0; i < FX_ArraySize(JS_Class_Methods) - 1; ++i) {         \
+      FXJS_DefineObjMethod(pIsolate, g_nObjDefnID, JS_Class_Methods[i].pName, \
+                           JS_Class_Methods[i].pMethodCall);                  \
+    }                                                                         \
+  }
+
+// Special JS classes implement methods, props, and queries, but not consts.
+#define DECLARE_SPECIAL_JS_CLASS() \
+  DECLARE_JS_CLASS_BASE_PART()     \
+  DECLARE_JS_CLASS_CONST_PART()    \
+  DECLARE_JS_CLASS_RICH_PART()     \
+  DECLARE_SPECIAL_JS_CLASS_PART()
+
+#define IMPLEMENT_SPECIAL_JS_CLASS(js_class_name, class_alternate, class_name) \
+  IMPLEMENT_JS_CLASS_BASE_PART(js_class_name, class_name)                      \
+  IMPLEMENT_JS_CLASS_CONST_PART(js_class_name, class_name)                     \
+  IMPLEMENT_JS_CLASS_RICH_PART(js_class_name, class_alternate, class_name)     \
+  IMPLEMENT_SPECIAL_JS_CLASS_PART(js_class_name, class_alternate, class_name)  \
+  void js_class_name::DefineJSObjects(v8::Isolate* pIsolate,                   \
+                                      FXJSOBJTYPE eObjType) {                  \
+    g_nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::g_pClassName,       \
+                                  eObjType, JSConstructor, JSDestructor);      \
+    DefineConsts(pIsolate);                                                    \
+    DefineProps(pIsolate);                                                     \
+    DefineMethods(pIsolate);                                                   \
+    DefineAllProperties(pIsolate);                                             \
+  }
+
+#define DECLARE_SPECIAL_JS_CLASS_PART()                                        \
+  static void queryprop_static(                                                \
+      v8::Local<v8::String> property,                                          \
+      const v8::PropertyCallbackInfo<v8::Integer>& info);                      \
+  static void getprop_static(v8::Local<v8::String> property,                   \
+                             const v8::PropertyCallbackInfo<v8::Value>& info); \
+  static void putprop_static(v8::Local<v8::String> property,                   \
+                             v8::Local<v8::Value> value,                       \
+                             const v8::PropertyCallbackInfo<v8::Value>& info); \
+  static void delprop_static(                                                  \
+      v8::Local<v8::String> property,                                          \
+      const v8::PropertyCallbackInfo<v8::Boolean>& info);                      \
+  static void DefineAllProperties(v8::Isolate* pIsolate);
+
+#define IMPLEMENT_SPECIAL_JS_CLASS_PART(js_class_name, class_alternate,    \
+                                        class_name)                        \
+  void js_class_name::queryprop_static(                                    \
+      v8::Local<v8::String> property,                                      \
+      const v8::PropertyCallbackInfo<v8::Integer>& info) {                 \
+    JSSpecialPropQuery<class_alternate>(#class_name, property, info);      \
+  }                                                                        \
+  void js_class_name::getprop_static(                                      \
+      v8::Local<v8::String> property,                                      \
+      const v8::PropertyCallbackInfo<v8::Value>& info) {                   \
+    JSSpecialPropGet<class_alternate>(#class_name, property, info);        \
+  }                                                                        \
+  void js_class_name::putprop_static(                                      \
+      v8::Local<v8::String> property, v8::Local<v8::Value> value,          \
+      const v8::PropertyCallbackInfo<v8::Value>& info) {                   \
+    JSSpecialPropPut<class_alternate>(#class_name, property, value, info); \
+  }                                                                        \
+  void js_class_name::delprop_static(                                      \
+      v8::Local<v8::String> property,                                      \
+      const v8::PropertyCallbackInfo<v8::Boolean>& info) {                 \
+    JSSpecialPropDel<class_alternate>(#class_name, property, info);        \
+  }                                                                        \
+  void js_class_name::DefineAllProperties(v8::Isolate* pIsolate) {         \
+    FXJS_DefineObjAllProperties(                                           \
+        pIsolate, g_nObjDefnID, js_class_name::queryprop_static,           \
+        js_class_name::getprop_static, js_class_name::putprop_static,      \
+        js_class_name::delprop_static);                                    \
+  }
 
 template <class Alt>
 void JSSpecialPropQuery(const char*,
@@ -345,91 +436,6 @@ void JSSpecialPropDel(const char* class_name,
   }
 }
 
-#define DECLARE_SPECIAL_JS_CLASS(js_class_name)                             \
-  static void JSConstructor(IFXJS_Context* cc, v8::Local<v8::Object> obj,   \
-                            v8::Local<v8::Object> global);                  \
-  static void JSDestructor(v8::Local<v8::Object> obj);                      \
-  static JSConstSpec JS_Class_Consts[];                                     \
-  static JSPropertySpec JS_Class_Properties[];                              \
-  static JSMethodSpec JS_Class_Methods[];                                   \
-  static void DefineJSObjects(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); \
-  static const wchar_t* m_pClassName;                                       \
-  static void queryprop_##js_class_name##_static(                           \
-      v8::Local<v8::String> property,                                       \
-      const v8::PropertyCallbackInfo<v8::Integer>& info);                   \
-  static void getprop_##js_class_name##_static(                             \
-      v8::Local<v8::String> property,                                       \
-      const v8::PropertyCallbackInfo<v8::Value>& info);                     \
-  static void putprop_##js_class_name##_static(                             \
-      v8::Local<v8::String> property, v8::Local<v8::Value> value,           \
-      const v8::PropertyCallbackInfo<v8::Value>& info);                     \
-  static void delprop_##js_class_name##_static(                             \
-      v8::Local<v8::String> property,                                       \
-      const v8::PropertyCallbackInfo<v8::Boolean>& info)
-
-#define IMPLEMENT_SPECIAL_JS_CLASS(js_class_name, class_alternate, class_name) \
-  const wchar_t* js_class_name::m_pClassName = JS_WIDESTRING(class_name);      \
-  void js_class_name::queryprop_##js_class_name##_static(                      \
-      v8::Local<v8::String> property,                                          \
-      const v8::PropertyCallbackInfo<v8::Integer>& info) {                     \
-    JSSpecialPropQuery<class_alternate>(#class_name, property, info);          \
-  }                                                                            \
-  void js_class_name::getprop_##js_class_name##_static(                        \
-      v8::Local<v8::String> property,                                          \
-      const v8::PropertyCallbackInfo<v8::Value>& info) {                       \
-    JSSpecialPropGet<class_alternate>(#class_name, property, info);            \
-  }                                                                            \
-  void js_class_name::putprop_##js_class_name##_static(                        \
-      v8::Local<v8::String> property, v8::Local<v8::Value> value,              \
-      const v8::PropertyCallbackInfo<v8::Value>& info) {                       \
-    JSSpecialPropPut<class_alternate>(#class_name, property, value, info);     \
-  }                                                                            \
-  void js_class_name::delprop_##js_class_name##_static(                        \
-      v8::Local<v8::String> property,                                          \
-      const v8::PropertyCallbackInfo<v8::Boolean>& info) {                     \
-    JSSpecialPropDel<class_alternate>(#class_name, property, info);            \
-  }                                                                            \
-  void js_class_name::JSConstructor(IFXJS_Context* cc,                         \
-                                    v8::Local<v8::Object> obj,                 \
-                                    v8::Local<v8::Object> global) {            \
-    CJS_Object* pObj = new js_class_name(obj);                                 \
-    pObj->SetEmbedObject(new class_alternate(pObj));                           \
-    FXJS_SetPrivate(NULL, obj, (void*)pObj);                                   \
-    pObj->InitInstance(cc);                                                    \
-  }                                                                            \
-                                                                               \
-  void js_class_name::JSDestructor(v8::Local<v8::Object> obj) {                \
-    js_class_name* pObj = (js_class_name*)FXJS_GetPrivate(NULL, obj);          \
-    ASSERT(pObj != NULL);                                                      \
-    pObj->ExitInstance();                                                      \
-    delete pObj;                                                               \
-  }                                                                            \
-                                                                               \
-  void js_class_name::DefineJSObjects(v8::Isolate* pIsolate,                   \
-                                      FXJSOBJTYPE eObjType) {                  \
-    int nObjDefnID = FXJS_DefineObj(pIsolate, js_class_name::m_pClassName,     \
-                                    eObjType, JSConstructor, JSDestructor);    \
-    for (int i = 0; i < FX_ArraySize(JS_Class_Properties) - 1; ++i) {          \
-      FXJS_DefineObjProperty(                                                  \
-          pIsolate, nObjDefnID, JS_Class_Properties[i].pName,                  \
-          JS_Class_Properties[i].pPropGet, JS_Class_Properties[i].pPropPut);   \
-    }                                                                          \
-                                                                               \
-    for (int i = 0; i < FX_ArraySize(JS_Class_Methods) - 1; ++i) {             \
-      FXJS_DefineObjMethod(pIsolate, nObjDefnID, JS_Class_Methods[i].pName,    \
-                           JS_Class_Methods[i].pMethodCall);                   \
-    }                                                                          \
-    FXJS_DefineObjAllProperties(                                               \
-        pIsolate, nObjDefnID,                                                  \
-        js_class_name::queryprop_##js_class_name##_static,                     \
-        js_class_name::getprop_##js_class_name##_static,                       \
-        js_class_name::putprop_##js_class_name##_static,                       \
-        js_class_name::delprop_##js_class_name##_static);                      \
-  }
-
-/* ======================================== GLOBAL METHODS
- * ============================================ */
-
 template <FX_BOOL (*F)(IFXJS_Context* cc,
                        const CJS_Parameters& params,
                        CJS_Value& vRet,
@@ -473,7 +479,7 @@ void JSGlobalFunc(const char* func_name_string,
 
 #define IMPLEMENT_JS_STATIC_GLOBAL_FUN(js_class_name)                        \
   void js_class_name::DefineJSObjects(v8::Isolate* pIsolate) {               \
-    for (int i = 0; i < FX_ArraySize(global_methods) - 1; ++i) {             \
+    for (size_t i = 0; i < FX_ArraySize(global_methods) - 1; ++i) {          \
       FXJS_DefineGlobalMethod(pIsolate,                                      \
                               js_class_name::global_methods[i].pName,        \
                               js_class_name::global_methods[i].pMethodCall); \
index 42d61f4..dd5c442 100644 (file)
@@ -613,13 +613,12 @@ FX_BOOL CJS_EventHandler::Shift() {
 Field* CJS_EventHandler::Source() {
   CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime();
   v8::Local<v8::Object> pDocObj = FXJS_NewFxDynamicObj(
-      pRuntime->GetIsolate(), m_pJSContext,
-      FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Document"));
-  ASSERT(pDocObj.IsEmpty() == FALSE);
-  v8::Local<v8::Object> pFieldObj =
-      FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), m_pJSContext,
-                           FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Field"));
-  ASSERT(pFieldObj.IsEmpty() == FALSE);
+      pRuntime->GetIsolate(), m_pJSContext, CJS_Document::g_nObjDefnID);
+  ASSERT(!pDocObj.IsEmpty());
+
+  v8::Local<v8::Object> pFieldObj = FXJS_NewFxDynamicObj(
+      pRuntime->GetIsolate(), m_pJSContext, CJS_Field::g_nObjDefnID);
+  ASSERT(!pFieldObj.IsEmpty());
 
   CJS_Document* pJSDocument =
       (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pDocObj);
@@ -637,13 +636,12 @@ Field* CJS_EventHandler::Source() {
 Field* CJS_EventHandler::Target_Field() {
   CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime();
   v8::Local<v8::Object> pDocObj = FXJS_NewFxDynamicObj(
-      pRuntime->GetIsolate(), m_pJSContext,
-      FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Document"));
-  ASSERT(pDocObj.IsEmpty() == FALSE);
-  v8::Local<v8::Object> pFieldObj =
-      FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), m_pJSContext,
-                           FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Field"));
-  ASSERT(pFieldObj.IsEmpty() == FALSE);
+      pRuntime->GetIsolate(), m_pJSContext, CJS_Document::g_nObjDefnID);
+  ASSERT(!pDocObj.IsEmpty());
+
+  v8::Local<v8::Object> pFieldObj = FXJS_NewFxDynamicObj(
+      pRuntime->GetIsolate(), m_pJSContext, CJS_Field::g_nObjDefnID);
+  ASSERT(!pFieldObj.IsEmpty());
 
   CJS_Document* pJSDocument =
       (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pDocObj);
index 2daa626..a17b8e2 100644 (file)
@@ -84,34 +84,34 @@ void CJS_Runtime::DefineJSObjects() {
 
   // The call order determines the "ObjDefID" assigned to each class.
   // ObjDefIDs 0 - 2
-  CJS_Border::DefineJSObjects(GetIsolate(), FXJS_STATIC);
-  CJS_Display::DefineJSObjects(GetIsolate(), FXJS_STATIC);
-  CJS_Font::DefineJSObjects(GetIsolate(), FXJS_STATIC);
+  CJS_Border::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
+  CJS_Display::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
+  CJS_Font::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
 
   // ObjDefIDs 3 - 5
-  CJS_Highlight::DefineJSObjects(GetIsolate(), FXJS_STATIC);
-  CJS_Position::DefineJSObjects(GetIsolate(), FXJS_STATIC);
-  CJS_ScaleHow::DefineJSObjects(GetIsolate(), FXJS_STATIC);
+  CJS_Highlight::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
+  CJS_Position::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
+  CJS_ScaleHow::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
 
   // ObjDefIDs 6 - 8
-  CJS_ScaleWhen::DefineJSObjects(GetIsolate(), FXJS_STATIC);
-  CJS_Style::DefineJSObjects(GetIsolate(), FXJS_STATIC);
-  CJS_Zoomtype::DefineJSObjects(GetIsolate(), FXJS_STATIC);
+  CJS_ScaleWhen::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
+  CJS_Style::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
+  CJS_Zoomtype::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
 
   // ObjDefIDs 9 - 11
-  CJS_App::DefineJSObjects(GetIsolate(), FXJS_STATIC);
-  CJS_Color::DefineJSObjects(GetIsolate(), FXJS_STATIC);
-  CJS_Console::DefineJSObjects(GetIsolate(), FXJS_STATIC);
+  CJS_App::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
+  CJS_Color::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
+  CJS_Console::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
 
   // ObjDefIDs 12 - 14
-  CJS_Document::DefineJSObjects(GetIsolate(), FXJS_DYNAMIC);
-  CJS_Event::DefineJSObjects(GetIsolate(), FXJS_STATIC);
-  CJS_Field::DefineJSObjects(GetIsolate(), FXJS_DYNAMIC);
+  CJS_Document::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_GLOBAL);
+  CJS_Event::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
+  CJS_Field::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC);
 
   // ObjDefIDs 15 - 17
-  CJS_Global::DefineJSObjects(GetIsolate(), FXJS_STATIC);
-  CJS_Icon::DefineJSObjects(GetIsolate(), FXJS_DYNAMIC);
-  CJS_Util::DefineJSObjects(GetIsolate(), FXJS_STATIC);
+  CJS_Global::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
+  CJS_Icon::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC);
+  CJS_Util::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_STATIC);
 
   // ObjDefIDs 18 - 20 (these can't fail, return void).
   CJS_PublicMethods::DefineJSObjects(GetIsolate());
@@ -119,8 +119,8 @@ void CJS_Runtime::DefineJSObjects() {
   CJS_GlobalArrays::DefineJSObjects(GetIsolate());
 
   // ObjDefIDs 21 - 22.
-  CJS_TimerObj::DefineJSObjects(GetIsolate(), FXJS_DYNAMIC);
-  CJS_PrintParamsObj::DefineJSObjects(GetIsolate(), FXJS_DYNAMIC);
+  CJS_TimerObj::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC);
+  CJS_PrintParamsObj::DefineJSObjects(GetIsolate(), FXJSOBJTYPE_DYNAMIC);
 }
 
 IFXJS_Context* CJS_Runtime::NewContext() {
@@ -159,8 +159,7 @@ void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc) {
     if (pReaderDoc) {
       v8::Local<v8::Object> pThis = FXJS_GetThisObj(GetIsolate());
       if (!pThis.IsEmpty()) {
-        if (FXJS_GetObjDefnID(pThis) ==
-            FXJS_GetObjDefnID(GetIsolate(), L"Document")) {
+        if (FXJS_GetObjDefnID(pThis) == CJS_Document::g_nObjDefnID) {
           if (CJS_Document* pJSDocument =
                   (CJS_Document*)FXJS_GetPrivate(GetIsolate(), pThis)) {
             if (Document* pDocument = (Document*)pJSDocument->GetEmbedObject())
index a2e1af4..eb79ad6 100644 (file)
@@ -124,14 +124,12 @@ FX_BOOL app::activeDocs(IFXJS_Context* cc,
     CJS_Document* pJSDocument = NULL;
     if (pDoc == pCurDoc) {
       v8::Local<v8::Object> pObj = FXJS_GetThisObj(pRuntime->GetIsolate());
-      if (FXJS_GetObjDefnID(pObj) ==
-          FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Document"))
+      if (FXJS_GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID)
         pJSDocument =
             (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
     } else {
       v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
-          pRuntime->GetIsolate(), pContext,
-          FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"Document"));
+          pRuntime->GetIsolate(), pContext, CJS_Document::g_nObjDefnID);
       pJSDocument =
           (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
       ASSERT(pJSDocument != NULL);
@@ -414,20 +412,13 @@ FX_BOOL app::setInterval(IFXJS_Context* cc,
   m_aTimer.Add(pTimer);
 
   v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj(
-      pRuntime->GetIsolate(), pContext,
-      FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj"));
-
+      pRuntime->GetIsolate(), pContext, CJS_TimerObj::g_nObjDefnID);
   CJS_TimerObj* pJS_TimerObj =
       (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj);
-  ASSERT(pJS_TimerObj != NULL);
-
   TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
-  ASSERT(pTimerObj != NULL);
-
   pTimerObj->SetTimer(pTimer);
 
   vRet = pRetObj;
-
   return TRUE;
 }
 
@@ -462,20 +453,13 @@ FX_BOOL app::setTimeOut(IFXJS_Context* cc,
   m_aTimer.Add(pTimer);
 
   v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj(
-      pRuntime->GetIsolate(), pContext,
-      FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj"));
-
+      pRuntime->GetIsolate(), pContext, CJS_TimerObj::g_nObjDefnID);
   CJS_TimerObj* pJS_TimerObj =
       (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj);
-  ASSERT(pJS_TimerObj != NULL);
-
   TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
-  ASSERT(pTimerObj != NULL);
-
   pTimerObj->SetTimer(pTimer);
 
   vRet = pRetObj;
-
   return TRUE;
 }
 
@@ -484,35 +468,28 @@ FX_BOOL app::clearTimeOut(IFXJS_Context* cc,
                           CJS_Value& vRet,
                           CFX_WideString& sError) {
   CJS_Context* pContext = (CJS_Context*)cc;
-  ASSERT(pContext != NULL);
-  CJS_Runtime* pRuntime = pContext->GetJSRuntime();
-  ASSERT(pRuntime != NULL);
-
   if (params.size() != 1) {
-    sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
+    sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
     return FALSE;
   }
 
   if (params[0].GetType() == CJS_Value::VT_fxobject) {
     v8::Local<v8::Object> pObj = params[0].ToV8Object();
-    {
-      if (FXJS_GetObjDefnID(pObj) ==
-          FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj")) {
-        if (CJS_Object* pJSObj = params[0].ToCJSObject()) {
-          if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) {
-            if (CJS_Timer* pTimer = pTimerObj->GetTimer()) {
-              pTimer->KillJSTimer();
-
-              for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) {
-                if (m_aTimer[i] == pTimer) {
-                  m_aTimer.RemoveAt(i);
-                  break;
-                }
+    if (FXJS_GetObjDefnID(pObj) == CJS_TimerObj::g_nObjDefnID) {
+      if (CJS_Object* pJSObj = params[0].ToCJSObject()) {
+        if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) {
+          if (CJS_Timer* pTimer = pTimerObj->GetTimer()) {
+            pTimer->KillJSTimer();
+
+            for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) {
+              if (m_aTimer[i] == pTimer) {
+                m_aTimer.RemoveAt(i);
+                break;
               }
-
-              delete pTimer;
-              pTimerObj->SetTimer(NULL);
             }
+
+            delete pTimer;
+            pTimerObj->SetTimer(NULL);
           }
         }
       }
@@ -527,35 +504,28 @@ FX_BOOL app::clearInterval(IFXJS_Context* cc,
                            CJS_Value& vRet,
                            CFX_WideString& sError) {
   CJS_Context* pContext = (CJS_Context*)cc;
-  ASSERT(pContext != NULL);
-  CJS_Runtime* pRuntime = pContext->GetJSRuntime();
-  ASSERT(pRuntime != NULL);
-
   if (params.size() != 1) {
-    sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
+    sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
     return FALSE;
   }
 
   if (params[0].GetType() == CJS_Value::VT_fxobject) {
     v8::Local<v8::Object> pObj = params[0].ToV8Object();
-    {
-      if (FXJS_GetObjDefnID(pObj) ==
-          FXJS_GetObjDefnID(pRuntime->GetIsolate(), L"TimerObj")) {
-        if (CJS_Object* pJSObj = params[0].ToCJSObject()) {
-          if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) {
-            if (CJS_Timer* pTimer = pTimerObj->GetTimer()) {
-              pTimer->KillJSTimer();
-
-              for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) {
-                if (m_aTimer[i] == pTimer) {
-                  m_aTimer.RemoveAt(i);
-                  break;
-                }
+    if (FXJS_GetObjDefnID(pObj) == CJS_TimerObj::g_nObjDefnID) {
+      if (CJS_Object* pJSObj = params[0].ToCJSObject()) {
+        if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) {
+          if (CJS_Timer* pTimer = pTimerObj->GetTimer()) {
+            pTimer->KillJSTimer();
+
+            for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) {
+              if (m_aTimer[i] == pTimer) {
+                m_aTimer.RemoveAt(i);
+                break;
               }
-
-              delete pTimer;
-              pTimerObj->SetTimer(NULL);
             }
+
+            delete pTimer;
+            pTimerObj->SetTimer(NULL);
           }
         }
       }
index 7824a1e..4cf1eca 100644 (file)
@@ -33,7 +33,7 @@ class CJS_TimerObj : public CJS_Object {
   CJS_TimerObj(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {}
   ~CJS_TimerObj() override {}
 
-  DECLARE_JS_CLASS(CJS_TimerObj);
+  DECLARE_JS_CLASS();
 };
 
 class app : public CJS_EmbedObj {
@@ -177,7 +177,7 @@ class CJS_App : public CJS_Object {
   explicit CJS_App(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {}
   ~CJS_App() override {}
 
-  DECLARE_JS_CLASS(CJS_App);
+  DECLARE_JS_CLASS();
 
   JS_STATIC_PROP(activeDocs, app);
   JS_STATIC_PROP(calculate, app);
index 9dec191..12b1f7a 100644 (file)
@@ -63,7 +63,7 @@ class CJS_Color : public CJS_Object {
   CJS_Color(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {}
   ~CJS_Color() override {}
 
-  DECLARE_JS_CLASS(CJS_Color);
+  DECLARE_JS_CLASS();
 
   JS_STATIC_PROP(black, color);
   JS_STATIC_PROP(blue, color);
index 747bc15..b3cdf26 100644 (file)
@@ -38,7 +38,7 @@ class CJS_Console : public CJS_Object {
   CJS_Console(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {}
   ~CJS_Console() override {}
 
-  DECLARE_JS_CLASS(CJS_Console);
+  DECLARE_JS_CLASS();
 
   JS_STATIC_METHOD(clear, console);
   JS_STATIC_METHOD(hide, console);
index 29ff3bc..8efa2df 100644 (file)
@@ -62,8 +62,7 @@ class CJS_Event : public CJS_Object {
   CJS_Event(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {}
   ~CJS_Event() override {}
 
-  DECLARE_JS_CLASS(CJS_Event);
-
+  DECLARE_JS_CLASS();
   JS_STATIC_PROP(change, event);
   JS_STATIC_PROP(changeEx, event);
   JS_STATIC_PROP(commitKey, event);
index 03b6e76..ac79ff2 100644 (file)
@@ -85,8 +85,7 @@ class CJS_Global : public CJS_Object {
   // CJS_Object
   FX_BOOL InitInstance(IFXJS_Context* cc) override;
 
-  DECLARE_SPECIAL_JS_CLASS(CJS_Global);
-
+  DECLARE_SPECIAL_JS_CLASS();
   JS_SPECIAL_STATIC_METHOD(setPersistent, JSGlobalAlternate, global);
 };
 
index 0b4be6d..798106b 100644 (file)
@@ -30,8 +30,7 @@ class CJS_Report : public CJS_Object {
   CJS_Report(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {}
   ~CJS_Report() override {}
 
- public:
-  DECLARE_JS_CLASS(CJS_Report);
+  DECLARE_JS_CLASS();
 
   JS_STATIC_METHOD(save, Report)
   JS_STATIC_METHOD(writeText, Report);
index c88462c..8d0d5bd 100644 (file)
@@ -54,7 +54,7 @@ class CJS_Util : public CJS_Object {
   CJS_Util(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {}
   ~CJS_Util() override {}
 
-  DECLARE_JS_CLASS(CJS_Util);
+  DECLARE_JS_CLASS();
 
   JS_STATIC_METHOD(printd, util);
   JS_STATIC_METHOD(printf, util);
index 70cdc2d..4715d2a 100644 (file)
@@ -52,11 +52,10 @@ class CFXJS_ObjDefinition {
                       FXJSOBJTYPE eObjType,
                       FXJS_CONSTRUCTOR pConstructor,
                       FXJS_DESTRUCTOR pDestructor)
-      : objName(sObjName),
-        objType(eObjType),
+      : m_ObjName(sObjName),
+        m_ObjType(eObjType),
         m_pConstructor(pConstructor),
         m_pDestructor(pDestructor),
-        m_bSetAsGlobalObject(FALSE),
         m_pIsolate(isolate) {
     v8::Isolate::Scope isolate_scope(isolate);
     v8::HandleScope handle_scope(isolate);
@@ -67,11 +66,6 @@ class CFXJS_ObjDefinition {
 
     v8::Local<v8::Signature> sig = v8::Signature::New(isolate, fun);
     m_Signature.Reset(isolate, sig);
-
-    // Document as the global object.
-    if (FXSYS_wcscmp(sObjName, L"Document") == 0) {
-      m_bSetAsGlobalObject = TRUE;
-    }
   }
 
   int AssignID() {
@@ -92,11 +86,10 @@ class CFXJS_ObjDefinition {
     return scope.Escape(m_Signature.Get(m_pIsolate));
   }
 
-  const wchar_t* objName;
-  const FXJSOBJTYPE objType;
+  const wchar_t* const m_ObjName;
+  const FXJSOBJTYPE m_ObjType;
   const FXJS_CONSTRUCTOR m_pConstructor;
   const FXJS_DESTRUCTOR m_pDestructor;
-  FX_BOOL m_bSetAsGlobalObject;
 
   v8::Isolate* m_pIsolate;
   v8::Global<v8::FunctionTemplate> m_FunctionTemplate;
@@ -109,10 +102,9 @@ static v8::Local<v8::ObjectTemplate> GetGlobalObjectTemplate(
   int maxID = CFXJS_ObjDefinition::MaxID(pIsolate);
   for (int i = 0; i < maxID; ++i) {
     CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i);
-    if (pObjDef->m_bSetAsGlobalObject)
+    if (pObjDef->m_ObjType == FXJSOBJTYPE_GLOBAL)
       return pObjDef->GetInstanceTemplate();
   }
-
   if (!g_DefaultGlobalObjectTemplate) {
     g_DefaultGlobalObjectTemplate = new v8::Global<v8::ObjectTemplate>;
     g_DefaultGlobalObjectTemplate->Reset(pIsolate,
@@ -299,36 +291,31 @@ void FXJS_InitializeRuntime(v8::Isolate* pIsolate,
   int maxID = CFXJS_ObjDefinition::MaxID(pIsolate);
   for (int i = 0; i < maxID; ++i) {
     CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i);
-    CFX_WideString ws = CFX_WideString(pObjDef->objName);
-    CFX_ByteString bs = ws.UTF8Encode();
-    v8::Local<v8::String> objName =
+    CFX_ByteString bs = CFX_WideString(pObjDef->m_ObjName).UTF8Encode();
+    v8::Local<v8::String> m_ObjName =
         v8::String::NewFromUtf8(pIsolate, bs.c_str(),
                                 v8::NewStringType::kNormal,
                                 bs.GetLength()).ToLocalChecked();
 
-    if (pObjDef->objType == FXJS_DYNAMIC) {
-      // Document is set as global object, need to construct it first.
-      if (ws.Equal(L"Document")) {
-        v8Context->Global()
-            ->GetPrototype()
-            ->ToObject(v8Context)
-            .ToLocalChecked()
-            ->SetAlignedPointerInInternalField(0, new CFXJS_PrivateData(i));
-
-        if (pObjDef->m_pConstructor) {
-          pObjDef->m_pConstructor(context, v8Context->Global()
-                                               ->GetPrototype()
-                                               ->ToObject(v8Context)
-                                               .ToLocalChecked(),
-                                  v8Context->Global()
-                                      ->GetPrototype()
-                                      ->ToObject(v8Context)
-                                      .ToLocalChecked());
-        }
-      }
-    } else {
+    if (pObjDef->m_ObjType == FXJSOBJTYPE_GLOBAL) {
+      v8Context->Global()
+          ->GetPrototype()
+          ->ToObject(v8Context)
+          .ToLocalChecked()
+          ->SetAlignedPointerInInternalField(0, new CFXJS_PrivateData(i));
+
+      if (pObjDef->m_pConstructor)
+        pObjDef->m_pConstructor(context, v8Context->Global()
+                                             ->GetPrototype()
+                                             ->ToObject(v8Context)
+                                             .ToLocalChecked(),
+                                v8Context->Global()
+                                    ->GetPrototype()
+                                    ->ToObject(v8Context)
+                                    .ToLocalChecked());
+    } else if (pObjDef->m_ObjType == FXJSOBJTYPE_STATIC) {
       v8::Local<v8::Object> obj = FXJS_NewFxDynamicObj(pIsolate, context, i);
-      v8Context->Global()->Set(v8Context, objName, obj).FromJust();
+      v8Context->Global()->Set(v8Context, m_ObjName, obj).FromJust();
       pObjDef->m_StaticObj.Reset(pIsolate, obj);
     }
   }
@@ -467,20 +454,6 @@ v8::Isolate* FXJS_GetRuntime(v8::Local<v8::Object> pObj) {
   return context->GetIsolate();
 }
 
-int FXJS_GetObjDefnID(v8::Isolate* pIsolate, const wchar_t* pObjName) {
-  v8::Isolate::Scope isolate_scope(pIsolate);
-  if (!FXJS_PerIsolateData::Get(pIsolate))
-    return -1;
-
-  int maxID = CFXJS_ObjDefinition::MaxID(pIsolate);
-  for (int i = 0; i < maxID; ++i) {
-    CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i);
-    if (FXSYS_wcscmp(pObjDef->objName, pObjName) == 0)
-      return i;
-  }
-  return -1;
-}
-
 void FXJS_Error(v8::Isolate* pIsolate, const CFX_WideString& message) {
   // Conversion from pdfium's wchar_t wide-strings to v8's uint16_t
   // wide-strings isn't handled by v8, so use UTF8 as a common