summaryrefslogtreecommitdiff
path: root/fpdfsdk/src
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/src')
-rw-r--r--fpdfsdk/src/javascript/Consts.cpp31
-rw-r--r--fpdfsdk/src/javascript/JS_Runtime.cpp65
2 files changed, 61 insertions, 35 deletions
diff --git a/fpdfsdk/src/javascript/Consts.cpp b/fpdfsdk/src/javascript/Consts.cpp
index 77cf445d77..b534d2b393 100644
--- a/fpdfsdk/src/javascript/Consts.cpp
+++ b/fpdfsdk/src/javascript/Consts.cpp
@@ -127,10 +127,16 @@ END_JS_STATIC_CONST()
IMPLEMENT_JS_CLASS_CONST(CJS_Zoomtype, zoomtype)
-/* ------------------------------ CJS_GlobalConsts
- * ------------------------------ */
+/* ------------------------------ CJS_GlobalConsts ------------------------- */
-int CJS_GlobalConsts::Init(v8::Isolate* pIsolate) {
+#define DEFINE_GLOBAL_CONST(pIsolate, const_name, const_value) \
+ if (JS_DefineGlobalConst( \
+ pIsolate, JS_WIDESTRING(const_name), \
+ JS_NewString(pIsolate, JS_WIDESTRING(const_value)))) { \
+ return -1; \
+ }
+
+int CJS_GlobalConsts::DefineJSObjects(v8::Isolate* pIsolate) {
DEFINE_GLOBAL_CONST(pIsolate, IDS_GREATER_THAN, Invalid value
: must be greater than or equal to % s.);
DEFINE_GLOBAL_CONST(
@@ -156,10 +162,23 @@ int CJS_GlobalConsts::Init(v8::Isolate* pIsolate) {
return 0;
}
-/* ------------------------------ CJS_GlobalArrays
- * ------------------------------ */
+/* ------------------------------ CJS_GlobalArrays ------------------------ */
+
+#define DEFINE_GLOBAL_ARRAY(pIsolate) \
+ int size = FX_ArraySize(ArrayContent); \
+ \
+ CJS_Array array(pIsolate); \
+ for (int i = 0; i < size; i++) \
+ array.SetElement(i, CJS_Value(pIsolate, ArrayContent[i])); \
+ \
+ CJS_PropValue prop(pIsolate); \
+ prop << array; \
+ if (JS_DefineGlobalConst(pIsolate, (const wchar_t*)ArrayName, \
+ prop.ToV8Value()) < 0) { \
+ return -1; \
+ }
-int CJS_GlobalArrays::Init(v8::Isolate* pIsolate) {
+int CJS_GlobalArrays::DefineJSObjects(v8::Isolate* pIsolate) {
{
const FX_WCHAR* ArrayName = L"RE_NUMBER_ENTRY_DOT_SEP";
const FX_WCHAR* ArrayContent[] = {L"[+-]?\\d*\\.?\\d*"};
diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp
index 062dd25b29..95060ae4ac 100644
--- a/fpdfsdk/src/javascript/JS_Runtime.cpp
+++ b/fpdfsdk/src/javascript/JS_Runtime.cpp
@@ -130,7 +130,7 @@ CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp)
return;
}
- InitJSObjects();
+ DefineJSObjects();
CJS_Context* pContext = (CJS_Context*)NewContext();
JS_InitialRuntime(GetIsolate(), this, pContext, m_context);
@@ -156,66 +156,73 @@ CJS_Runtime::~CJS_Runtime() {
m_isolate = NULL;
}
-FX_BOOL CJS_Runtime::InitJSObjects() {
+FX_BOOL CJS_Runtime::DefineJSObjects() {
v8::Isolate::Scope isolate_scope(GetIsolate());
v8::Locker locker(GetIsolate());
v8::HandleScope handle_scope(GetIsolate());
v8::Local<v8::Context> context = v8::Context::New(GetIsolate());
v8::Context::Scope context_scope(context);
- // 0 - 8
- if (CJS_Border::Init(GetIsolate(), JS_STATIC) < 0)
+
+ // The call order determines the "ObjDefID" assigned to each class.
+ // ObjDefIDs 0 - 2
+ if (CJS_Border::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
return FALSE;
- if (CJS_Display::Init(GetIsolate(), JS_STATIC) < 0)
+ if (CJS_Display::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
return FALSE;
- if (CJS_Font::Init(GetIsolate(), JS_STATIC) < 0)
+ if (CJS_Font::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
return FALSE;
- if (CJS_Highlight::Init(GetIsolate(), JS_STATIC) < 0)
+
+ // ObjDefIDs 3 - 5
+ if (CJS_Highlight::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
return FALSE;
- if (CJS_Position::Init(GetIsolate(), JS_STATIC) < 0)
+ if (CJS_Position::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
return FALSE;
- if (CJS_ScaleHow::Init(GetIsolate(), JS_STATIC) < 0)
+ if (CJS_ScaleHow::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
return FALSE;
- if (CJS_ScaleWhen::Init(GetIsolate(), JS_STATIC) < 0)
+
+ // ObjDefIDs 6 - 8
+ if (CJS_ScaleWhen::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
return FALSE;
- if (CJS_Style::Init(GetIsolate(), JS_STATIC) < 0)
+ if (CJS_Style::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
return FALSE;
- if (CJS_Zoomtype::Init(GetIsolate(), JS_STATIC) < 0)
+ if (CJS_Zoomtype::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
return FALSE;
- // 9 - 11
- if (CJS_App::Init(GetIsolate(), JS_STATIC) < 0)
+ // ObjDefIDs 9 - 11
+ if (CJS_App::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
return FALSE;
- if (CJS_Color::Init(GetIsolate(), JS_STATIC) < 0)
+ if (CJS_Color::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
return FALSE;
- if (CJS_Console::Init(GetIsolate(), JS_STATIC) < 0)
+ if (CJS_Console::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
return FALSE;
- // 12 - 14
- if (CJS_Document::Init(GetIsolate(), JS_DYNAMIC) < 0)
+ // ObjDefIDs 12 - 14
+ if (CJS_Document::DefineJSObjects(GetIsolate(), JS_DYNAMIC) < 0)
return FALSE;
- if (CJS_Event::Init(GetIsolate(), JS_STATIC) < 0)
+ if (CJS_Event::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
return FALSE;
- if (CJS_Field::Init(GetIsolate(), JS_DYNAMIC) < 0)
+ if (CJS_Field::DefineJSObjects(GetIsolate(), JS_DYNAMIC) < 0)
return FALSE;
- // 15 - 17
- if (CJS_Global::Init(GetIsolate(), JS_STATIC) < 0)
+ // ObjDefIDs 15 - 17
+ if (CJS_Global::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
return FALSE;
- if (CJS_Icon::Init(GetIsolate(), JS_DYNAMIC) < 0)
+ if (CJS_Icon::DefineJSObjects(GetIsolate(), JS_DYNAMIC) < 0)
return FALSE;
- if (CJS_Util::Init(GetIsolate(), JS_STATIC) < 0)
+ if (CJS_Util::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
return FALSE;
- if (CJS_PublicMethods::Init(GetIsolate()) < 0)
+ // ObjDefIDs 18 - 20
+ if (CJS_PublicMethods::DefineJSObjects(GetIsolate()) < 0)
return FALSE;
- if (CJS_GlobalConsts::Init(GetIsolate()) < 0)
+ if (CJS_GlobalConsts::DefineJSObjects(GetIsolate()) < 0)
return FALSE;
- if (CJS_GlobalArrays::Init(GetIsolate()) < 0)
+ if (CJS_GlobalArrays::DefineJSObjects(GetIsolate()) < 0)
return FALSE;
- if (CJS_TimerObj::Init(GetIsolate(), JS_DYNAMIC) < 0)
+ if (CJS_TimerObj::DefineJSObjects(GetIsolate(), JS_DYNAMIC) < 0)
return FALSE;
- if (CJS_PrintParamsObj::Init(GetIsolate(), JS_DYNAMIC) < 0)
+ if (CJS_PrintParamsObj::DefineJSObjects(GetIsolate(), JS_DYNAMIC) < 0)
return FALSE;
return TRUE;