From 4b172c4934ddda46e06b1c4dc7554e96e1a2f54a Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 23 Oct 2017 11:22:31 -0400 Subject: Cleaning up JS macros This Cl moves JS_Defines macros with only one usage to be inline. Moves macros to where they're used and expands as needed. Change-Id: I7296aa0b7a815ef8f2a80dd813e7466056fe37af Reviewed-on: https://pdfium-review.googlesource.com/16510 Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- fpdfsdk/javascript/PublicMethods.cpp | 62 ++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) (limited to 'fpdfsdk/javascript/PublicMethods.cpp') diff --git a/fpdfsdk/javascript/PublicMethods.cpp b/fpdfsdk/javascript/PublicMethods.cpp index a48f647b77..2e7387e9d2 100644 --- a/fpdfsdk/javascript/PublicMethods.cpp +++ b/fpdfsdk/javascript/PublicMethods.cpp @@ -57,8 +57,6 @@ JSMethodSpec CJS_PublicMethods::GlobalFunctionSpecs[] = { {"AFExtractNums", AFExtractNums_static}, {0, 0}}; -IMPLEMENT_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods) - namespace { const wchar_t* const months[] = {L"Jan", L"Feb", L"Mar", L"Apr", @@ -113,8 +111,68 @@ ByteString CalculateString(double dValue, } #endif +// NOLINTNEXTLINE(whitespace/parens) +template &, CJS_Value&, WideString&)> +void JSGlobalFunc(const char* func_name_string, + const v8::FunctionCallbackInfo& info) { + CJS_Runtime* pRuntime = + CJS_Runtime::CurrentRuntimeFromIsolate(info.GetIsolate()); + if (!pRuntime) + return; + std::vector parameters; + for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) { + parameters.push_back(CJS_Value(pRuntime, info[i])); + } + CJS_Value valueRes(pRuntime); + WideString sError; + if (!(*F)(pRuntime, parameters, valueRes, sError)) { + pRuntime->Error(JSFormatErrorString(func_name_string, nullptr, sError)); + return; + } + info.GetReturnValue().Set(valueRes.ToV8Value(pRuntime)); +} + } // namespace +// static +void CJS_PublicMethods::DefineJSObjects(CFXJS_Engine* pEngine) { + for (size_t i = 0; i < FX_ArraySize(GlobalFunctionSpecs) - 1; ++i) { + pEngine->DefineGlobalMethod( + CJS_PublicMethods::GlobalFunctionSpecs[i].pName, + CJS_PublicMethods::GlobalFunctionSpecs[i].pMethodCall); + } +} + +#define JS_STATIC_GLOBAL_FUN(fun_name) \ + void CJS_PublicMethods::fun_name##_static( \ + const v8::FunctionCallbackInfo& info) { \ + JSGlobalFunc(#fun_name, info); \ + } + +JS_STATIC_GLOBAL_FUN(AFNumber_Format); +JS_STATIC_GLOBAL_FUN(AFNumber_Keystroke); +JS_STATIC_GLOBAL_FUN(AFPercent_Format); +JS_STATIC_GLOBAL_FUN(AFPercent_Keystroke); +JS_STATIC_GLOBAL_FUN(AFDate_FormatEx); +JS_STATIC_GLOBAL_FUN(AFDate_KeystrokeEx); +JS_STATIC_GLOBAL_FUN(AFDate_Format); +JS_STATIC_GLOBAL_FUN(AFDate_Keystroke); +JS_STATIC_GLOBAL_FUN(AFTime_FormatEx); +JS_STATIC_GLOBAL_FUN(AFTime_KeystrokeEx); +JS_STATIC_GLOBAL_FUN(AFTime_Format); +JS_STATIC_GLOBAL_FUN(AFTime_Keystroke); +JS_STATIC_GLOBAL_FUN(AFSpecial_Format); +JS_STATIC_GLOBAL_FUN(AFSpecial_Keystroke); +JS_STATIC_GLOBAL_FUN(AFSpecial_KeystrokeEx); +JS_STATIC_GLOBAL_FUN(AFSimple); +JS_STATIC_GLOBAL_FUN(AFMakeNumber); +JS_STATIC_GLOBAL_FUN(AFSimple_Calculate); +JS_STATIC_GLOBAL_FUN(AFRange_Validate); +JS_STATIC_GLOBAL_FUN(AFMergeChange); +JS_STATIC_GLOBAL_FUN(AFParseDateEx); +JS_STATIC_GLOBAL_FUN(AFExtractNums); + bool CJS_PublicMethods::IsNumber(const WideString& str) { WideString sTrim = StrTrim(str); const wchar_t* pTrim = sTrim.c_str(); -- cgit v1.2.3