summaryrefslogtreecommitdiff
path: root/fxjs/xfa/cjx_list.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-12-11 22:01:08 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-12-11 22:01:08 +0000
commitcb22f9ad9265f40b1104ed2b09488ccc6ec9e5aa (patch)
tree4aaa14dfb0528268fb9a9a94a4cac82df1af4602 /fxjs/xfa/cjx_list.cpp
parent731526e3b9f32ceac1cdac600fe3ecd55a0bc9b5 (diff)
downloadpdfium-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_list.cpp')
-rw-r--r--fxjs/xfa/cjx_list.cpp91
1 files changed, 42 insertions, 49 deletions
diff --git a/fxjs/xfa/cjx_list.cpp b/fxjs/xfa/cjx_list.cpp
index 34cf9da7a5..84bdf7bd07 100644
--- a/fxjs/xfa/cjx_list.cpp
+++ b/fxjs/xfa/cjx_list.cpp
@@ -6,9 +6,11 @@
#include "fxjs/xfa/cjx_list.h"
-#include "fxjs/cfxjse_arguments.h"
+#include <vector>
+
#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_list.h"
#include "xfa/fxfa/parser/cxfa_node.h"
@@ -29,67 +31,58 @@ CXFA_List* CJX_List::GetXFAList() {
return static_cast<CXFA_List*>(GetXFAObject());
}
-void CJX_List::append(CFXJSE_Arguments* pArguments) {
- int32_t argc = pArguments->GetLength();
- if (argc != 1) {
- ThrowParamCountMismatchException(L"append");
- return;
- }
+CJS_Return CJX_List::append(CJS_V8* runtime,
+ const std::vector<v8::Local<v8::Value>>& params) {
+ if (params.size() != 1)
+ return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
+
+ auto* pNode = ToNode(runtime->ToXFAObject(params[0]));
+ if (!pNode)
+ return CJS_Return(JSGetStringFromID(JSMessage::kValueError));
- auto* pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
- if (!pNode) {
- ThrowArgumentMismatchException();
- return;
- }
GetXFAList()->Append(pNode);
+ return CJS_Return(true);
}
-void CJX_List::insert(CFXJSE_Arguments* pArguments) {
- int32_t argc = pArguments->GetLength();
- if (argc != 2) {
- ThrowParamCountMismatchException(L"insert");
- return;
- }
+CJS_Return CJX_List::insert(CJS_V8* runtime,
+ const std::vector<v8::Local<v8::Value>>& params) {
+ if (params.size() != 2)
+ return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
- auto* pNewNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
- auto* pBeforeNode = static_cast<CXFA_Node*>(pArguments->GetObject(1));
- if (!pNewNode) {
- ThrowArgumentMismatchException();
- return;
- }
+ auto* pNewNode = ToNode(runtime->ToXFAObject(params[0]));
+ if (!pNewNode)
+ return CJS_Return(JSGetStringFromID(JSMessage::kValueError));
+
+ auto* pBeforeNode = ToNode(runtime->ToXFAObject(params[1]));
GetXFAList()->Insert(pNewNode, pBeforeNode);
+ return CJS_Return(true);
}
-void CJX_List::remove(CFXJSE_Arguments* pArguments) {
- int32_t argc = pArguments->GetLength();
- if (argc != 1) {
- ThrowParamCountMismatchException(L"remove");
- return;
- }
+CJS_Return CJX_List::remove(CJS_V8* runtime,
+ const std::vector<v8::Local<v8::Value>>& params) {
+ if (params.size() != 1)
+ return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
+
+ auto* pNode = ToNode(runtime->ToXFAObject(params[0]));
+ if (!pNode)
+ return CJS_Return(JSGetStringFromID(JSMessage::kValueError));
- auto* pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
- if (!pNode) {
- ThrowArgumentMismatchException();
- return;
- }
GetXFAList()->Remove(pNode);
+ return CJS_Return(true);
}
-void CJX_List::item(CFXJSE_Arguments* pArguments) {
- int32_t argc = pArguments->GetLength();
- if (argc != 1) {
- ThrowParamCountMismatchException(L"item");
- return;
- }
+CJS_Return CJX_List::item(CJS_V8* runtime,
+ const std::vector<v8::Local<v8::Value>>& params) {
+ if (params.size() != 1)
+ return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
- int32_t iIndex = pArguments->GetInt32(0);
- if (iIndex < 0 || iIndex >= GetXFAList()->GetLength()) {
- ThrowIndexOutOfBoundsException();
- return;
- }
- pArguments->GetReturnValue()->Assign(
- GetDocument()->GetScriptContext()->GetJSValueFromMap(
- GetXFAList()->Item(iIndex)));
+ int32_t iIndex = runtime->ToInt32(params[0]);
+ if (iIndex < 0 || iIndex >= GetXFAList()->GetLength())
+ return CJS_Return(JSGetStringFromID(JSMessage::kInvalidInputError));
+
+ return CJS_Return(runtime->NewXFAObject(
+ GetXFAList()->Item(iIndex),
+ GetDocument()->GetScriptContext()->GetJseNormalClass()->GetTemplate()));
}
void CJX_List::length(CFXJSE_Value* pValue,