summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fpdfsdk/include/jsapi/fxjs_v8.h6
-rw-r--r--fpdfsdk/src/javascript/Document.cpp28
-rw-r--r--fpdfsdk/src/javascript/Document.h4
-rw-r--r--fpdfsdk/src/javascript/Field.cpp10
-rw-r--r--fpdfsdk/src/javascript/Field.h3
-rw-r--r--fpdfsdk/src/javascript/Icon.h4
-rw-r--r--fpdfsdk/src/javascript/JS_Define.h328
-rw-r--r--fpdfsdk/src/javascript/JS_EventHandler.cpp26
-rw-r--r--fpdfsdk/src/javascript/JS_Runtime.cpp43
-rw-r--r--fpdfsdk/src/javascript/app.cpp94
-rw-r--r--fpdfsdk/src/javascript/app.h4
-rw-r--r--fpdfsdk/src/javascript/color.h2
-rw-r--r--fpdfsdk/src/javascript/console.h2
-rw-r--r--fpdfsdk/src/javascript/event.h3
-rw-r--r--fpdfsdk/src/javascript/global.h3
-rw-r--r--fpdfsdk/src/javascript/report.h3
-rw-r--r--fpdfsdk/src/javascript/util.h2
-rw-r--r--fpdfsdk/src/jsapi/fxjs_v8.cpp77
18 files changed, 284 insertions, 358 deletions
diff --git a/fpdfsdk/include/jsapi/fxjs_v8.h b/fpdfsdk/include/jsapi/fxjs_v8.h
index 8b5c0b2dd0..289a73e14a 100644
--- a/fpdfsdk/include/jsapi/fxjs_v8.h
+++ b/fpdfsdk/include/jsapi/fxjs_v8.h
@@ -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);
diff --git a/fpdfsdk/src/javascript/Document.cpp b/fpdfsdk/src/javascript/Document.cpp
index 748aad3a15..d31bdc4a4e 100644
--- a/fpdfsdk/src/javascript/Document.cpp
+++ b/fpdfsdk/src/javascript/Document.cpp
@@ -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.
diff --git a/fpdfsdk/src/javascript/Document.h b/fpdfsdk/src/javascript/Document.h
index 6c403e383b..42ba9d7dbf 100644
--- a/fpdfsdk/src/javascript/Document.h
+++ b/fpdfsdk/src/javascript/Document.h
@@ -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);
diff --git a/fpdfsdk/src/javascript/Field.cpp b/fpdfsdk/src/javascript/Field.cpp
index 7026530d72..973d912273 100644
--- a/fpdfsdk/src/javascript/Field.cpp
+++ b/fpdfsdk/src/javascript/Field.cpp
@@ -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);
diff --git a/fpdfsdk/src/javascript/Field.h b/fpdfsdk/src/javascript/Field.h
index a62bf39a9a..daf47d5c37 100644
--- a/fpdfsdk/src/javascript/Field.h
+++ b/fpdfsdk/src/javascript/Field.h
@@ -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);
diff --git a/fpdfsdk/src/javascript/Icon.h b/fpdfsdk/src/javascript/Icon.h
index b03048b47b..c1880601dc 100644
--- a/fpdfsdk/src/javascript/Icon.h
+++ b/fpdfsdk/src/javascript/Icon.h
@@ -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);
};
diff --git a/fpdfsdk/src/javascript/JS_Define.h b/fpdfsdk/src/javascript/JS_Define.h
index 5e98b4f0ea..3881951ff8 100644
--- a/fpdfsdk/src/javascript/JS_Define.h
+++ b/fpdfsdk/src/javascript/JS_Define.h
@@ -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); \
diff --git a/fpdfsdk/src/javascript/JS_EventHandler.cpp b/fpdfsdk/src/javascript/JS_EventHandler.cpp
index 42d61f4c1e..dd5c4427ce 100644
--- a/fpdfsdk/src/javascript/JS_EventHandler.cpp
+++ b/fpdfsdk/src/javascript/JS_EventHandler.cpp
@@ -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);
diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp
index 2daa62608b..a17b8e23a5 100644
--- a/fpdfsdk/src/javascript/JS_Runtime.cpp
+++ b/fpdfsdk/src/javascript/JS_Runtime.cpp
@@ -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())
diff --git a/fpdfsdk/src/javascript/app.cpp b/fpdfsdk/src/javascript/app.cpp
index a2e1af4dca..eb79ad6208 100644
--- a/fpdfsdk/src/javascript/app.cpp
+++ b/fpdfsdk/src/javascript/app.cpp
@@ -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);
}
}
}
diff --git a/fpdfsdk/src/javascript/app.h b/fpdfsdk/src/javascript/app.h
index 7824a1e99e..4cf1eca1b2 100644
--- a/fpdfsdk/src/javascript/app.h
+++ b/fpdfsdk/src/javascript/app.h
@@ -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);
diff --git a/fpdfsdk/src/javascript/color.h b/fpdfsdk/src/javascript/color.h
index 9dec19174e..12b1f7a01b 100644
--- a/fpdfsdk/src/javascript/color.h
+++ b/fpdfsdk/src/javascript/color.h
@@ -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);
diff --git a/fpdfsdk/src/javascript/console.h b/fpdfsdk/src/javascript/console.h
index 747bc15098..b3cdf268c2 100644
--- a/fpdfsdk/src/javascript/console.h
+++ b/fpdfsdk/src/javascript/console.h
@@ -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);
diff --git a/fpdfsdk/src/javascript/event.h b/fpdfsdk/src/javascript/event.h
index 29ff3bc290..8efa2dfbb8 100644
--- a/fpdfsdk/src/javascript/event.h
+++ b/fpdfsdk/src/javascript/event.h
@@ -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);
diff --git a/fpdfsdk/src/javascript/global.h b/fpdfsdk/src/javascript/global.h
index 03b6e76bc8..ac79ff2f3d 100644
--- a/fpdfsdk/src/javascript/global.h
+++ b/fpdfsdk/src/javascript/global.h
@@ -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);
};
diff --git a/fpdfsdk/src/javascript/report.h b/fpdfsdk/src/javascript/report.h
index 0b4be6d6d7..798106bb11 100644
--- a/fpdfsdk/src/javascript/report.h
+++ b/fpdfsdk/src/javascript/report.h
@@ -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);
diff --git a/fpdfsdk/src/javascript/util.h b/fpdfsdk/src/javascript/util.h
index c88462c349..8d0d5bd562 100644
--- a/fpdfsdk/src/javascript/util.h
+++ b/fpdfsdk/src/javascript/util.h
@@ -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);
diff --git a/fpdfsdk/src/jsapi/fxjs_v8.cpp b/fpdfsdk/src/jsapi/fxjs_v8.cpp
index 70cdc2dc15..4715d2a8d2 100644
--- a/fpdfsdk/src/jsapi/fxjs_v8.cpp
+++ b/fpdfsdk/src/jsapi/fxjs_v8.cpp
@@ -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