diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-12-11 22:01:08 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-12-11 22:01:08 +0000 |
commit | cb22f9ad9265f40b1104ed2b09488ccc6ec9e5aa (patch) | |
tree | 4aaa14dfb0528268fb9a9a94a4cac82df1af4602 /fxjs/xfa/cjx_subform.cpp | |
parent | 731526e3b9f32ceac1cdac600fe3ecd55a0bc9b5 (diff) | |
download | pdfium-cb22f9ad9265f40b1104ed2b09488ccc6ec9e5aa.tar.xz |
[xfa] Refactor CJX method signatures.
This CL changes the CJX methods from void (*)(CFXJSE_Arguments*) to
CJS_Return (*)(CJS_V8* runtime, const std::vector<v8::Local<v8::Value>>&
params) which is closer to how CJS works in practice.
Change-Id: I3a3129268acfe4262dfeb04179919ed19f6c24e1
Reviewed-on: https://pdfium-review.googlesource.com/20491
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fxjs/xfa/cjx_subform.cpp')
-rw-r--r-- | fxjs/xfa/cjx_subform.cpp | 74 |
1 files changed, 35 insertions, 39 deletions
diff --git a/fxjs/xfa/cjx_subform.cpp b/fxjs/xfa/cjx_subform.cpp index 32de182e7b..a7e1d2a587 100644 --- a/fxjs/xfa/cjx_subform.cpp +++ b/fxjs/xfa/cjx_subform.cpp @@ -6,8 +6,10 @@ #include "fxjs/xfa/cjx_subform.h" -#include "fxjs/cfxjse_arguments.h" +#include <vector> + #include "fxjs/cfxjse_value.h" +#include "fxjs/js_resources.h" #include "xfa/fxfa/cxfa_eventparam.h" #include "xfa/fxfa/cxfa_ffnotify.h" #include "xfa/fxfa/fxfa.h" @@ -27,58 +29,52 @@ CJX_Subform::CJX_Subform(CXFA_Node* node) : CJX_Container(node) { CJX_Subform::~CJX_Subform() {} -void CJX_Subform::execEvent(CFXJSE_Arguments* pArguments) { - if (pArguments->GetLength() != 1) { - ThrowParamCountMismatchException(L"execEvent"); - return; - } +CJS_Return CJX_Subform::execEvent( + CJS_V8* runtime, + const std::vector<v8::Local<v8::Value>>& params) { + if (params.size() != 1) + return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - ByteString eventString = pArguments->GetUTF8String(0); - execSingleEventByName( - WideString::FromUTF8(eventString.AsStringView()).AsStringView(), - XFA_Element::Subform); + execSingleEventByName(runtime->ToWideString(params[0]).AsStringView(), + XFA_Element::Subform); + return CJS_Return(true); } -void CJX_Subform::execInitialize(CFXJSE_Arguments* pArguments) { - if (pArguments->GetLength() != 0) { - ThrowParamCountMismatchException(L"execInitialize"); - return; - } +CJS_Return CJX_Subform::execInitialize( + CJS_V8* runtime, + const std::vector<v8::Local<v8::Value>>& params) { + if (!params.empty()) + return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); CXFA_FFNotify* pNotify = GetDocument()->GetNotify(); - if (!pNotify) - return; - - pNotify->ExecEventByDeepFirst(GetXFANode(), XFA_EVENT_Initialize); + if (pNotify) + pNotify->ExecEventByDeepFirst(GetXFANode(), XFA_EVENT_Initialize); + return CJS_Return(true); } -void CJX_Subform::execCalculate(CFXJSE_Arguments* pArguments) { - if (pArguments->GetLength() != 0) { - ThrowParamCountMismatchException(L"execCalculate"); - return; - } +CJS_Return CJX_Subform::execCalculate( + CJS_V8* runtime, + const std::vector<v8::Local<v8::Value>>& params) { + if (!params.empty()) + return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); CXFA_FFNotify* pNotify = GetDocument()->GetNotify(); - if (!pNotify) - return; - - pNotify->ExecEventByDeepFirst(GetXFANode(), XFA_EVENT_Calculate); + if (pNotify) + pNotify->ExecEventByDeepFirst(GetXFANode(), XFA_EVENT_Calculate); + return CJS_Return(true); } -void CJX_Subform::execValidate(CFXJSE_Arguments* pArguments) { - if (pArguments->GetLength() != 0) { - ThrowParamCountMismatchException(L"execValidate"); - return; - } +CJS_Return CJX_Subform::execValidate( + CJS_V8* runtime, + const std::vector<v8::Local<v8::Value>>& params) { + if (!params.empty()) + return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); CXFA_FFNotify* pNotify = GetDocument()->GetNotify(); - if (!pNotify) { - pArguments->GetReturnValue()->SetBoolean(false); - return; - } + if (!pNotify) + return CJS_Return(runtime->NewBoolean(false)); int32_t iRet = pNotify->ExecEventByDeepFirst(GetXFANode(), XFA_EVENT_Validate); - pArguments->GetReturnValue()->SetBoolean( - (iRet == XFA_EVENTERROR_Error) ? false : true); + return CJS_Return(runtime->NewBoolean(iRet != XFA_EVENTERROR_Error)); } |