summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-09-11 13:04:48 -0700
committerTom Sepez <tsepez@chromium.org>2015-09-11 13:04:48 -0700
commitf9e40aec10263f9445d69598657f42550294d653 (patch)
treeeb20eaef0841334b14266b4a83efe34ade7b1b0e /fpdfsdk
parentdf4de98c06075b0e491ac645f2d118a6813cedc9 (diff)
downloadpdfium-f9e40aec10263f9445d69598657f42550294d653.tar.xz
Fix strings, remove stringify macros, void return types for Consts.h.
Replace multiple #defines of the same strings with externs. Fix strings mangled by interaction of # and clang-format. Remove macros as possible. Make more JS_ functions void and simplify. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1342433002 .
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/include/javascript/Consts.h4
-rw-r--r--fpdfsdk/include/javascript/JS_Define.h227
-rw-r--r--fpdfsdk/include/javascript/JS_Runtime.h2
-rw-r--r--fpdfsdk/include/jsapi/fxjs_v8.h60
-rw-r--r--fpdfsdk/src/javascript/Consts.cpp125
-rw-r--r--fpdfsdk/src/javascript/JS_Runtime.cpp80
-rw-r--r--fpdfsdk/src/javascript/global.cpp16
-rw-r--r--fpdfsdk/src/jsapi/fxjs_v8.cpp114
8 files changed, 280 insertions, 348 deletions
diff --git a/fpdfsdk/include/javascript/Consts.h b/fpdfsdk/include/javascript/Consts.h
index 778e2216f4..c6abd8549a 100644
--- a/fpdfsdk/include/javascript/Consts.h
+++ b/fpdfsdk/include/javascript/Consts.h
@@ -103,14 +103,14 @@ class CJS_Zoomtype : public CJS_Object {
class CJS_GlobalConsts : public CJS_Object {
public:
- static int DefineJSObjects(v8::Isolate* pIsolate);
+ static void DefineJSObjects(v8::Isolate* pIsolate);
};
/* ------------------------------ CJS_GlobalArrays -------------------------- */
class CJS_GlobalArrays : public CJS_Object {
public:
- static int DefineJSObjects(v8::Isolate* pIsolate);
+ static void DefineJSObjects(v8::Isolate* pIsolate);
};
#endif // FPDFSDK_INCLUDE_JAVASCRIPT_CONSTS_H_
diff --git a/fpdfsdk/include/javascript/JS_Define.h b/fpdfsdk/include/javascript/JS_Define.h
index 0731212f67..ff9ab48817 100644
--- a/fpdfsdk/include/javascript/JS_Define.h
+++ b/fpdfsdk/include/javascript/JS_Define.h
@@ -189,52 +189,46 @@ void JSMethod(const char* method_name_string,
/* ===================================== 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 int DefineJSObjects(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); \
- static JSConstSpec JS_Class_Consts[]; \
- static JSPropertySpec JS_Class_Properties[]; \
- static JSMethodSpec JS_Class_Methods[]; \
+#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)); \
- JS_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*)JS_GetPrivate(NULL, obj); \
- pObj->ExitInstance(); \
- delete pObj; \
- } \
- \
- int js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \
- FXJSOBJTYPE eObjType) { \
- int nObjDefnID = JS_DefineObj(pIsolate, js_class_name::m_pClassName, \
- eObjType, JSConstructor, JSDestructor); \
- if (nObjDefnID < 0) \
- return -1; \
- for (int i = 0; i < FX_ArraySize(JS_Class_Properties) - 1; ++i) { \
- if (JS_DefineObjProperty(pIsolate, nObjDefnID, \
- JS_Class_Properties[i].pName, \
- JS_Class_Properties[i].pPropGet, \
- JS_Class_Properties[i].pPropPut) < 0) \
- return -1; \
- } \
- for (int i = 0; i < FX_ArraySize(JS_Class_Methods) - 1; ++i) { \
- if (JS_DefineObjMethod(pIsolate, nObjDefnID, JS_Class_Methods[i].pName, \
- JS_Class_Methods[i].pMethodCall) < 0) \
- return -1; \
- } \
- return nObjDefnID; \
+#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)); \
+ JS_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*)JS_GetPrivate(NULL, obj); \
+ pObj->ExitInstance(); \
+ delete pObj; \
+ } \
+ \
+ void js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \
+ FXJSOBJTYPE eObjType) { \
+ int nObjDefnID = JS_DefineObj(pIsolate, js_class_name::m_pClassName, \
+ eObjType, JSConstructor, JSDestructor); \
+ for (int i = 0; i < FX_ArraySize(JS_Class_Properties) - 1; ++i) { \
+ JS_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) { \
+ JS_DefineObjMethod(pIsolate, nObjDefnID, JS_Class_Methods[i].pName, \
+ JS_Class_Methods[i].pMethodCall); \
+ } \
}
#define IMPLEMENT_JS_CLASS(js_class_name, class_name) \
@@ -243,35 +237,24 @@ void JSMethod(const char* method_name_string,
/* ======================================== CONST CLASS
* ============================================ */
-#define DECLARE_JS_CLASS_CONST() \
- static int DefineJSObjects(v8::Isolate* pIsolate, FXJSOBJTYPE eObjType); \
- static JSConstSpec JS_Class_Consts[]; \
+#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); \
- int js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \
- FXJSOBJTYPE eObjType) { \
- int nObjDefnID = JS_DefineObj(pIsolate, js_class_name::m_pClassName, \
- eObjType, NULL, NULL); \
- if (nObjDefnID >= 0) { \
- for (int i = 0, sz = sizeof(JS_Class_Consts) / sizeof(JSConstSpec) - 1; \
- i < sz; i++) { \
- if (JS_Class_Consts[i].t == 0) { \
- if (JS_DefineObjConst( \
- pIsolate, nObjDefnID, JS_Class_Consts[i].pName, \
- JS_NewNumber(pIsolate, JS_Class_Consts[i].number)) < 0) \
- return -1; \
- } else { \
- if (JS_DefineObjConst( \
- pIsolate, nObjDefnID, JS_Class_Consts[i].pName, \
- JS_NewString(pIsolate, JS_Class_Consts[i].string)) < 0) \
- return -1; \
- } \
- } \
- return nObjDefnID; \
- } \
- return -1; \
+#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 = JS_DefineObj(pIsolate, js_class_name::m_pClassName, \
+ eObjType, NULL, NULL); \
+ for (int i = 0; i < FX_ArraySize(JS_Class_Consts) - 1; ++i) { \
+ JS_DefineObjConst( \
+ pIsolate, nObjDefnID, JS_Class_Consts[i].pName, \
+ JS_Class_Consts[i].t == 0 \
+ ? JS_NewNumber(pIsolate, JS_Class_Consts[i].number) \
+ : JS_NewString(pIsolate, JS_Class_Consts[i].string)); \
+ } \
}
/* ===================================== SPECIAL JS CLASS
@@ -367,26 +350,26 @@ 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 int 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, \
+#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) \
@@ -427,34 +410,26 @@ void JSSpecialPropDel(const char* class_name,
delete pObj; \
} \
\
- int js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \
- FXJSOBJTYPE eObjType) { \
+ void js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \
+ FXJSOBJTYPE eObjType) { \
int nObjDefnID = JS_DefineObj(pIsolate, js_class_name::m_pClassName, \
eObjType, JSConstructor, JSDestructor); \
- \
- if (nObjDefnID < 0) \
- return -1; \
for (int i = 0; i < FX_ArraySize(JS_Class_Properties) - 1; ++i) { \
- if (JS_DefineObjProperty(pIsolate, nObjDefnID, \
- JS_Class_Properties[i].pName, \
- JS_Class_Properties[i].pPropGet, \
- JS_Class_Properties[i].pPropPut) < 0) \
- return -1; \
+ JS_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) { \
- if (JS_DefineObjMethod(pIsolate, nObjDefnID, JS_Class_Methods[i].pName, \
- JS_Class_Methods[i].pMethodCall) < 0) \
- return -1; \
+ JS_DefineObjMethod(pIsolate, nObjDefnID, JS_Class_Methods[i].pName, \
+ JS_Class_Methods[i].pMethodCall); \
} \
- if (JS_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) < 0) \
- return -1; \
- return nObjDefnID; \
+ JS_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
@@ -493,7 +468,7 @@ void JSGlobalFunc(const char* func_name_string,
#define JS_STATIC_DECLARE_GLOBAL_FUN() \
static JSMethodSpec global_methods[]; \
- static int DefineJSObjects(v8::Isolate* pIsolate)
+ static void DefineJSObjects(v8::Isolate* pIsolate)
#define BEGIN_JS_STATIC_GLOBAL_FUN(js_class_name) \
JSMethodSpec js_class_name::global_methods[] = {
@@ -502,28 +477,14 @@ void JSGlobalFunc(const char* func_name_string,
#define END_JS_STATIC_GLOBAL_FUN() END_JS_STATIC_METHOD()
-#define IMPLEMENT_JS_STATIC_GLOBAL_FUN(js_class_name) \
- int js_class_name::DefineJSObjects(v8::Isolate* pIsolate) { \
- for (int i = 0; i < FX_ArraySize(global_methods) - 1; ++i) { \
- if (JS_DefineGlobalMethod( \
- pIsolate, js_class_name::global_methods[i].pName, \
- js_class_name::global_methods[i].pMethodCall) < 0) \
- return -1; \
- } \
- return 0; \
+#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) { \
+ JS_DefineGlobalMethod(pIsolate, js_class_name::global_methods[i].pName, \
+ js_class_name::global_methods[i].pMethodCall); \
+ } \
}
-/* ============================================================ */
-
-#define VALUE_NAME_STRING L"string"
-#define VALUE_NAME_NUMBER L"number"
-#define VALUE_NAME_BOOLEAN L"boolean"
-#define VALUE_NAME_DATE L"date"
-#define VALUE_NAME_OBJECT L"object"
-#define VALUE_NAME_FXOBJ L"fxobj"
-#define VALUE_NAME_NULL L"null"
-#define VALUE_NAME_UNDEFINED L"undefined"
-
FXJSVALUETYPE GET_VALUE_TYPE(v8::Local<v8::Value> p);
#endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_DEFINE_H_
diff --git a/fpdfsdk/include/javascript/JS_Runtime.h b/fpdfsdk/include/javascript/JS_Runtime.h
index e93f8b3cbe..5ae6f1bc79 100644
--- a/fpdfsdk/include/javascript/JS_Runtime.h
+++ b/fpdfsdk/include/javascript/JS_Runtime.h
@@ -56,7 +56,7 @@ class CJS_Runtime : public IFXJS_Runtime {
v8::Local<v8::Context> NewJSContext();
private:
- FX_BOOL DefineJSObjects();
+ void DefineJSObjects();
CFX_ArrayTemplate<CJS_Context*> m_ContextArray;
CPDFDoc_Environment* m_pApp;
diff --git a/fpdfsdk/include/jsapi/fxjs_v8.h b/fpdfsdk/include/jsapi/fxjs_v8.h
index 8e52c68845..4195686731 100644
--- a/fpdfsdk/include/jsapi/fxjs_v8.h
+++ b/fpdfsdk/include/jsapi/fxjs_v8.h
@@ -36,8 +36,14 @@ struct FXJSErr {
unsigned linnum;
};
-/* --------------------------------------------- API
- * --------------------------------------------- */
+extern const wchar_t kFXJSValueNameString[];
+extern const wchar_t kFXJSValueNameNumber[];
+extern const wchar_t kFXJSValueNameBoolean[];
+extern const wchar_t kFXJSValueNameDate[];
+extern const wchar_t kFXJSValueNameObject[];
+extern const wchar_t kFXJSValueNameFxobj[];
+extern const wchar_t kFXJSValueNameNull[];
+extern const wchar_t kFXJSValueNameUndefined[];
class IFXJS_Context;
class IFXJS_Runtime;
@@ -47,36 +53,38 @@ typedef void (*LP_CONSTRUCTOR)(IFXJS_Context* cc,
v8::Local<v8::Object> global);
typedef void (*LP_DESTRUCTOR)(v8::Local<v8::Object> obj);
+// Always returns a valid, newly-created objDefnID.
int JS_DefineObj(v8::Isolate* pIsolate,
const wchar_t* sObjName,
FXJSOBJTYPE eObjType,
LP_CONSTRUCTOR pConstructor,
LP_DESTRUCTOR pDestructor);
-int JS_DefineObjMethod(v8::Isolate* pIsolate,
+
+void JS_DefineObjMethod(v8::Isolate* pIsolate,
+ int nObjDefnID,
+ const wchar_t* sMethodName,
+ v8::FunctionCallback pMethodCall);
+void JS_DefineObjProperty(v8::Isolate* pIsolate,
+ int nObjDefnID,
+ const wchar_t* sPropName,
+ v8::AccessorGetterCallback pPropGet,
+ v8::AccessorSetterCallback pPropPut);
+void JS_DefineObjAllProperties(v8::Isolate* pIsolate,
+ int nObjDefnID,
+ v8::NamedPropertyQueryCallback pPropQurey,
+ v8::NamedPropertyGetterCallback pPropGet,
+ v8::NamedPropertySetterCallback pPropPut,
+ v8::NamedPropertyDeleterCallback pPropDel);
+void JS_DefineObjConst(v8::Isolate* pIsolate,
int nObjDefnID,
- const wchar_t* sMethodName,
- v8::FunctionCallback pMethodCall);
-int JS_DefineObjProperty(v8::Isolate* pIsolate,
- int nObjDefnID,
- const wchar_t* sPropName,
- v8::AccessorGetterCallback pPropGet,
- v8::AccessorSetterCallback pPropPut);
-int JS_DefineObjAllProperties(v8::Isolate* pIsolate,
- int nObjDefnID,
- v8::NamedPropertyQueryCallback pPropQurey,
- v8::NamedPropertyGetterCallback pPropGet,
- v8::NamedPropertySetterCallback pPropPut,
- v8::NamedPropertyDeleterCallback pPropDel);
-int JS_DefineObjConst(v8::Isolate* pIsolate,
- int nObjDefnID,
- const wchar_t* sConstName,
- v8::Local<v8::Value> pDefault);
-int JS_DefineGlobalMethod(v8::Isolate* pIsolate,
- const wchar_t* sMethodName,
- v8::FunctionCallback pMethodCall);
-int JS_DefineGlobalConst(v8::Isolate* pIsolate,
- const wchar_t* sConstName,
- v8::Local<v8::Value> pDefault);
+ const wchar_t* sConstName,
+ v8::Local<v8::Value> pDefault);
+void JS_DefineGlobalMethod(v8::Isolate* pIsolate,
+ const wchar_t* sMethodName,
+ v8::FunctionCallback pMethodCall);
+void JS_DefineGlobalConst(v8::Isolate* pIsolate,
+ const wchar_t* sConstName,
+ v8::Local<v8::Value> pDefault);
void JS_InitialRuntime(v8::Isolate* pIsolate,
IFXJS_Runtime* pFXRuntime,
diff --git a/fpdfsdk/src/javascript/Consts.cpp b/fpdfsdk/src/javascript/Consts.cpp
index b534d2b393..9574c44730 100644
--- a/fpdfsdk/src/javascript/Consts.cpp
+++ b/fpdfsdk/src/javascript/Consts.cpp
@@ -129,60 +129,62 @@ IMPLEMENT_JS_CLASS_CONST(CJS_Zoomtype, zoomtype)
/* ------------------------------ CJS_GlobalConsts ------------------------- */
-#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; \
- }
+static void DefineGlobalConstString(v8::Isolate* pIsolate,
+ const wchar_t* pConstName,
+ const wchar_t* pValue) {
+ JS_DefineGlobalConst(pIsolate, pConstName, JS_NewString(pIsolate, pValue));
+}
-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(
- pIsolate, IDS_GT_AND_LT, Invalid value
- : must be greater than or equal to % s and less than or equal to % s.);
- DEFINE_GLOBAL_CONST(pIsolate, IDS_LESS_THAN, Invalid value
- : must be less than or equal to % s.);
- DEFINE_GLOBAL_CONST(pIsolate, IDS_INVALID_MONTH, **Invalid**);
- DEFINE_GLOBAL_CONST(pIsolate, IDS_INVALID_DATE, Invalid date / time
- : please ensure that the date / time exists.Field);
- DEFINE_GLOBAL_CONST(pIsolate, IDS_INVALID_VALUE,
- The value entered does not match the format of the field);
- DEFINE_GLOBAL_CONST(pIsolate, IDS_AM, am);
- DEFINE_GLOBAL_CONST(pIsolate, IDS_PM, pm);
- DEFINE_GLOBAL_CONST(
- pIsolate, IDS_MONTH_INFO,
- January[1] February[2] March[3] April[4] May[5] June[6] July[7] August
- [8] September[9] October[10] November[11] December[12] Sept[9] Jan
- [1] Feb[2] Mar[3] Apr[4] Jun[6] Jul[7] Aug[8] Sep[9] Oct[10] Nov
- [11] Dec[12]);
- DEFINE_GLOBAL_CONST(pIsolate, IDS_STARTUP_CONSOLE_MSG, ** ^ _ ^ **);
-
- return 0;
+void CJS_GlobalConsts::DefineJSObjects(v8::Isolate* pIsolate) {
+ DefineGlobalConstString(
+ pIsolate, L"IDS_GREATER_THAN",
+ L"Invalid value: must be greater than or equal to % s.");
+ DefineGlobalConstString(
+ pIsolate, L"IDS_GT_AND_LT",
+ L"Invalid value: must be greater than or equal to % s "
+ L"and less than or equal to % s.");
+ DefineGlobalConstString(pIsolate, L"IDS_LESS_THAN",
+ L"Invalid value: must be less than or equal to % s.");
+ DefineGlobalConstString(pIsolate, L"IDS_INVALID_MONTH", L"**Invalid**");
+ DefineGlobalConstString(
+ pIsolate, L"IDS_INVALID_DATE",
+ L"Invalid date / time: please ensure that the date / time exists.Field");
+ DefineGlobalConstString(
+ pIsolate, L"IDS_INVALID_VALUE",
+ L"The value entered does not match the format of the field");
+ DefineGlobalConstString(pIsolate, L"IDS_AM", L"am");
+ DefineGlobalConstString(pIsolate, L"IDS_PM", L"pm");
+ DefineGlobalConstString(
+ pIsolate, L"IDS_MONTH_INFO",
+ L"January[1] February[2] March[3] April[4] May[5] "
+ L"June[6] July[7] August[8] September[9] October[10] "
+ L"November[11] December[12] Sept[9] Jan[1] Feb[2] Mar[3] "
+ L"Apr[4] Jun[6] Jul[7] Aug[8] Sep[9] Oct[10] Nov[11] "
+ L"Dec[12]");
+ DefineGlobalConstString(pIsolate, L"IDS_STARTUP_CONSOLE_MSG", L"** ^ _ ^ **");
}
/* ------------------------------ 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; \
+void DefineGlobalConstStringArray(v8::Isolate* pIsolate,
+ const wchar_t* sConstName,
+ const wchar_t** pValues,
+ size_t nValues) {
+ CJS_Array array(pIsolate);
+ for (size_t i = 0; i < nValues; ++i) {
+ array.SetElement(i, CJS_Value(pIsolate, pValues[i]));
}
+ CJS_PropValue prop(pIsolate);
+ prop << array;
+ JS_DefineGlobalConst(pIsolate, sConstName, prop.ToV8Value());
+}
-int CJS_GlobalArrays::DefineJSObjects(v8::Isolate* pIsolate) {
+void CJS_GlobalArrays::DefineJSObjects(v8::Isolate* pIsolate) {
{
const FX_WCHAR* ArrayName = L"RE_NUMBER_ENTRY_DOT_SEP";
const FX_WCHAR* ArrayContent[] = {L"[+-]?\\d*\\.?\\d*"};
- DEFINE_GLOBAL_ARRAY(pIsolate);
+ DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ FX_ArraySize(ArrayContent));
}
{
@@ -192,14 +194,16 @@ int CJS_GlobalArrays::DefineJSObjects(v8::Isolate* pIsolate) {
L"[+-]?\\.\\d+", /* -.1 */
L"[+-]?\\d+\\." /* -1. */
};
- DEFINE_GLOBAL_ARRAY(pIsolate);
+ DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ FX_ArraySize(ArrayContent));
}
{
const FX_WCHAR* ArrayName = L"RE_NUMBER_ENTRY_COMMA_SEP";
const FX_WCHAR* ArrayContent[] = {L"[+-]?\\d*,?\\d*"};
- DEFINE_GLOBAL_ARRAY(pIsolate);
+ DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ FX_ArraySize(ArrayContent));
}
{
@@ -209,31 +213,36 @@ int CJS_GlobalArrays::DefineJSObjects(v8::Isolate* pIsolate) {
L"[+-]?[.,]\\d+", /* -,1 */
L"[+-]?\\d+[.,]" /* -1, */
};
- DEFINE_GLOBAL_ARRAY(pIsolate);
+ DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ FX_ArraySize(ArrayContent));
}
{
const FX_WCHAR* ArrayName = L"RE_ZIP_ENTRY";
const FX_WCHAR* ArrayContent[] = {L"\\d{0,5}"};
- DEFINE_GLOBAL_ARRAY(pIsolate);
+ DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ FX_ArraySize(ArrayContent));
}
{
const FX_WCHAR* ArrayName = L"RE_ZIP_COMMIT";
const FX_WCHAR* ArrayContent[] = {L"\\d{5}"};
- DEFINE_GLOBAL_ARRAY(pIsolate);
+ DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ FX_ArraySize(ArrayContent));
}
{
const FX_WCHAR* ArrayName = L"RE_ZIP4_ENTRY";
const FX_WCHAR* ArrayContent[] = {L"\\d{0,5}(\\.|[- ])?\\d{0,4}"};
- DEFINE_GLOBAL_ARRAY(pIsolate);
+ DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ FX_ArraySize(ArrayContent));
}
{
const FX_WCHAR* ArrayName = L"RE_ZIP4_COMMIT";
const FX_WCHAR* ArrayContent[] = {L"\\d{5}(\\.|[- ])?\\d{4}"};
- DEFINE_GLOBAL_ARRAY(pIsolate);
+ DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ FX_ArraySize(ArrayContent));
}
{
@@ -251,7 +260,8 @@ int CJS_GlobalArrays::DefineJSObjects(v8::Isolate* pIsolate) {
*/
L"011(\\.|[- \\d])*" /* international */
};
- DEFINE_GLOBAL_ARRAY(pIsolate);
+ DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ FX_ArraySize(ArrayContent));
}
{
@@ -262,22 +272,23 @@ int CJS_GlobalArrays::DefineJSObjects(v8::Isolate* pIsolate) {
L"\\(\\d{3}\\)(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", /* (408) 555-1234 */
L"011(\\.|[- \\d])*" /* international */
};
- DEFINE_GLOBAL_ARRAY(pIsolate);
+ DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ FX_ArraySize(ArrayContent));
}
{
const FX_WCHAR* ArrayName = L"RE_SSN_ENTRY";
const FX_WCHAR* ArrayContent[] = {
L"\\d{0,3}(\\.|[- ])?\\d{0,2}(\\.|[- ])?\\d{0,4}"};
- DEFINE_GLOBAL_ARRAY(pIsolate);
+ DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ FX_ArraySize(ArrayContent));
}
{
const FX_WCHAR* ArrayName = L"RE_SSN_COMMIT";
const FX_WCHAR* ArrayContent[] = {
L"\\d{3}(\\.|[- ])?\\d{2}(\\.|[- ])?\\d{4}"};
- DEFINE_GLOBAL_ARRAY(pIsolate);
+ DefineGlobalConstStringArray(pIsolate, ArrayName, ArrayContent,
+ FX_ArraySize(ArrayContent));
}
-
- return 0;
}
diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp
index 5f4a473c87..4b18d80f6c 100644
--- a/fpdfsdk/src/javascript/JS_Runtime.cpp
+++ b/fpdfsdk/src/javascript/JS_Runtime.cpp
@@ -137,7 +137,7 @@ CJS_Runtime::~CJS_Runtime() {
m_isolate->Dispose();
}
-FX_BOOL CJS_Runtime::DefineJSObjects() {
+void CJS_Runtime::DefineJSObjects() {
v8::Isolate::Scope isolate_scope(GetIsolate());
v8::HandleScope handle_scope(GetIsolate());
v8::Local<v8::Context> context = v8::Context::New(GetIsolate());
@@ -145,67 +145,43 @@ FX_BOOL CJS_Runtime::DefineJSObjects() {
// 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::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
- return FALSE;
- if (CJS_Font::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
- return FALSE;
+ CJS_Border::DefineJSObjects(GetIsolate(), JS_STATIC);
+ CJS_Display::DefineJSObjects(GetIsolate(), JS_STATIC);
+ CJS_Font::DefineJSObjects(GetIsolate(), JS_STATIC);
// ObjDefIDs 3 - 5
- if (CJS_Highlight::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
- return FALSE;
- if (CJS_Position::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
- return FALSE;
- if (CJS_ScaleHow::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
- return FALSE;
+ CJS_Highlight::DefineJSObjects(GetIsolate(), JS_STATIC);
+ CJS_Position::DefineJSObjects(GetIsolate(), JS_STATIC);
+ CJS_ScaleHow::DefineJSObjects(GetIsolate(), JS_STATIC);
// ObjDefIDs 6 - 8
- if (CJS_ScaleWhen::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
- return FALSE;
- if (CJS_Style::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
- return FALSE;
- if (CJS_Zoomtype::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
- return FALSE;
+ CJS_ScaleWhen::DefineJSObjects(GetIsolate(), JS_STATIC);
+ CJS_Style::DefineJSObjects(GetIsolate(), JS_STATIC);
+ CJS_Zoomtype::DefineJSObjects(GetIsolate(), JS_STATIC);
// ObjDefIDs 9 - 11
- if (CJS_App::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
- return FALSE;
- if (CJS_Color::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
- return FALSE;
- if (CJS_Console::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
- return FALSE;
+ CJS_App::DefineJSObjects(GetIsolate(), JS_STATIC);
+ CJS_Color::DefineJSObjects(GetIsolate(), JS_STATIC);
+ CJS_Console::DefineJSObjects(GetIsolate(), JS_STATIC);
// ObjDefIDs 12 - 14
- if (CJS_Document::DefineJSObjects(GetIsolate(), JS_DYNAMIC) < 0)
- return FALSE;
- if (CJS_Event::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
- return FALSE;
- if (CJS_Field::DefineJSObjects(GetIsolate(), JS_DYNAMIC) < 0)
- return FALSE;
+ CJS_Document::DefineJSObjects(GetIsolate(), JS_DYNAMIC);
+ CJS_Event::DefineJSObjects(GetIsolate(), JS_STATIC);
+ CJS_Field::DefineJSObjects(GetIsolate(), JS_DYNAMIC);
// ObjDefIDs 15 - 17
- if (CJS_Global::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
- return FALSE;
- if (CJS_Icon::DefineJSObjects(GetIsolate(), JS_DYNAMIC) < 0)
- return FALSE;
- if (CJS_Util::DefineJSObjects(GetIsolate(), JS_STATIC) < 0)
- return FALSE;
-
- // ObjDefIDs 18 - 20
- if (CJS_PublicMethods::DefineJSObjects(GetIsolate()) < 0)
- return FALSE;
- if (CJS_GlobalConsts::DefineJSObjects(GetIsolate()) < 0)
- return FALSE;
- if (CJS_GlobalArrays::DefineJSObjects(GetIsolate()) < 0)
- return FALSE;
-
- if (CJS_TimerObj::DefineJSObjects(GetIsolate(), JS_DYNAMIC) < 0)
- return FALSE;
- if (CJS_PrintParamsObj::DefineJSObjects(GetIsolate(), JS_DYNAMIC) < 0)
- return FALSE;
-
- return TRUE;
+ CJS_Global::DefineJSObjects(GetIsolate(), JS_STATIC);
+ CJS_Icon::DefineJSObjects(GetIsolate(), JS_DYNAMIC);
+ CJS_Util::DefineJSObjects(GetIsolate(), JS_STATIC);
+
+ // ObjDefIDs 18 - 20 (these can't fail, return void).
+ CJS_PublicMethods::DefineJSObjects(GetIsolate());
+ CJS_GlobalConsts::DefineJSObjects(GetIsolate());
+ CJS_GlobalArrays::DefineJSObjects(GetIsolate());
+
+ // ObjDefIDs 21 - 22.
+ CJS_TimerObj::DefineJSObjects(GetIsolate(), JS_DYNAMIC);
+ CJS_PrintParamsObj::DefineJSObjects(GetIsolate(), JS_DYNAMIC);
}
IFXJS_Context* CJS_Runtime::NewContext() {
diff --git a/fpdfsdk/src/javascript/global.cpp b/fpdfsdk/src/javascript/global.cpp
index e817eca32c..bde4e7d5ae 100644
--- a/fpdfsdk/src/javascript/global.cpp
+++ b/fpdfsdk/src/javascript/global.cpp
@@ -60,21 +60,21 @@ class HashVerify {
HashVerify::HashVerify() {
ASSERT(JSCONST_nStringHash ==
- JS_CalcHash(VALUE_NAME_STRING, wcslen(VALUE_NAME_STRING)));
+ JS_CalcHash(kFXJSValueNameString, wcslen(kFXJSValueNameString)));
ASSERT(JSCONST_nNumberHash ==
- JS_CalcHash(VALUE_NAME_NUMBER, wcslen(VALUE_NAME_NUMBER)));
+ JS_CalcHash(kFXJSValueNameNumber, wcslen(kFXJSValueNameNumber)));
ASSERT(JSCONST_nBoolHash ==
- JS_CalcHash(VALUE_NAME_BOOLEAN, wcslen(VALUE_NAME_BOOLEAN)));
+ JS_CalcHash(kFXJSValueNameBoolean, wcslen(kFXJSValueNameBoolean)));
ASSERT(JSCONST_nDateHash ==
- JS_CalcHash(VALUE_NAME_DATE, wcslen(VALUE_NAME_DATE)));
+ JS_CalcHash(kFXJSValueNameDate, wcslen(kFXJSValueNameDate)));
ASSERT(JSCONST_nObjectHash ==
- JS_CalcHash(VALUE_NAME_OBJECT, wcslen(VALUE_NAME_OBJECT)));
+ JS_CalcHash(kFXJSValueNameObject, wcslen(kFXJSValueNameObject)));
ASSERT(JSCONST_nFXobjHash ==
- JS_CalcHash(VALUE_NAME_FXOBJ, wcslen(VALUE_NAME_FXOBJ)));
+ JS_CalcHash(kFXJSValueNameFxobj, wcslen(kFXJSValueNameFxobj)));
ASSERT(JSCONST_nNullHash ==
- JS_CalcHash(VALUE_NAME_NULL, wcslen(VALUE_NAME_NULL)));
+ JS_CalcHash(kFXJSValueNameNull, wcslen(kFXJSValueNameNull)));
ASSERT(JSCONST_nUndefHash ==
- JS_CalcHash(VALUE_NAME_UNDEFINED, wcslen(VALUE_NAME_UNDEFINED)));
+ JS_CalcHash(kFXJSValueNameUndefined, wcslen(kFXJSValueNameUndefined)));
}
#endif
diff --git a/fpdfsdk/src/jsapi/fxjs_v8.cpp b/fpdfsdk/src/jsapi/fxjs_v8.cpp
index b31284847a..e0c8938c34 100644
--- a/fpdfsdk/src/jsapi/fxjs_v8.cpp
+++ b/fpdfsdk/src/jsapi/fxjs_v8.cpp
@@ -12,14 +12,14 @@
#include <cmath>
#include <limits>
-#define VALUE_NAME_STRING L"string"
-#define VALUE_NAME_NUMBER L"number"
-#define VALUE_NAME_BOOLEAN L"boolean"
-#define VALUE_NAME_DATE L"date"
-#define VALUE_NAME_OBJECT L"object"
-#define VALUE_NAME_FXOBJ L"fxobj"
-#define VALUE_NAME_NULL L"null"
-#define VALUE_NAME_UNDEFINED L"undefined"
+const wchar_t kFXJSValueNameString[] = L"string";
+const wchar_t kFXJSValueNameNumber[] = L"number";
+const wchar_t kFXJSValueNameBoolean[] = L"boolean";
+const wchar_t kFXJSValueNameDate[] = L"date";
+const wchar_t kFXJSValueNameObject[] = L"object";
+const wchar_t kFXJSValueNameFxobj[] = L"fxobj";
+const wchar_t kFXJSValueNameNull[] = L"null";
+const wchar_t kFXJSValueNameUndefined[] = L"undefined";
const static FX_DWORD g_nan[2] = {0, 0x7FF80000};
static double GetNan() {
@@ -93,22 +93,18 @@ int JS_DefineObj(v8::Isolate* pIsolate,
return pArray->GetSize() - 1;
}
-int JS_DefineObjMethod(v8::Isolate* pIsolate,
- int nObjDefnID,
- const wchar_t* sMethodName,
- v8::FunctionCallback pMethodCall) {
+void JS_DefineObjMethod(v8::Isolate* pIsolate,
+ int nObjDefnID,
+ const wchar_t* sMethodName,
+ v8::FunctionCallback pMethodCall) {
v8::Isolate::Scope isolate_scope(pIsolate);
v8::HandleScope handle_scope(pIsolate);
CFX_WideString ws = CFX_WideString(sMethodName);
CFX_ByteString bsMethodName = ws.UTF8Encode();
-
CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
- if (!pArray)
- return 0;
- if (nObjDefnID < 0 || nObjDefnID >= pArray->GetSize())
- return 0;
+ // Note: GetAt() halts if out-of-range even in release builds.
CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
v8::Local<v8::ObjectTemplate> objTemp =
v8::Local<v8::ObjectTemplate>::New(pIsolate, pObjDef->m_objTemplate);
@@ -117,26 +113,21 @@ int JS_DefineObjMethod(v8::Isolate* pIsolate,
v8::NewStringType::kNormal).ToLocalChecked(),
v8::FunctionTemplate::New(pIsolate, pMethodCall), v8::ReadOnly);
pObjDef->m_objTemplate.Reset(pIsolate, objTemp);
- return 0;
}
-int JS_DefineObjProperty(v8::Isolate* pIsolate,
- int nObjDefnID,
- const wchar_t* sPropName,
- v8::AccessorGetterCallback pPropGet,
- v8::AccessorSetterCallback pPropPut) {
+void JS_DefineObjProperty(v8::Isolate* pIsolate,
+ int nObjDefnID,
+ const wchar_t* sPropName,
+ v8::AccessorGetterCallback pPropGet,
+ v8::AccessorSetterCallback pPropPut) {
v8::Isolate::Scope isolate_scope(pIsolate);
v8::HandleScope handle_scope(pIsolate);
CFX_WideString ws = CFX_WideString(sPropName);
CFX_ByteString bsPropertyName = ws.UTF8Encode();
-
CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
- if (!pArray)
- return 0;
- if (nObjDefnID < 0 || nObjDefnID >= pArray->GetSize())
- return 0;
+ // Note: GetAt() halts if out-of-range even in release builds.
CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
v8::Local<v8::ObjectTemplate> objTemp =
v8::Local<v8::ObjectTemplate>::New(pIsolate, pObjDef->m_objTemplate);
@@ -145,54 +136,43 @@ int JS_DefineObjProperty(v8::Isolate* pIsolate,
v8::NewStringType::kNormal).ToLocalChecked(),
pPropGet, pPropPut);
pObjDef->m_objTemplate.Reset(pIsolate, objTemp);
- return 0;
}
-int JS_DefineObjAllProperties(v8::Isolate* pIsolate,
- int nObjDefnID,
- v8::NamedPropertyQueryCallback pPropQurey,
- v8::NamedPropertyGetterCallback pPropGet,
- v8::NamedPropertySetterCallback pPropPut,
- v8::NamedPropertyDeleterCallback pPropDel) {
+void JS_DefineObjAllProperties(v8::Isolate* pIsolate,
+ int nObjDefnID,
+ v8::NamedPropertyQueryCallback pPropQurey,
+ v8::NamedPropertyGetterCallback pPropGet,
+ v8::NamedPropertySetterCallback pPropPut,
+ v8::NamedPropertyDeleterCallback pPropDel) {
v8::Isolate::Scope isolate_scope(pIsolate);
v8::HandleScope handle_scope(pIsolate);
-
CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
- if (!pArray)
- return 0;
- if (nObjDefnID < 0 || nObjDefnID >= pArray->GetSize())
- return 0;
+ // Note: GetAt() halts if out-of-range even in release builds.
CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
v8::Local<v8::ObjectTemplate> objTemp =
v8::Local<v8::ObjectTemplate>::New(pIsolate, pObjDef->m_objTemplate);
objTemp->SetNamedPropertyHandler(pPropGet, pPropPut, pPropQurey, pPropDel);
pObjDef->m_objTemplate.Reset(pIsolate, objTemp);
- return 0;
}
-int JS_DefineObjConst(v8::Isolate* pIsolate,
- int nObjDefnID,
- const wchar_t* sConstName,
- v8::Local<v8::Value> pDefault) {
+void JS_DefineObjConst(v8::Isolate* pIsolate,
+ int nObjDefnID,
+ const wchar_t* sConstName,
+ v8::Local<v8::Value> pDefault) {
v8::Isolate::Scope isolate_scope(pIsolate);
v8::HandleScope handle_scope(pIsolate);
- CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
- if (!pArray)
- return 0;
-
CFX_WideString ws = CFX_WideString(sConstName);
CFX_ByteString bsConstName = ws.UTF8Encode();
+ CFX_PtrArray* pArray = (CFX_PtrArray*)pIsolate->GetData(g_embedderDataSlot);
- if (nObjDefnID < 0 || nObjDefnID >= pArray->GetSize())
- return 0;
+ // Note: GetAt() halts if out-of-range even in release builds.
CJS_ObjDefintion* pObjDef = (CJS_ObjDefintion*)pArray->GetAt(nObjDefnID);
v8::Local<v8::ObjectTemplate> objTemp =
v8::Local<v8::ObjectTemplate>::New(pIsolate, pObjDef->m_objTemplate);
objTemp->Set(pIsolate, bsConstName.c_str(), pDefault);
pObjDef->m_objTemplate.Reset(pIsolate, objTemp);
- return 0;
}
static v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate(
@@ -211,9 +191,9 @@ static v8::Global<v8::ObjectTemplate>& _getGlobalObjectTemplate(
return gloabalObjectTemplate;
}
-int JS_DefineGlobalMethod(v8::Isolate* pIsolate,
- const wchar_t* sMethodName,
- v8::FunctionCallback pMethodCall) {
+void JS_DefineGlobalMethod(v8::Isolate* pIsolate,
+ const wchar_t* sMethodName,
+ v8::FunctionCallback pMethodCall) {
v8::Isolate::Scope isolate_scope(pIsolate);
v8::HandleScope handle_scope(pIsolate);
@@ -236,13 +216,11 @@ int JS_DefineGlobalMethod(v8::Isolate* pIsolate,
funTempl, v8::ReadOnly);
globalObjTemp.Reset(pIsolate, objTemp);
-
- return 0;
}
-int JS_DefineGlobalConst(v8::Isolate* pIsolate,
- const wchar_t* sConstName,
- v8::Local<v8::Value> pDefault) {
+void JS_DefineGlobalConst(v8::Isolate* pIsolate,
+ const wchar_t* sConstName,
+ v8::Local<v8::Value> pDefault) {
v8::Isolate::Scope isolate_scope(pIsolate);
v8::HandleScope handle_scope(pIsolate);
@@ -263,8 +241,6 @@ int JS_DefineGlobalConst(v8::Isolate* pIsolate,
pDefault, v8::ReadOnly);
globalObjTemp.Reset(pIsolate, objTemp);
-
- return 0;
}
void JS_InitialRuntime(v8::Isolate* pIsolate,
@@ -510,19 +486,19 @@ const wchar_t* JS_GetTypeof(v8::Local<v8::Value> pObj) {
if (pObj.IsEmpty())
return NULL;
if (pObj->IsString())
- return VALUE_NAME_STRING;
+ return kFXJSValueNameString;
if (pObj->IsNumber())
- return VALUE_NAME_NUMBER;
+ return kFXJSValueNameNumber;
if (pObj->IsBoolean())
- return VALUE_NAME_BOOLEAN;
+ return kFXJSValueNameBoolean;
if (pObj->IsDate())
- return VALUE_NAME_DATE;
+ return kFXJSValueNameDate;
if (pObj->IsObject())
- return VALUE_NAME_OBJECT;
+ return kFXJSValueNameObject;
if (pObj->IsNull())
- return VALUE_NAME_NULL;
+ return kFXJSValueNameNull;
if (pObj->IsUndefined())
- return VALUE_NAME_UNDEFINED;
+ return kFXJSValueNameUndefined;
return NULL;
}
void JS_SetPrivate(v8::Local<v8::Object> pObj, void* p) {