diff options
-rw-r--r-- | fxjs/cfxjse_class.cpp | 50 | ||||
-rw-r--r-- | fxjs/cfxjse_engine.cpp | 11 | ||||
-rw-r--r-- | fxjs/cfxjse_formcalc_context.cpp | 186 | ||||
-rw-r--r-- | fxjs/fxjse.cpp | 9 | ||||
-rw-r--r-- | fxjs/fxjse.h | 11 |
5 files changed, 157 insertions, 110 deletions
diff --git a/fxjs/cfxjse_class.cpp b/fxjs/cfxjse_class.cpp index 67186ff66f..e7e54c8867 100644 --- a/fxjs/cfxjse_class.cpp +++ b/fxjs/cfxjse_class.cpp @@ -16,13 +16,25 @@ #include "fxjs/js_resources.h" #include "third_party/base/ptr_util.h" +using pdfium::fxjse::kFuncTag; +using pdfium::fxjse::kClassTag; + namespace { +FXJSE_FUNCTION_DESCRIPTOR* AsFunctionDescriptor(void* ptr) { + auto* result = static_cast<FXJSE_FUNCTION_DESCRIPTOR*>(ptr); + return result && result->tag == kFuncTag ? result : nullptr; +} + +FXJSE_CLASS_DESCRIPTOR* AsClassDescriptor(void* ptr) { + auto* result = static_cast<FXJSE_CLASS_DESCRIPTOR*>(ptr); + return result && result->tag == kClassTag ? result : nullptr; +} + void V8FunctionCallback_Wrapper( const v8::FunctionCallbackInfo<v8::Value>& info) { const FXJSE_FUNCTION_DESCRIPTOR* lpFunctionInfo = - static_cast<FXJSE_FUNCTION_DESCRIPTOR*>( - info.Data().As<v8::External>()->Value()); + AsFunctionDescriptor(info.Data().As<v8::External>()->Value()); if (!lpFunctionInfo) return; @@ -42,8 +54,7 @@ void V8ConstructorCallback_Wrapper( return; const FXJSE_CLASS_DESCRIPTOR* lpClassDefinition = - static_cast<FXJSE_CLASS_DESCRIPTOR*>( - info.Data().As<v8::External>()->Value()); + AsClassDescriptor(info.Data().As<v8::External>()->Value()); if (!lpClassDefinition) return; @@ -54,8 +65,8 @@ void V8ConstructorCallback_Wrapper( void Context_GlobalObjToString( const v8::FunctionCallbackInfo<v8::Value>& info) { - const FXJSE_CLASS_DESCRIPTOR* lpClass = static_cast<FXJSE_CLASS_DESCRIPTOR*>( - info.Data().As<v8::External>()->Value()); + const FXJSE_CLASS_DESCRIPTOR* lpClass = + AsClassDescriptor(info.Data().As<v8::External>()->Value()); if (!lpClass) return; @@ -178,11 +189,13 @@ void NamedPropertyQueryCallback( v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Integer>& info) { v8::Local<v8::Object> thisObject = info.Holder(); - const FXJSE_CLASS_DESCRIPTOR* lpClass = static_cast<FXJSE_CLASS_DESCRIPTOR*>( - info.Data().As<v8::External>()->Value()); - v8::Isolate* pIsolate = info.GetIsolate(); - v8::HandleScope scope(pIsolate); - v8::String::Utf8Value szPropName(pIsolate, property); + const FXJSE_CLASS_DESCRIPTOR* lpClass = + AsClassDescriptor(info.Data().As<v8::External>()->Value()); + if (!lpClass) + return; + + v8::HandleScope scope(info.GetIsolate()); + v8::String::Utf8Value szPropName(info.GetIsolate(), property); ByteStringView szFxPropName(*szPropName, szPropName.length()); auto lpThisValue = pdfium::MakeUnique<CFXJSE_Value>(info.GetIsolate()); lpThisValue->ForceSetValue(thisObject); @@ -198,8 +211,11 @@ void NamedPropertyGetterCallback( v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& info) { v8::Local<v8::Object> thisObject = info.Holder(); - const FXJSE_CLASS_DESCRIPTOR* lpClass = static_cast<FXJSE_CLASS_DESCRIPTOR*>( - info.Data().As<v8::External>()->Value()); + const FXJSE_CLASS_DESCRIPTOR* lpClass = + AsClassDescriptor(info.Data().As<v8::External>()->Value()); + if (!lpClass) + return; + v8::String::Utf8Value szPropName(info.GetIsolate(), property); ByteStringView szFxPropName(*szPropName, szPropName.length()); auto lpThisValue = pdfium::MakeUnique<CFXJSE_Value>(info.GetIsolate()); @@ -215,13 +231,15 @@ void NamedPropertySetterCallback( v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) { v8::Local<v8::Object> thisObject = info.Holder(); - const FXJSE_CLASS_DESCRIPTOR* lpClass = static_cast<FXJSE_CLASS_DESCRIPTOR*>( - info.Data().As<v8::External>()->Value()); + const FXJSE_CLASS_DESCRIPTOR* lpClass = + AsClassDescriptor(info.Data().As<v8::External>()->Value()); + if (!lpClass) + return; + v8::String::Utf8Value szPropName(info.GetIsolate(), property); ByteStringView szFxPropName(*szPropName, szPropName.length()); auto lpThisValue = pdfium::MakeUnique<CFXJSE_Value>(info.GetIsolate()); lpThisValue->ForceSetValue(thisObject); - auto lpNewValue = pdfium::MakeUnique<CFXJSE_Value>(info.GetIsolate()); lpNewValue->ForceSetValue(value); DynPropSetterAdapter(lpClass, lpThisValue.get(), szFxPropName, diff --git a/fxjs/cfxjse_engine.cpp b/fxjs/cfxjse_engine.cpp index cc584a3fa3..bf5778bf9a 100644 --- a/fxjs/cfxjse_engine.cpp +++ b/fxjs/cfxjse_engine.cpp @@ -31,10 +31,13 @@ #include "xfa/fxfa/parser/xfa_resolvenode_rs.h" #include "xfa/fxfa/parser/xfa_utils.h" +using pdfium::fxjse::kClassTag; + const FXJSE_CLASS_DESCRIPTOR GlobalClassDescriptor = { - "Root", // name - nullptr, // methods - 0, // method count + kClassTag, // tag + "Root", // name + nullptr, // methods + 0, // method count CFXJSE_Engine::GlobalPropTypeGetter, CFXJSE_Engine::GlobalPropertyGetter, CFXJSE_Engine::GlobalPropertySetter, @@ -42,6 +45,7 @@ const FXJSE_CLASS_DESCRIPTOR GlobalClassDescriptor = { }; const FXJSE_CLASS_DESCRIPTOR NormalClassDescriptor = { + kClassTag, // tag "XFAObject", // name nullptr, // methods 0, // method count @@ -52,6 +56,7 @@ const FXJSE_CLASS_DESCRIPTOR NormalClassDescriptor = { }; const FXJSE_CLASS_DESCRIPTOR VariablesClassDescriptor = { + kClassTag, // tag "XFAScriptObject", // name nullptr, // methods 0, // method count diff --git a/fxjs/cfxjse_formcalc_context.cpp b/fxjs/cfxjse_formcalc_context.cpp index 5319466cfa..40f4249ab7 100644 --- a/fxjs/cfxjse_formcalc_context.cpp +++ b/fxjs/cfxjse_formcalc_context.cpp @@ -32,6 +32,9 @@ #include "xfa/fxfa/parser/cxfa_timezoneprovider.h" #include "xfa/fxfa/parser/xfa_utils.h" +using pdfium::fxjse::kFuncTag; +using pdfium::fxjse::kClassTag; + namespace { const double kFinancialPrecision = 0.00000001; @@ -218,97 +221,97 @@ const XFA_FMHtmlReserveCode kReservesForEncode[] = { }; const FXJSE_FUNCTION_DESCRIPTOR kFormCalcFM2JSFunctions[] = { - {"Abs", CFXJSE_FormCalcContext::Abs}, - {"Avg", CFXJSE_FormCalcContext::Avg}, - {"Ceil", CFXJSE_FormCalcContext::Ceil}, - {"Count", CFXJSE_FormCalcContext::Count}, - {"Floor", CFXJSE_FormCalcContext::Floor}, - {"Max", CFXJSE_FormCalcContext::Max}, - {"Min", CFXJSE_FormCalcContext::Min}, - {"Mod", CFXJSE_FormCalcContext::Mod}, - {"Round", CFXJSE_FormCalcContext::Round}, - {"Sum", CFXJSE_FormCalcContext::Sum}, - {"Date", CFXJSE_FormCalcContext::Date}, - {"Date2Num", CFXJSE_FormCalcContext::Date2Num}, - {"DateFmt", CFXJSE_FormCalcContext::DateFmt}, - {"IsoDate2Num", CFXJSE_FormCalcContext::IsoDate2Num}, - {"IsoTime2Num", CFXJSE_FormCalcContext::IsoTime2Num}, - {"LocalDateFmt", CFXJSE_FormCalcContext::LocalDateFmt}, - {"LocalTimeFmt", CFXJSE_FormCalcContext::LocalTimeFmt}, - {"Num2Date", CFXJSE_FormCalcContext::Num2Date}, - {"Num2GMTime", CFXJSE_FormCalcContext::Num2GMTime}, - {"Num2Time", CFXJSE_FormCalcContext::Num2Time}, - {"Time", CFXJSE_FormCalcContext::Time}, - {"Time2Num", CFXJSE_FormCalcContext::Time2Num}, - {"TimeFmt", CFXJSE_FormCalcContext::TimeFmt}, - {"Apr", CFXJSE_FormCalcContext::Apr}, - {"Cterm", CFXJSE_FormCalcContext::CTerm}, - {"FV", CFXJSE_FormCalcContext::FV}, - {"Ipmt", CFXJSE_FormCalcContext::IPmt}, - {"NPV", CFXJSE_FormCalcContext::NPV}, - {"Pmt", CFXJSE_FormCalcContext::Pmt}, - {"PPmt", CFXJSE_FormCalcContext::PPmt}, - {"PV", CFXJSE_FormCalcContext::PV}, - {"Rate", CFXJSE_FormCalcContext::Rate}, - {"Term", CFXJSE_FormCalcContext::Term}, - {"Choose", CFXJSE_FormCalcContext::Choose}, - {"Exists", CFXJSE_FormCalcContext::Exists}, - {"HasValue", CFXJSE_FormCalcContext::HasValue}, - {"Oneof", CFXJSE_FormCalcContext::Oneof}, - {"Within", CFXJSE_FormCalcContext::Within}, - {"If", CFXJSE_FormCalcContext::If}, - {"Eval", CFXJSE_FormCalcContext::Eval}, - {"Translate", CFXJSE_FormCalcContext::eval_translation}, - {"Ref", CFXJSE_FormCalcContext::Ref}, - {"UnitType", CFXJSE_FormCalcContext::UnitType}, - {"UnitValue", CFXJSE_FormCalcContext::UnitValue}, - {"At", CFXJSE_FormCalcContext::At}, - {"Concat", CFXJSE_FormCalcContext::Concat}, - {"Decode", CFXJSE_FormCalcContext::Decode}, - {"Encode", CFXJSE_FormCalcContext::Encode}, - {"Format", CFXJSE_FormCalcContext::Format}, - {"Left", CFXJSE_FormCalcContext::Left}, - {"Len", CFXJSE_FormCalcContext::Len}, - {"Lower", CFXJSE_FormCalcContext::Lower}, - {"Ltrim", CFXJSE_FormCalcContext::Ltrim}, - {"Parse", CFXJSE_FormCalcContext::Parse}, - {"Replace", CFXJSE_FormCalcContext::Replace}, - {"Right", CFXJSE_FormCalcContext::Right}, - {"Rtrim", CFXJSE_FormCalcContext::Rtrim}, - {"Space", CFXJSE_FormCalcContext::Space}, - {"Str", CFXJSE_FormCalcContext::Str}, - {"Stuff", CFXJSE_FormCalcContext::Stuff}, - {"Substr", CFXJSE_FormCalcContext::Substr}, - {"Uuid", CFXJSE_FormCalcContext::Uuid}, - {"Upper", CFXJSE_FormCalcContext::Upper}, - {"WordNum", CFXJSE_FormCalcContext::WordNum}, - {"Get", CFXJSE_FormCalcContext::Get}, - {"Post", CFXJSE_FormCalcContext::Post}, - {"Put", CFXJSE_FormCalcContext::Put}, - {"pos_op", CFXJSE_FormCalcContext::positive_operator}, - {"neg_op", CFXJSE_FormCalcContext::negative_operator}, - {"log_or_op", CFXJSE_FormCalcContext::logical_or_operator}, - {"log_and_op", CFXJSE_FormCalcContext::logical_and_operator}, - {"log_not_op", CFXJSE_FormCalcContext::logical_not_operator}, - {"eq_op", CFXJSE_FormCalcContext::equality_operator}, - {"neq_op", CFXJSE_FormCalcContext::notequality_operator}, - {"lt_op", CFXJSE_FormCalcContext::less_operator}, - {"le_op", CFXJSE_FormCalcContext::lessequal_operator}, - {"gt_op", CFXJSE_FormCalcContext::greater_operator}, - {"ge_op", CFXJSE_FormCalcContext::greaterequal_operator}, - {"plus_op", CFXJSE_FormCalcContext::plus_operator}, - {"minus_op", CFXJSE_FormCalcContext::minus_operator}, - {"mul_op", CFXJSE_FormCalcContext::multiple_operator}, - {"div_op", CFXJSE_FormCalcContext::divide_operator}, - {"asgn_val_op", CFXJSE_FormCalcContext::assign_value_operator}, - {"dot_acc", CFXJSE_FormCalcContext::dot_accessor}, - {"dotdot_acc", CFXJSE_FormCalcContext::dotdot_accessor}, - {"concat_obj", CFXJSE_FormCalcContext::concat_fm_object}, - {"is_obj", CFXJSE_FormCalcContext::is_fm_object}, - {"is_ary", CFXJSE_FormCalcContext::is_fm_array}, - {"get_val", CFXJSE_FormCalcContext::get_fm_value}, - {"get_jsobj", CFXJSE_FormCalcContext::get_fm_jsobj}, - {"var_filter", CFXJSE_FormCalcContext::fm_var_filter}, + {kFuncTag, "Abs", CFXJSE_FormCalcContext::Abs}, + {kFuncTag, "Avg", CFXJSE_FormCalcContext::Avg}, + {kFuncTag, "Ceil", CFXJSE_FormCalcContext::Ceil}, + {kFuncTag, "Count", CFXJSE_FormCalcContext::Count}, + {kFuncTag, "Floor", CFXJSE_FormCalcContext::Floor}, + {kFuncTag, "Max", CFXJSE_FormCalcContext::Max}, + {kFuncTag, "Min", CFXJSE_FormCalcContext::Min}, + {kFuncTag, "Mod", CFXJSE_FormCalcContext::Mod}, + {kFuncTag, "Round", CFXJSE_FormCalcContext::Round}, + {kFuncTag, "Sum", CFXJSE_FormCalcContext::Sum}, + {kFuncTag, "Date", CFXJSE_FormCalcContext::Date}, + {kFuncTag, "Date2Num", CFXJSE_FormCalcContext::Date2Num}, + {kFuncTag, "DateFmt", CFXJSE_FormCalcContext::DateFmt}, + {kFuncTag, "IsoDate2Num", CFXJSE_FormCalcContext::IsoDate2Num}, + {kFuncTag, "IsoTime2Num", CFXJSE_FormCalcContext::IsoTime2Num}, + {kFuncTag, "LocalDateFmt", CFXJSE_FormCalcContext::LocalDateFmt}, + {kFuncTag, "LocalTimeFmt", CFXJSE_FormCalcContext::LocalTimeFmt}, + {kFuncTag, "Num2Date", CFXJSE_FormCalcContext::Num2Date}, + {kFuncTag, "Num2GMTime", CFXJSE_FormCalcContext::Num2GMTime}, + {kFuncTag, "Num2Time", CFXJSE_FormCalcContext::Num2Time}, + {kFuncTag, "Time", CFXJSE_FormCalcContext::Time}, + {kFuncTag, "Time2Num", CFXJSE_FormCalcContext::Time2Num}, + {kFuncTag, "TimeFmt", CFXJSE_FormCalcContext::TimeFmt}, + {kFuncTag, "Apr", CFXJSE_FormCalcContext::Apr}, + {kFuncTag, "Cterm", CFXJSE_FormCalcContext::CTerm}, + {kFuncTag, "FV", CFXJSE_FormCalcContext::FV}, + {kFuncTag, "Ipmt", CFXJSE_FormCalcContext::IPmt}, + {kFuncTag, "NPV", CFXJSE_FormCalcContext::NPV}, + {kFuncTag, "Pmt", CFXJSE_FormCalcContext::Pmt}, + {kFuncTag, "PPmt", CFXJSE_FormCalcContext::PPmt}, + {kFuncTag, "PV", CFXJSE_FormCalcContext::PV}, + {kFuncTag, "Rate", CFXJSE_FormCalcContext::Rate}, + {kFuncTag, "Term", CFXJSE_FormCalcContext::Term}, + {kFuncTag, "Choose", CFXJSE_FormCalcContext::Choose}, + {kFuncTag, "Exists", CFXJSE_FormCalcContext::Exists}, + {kFuncTag, "HasValue", CFXJSE_FormCalcContext::HasValue}, + {kFuncTag, "Oneof", CFXJSE_FormCalcContext::Oneof}, + {kFuncTag, "Within", CFXJSE_FormCalcContext::Within}, + {kFuncTag, "If", CFXJSE_FormCalcContext::If}, + {kFuncTag, "Eval", CFXJSE_FormCalcContext::Eval}, + {kFuncTag, "Translate", CFXJSE_FormCalcContext::eval_translation}, + {kFuncTag, "Ref", CFXJSE_FormCalcContext::Ref}, + {kFuncTag, "UnitType", CFXJSE_FormCalcContext::UnitType}, + {kFuncTag, "UnitValue", CFXJSE_FormCalcContext::UnitValue}, + {kFuncTag, "At", CFXJSE_FormCalcContext::At}, + {kFuncTag, "Concat", CFXJSE_FormCalcContext::Concat}, + {kFuncTag, "Decode", CFXJSE_FormCalcContext::Decode}, + {kFuncTag, "Encode", CFXJSE_FormCalcContext::Encode}, + {kFuncTag, "Format", CFXJSE_FormCalcContext::Format}, + {kFuncTag, "Left", CFXJSE_FormCalcContext::Left}, + {kFuncTag, "Len", CFXJSE_FormCalcContext::Len}, + {kFuncTag, "Lower", CFXJSE_FormCalcContext::Lower}, + {kFuncTag, "Ltrim", CFXJSE_FormCalcContext::Ltrim}, + {kFuncTag, "Parse", CFXJSE_FormCalcContext::Parse}, + {kFuncTag, "Replace", CFXJSE_FormCalcContext::Replace}, + {kFuncTag, "Right", CFXJSE_FormCalcContext::Right}, + {kFuncTag, "Rtrim", CFXJSE_FormCalcContext::Rtrim}, + {kFuncTag, "Space", CFXJSE_FormCalcContext::Space}, + {kFuncTag, "Str", CFXJSE_FormCalcContext::Str}, + {kFuncTag, "Stuff", CFXJSE_FormCalcContext::Stuff}, + {kFuncTag, "Substr", CFXJSE_FormCalcContext::Substr}, + {kFuncTag, "Uuid", CFXJSE_FormCalcContext::Uuid}, + {kFuncTag, "Upper", CFXJSE_FormCalcContext::Upper}, + {kFuncTag, "WordNum", CFXJSE_FormCalcContext::WordNum}, + {kFuncTag, "Get", CFXJSE_FormCalcContext::Get}, + {kFuncTag, "Post", CFXJSE_FormCalcContext::Post}, + {kFuncTag, "Put", CFXJSE_FormCalcContext::Put}, + {kFuncTag, "pos_op", CFXJSE_FormCalcContext::positive_operator}, + {kFuncTag, "neg_op", CFXJSE_FormCalcContext::negative_operator}, + {kFuncTag, "log_or_op", CFXJSE_FormCalcContext::logical_or_operator}, + {kFuncTag, "log_and_op", CFXJSE_FormCalcContext::logical_and_operator}, + {kFuncTag, "log_not_op", CFXJSE_FormCalcContext::logical_not_operator}, + {kFuncTag, "eq_op", CFXJSE_FormCalcContext::equality_operator}, + {kFuncTag, "neq_op", CFXJSE_FormCalcContext::notequality_operator}, + {kFuncTag, "lt_op", CFXJSE_FormCalcContext::less_operator}, + {kFuncTag, "le_op", CFXJSE_FormCalcContext::lessequal_operator}, + {kFuncTag, "gt_op", CFXJSE_FormCalcContext::greater_operator}, + {kFuncTag, "ge_op", CFXJSE_FormCalcContext::greaterequal_operator}, + {kFuncTag, "plus_op", CFXJSE_FormCalcContext::plus_operator}, + {kFuncTag, "minus_op", CFXJSE_FormCalcContext::minus_operator}, + {kFuncTag, "mul_op", CFXJSE_FormCalcContext::multiple_operator}, + {kFuncTag, "div_op", CFXJSE_FormCalcContext::divide_operator}, + {kFuncTag, "asgn_val_op", CFXJSE_FormCalcContext::assign_value_operator}, + {kFuncTag, "dot_acc", CFXJSE_FormCalcContext::dot_accessor}, + {kFuncTag, "dotdot_acc", CFXJSE_FormCalcContext::dotdot_accessor}, + {kFuncTag, "concat_obj", CFXJSE_FormCalcContext::concat_fm_object}, + {kFuncTag, "is_obj", CFXJSE_FormCalcContext::is_fm_object}, + {kFuncTag, "is_ary", CFXJSE_FormCalcContext::is_fm_array}, + {kFuncTag, "get_val", CFXJSE_FormCalcContext::get_fm_value}, + {kFuncTag, "get_jsobj", CFXJSE_FormCalcContext::get_fm_jsobj}, + {kFuncTag, "var_filter", CFXJSE_FormCalcContext::fm_var_filter}, }; const uint8_t kAltTableDate[] = { @@ -607,6 +610,7 @@ double ByteStringToDouble(const ByteStringView& szStringVal) { } // namespace const FXJSE_CLASS_DESCRIPTOR kFormCalcFM2JSDescriptor = { + kClassTag, // tag "XFA_FM2JS_FormCalcClass", // name kFormCalcFM2JSFunctions, // methods FX_ArraySize(kFormCalcFM2JSFunctions), // number of methods diff --git a/fxjs/fxjse.cpp b/fxjs/fxjse.cpp index 68adaa5dd3..44849fdfec 100644 --- a/fxjs/fxjse.cpp +++ b/fxjs/fxjse.cpp @@ -6,6 +6,15 @@ #include "fxjs/fxjse.h" +namespace pdfium { +namespace fxjse { + +const char kFuncTag[] = "function descriptor tag"; +const char kClassTag[] = "class descriptor tag"; + +} // namespace fxjse +} // namespace pdfium + CFXJSE_HostObject::CFXJSE_HostObject() = default; CFXJSE_HostObject::~CFXJSE_HostObject() = default; diff --git a/fxjs/fxjse.h b/fxjs/fxjse.h index 3f2eb1d836..c28cc6c919 100644 --- a/fxjs/fxjse.h +++ b/fxjs/fxjse.h @@ -11,6 +11,15 @@ #include "core/fxcrt/fx_system.h" #include "v8/include/v8.h" +namespace pdfium { +namespace fxjse { + +extern const char kFuncTag[]; +extern const char kClassTag[]; + +} // namespace fxjse +} // namespace pdfium + class CFXJSE_Arguments; class CFXJSE_FormCalcContext; class CFXJSE_Value; @@ -50,11 +59,13 @@ enum FXJSE_ClassPropTypes { }; struct FXJSE_FUNCTION_DESCRIPTOR { + const char* tag; // pdfium::kFuncTag always. const char* name; FXJSE_FuncCallback callbackProc; }; struct FXJSE_CLASS_DESCRIPTOR { + const char* tag; // pdfium::kClassTag always. const char* name; const FXJSE_FUNCTION_DESCRIPTOR* methods; int32_t methNum; |