diff options
-rw-r--r-- | fxjs/cfxjse_engine.cpp | 14 | ||||
-rw-r--r-- | fxjs/cfxjse_formcalc_context_embeddertest.cpp | 31 | ||||
-rw-r--r-- | testing/xfa_js_embedder_test.h | 1 |
3 files changed, 46 insertions, 0 deletions
diff --git a/fxjs/cfxjse_engine.cpp b/fxjs/cfxjse_engine.cpp index f0c522f018..ff2bcc4618 100644 --- a/fxjs/cfxjse_engine.cpp +++ b/fxjs/cfxjse_engine.cpp @@ -325,6 +325,19 @@ void CFXJSE_Engine::NormalPropertyGetter(CFXJSE_Value* pOriginalValue, if (pScriptObject) { bRet = lpScriptContext->QueryVariableValue(ToNode(pScriptObject), szPropName, pReturnValue, true); + + if (!bRet) { + WideString wsPropName = WideString::FromUTF8(szPropName); + const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = + XFA_GetScriptAttributeByName(pObject->GetElementType(), + wsPropName.AsStringView()); + if (lpAttributeInfo) { + CJX_Object* jsObject = pObject->JSObject(); + (jsObject->*(lpAttributeInfo->callback))(pReturnValue, false, + lpAttributeInfo->attribute); + return; + } + } } if (!bRet) pReturnValue->SetUndefined(); @@ -510,6 +523,7 @@ bool CFXJSE_Engine::QueryVariableValue(CXFA_Node* pScriptNode, pObject->SetObjectOwnProperty(szPropName, pValue); return true; } + if (pObject->HasObjectOwnProperty(szPropName, false)) { pObject->GetObjectProperty(szPropName, hVariableValue.get()); if (hVariableValue->IsFunction()) diff --git a/fxjs/cfxjse_formcalc_context_embeddertest.cpp b/fxjs/cfxjse_formcalc_context_embeddertest.cpp index a7efc14d20..a32f988d06 100644 --- a/fxjs/cfxjse_formcalc_context_embeddertest.cpp +++ b/fxjs/cfxjse_formcalc_context_embeddertest.cpp @@ -2,8 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "fxjs/cfxjse_engine.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/xfa_js_embedder_test.h" +#include "xfa/fxfa/cxfa_eventparam.h" class CFXJSE_FormCalcContextEmbedderTest : public XFAJSEmbedderTest {}; @@ -1455,3 +1457,32 @@ TEST_F(CFXJSE_FormCalcContextEmbedderTest, MethodCall) { EXPECT_TRUE(value->IsString()); EXPECT_STREQ("12.7mm", value->ToString().c_str()); } + +TEST_F(CFXJSE_FormCalcContextEmbedderTest, GetXFAEventChange) { + ASSERT_TRUE(OpenDocument("simple_xfa.pdf")); + + CXFA_EventParam params; + params.m_wsChange = L"changed"; + + CFXJSE_Engine* context = GetScriptContext(); + context->SetEventParam(params); + + const char test[] = {"xfa.event.change"}; + EXPECT_TRUE(Execute(test)); + + CFXJSE_Value* value = GetValue(); + EXPECT_TRUE(value->IsString()); + EXPECT_STREQ("changed", value->ToString().c_str()); +} + +TEST_F(CFXJSE_FormCalcContextEmbedderTest, SetXFAEventChange) { + ASSERT_TRUE(OpenDocument("simple_xfa.pdf")); + + CXFA_EventParam params; + CFXJSE_Engine* context = GetScriptContext(); + context->SetEventParam(params); + + const char test[] = {"xfa.event.change = \"changed\""}; + EXPECT_TRUE(Execute(test)); + EXPECT_EQ(L"changed", context->GetEventParam()->m_wsChange); +} diff --git a/testing/xfa_js_embedder_test.h b/testing/xfa_js_embedder_test.h index 73487d27c8..27dddc3084 100644 --- a/testing/xfa_js_embedder_test.h +++ b/testing/xfa_js_embedder_test.h @@ -36,6 +36,7 @@ class XFAJSEmbedderTest : public EmbedderTest { bool Execute(const ByteStringView& input); bool ExecuteSilenceFailure(const ByteStringView& input); + CFXJSE_Engine* GetScriptContext() { return script_context_; } CFXJSE_Value* GetValue() const { return value_.get(); } private: |