From cb22f9ad9265f40b1104ed2b09488ccc6ec9e5aa Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 11 Dec 2017 22:01:08 +0000 Subject: [xfa] Refactor CJX method signatures. This CL changes the CJX methods from void (*)(CFXJSE_Arguments*) to CJS_Return (*)(CJS_V8* runtime, const std::vector>& params) which is closer to how CJS works in practice. Change-Id: I3a3129268acfe4262dfeb04179919ed19f6c24e1 Reviewed-on: https://pdfium-review.googlesource.com/20491 Commit-Queue: dsinclair Reviewed-by: Tom Sepez --- fxjs/xfa/cjx_treelist.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'fxjs/xfa/cjx_treelist.cpp') diff --git a/fxjs/xfa/cjx_treelist.cpp b/fxjs/xfa/cjx_treelist.cpp index f82f30db29..bb9e4167f8 100644 --- a/fxjs/xfa/cjx_treelist.cpp +++ b/fxjs/xfa/cjx_treelist.cpp @@ -6,9 +6,11 @@ #include "fxjs/xfa/cjx_treelist.h" -#include "fxjs/cfxjse_arguments.h" +#include + #include "fxjs/cfxjse_engine.h" #include "fxjs/cfxjse_value.h" +#include "fxjs/js_resources.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_node.h" #include "xfa/fxfa/parser/cxfa_treelist.h" @@ -27,19 +29,21 @@ CXFA_TreeList* CJX_TreeList::GetXFATreeList() { return static_cast(GetXFAObject()); } -void CJX_TreeList::namedItem(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc != 1) { - ThrowParamCountMismatchException(L"namedItem"); - return; - } +CJS_Return CJX_TreeList::namedItem( + CJS_V8* runtime, + const std::vector>& params) { + if (params.size() != 1) + return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - ByteString szName = pArguments->GetUTF8String(0); CXFA_Node* pNode = GetXFATreeList()->NamedItem( - WideString::FromUTF8(szName.AsStringView()).AsStringView()); + runtime->ToWideString(params[0]).AsStringView()); if (!pNode) - return; + return CJS_Return(true); + + CFXJSE_Value* value = + GetDocument()->GetScriptContext()->GetJSValueFromMap(pNode); + if (!value) + return CJS_Return(runtime->NewNull()); - pArguments->GetReturnValue()->Assign( - GetDocument()->GetScriptContext()->GetJSValueFromMap(pNode)); + return CJS_Return(value->DirectGetValue().Get(runtime->GetIsolate())); } -- cgit v1.2.3