summaryrefslogtreecommitdiff
path: root/fpdfsdk/src
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/src
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/src')
-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
4 files changed, 149 insertions, 186 deletions
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) {