diff options
author | Tom Sepez <tsepez@chromium.org> | 2015-09-16 10:42:08 -0700 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2015-09-16 10:42:08 -0700 |
commit | 506df426d5d64d68e9dc27ffebcf56f6c6a1bccf (patch) | |
tree | 3ba8d38a3bef95c0555549953bce0cce90845cdb /fpdfsdk/include/javascript | |
parent | 615d7aba0f7d53a78eb05fbd4ae0e1a7e1d3b103 (diff) | |
download | pdfium-506df426d5d64d68e9dc27ffebcf56f6c6a1bccf.tar.xz |
Ensure functions in FXJS_V8 are prefixed by FXJS_.
Currently, its hard to tell which functions come from the JS_
layer at fpdfsdk/include/javascript vs. which functions come
from the FXJS_V8 layer at fpdfsdk/include/jsapi. Until we
take up the task of using namespaces, at least make the
prefix consistent.
Move objects out of FXJS_V8 that are really part of JS_.
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1347833002 .
Diffstat (limited to 'fpdfsdk/include/javascript')
-rw-r--r-- | fpdfsdk/include/javascript/JS_Define.h | 163 | ||||
-rw-r--r-- | fpdfsdk/include/javascript/JS_Runtime.h | 2 | ||||
-rw-r--r-- | fpdfsdk/include/javascript/JS_Value.h | 35 |
3 files changed, 113 insertions, 87 deletions
diff --git a/fpdfsdk/include/javascript/JS_Define.h b/fpdfsdk/include/javascript/JS_Define.h index 4b1b224aef..04f5eceef5 100644 --- a/fpdfsdk/include/javascript/JS_Define.h +++ b/fpdfsdk/include/javascript/JS_Define.h @@ -88,14 +88,14 @@ void JSPropGetter(const char* prop_name_string, v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); IFXJS_Context* pContext = pRuntime->GetCurrentContext(); - 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; CJS_PropValue value(isolate); value.StartGetting(); if (!(pObj->*M)(pContext, 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); @@ -118,14 +118,14 @@ void JSPropSetter(const char* prop_name_string, v8::Local<v8::External> field = v8::Local<v8::External>::Cast(v); IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); IFXJS_Context* pContext = pRuntime->GetCurrentContext(); - 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; - CJS_PropValue propValue(CJS_Value(isolate, value, VT_unknown)); + CJS_PropValue propValue(CJS_Value(isolate, value, CJS_Value::VT_unknown)); propValue.StartSetting(); if (!(pObj->*M)(pContext, propValue, sError)) { - JS_Error(isolate, - JSFormatErrorString(class_name_string, prop_name_string, sError)); + FXJS_Error(isolate, JSFormatErrorString(class_name_string, prop_name_string, + sError)); } } @@ -164,15 +164,15 @@ void JSMethod(const char* method_name_string, IFXJS_Context* cc = 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)(cc, 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()); @@ -205,36 +205,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) \ @@ -248,19 +248,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 @@ -275,7 +275,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); @@ -294,7 +294,7 @@ void JSSpecialPropGet(const char* class_name, IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); 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 = @@ -303,7 +303,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); @@ -323,16 +323,16 @@ void JSSpecialPropPut(const char* class_name, IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); 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)); } } @@ -349,7 +349,7 @@ void JSSpecialPropDel(const char* class_name, IFXJS_Runtime* pRuntime = (IFXJS_Runtime*)field->Value(); 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 = @@ -358,7 +358,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(). } } @@ -411,12 +411,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; \ @@ -424,19 +424,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, \ @@ -463,12 +463,12 @@ void JSGlobalFunc(const char* func_name_string, IFXJS_Context* cc = 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)(cc, 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()); @@ -491,14 +491,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 9d1927f192..a5d6954875 100644 --- a/fpdfsdk/include/javascript/JS_Runtime.h +++ b/fpdfsdk/include/javascript/JS_Runtime.h @@ -59,7 +59,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_ |