summaryrefslogtreecommitdiff
path: root/fpdfsdk/include/javascript
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-09-17 15:25:23 -0700
committerTom Sepez <tsepez@chromium.org>2015-09-17 15:25:23 -0700
commit39bfe122b4867601051c56562a5ab9cf6be644ad (patch)
tree73ea2387759b2ba2a80ab344da69dc063fc69172 /fpdfsdk/include/javascript
parent4babdcf9c7abc9edefb179e5ed23db8e7a5840f7 (diff)
downloadpdfium-39bfe122b4867601051c56562a5ab9cf6be644ad.tar.xz
Merge to XFA: Ensure functions in FXJS_V8 are prefixed by FXJS_.
Manual edits: fpdfsdk/include/javascript/JS_Define.h fpdfsdk/src/fpdfxfa/fpdfxfa_app.cpp fpdfsdk/src/javascript/Document.cpp fpdfsdk/src/javascript/JS_Runtime.cpp fpdfsdk/src/jsapi/fxjs_v8.cpp (cherry picked from commit 506df426d5d64d68e9dc27ffebcf56f6c6a1bccf) Original Review URL: https://codereview.chromium.org/1347833002 . (cherry picked from commit 455019ca48f60bd285e043986471f51f17c69a0d) Original Review URL: https://codereview.chromium.org/1349783003 . (cherry picked from commit 1af240cc45480520b447be767686e73a29c48f9e) Original Review URL: https://codereview.chromium.org/1348693003 . R=thestig@chromium.org Review URL: https://codereview.chromium.org/1356563003 .
Diffstat (limited to 'fpdfsdk/include/javascript')
-rw-r--r--fpdfsdk/include/javascript/JS_Define.h163
-rw-r--r--fpdfsdk/include/javascript/JS_Runtime.h2
-rw-r--r--fpdfsdk/include/javascript/JS_Value.h35
3 files changed, 113 insertions, 87 deletions
diff --git a/fpdfsdk/include/javascript/JS_Define.h b/fpdfsdk/include/javascript/JS_Define.h
index 7cade587b5..1addca5cec 100644
--- a/fpdfsdk/include/javascript/JS_Define.h
+++ b/fpdfsdk/include/javascript/JS_Define.h
@@ -83,12 +83,12 @@ void JSPropGetter(const char* prop_name_string,
IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
CJS_PropValue value(isolate);
value.StartGetting();
- CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate, info.Holder());
+ CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder());
C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
CFX_WideString sError;
if (!(pObj->*M)(pRuntimeContext, value, sError)) {
- JS_Error(isolate,
- JSFormatErrorString(class_name_string, prop_name_string, sError));
+ FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string,
+ sError));
return;
}
info.GetReturnValue().Set((v8::Local<v8::Value>)value);
@@ -104,14 +104,14 @@ void JSPropSetter(const char* prop_name_string,
v8::Isolate* isolate = info.GetIsolate();
IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);
IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
- CJS_PropValue propValue(CJS_Value(isolate, value, VT_unknown));
+ CJS_PropValue propValue(CJS_Value(isolate, value, CJS_Value::VT_unknown));
propValue.StartSetting();
- CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate, info.Holder());
+ CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder());
C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
CFX_WideString sError;
if (!(pObj->*M)(pRuntimeContext, propValue, sError)) {
- JS_Error(isolate,
- JSFormatErrorString(class_name_string, prop_name_string, sError));
+ FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string,
+ sError));
}
}
@@ -145,15 +145,15 @@ void JSMethod(const char* method_name_string,
IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
CJS_Parameters parameters;
for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) {
- parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));
+ parameters.push_back(CJS_Value(isolate, info[i], CJS_Value::VT_unknown));
}
CJS_Value valueRes(isolate);
- CJS_Object* pJSObj = (CJS_Object*)JS_GetPrivate(isolate, info.Holder());
+ CJS_Object* pJSObj = (CJS_Object*)FXJS_GetPrivate(isolate, info.Holder());
C* pObj = reinterpret_cast<C*>(pJSObj->GetEmbedObject());
CFX_WideString sError;
if (!(pObj->*M)(pRuntimeContext, parameters, valueRes, sError)) {
- JS_Error(isolate, JSFormatErrorString(class_name_string, method_name_string,
- sError));
+ FXJS_Error(isolate, JSFormatErrorString(class_name_string,
+ method_name_string, sError));
return;
}
info.GetReturnValue().Set(valueRes.ToV8Value());
@@ -186,36 +186,36 @@ void JSMethod(const char* method_name_string,
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; \
- } \
- \
- 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_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); \
+ } \
}
#define IMPLEMENT_JS_CLASS(js_class_name, class_name) \
@@ -229,19 +229,19 @@ void JSMethod(const char* method_name_string,
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 = 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)); \
- } \
+#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)); \
+ } \
}
/* ===================================== SPECIAL JS CLASS
@@ -256,7 +256,7 @@ void JSSpecialPropQuery(const char*,
CFX_WideString propname =
CFX_WideString::FromUTF8(*utf8_value, utf8_value.length());
CJS_Object* pJSObj =
- reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info.Holder()));
+ reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder()));
Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
FX_BOOL bRet = pObj->QueryProperty(propname.c_str());
info.GetReturnValue().Set(bRet ? 4 : 0);
@@ -271,7 +271,7 @@ void JSSpecialPropGet(const char* class_name,
IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);
IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
CJS_Object* pJSObj =
- reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info.Holder()));
+ reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder()));
Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
v8::String::Utf8Value utf8_value(property);
CFX_WideString propname =
@@ -280,7 +280,7 @@ void JSSpecialPropGet(const char* class_name,
CJS_PropValue value(isolate);
value.StartGetting();
if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), value, sError)) {
- JS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError));
+ FXJS_Error(isolate, JSFormatErrorString(class_name, "GetProperty", sError));
return;
}
info.GetReturnValue().Set((v8::Local<v8::Value>)value);
@@ -296,16 +296,16 @@ void JSSpecialPropPut(const char* class_name,
IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);
IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
CJS_Object* pJSObj =
- reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info.Holder()));
+ reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder()));
Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
v8::String::Utf8Value utf8_value(property);
CFX_WideString propname =
CFX_WideString::FromUTF8(*utf8_value, utf8_value.length());
CFX_WideString sError;
- CJS_PropValue PropValue(CJS_Value(isolate, value, VT_unknown));
+ CJS_PropValue PropValue(CJS_Value(isolate, value, CJS_Value::VT_unknown));
PropValue.StartSetting();
if (!pObj->DoProperty(pRuntimeContext, propname.c_str(), PropValue, sError)) {
- JS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError));
+ FXJS_Error(isolate, JSFormatErrorString(class_name, "PutProperty", sError));
}
}
@@ -318,7 +318,7 @@ void JSSpecialPropDel(const char* class_name,
IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)isolate->GetData(2);
IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
CJS_Object* pJSObj =
- reinterpret_cast<CJS_Object*>(JS_GetPrivate(isolate, info.Holder()));
+ reinterpret_cast<CJS_Object*>(FXJS_GetPrivate(isolate, info.Holder()));
Alt* pObj = reinterpret_cast<Alt*>(pJSObj->GetEmbedObject());
v8::String::Utf8Value utf8_value(property);
CFX_WideString propname =
@@ -327,7 +327,7 @@ void JSSpecialPropDel(const char* class_name,
if (!pObj->DelProperty(pRuntimeContext, propname.c_str(), sError)) {
CFX_ByteString cbName;
cbName.Format("%s.%s", class_name, "DelProperty");
- // Probably a missing call to JS_Error().
+ // Probably a missing call to JSFX_Error().
}
}
@@ -380,12 +380,12 @@ void JSSpecialPropDel(const char* class_name,
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); \
+ 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*)JS_GetPrivate(NULL, obj); \
+ js_class_name* pObj = (js_class_name*)FXJS_GetPrivate(NULL, obj); \
ASSERT(pObj != NULL); \
pObj->ExitInstance(); \
delete pObj; \
@@ -393,19 +393,19 @@ void JSSpecialPropDel(const char* class_name,
\
void js_class_name::DefineJSObjects(v8::Isolate* pIsolate, \
FXJSOBJTYPE eObjType) { \
- int nObjDefnID = JS_DefineObj(pIsolate, js_class_name::m_pClassName, \
- eObjType, JSConstructor, JSDestructor); \
+ 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) { \
- JS_DefineObjProperty(pIsolate, nObjDefnID, JS_Class_Properties[i].pName, \
- JS_Class_Properties[i].pPropGet, \
- JS_Class_Properties[i].pPropPut); \
+ 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) { \
- JS_DefineObjMethod(pIsolate, nObjDefnID, JS_Class_Methods[i].pName, \
- JS_Class_Methods[i].pMethodCall); \
+ FXJS_DefineObjMethod(pIsolate, nObjDefnID, JS_Class_Methods[i].pName, \
+ JS_Class_Methods[i].pMethodCall); \
} \
- JS_DefineObjAllProperties( \
+ FXJS_DefineObjAllProperties( \
pIsolate, nObjDefnID, \
js_class_name::queryprop_##js_class_name##_static, \
js_class_name::getprop_##js_class_name##_static, \
@@ -425,12 +425,12 @@ void JSGlobalFunc(const char* func_name_string,
IFXJS_Context* pRuntimeContext = pRuntime->GetCurrentContext();
CJS_Parameters parameters;
for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) {
- parameters.push_back(CJS_Value(isolate, info[i], VT_unknown));
+ parameters.push_back(CJS_Value(isolate, info[i], CJS_Value::VT_unknown));
}
CJS_Value valueRes(isolate);
CFX_WideString sError;
if (!(*F)(pRuntimeContext, parameters, valueRes, sError)) {
- JS_Error(isolate, JSFormatErrorString(func_name_string, nullptr, sError));
+ FXJS_Error(isolate, JSFormatErrorString(func_name_string, nullptr, sError));
return;
}
info.GetReturnValue().Set(valueRes.ToV8Value());
@@ -453,14 +453,15 @@ 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) \
- 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 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) { \
+ FXJS_DefineGlobalMethod(pIsolate, \
+ js_class_name::global_methods[i].pName, \
+ js_class_name::global_methods[i].pMethodCall); \
+ } \
}
-FXJSVALUETYPE GET_VALUE_TYPE(v8::Local<v8::Value> p);
+CJS_Value::Type 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 f0285b271c..b53e50e6ce 100644
--- a/fpdfsdk/include/javascript/JS_Runtime.h
+++ b/fpdfsdk/include/javascript/JS_Runtime.h
@@ -64,7 +64,7 @@ class CJS_Runtime : public IFXJS_Runtime {
CJS_FieldEvent* m_pFieldEventPath;
v8::Isolate* m_isolate;
bool m_isolateManaged;
- nonstd::unique_ptr<JS_ArrayBufferAllocator> m_pArrayBufferAllocator;
+ nonstd::unique_ptr<FXJS_ArrayBufferAllocator> m_pArrayBufferAllocator;
v8::Global<v8::Context> m_context;
};
diff --git a/fpdfsdk/include/javascript/JS_Value.h b/fpdfsdk/include/javascript/JS_Value.h
index 771214d968..384e772572 100644
--- a/fpdfsdk/include/javascript/JS_Value.h
+++ b/fpdfsdk/include/javascript/JS_Value.h
@@ -17,8 +17,20 @@ class CJS_Object;
class CJS_Value {
public:
+ enum Type {
+ VT_unknown,
+ VT_string,
+ VT_number,
+ VT_boolean,
+ VT_date,
+ VT_object,
+ VT_fxobject,
+ VT_null,
+ VT_undefined
+ };
+
CJS_Value(v8::Isolate* isolate);
- CJS_Value(v8::Isolate* isolate, v8::Local<v8::Value> pValue, FXJSVALUETYPE t);
+ CJS_Value(v8::Isolate* isolate, v8::Local<v8::Value> pValue, Type t);
CJS_Value(v8::Isolate* isolate, const int& iValue);
CJS_Value(v8::Isolate* isolate, const double& dValue);
CJS_Value(v8::Isolate* isolate, const float& fValue);
@@ -33,10 +45,11 @@ class CJS_Value {
~CJS_Value();
void SetNull();
- void Attach(v8::Local<v8::Value> pValue, FXJSVALUETYPE t);
+ void Attach(v8::Local<v8::Value> pValue, Type t);
void Attach(CJS_Value* pValue);
void Detach();
+ Type GetType() const;
int ToInt() const;
bool ToBool() const;
double ToDouble() const;
@@ -63,16 +76,14 @@ class CJS_Value {
FX_BOOL IsArrayObject() const;
FX_BOOL IsDateObject() const;
- FXJSVALUETYPE GetType() const;
-
FX_BOOL ConvertToArray(CJS_Array&) const;
FX_BOOL ConvertToDate(CJS_Date&) const;
v8::Isolate* GetIsolate() { return m_isolate; }
protected:
+ Type m_eType;
v8::Local<v8::Value> m_pValue;
- FXJSVALUETYPE m_eType;
v8::Isolate* m_isolate;
};
@@ -190,4 +201,18 @@ class CJS_Date {
v8::Isolate* m_isolate;
};
+double JS_GetDateTime();
+int JS_GetYearFromTime(double dt);
+int JS_GetMonthFromTime(double dt);
+int JS_GetDayFromTime(double dt);
+int JS_GetHourFromTime(double dt);
+int JS_GetMinFromTime(double dt);
+int JS_GetSecFromTime(double dt);
+double JS_DateParse(const wchar_t* string);
+double JS_MakeDay(int nYear, int nMonth, int nDay);
+double JS_MakeTime(int nHour, int nMin, int nSec, int nMs);
+double JS_MakeDate(double day, double time);
+bool JS_PortIsNan(double d);
+double JS_LocalTime(double d);
+
#endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_VALUE_H_