diff options
Diffstat (limited to 'fxjs/xfa/cjx_instancemanager.cpp')
-rw-r--r-- | fxjs/xfa/cjx_instancemanager.cpp | 171 |
1 files changed, 87 insertions, 84 deletions
diff --git a/fxjs/xfa/cjx_instancemanager.cpp b/fxjs/xfa/cjx_instancemanager.cpp index da8422ea35..19c6d72cc3 100644 --- a/fxjs/xfa/cjx_instancemanager.cpp +++ b/fxjs/xfa/cjx_instancemanager.cpp @@ -6,9 +6,11 @@ #include "fxjs/xfa/cjx_instancemanager.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/cxfa_ffnotify.h" #include "xfa/fxfa/parser/cxfa_document.h" #include "xfa/fxfa/parser/cxfa_instancemanager.h" @@ -30,18 +32,19 @@ CJX_InstanceManager::CJX_InstanceManager(CXFA_InstanceManager* mgr) CJX_InstanceManager::~CJX_InstanceManager() {} -void CJX_InstanceManager::moveInstance(CFXJSE_Arguments* pArguments) { - if (pArguments->GetLength() != 2) { - pArguments->GetReturnValue()->SetUndefined(); - return; - } +CJS_Return CJX_InstanceManager::moveInstance( + CJS_V8* runtime, + const std::vector<v8::Local<v8::Value>>& params) { + if (params.size() != 2) + return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - int32_t iFrom = pArguments->GetInt32(0); - int32_t iTo = pArguments->GetInt32(1); + int32_t iFrom = runtime->ToInt32(params[0]); + int32_t iTo = runtime->ToInt32(params[1]); InstanceManager_MoveInstance(iTo, iFrom); + CXFA_FFNotify* pNotify = GetDocument()->GetNotify(); if (!pNotify) - return; + return CJS_Return(true); CXFA_Node* pToInstance = GetXFANode()->GetItem(iTo); if (pToInstance && pToInstance->GetElementType() == XFA_Element::Subform) @@ -52,29 +55,28 @@ void CJX_InstanceManager::moveInstance(CFXJSE_Arguments* pArguments) { pFromInstance->GetElementType() == XFA_Element::Subform) { pNotify->RunSubformIndexChange(pFromInstance); } + + return CJS_Return(true); } -void CJX_InstanceManager::removeInstance(CFXJSE_Arguments* pArguments) { - if (pArguments->GetLength() != 1) { - pArguments->GetReturnValue()->SetUndefined(); - return; - } +CJS_Return CJX_InstanceManager::removeInstance( + 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); + int32_t iIndex = runtime->ToInt32(params[0]); int32_t iCount = GetXFANode()->GetCount(); - if (iIndex < 0 || iIndex >= iCount) { - ThrowIndexOutOfBoundsException(); - return; - } + if (iIndex < 0 || iIndex >= iCount) + return CJS_Return(JSGetStringFromID(JSMessage::kInvalidInputError)); int32_t iMin = CXFA_OccurData(GetXFANode()->GetOccurNode()).GetMin(); - if (iCount - 1 < iMin) { - ThrowTooManyOccurancesException(L"min"); - return; - } + if (iCount - 1 < iMin) + return CJS_Return(JSGetStringFromID(JSMessage::kTooManyOccurances)); CXFA_Node* pRemoveInstance = GetXFANode()->GetItem(iIndex); GetXFANode()->RemoveItem(pRemoveInstance, true); + CXFA_FFNotify* pNotify = GetDocument()->GetNotify(); if (pNotify) { for (int32_t i = iIndex; i < iCount - 1; i++) { @@ -86,95 +88,96 @@ void CJX_InstanceManager::removeInstance(CFXJSE_Arguments* pArguments) { } } CXFA_LayoutProcessor* pLayoutPro = GetDocument()->GetLayoutProcessor(); - if (!pLayoutPro) - return; - - pLayoutPro->AddChangedContainer( - ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Form))); + if (pLayoutPro) { + pLayoutPro->AddChangedContainer( + ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Form))); + } + return CJS_Return(true); } -void CJX_InstanceManager::setInstances(CFXJSE_Arguments* pArguments) { - if (pArguments->GetLength() != 1) { - pArguments->GetReturnValue()->SetUndefined(); - return; - } +CJS_Return CJX_InstanceManager::setInstances( + CJS_V8* runtime, + const std::vector<v8::Local<v8::Value>>& params) { + if (params.size() != 1) + return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - int32_t iDesired = pArguments->GetInt32(0); - InstanceManager_SetInstances(iDesired); + InstanceManager_SetInstances(runtime->ToInt32(params[0])); + return CJS_Return(true); } -void CJX_InstanceManager::addInstance(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc != 0 && argc != 1) { - ThrowParamCountMismatchException(L"addInstance"); - return; - } +CJS_Return CJX_InstanceManager::addInstance( + CJS_V8* runtime, + const std::vector<v8::Local<v8::Value>>& params) { + if (!params.empty() && params.size() != 1) + return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); bool fFlags = true; - if (argc == 1) - fFlags = pArguments->GetInt32(0) == 0 ? false : true; + if (params.size() == 1) + fFlags = runtime->ToBoolean(params[0]); int32_t iCount = GetXFANode()->GetCount(); int32_t iMax = CXFA_OccurData(GetXFANode()->GetOccurNode()).GetMax(); - if (iMax >= 0 && iCount >= iMax) { - ThrowTooManyOccurancesException(L"max"); - return; - } + if (iMax >= 0 && iCount >= iMax) + return CJS_Return(JSGetStringFromID(JSMessage::kTooManyOccurances)); CXFA_Node* pNewInstance = GetXFANode()->CreateInstance(fFlags); GetXFANode()->InsertItem(pNewInstance, iCount, iCount, false); - pArguments->GetReturnValue()->Assign( - GetDocument()->GetScriptContext()->GetJSValueFromMap(pNewInstance)); + CXFA_FFNotify* pNotify = GetDocument()->GetNotify(); - if (!pNotify) - return; + if (pNotify) { + pNotify->RunNodeInitialize(pNewInstance); - pNotify->RunNodeInitialize(pNewInstance); - CXFA_LayoutProcessor* pLayoutPro = GetDocument()->GetLayoutProcessor(); - if (!pLayoutPro) - return; + CXFA_LayoutProcessor* pLayoutPro = GetDocument()->GetLayoutProcessor(); + if (pLayoutPro) { + pLayoutPro->AddChangedContainer( + ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Form))); + } + } - pLayoutPro->AddChangedContainer( - ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Form))); + CFXJSE_Value* value = + GetDocument()->GetScriptContext()->GetJSValueFromMap(pNewInstance); + if (!value) + return CJS_Return(runtime->NewNull()); + + return CJS_Return(value->DirectGetValue().Get(runtime->GetIsolate())); } -void CJX_InstanceManager::insertInstance(CFXJSE_Arguments* pArguments) { - int32_t argc = pArguments->GetLength(); - if (argc != 1 && argc != 2) { - ThrowParamCountMismatchException(L"insertInstance"); - return; - } +CJS_Return CJX_InstanceManager::insertInstance( + CJS_V8* runtime, + const std::vector<v8::Local<v8::Value>>& params) { + if (params.size() != 1 && params.size() != 2) + return CJS_Return(JSGetStringFromID(JSMessage::kParamError)); - int32_t iIndex = pArguments->GetInt32(0); + int32_t iIndex = runtime->ToInt32(params[0]); bool bBind = false; - if (argc == 2) - bBind = pArguments->GetInt32(1) == 0 ? false : true; + if (params.size() == 2) + bBind = runtime->ToBoolean(params[1]); int32_t iCount = GetXFANode()->GetCount(); - if (iIndex < 0 || iIndex > iCount) { - ThrowIndexOutOfBoundsException(); - return; - } + if (iIndex < 0 || iIndex > iCount) + return CJS_Return(JSGetStringFromID(JSMessage::kInvalidInputError)); int32_t iMax = CXFA_OccurData(GetXFANode()->GetOccurNode()).GetMax(); - if (iMax >= 0 && iCount >= iMax) { - ThrowTooManyOccurancesException(L"max"); - return; - } + if (iMax >= 0 && iCount >= iMax) + return CJS_Return(JSGetStringFromID(JSMessage::kInvalidInputError)); CXFA_Node* pNewInstance = GetXFANode()->CreateInstance(bBind); GetXFANode()->InsertItem(pNewInstance, iIndex, iCount, true); - pArguments->GetReturnValue()->Assign( - GetDocument()->GetScriptContext()->GetJSValueFromMap(pNewInstance)); + CXFA_FFNotify* pNotify = GetDocument()->GetNotify(); - if (!pNotify) - return; + if (pNotify) { + pNotify->RunNodeInitialize(pNewInstance); + CXFA_LayoutProcessor* pLayoutPro = GetDocument()->GetLayoutProcessor(); + if (pLayoutPro) { + pLayoutPro->AddChangedContainer( + ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Form))); + } + } - pNotify->RunNodeInitialize(pNewInstance); - CXFA_LayoutProcessor* pLayoutPro = GetDocument()->GetLayoutProcessor(); - if (!pLayoutPro) - return; + CFXJSE_Value* value = + GetDocument()->GetScriptContext()->GetJSValueFromMap(pNewInstance); + if (!value) + return CJS_Return(runtime->NewNull()); - pLayoutPro->AddChangedContainer( - ToNode(GetDocument()->GetXFAObject(XFA_HASHCODE_Form))); + return CJS_Return(value->DirectGetValue().Get(runtime->GetIsolate())); } |