| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "xfa/fxfa/parser/xfa_script_imp.h" | 7 #include "xfa/fxfa/parser/xfa_script_imp.h" |
| 8 | 8 |
| 9 #include "core/fxcrt/include/fx_ext.h" | 9 #include "core/fxcrt/include/fx_ext.h" |
| 10 #include "xfa/fxfa/app/xfa_ffnotify.h" | 10 #include "xfa/fxfa/app/xfa_ffnotify.h" |
| 11 #include "xfa/fxfa/fm2js/xfa_fm2jsapi.h" | 11 #include "xfa/fxfa/fm2js/xfa_fm2jsapi.h" |
| 12 #include "xfa/fxfa/parser/xfa_doclayout.h" | 12 #include "xfa/fxfa/parser/xfa_doclayout.h" |
| 13 #include "xfa/fxfa/parser/xfa_document.h" | 13 #include "xfa/fxfa/parser/xfa_document.h" |
| 14 #include "xfa/fxfa/parser/xfa_localemgr.h" | 14 #include "xfa/fxfa/parser/xfa_localemgr.h" |
| 15 #include "xfa/fxfa/parser/xfa_object.h" | 15 #include "xfa/fxfa/parser/xfa_object.h" |
| 16 #include "xfa/fxfa/parser/xfa_parser.h" | 16 #include "xfa/fxfa/parser/xfa_parser.h" |
| 17 #include "xfa/fxfa/parser/xfa_script.h" | 17 #include "xfa/fxfa/parser/xfa_script.h" |
| 18 #include "xfa/fxfa/parser/xfa_script_nodehelper.h" | 18 #include "xfa/fxfa/parser/xfa_script_nodehelper.h" |
| 19 #include "xfa/fxfa/parser/xfa_script_resolveprocessor.h" | 19 #include "xfa/fxfa/parser/xfa_script_resolveprocessor.h" |
| 20 #include "xfa/fxfa/parser/xfa_utils.h" | 20 #include "xfa/fxfa/parser/xfa_utils.h" |
| 21 #include "xfa/fxjse/cfxjse_arguments.h" | 21 #include "xfa/fxjse/cfxjse_arguments.h" |
| 22 #include "xfa/fxjse/value.h" |
| 22 | 23 |
| 23 CXFA_ScriptContext::CXFA_ScriptContext(CXFA_Document* pDocument) | 24 CXFA_ScriptContext::CXFA_ScriptContext(CXFA_Document* pDocument) |
| 24 : m_pDocument(pDocument), | 25 : m_pDocument(pDocument), |
| 25 m_pJsContext(nullptr), | 26 m_pJsContext(nullptr), |
| 26 m_pIsolate(nullptr), | 27 m_pIsolate(nullptr), |
| 27 m_pJsClass(nullptr), | 28 m_pJsClass(nullptr), |
| 28 m_eScriptType(XFA_SCRIPTLANGTYPE_Unkown), | 29 m_eScriptType(XFA_SCRIPTLANGTYPE_Unkown), |
| 29 m_pScriptNodeArray(nullptr), | 30 m_pScriptNodeArray(nullptr), |
| 30 m_pResolveProcessor(nullptr), | 31 m_pResolveProcessor(nullptr), |
| 31 m_hFM2JSContext(nullptr), | 32 m_hFM2JSContext(nullptr), |
| 32 m_pThisObject(nullptr), | 33 m_pThisObject(nullptr), |
| 33 m_dwBuiltInInFlags(0), | 34 m_dwBuiltInInFlags(0), |
| 34 m_eRunAtType(XFA_ATTRIBUTEENUM_Client) { | 35 m_eRunAtType(XFA_ATTRIBUTEENUM_Client) { |
| 35 FXSYS_memset(&m_JsGlobalClass, 0, sizeof(FXJSE_CLASS)); | 36 FXSYS_memset(&m_JsGlobalClass, 0, sizeof(FXJSE_CLASS)); |
| 36 FXSYS_memset(&m_JsNormalClass, 0, sizeof(FXJSE_CLASS)); | 37 FXSYS_memset(&m_JsNormalClass, 0, sizeof(FXJSE_CLASS)); |
| 37 } | 38 } |
| 38 CXFA_ScriptContext::~CXFA_ScriptContext() { | 39 CXFA_ScriptContext::~CXFA_ScriptContext() { |
| 39 FX_POSITION ps = m_mapXFAToHValue.GetStartPosition(); | 40 FX_POSITION ps = m_mapXFAToValue.GetStartPosition(); |
| 40 while (ps) { | 41 while (ps) { |
| 41 CXFA_Object* pXFAObj; | 42 CXFA_Object* pXFAObj; |
| 42 FXJSE_HVALUE pValue; | 43 CFXJSE_Value* pValue; |
| 43 m_mapXFAToHValue.GetNextAssoc(ps, pXFAObj, pValue); | 44 m_mapXFAToValue.GetNextAssoc(ps, pXFAObj, pValue); |
| 44 FXJSE_Value_Release(pValue); | 45 FXJSE_Value_Release(pValue); |
| 45 } | 46 } |
| 46 m_mapXFAToHValue.RemoveAll(); | 47 m_mapXFAToValue.RemoveAll(); |
| 47 ReleaseVariablesMap(); | 48 ReleaseVariablesMap(); |
| 48 if (m_hFM2JSContext) { | 49 if (m_hFM2JSContext) { |
| 49 XFA_FM2JS_ContextRelease(m_hFM2JSContext); | 50 XFA_FM2JS_ContextRelease(m_hFM2JSContext); |
| 50 m_hFM2JSContext = NULL; | 51 m_hFM2JSContext = NULL; |
| 51 } | 52 } |
| 52 if (m_pJsContext) { | 53 if (m_pJsContext) { |
| 53 FXJSE_Context_Release(m_pJsContext); | 54 FXJSE_Context_Release(m_pJsContext); |
| 54 m_pJsContext = NULL; | 55 m_pJsContext = NULL; |
| 55 } | 56 } |
| 56 delete m_pResolveProcessor; | 57 delete m_pResolveProcessor; |
| 57 m_upObjectArray.RemoveAll(); | 58 m_upObjectArray.RemoveAll(); |
| 58 for (int32_t i = 0; i < m_CacheListArray.GetSize(); i++) | 59 for (int32_t i = 0; i < m_CacheListArray.GetSize(); i++) |
| 59 delete m_CacheListArray[i]; | 60 delete m_CacheListArray[i]; |
| 60 } | 61 } |
| 61 void CXFA_ScriptContext::Initialize(v8::Isolate* pIsolate) { | 62 void CXFA_ScriptContext::Initialize(v8::Isolate* pIsolate) { |
| 62 m_pIsolate = pIsolate; | 63 m_pIsolate = pIsolate; |
| 63 DefineJsContext(); | 64 DefineJsContext(); |
| 64 DefineJsClass(); | 65 DefineJsClass(); |
| 65 m_pResolveProcessor = new CXFA_ResolveProcessor; | 66 m_pResolveProcessor = new CXFA_ResolveProcessor; |
| 66 } | 67 } |
| 67 FX_BOOL CXFA_ScriptContext::RunScript(XFA_SCRIPTLANGTYPE eScriptType, | 68 FX_BOOL CXFA_ScriptContext::RunScript(XFA_SCRIPTLANGTYPE eScriptType, |
| 68 const CFX_WideStringC& wsScript, | 69 const CFX_WideStringC& wsScript, |
| 69 FXJSE_HVALUE hRetValue, | 70 CFXJSE_Value* hRetValue, |
| 70 CXFA_Object* pThisObject) { | 71 CXFA_Object* pThisObject) { |
| 71 CFX_ByteString btScript; | 72 CFX_ByteString btScript; |
| 72 XFA_SCRIPTLANGTYPE eSaveType = m_eScriptType; | 73 XFA_SCRIPTLANGTYPE eSaveType = m_eScriptType; |
| 73 m_eScriptType = eScriptType; | 74 m_eScriptType = eScriptType; |
| 74 if (eScriptType == XFA_SCRIPTLANGTYPE_Formcalc) { | 75 if (eScriptType == XFA_SCRIPTLANGTYPE_Formcalc) { |
| 75 if (!m_hFM2JSContext) { | 76 if (!m_hFM2JSContext) { |
| 76 m_hFM2JSContext = XFA_FM2JS_ContextCreate(); | 77 m_hFM2JSContext = XFA_FM2JS_ContextCreate(); |
| 77 XFA_FM2JS_ContextInitialize(m_hFM2JSContext, m_pIsolate, m_pJsContext, | 78 XFA_FM2JS_ContextInitialize(m_hFM2JSContext, m_pIsolate, m_pJsContext, |
| 78 m_pDocument); | 79 m_pDocument); |
| 79 } | 80 } |
| 80 CFX_WideTextBuf wsJavaScript; | 81 CFX_WideTextBuf wsJavaScript; |
| 81 CFX_WideString wsErrorInfo; | 82 CFX_WideString wsErrorInfo; |
| 82 int32_t iFlags = XFA_FM2JS_Translate(wsScript, wsJavaScript, wsErrorInfo); | 83 int32_t iFlags = XFA_FM2JS_Translate(wsScript, wsJavaScript, wsErrorInfo); |
| 83 if (iFlags) { | 84 if (iFlags) { |
| 84 FXJSE_Value_SetUndefined(hRetValue); | 85 FXJSE_Value_SetUndefined(hRetValue); |
| 85 return FALSE; | 86 return FALSE; |
| 86 } | 87 } |
| 87 btScript = | 88 btScript = |
| 88 FX_UTF8Encode(wsJavaScript.GetBuffer(), wsJavaScript.GetLength()); | 89 FX_UTF8Encode(wsJavaScript.GetBuffer(), wsJavaScript.GetLength()); |
| 89 } else { | 90 } else { |
| 90 btScript = FX_UTF8Encode(wsScript.c_str(), wsScript.GetLength()); | 91 btScript = FX_UTF8Encode(wsScript.c_str(), wsScript.GetLength()); |
| 91 } | 92 } |
| 92 CXFA_Object* pOriginalObject = m_pThisObject; | 93 CXFA_Object* pOriginalObject = m_pThisObject; |
| 93 m_pThisObject = pThisObject; | 94 m_pThisObject = pThisObject; |
| 94 FXJSE_HVALUE pValue = pThisObject ? GetJSValueFromMap(pThisObject) : NULL; | 95 CFXJSE_Value* pValue = pThisObject ? GetJSValueFromMap(pThisObject) : NULL; |
| 95 FX_BOOL bRet = | 96 FX_BOOL bRet = |
| 96 FXJSE_ExecuteScript(m_pJsContext, btScript.c_str(), hRetValue, pValue); | 97 FXJSE_ExecuteScript(m_pJsContext, btScript.c_str(), hRetValue, pValue); |
| 97 m_pThisObject = pOriginalObject; | 98 m_pThisObject = pOriginalObject; |
| 98 m_eScriptType = eSaveType; | 99 m_eScriptType = eSaveType; |
| 99 return bRet; | 100 return bRet; |
| 100 } | 101 } |
| 101 void CXFA_ScriptContext::GlobalPropertySetter(FXJSE_HOBJECT hObject, | 102 void CXFA_ScriptContext::GlobalPropertySetter(CFXJSE_Value* pObject, |
| 102 const CFX_ByteStringC& szPropName, | 103 const CFX_ByteStringC& szPropName, |
| 103 FXJSE_HVALUE hValue) { | 104 CFXJSE_Value* pValue) { |
| 104 CXFA_Object* lpOrginalNode = | 105 CXFA_Object* lpOrginalNode = |
| 105 (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); | 106 (CXFA_Object*)FXJSE_Value_ToObject(pObject, nullptr); |
| 106 CXFA_Document* pDoc = lpOrginalNode->GetDocument(); | 107 CXFA_Document* pDoc = lpOrginalNode->GetDocument(); |
| 107 CXFA_ScriptContext* lpScriptContext = | 108 CXFA_ScriptContext* lpScriptContext = |
| 108 (CXFA_ScriptContext*)pDoc->GetScriptContext(); | 109 (CXFA_ScriptContext*)pDoc->GetScriptContext(); |
| 109 CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(lpOrginalNode); | 110 CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(lpOrginalNode); |
| 110 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); | 111 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
| 111 uint32_t dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings | | 112 uint32_t dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings | |
| 112 XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | | 113 XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | |
| 113 XFA_RESOLVENODE_Attributes; | 114 XFA_RESOLVENODE_Attributes; |
| 114 CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject()); | 115 CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject()); |
| 115 if (lpOrginalNode->GetObjectType() == XFA_OBJECTTYPE_VariablesThis) { | 116 if (lpOrginalNode->GetObjectType() == XFA_OBJECTTYPE_VariablesThis) { |
| 116 pRefNode = ToNode(lpCurNode); | 117 pRefNode = ToNode(lpCurNode); |
| 117 } | 118 } |
| 118 if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringC(), hValue, | 119 if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringC(), pValue, |
| 119 dwFlag, TRUE)) { | 120 dwFlag, TRUE)) { |
| 120 return; | 121 return; |
| 121 } | 122 } |
| 122 if (lpOrginalNode->GetObjectType() == XFA_OBJECTTYPE_VariablesThis) { | 123 if (lpOrginalNode->GetObjectType() == XFA_OBJECTTYPE_VariablesThis) { |
| 123 if (FXJSE_Value_IsUndefined(hValue)) { | 124 if (FXJSE_Value_IsUndefined(pValue)) { |
| 124 FXJSE_Value_SetObjectOwnProp(hObject, szPropName, hValue); | 125 FXJSE_Value_SetObjectOwnProp(pObject, szPropName, pValue); |
| 125 return; | 126 return; |
| 126 } | 127 } |
| 127 } | 128 } |
| 128 CXFA_FFNotify* pNotify = pDoc->GetNotify(); | 129 CXFA_FFNotify* pNotify = pDoc->GetNotify(); |
| 129 if (!pNotify) { | 130 if (!pNotify) { |
| 130 return; | 131 return; |
| 131 } | 132 } |
| 132 pNotify->GetDocProvider()->SetGlobalProperty(pNotify->GetHDOC(), szPropName, | 133 pNotify->GetDocProvider()->SetGlobalProperty(pNotify->GetHDOC(), szPropName, |
| 133 hValue); | 134 pValue); |
| 134 } | 135 } |
| 135 FX_BOOL CXFA_ScriptContext::QueryNodeByFlag(CXFA_Node* refNode, | 136 FX_BOOL CXFA_ScriptContext::QueryNodeByFlag(CXFA_Node* refNode, |
| 136 const CFX_WideStringC& propname, | 137 const CFX_WideStringC& propname, |
| 137 FXJSE_HVALUE hValue, | 138 CFXJSE_Value* pValue, |
| 138 uint32_t dwFlag, | 139 uint32_t dwFlag, |
| 139 FX_BOOL bSetting) { | 140 FX_BOOL bSetting) { |
| 140 if (!refNode) | 141 if (!refNode) |
| 141 return false; | 142 return false; |
| 142 XFA_RESOLVENODE_RS resolveRs; | 143 XFA_RESOLVENODE_RS resolveRs; |
| 143 if (ResolveObjects(refNode, propname, resolveRs, dwFlag) <= 0) | 144 if (ResolveObjects(refNode, propname, resolveRs, dwFlag) <= 0) |
| 144 return false; | 145 return false; |
| 145 if (resolveRs.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { | 146 if (resolveRs.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { |
| 146 FXJSE_HVALUE pValue = GetJSValueFromMap(resolveRs.nodes[0]); | 147 FXJSE_Value_Set(pValue, GetJSValueFromMap(resolveRs.nodes[0])); |
| 147 FXJSE_Value_Set(hValue, pValue); | |
| 148 return true; | 148 return true; |
| 149 } | 149 } |
| 150 if (resolveRs.dwFlags == XFA_RESOVENODE_RSTYPE_Attribute) { | 150 if (resolveRs.dwFlags == XFA_RESOVENODE_RSTYPE_Attribute) { |
| 151 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = resolveRs.pScriptAttribute; | 151 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = resolveRs.pScriptAttribute; |
| 152 if (lpAttributeInfo) { | 152 if (lpAttributeInfo) { |
| 153 (resolveRs.nodes[0]->*(lpAttributeInfo->lpfnCallback))( | 153 (resolveRs.nodes[0]->*(lpAttributeInfo->lpfnCallback))( |
| 154 hValue, bSetting, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); | 154 pValue, bSetting, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 return true; | 157 return true; |
| 158 } | 158 } |
| 159 void CXFA_ScriptContext::GlobalPropertyGetter(FXJSE_HOBJECT hObject, | 159 void CXFA_ScriptContext::GlobalPropertyGetter(CFXJSE_Value* pObject, |
| 160 const CFX_ByteStringC& szPropName, | 160 const CFX_ByteStringC& szPropName, |
| 161 FXJSE_HVALUE hValue) { | 161 CFXJSE_Value* pValue) { |
| 162 CXFA_Object* pOrginalObject = | 162 CXFA_Object* pOriginalObject = |
| 163 (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); | 163 (CXFA_Object*)FXJSE_Value_ToObject(pObject, nullptr); |
| 164 CXFA_Document* pDoc = pOrginalObject->GetDocument(); | 164 CXFA_Document* pDoc = pOriginalObject->GetDocument(); |
| 165 CXFA_ScriptContext* lpScriptContext = | 165 CXFA_ScriptContext* lpScriptContext = |
| 166 (CXFA_ScriptContext*)pDoc->GetScriptContext(); | 166 (CXFA_ScriptContext*)pDoc->GetScriptContext(); |
| 167 CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(pOrginalObject); | 167 CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(pOriginalObject); |
| 168 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); | 168 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
| 169 if (lpScriptContext->GetType() == XFA_SCRIPTLANGTYPE_Formcalc) { | 169 if (lpScriptContext->GetType() == XFA_SCRIPTLANGTYPE_Formcalc) { |
| 170 if (szPropName == FOXIT_XFA_FM2JS_FORMCALC_RUNTIME) { | 170 if (szPropName == FOXIT_XFA_FM2JS_FORMCALC_RUNTIME) { |
| 171 XFA_FM2JS_GlobalPropertyGetter(lpScriptContext->m_hFM2JSContext, hValue); | 171 XFA_FM2JS_GlobalPropertyGetter(lpScriptContext->m_hFM2JSContext, pValue); |
| 172 return; | 172 return; |
| 173 } | 173 } |
| 174 XFA_HashCode uHashCode = static_cast<XFA_HashCode>( | 174 XFA_HashCode uHashCode = static_cast<XFA_HashCode>( |
| 175 FX_HashCode_GetW(wsPropName.AsStringC(), false)); | 175 FX_HashCode_GetW(wsPropName.AsStringC(), false)); |
| 176 if (uHashCode != XFA_HASHCODE_Layout) { | 176 if (uHashCode != XFA_HASHCODE_Layout) { |
| 177 CXFA_Object* pObject = | 177 CXFA_Object* pObject = |
| 178 lpScriptContext->GetDocument()->GetXFAObject(uHashCode); | 178 lpScriptContext->GetDocument()->GetXFAObject(uHashCode); |
| 179 if (pObject) { | 179 if (pObject) { |
| 180 FXJSE_Value_Set(hValue, lpScriptContext->GetJSValueFromMap(pObject)); | 180 FXJSE_Value_Set(pValue, lpScriptContext->GetJSValueFromMap(pObject)); |
| 181 return; | 181 return; |
| 182 } | 182 } |
| 183 } | 183 } |
| 184 } | 184 } |
| 185 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | | 185 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | |
| 186 XFA_RESOLVENODE_Attributes; | 186 XFA_RESOLVENODE_Attributes; |
| 187 CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject()); | 187 CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject()); |
| 188 if (pOrginalObject->GetObjectType() == XFA_OBJECTTYPE_VariablesThis) { | 188 if (pOriginalObject->GetObjectType() == XFA_OBJECTTYPE_VariablesThis) { |
| 189 pRefNode = ToNode(lpCurNode); | 189 pRefNode = ToNode(lpCurNode); |
| 190 } | 190 } |
| 191 if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringC(), hValue, | 191 if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringC(), pValue, |
| 192 dwFlag, FALSE)) { | 192 dwFlag, FALSE)) { |
| 193 return; | 193 return; |
| 194 } | 194 } |
| 195 dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; | 195 dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; |
| 196 if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringC(), hValue, | 196 if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringC(), pValue, |
| 197 dwFlag, FALSE)) { | 197 dwFlag, FALSE)) { |
| 198 return; | 198 return; |
| 199 } | 199 } |
| 200 CXFA_Object* pScriptObject = | 200 CXFA_Object* pScriptObject = |
| 201 lpScriptContext->GetVariablesThis(pOrginalObject, TRUE); | 201 lpScriptContext->GetVariablesThis(pOriginalObject, TRUE); |
| 202 if (pScriptObject && | 202 if (pScriptObject && |
| 203 lpScriptContext->QueryVariableHValue(pScriptObject->AsNode(), szPropName, | 203 lpScriptContext->QueryVariableValue(pScriptObject->AsNode(), szPropName, |
| 204 hValue, TRUE)) { | 204 pValue, TRUE)) { |
| 205 return; | 205 return; |
| 206 } | 206 } |
| 207 CXFA_FFNotify* pNotify = pDoc->GetNotify(); | 207 CXFA_FFNotify* pNotify = pDoc->GetNotify(); |
| 208 if (!pNotify) { | 208 if (!pNotify) { |
| 209 return; | 209 return; |
| 210 } | 210 } |
| 211 pNotify->GetDocProvider()->GetGlobalProperty(pNotify->GetHDOC(), szPropName, | 211 pNotify->GetDocProvider()->GetGlobalProperty(pNotify->GetHDOC(), szPropName, |
| 212 hValue); | 212 pValue); |
| 213 } | 213 } |
| 214 void CXFA_ScriptContext::NormalPropertyGetter(FXJSE_HOBJECT hObject, | 214 void CXFA_ScriptContext::NormalPropertyGetter(CFXJSE_Value* pOriginalValue, |
| 215 const CFX_ByteStringC& szPropName, | 215 const CFX_ByteStringC& szPropName, |
| 216 FXJSE_HVALUE hValue) { | 216 CFXJSE_Value* pReturnValue) { |
| 217 CXFA_Object* pOrginalObject = | 217 CXFA_Object* pOriginalObject = |
| 218 (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); | 218 (CXFA_Object*)FXJSE_Value_ToObject(pOriginalValue, nullptr); |
| 219 if (pOrginalObject == NULL) { | 219 if (!pOriginalObject) { |
| 220 FXJSE_Value_SetUndefined(hValue); | 220 FXJSE_Value_SetUndefined(pReturnValue); |
| 221 return; | 221 return; |
| 222 } | 222 } |
| 223 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); | 223 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
| 224 CXFA_ScriptContext* lpScriptContext = | 224 CXFA_ScriptContext* lpScriptContext = |
| 225 (CXFA_ScriptContext*)pOrginalObject->GetDocument()->GetScriptContext(); | 225 (CXFA_ScriptContext*)pOriginalObject->GetDocument()->GetScriptContext(); |
| 226 CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOrginalObject); | 226 CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOriginalObject); |
| 227 if (wsPropName == FX_WSTRC(L"xfa")) { | 227 if (wsPropName == FX_WSTRC(L"xfa")) { |
| 228 FXJSE_HVALUE pValue = lpScriptContext->GetJSValueFromMap( | 228 CFXJSE_Value* pValue = lpScriptContext->GetJSValueFromMap( |
| 229 lpScriptContext->GetDocument()->GetRoot()); | 229 lpScriptContext->GetDocument()->GetRoot()); |
| 230 FXJSE_Value_Set(hValue, pValue); | 230 FXJSE_Value_Set(pReturnValue, pValue); |
| 231 return; | 231 return; |
| 232 } | 232 } |
| 233 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | | 233 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | |
| 234 XFA_RESOLVENODE_Attributes; | 234 XFA_RESOLVENODE_Attributes; |
| 235 FX_BOOL bRet = lpScriptContext->QueryNodeByFlag( | 235 FX_BOOL bRet = lpScriptContext->QueryNodeByFlag( |
| 236 ToNode(pObject), wsPropName.AsStringC(), hValue, dwFlag, FALSE); | 236 ToNode(pObject), wsPropName.AsStringC(), pReturnValue, dwFlag, FALSE); |
| 237 if (bRet) { | 237 if (bRet) { |
| 238 return; | 238 return; |
| 239 } | 239 } |
| 240 if (pObject == lpScriptContext->GetThisObject() || | 240 if (pObject == lpScriptContext->GetThisObject() || |
| 241 (lpScriptContext->GetType() == XFA_SCRIPTLANGTYPE_Javascript && | 241 (lpScriptContext->GetType() == XFA_SCRIPTLANGTYPE_Javascript && |
| 242 !lpScriptContext->IsStrictScopeInJavaScript())) { | 242 !lpScriptContext->IsStrictScopeInJavaScript())) { |
| 243 dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; | 243 dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; |
| 244 bRet = lpScriptContext->QueryNodeByFlag( | 244 bRet = lpScriptContext->QueryNodeByFlag( |
| 245 ToNode(pObject), wsPropName.AsStringC(), hValue, dwFlag, FALSE); | 245 ToNode(pObject), wsPropName.AsStringC(), pReturnValue, dwFlag, FALSE); |
| 246 } | 246 } |
| 247 if (bRet) { | 247 if (bRet) { |
| 248 return; | 248 return; |
| 249 } | 249 } |
| 250 CXFA_Object* pScriptObject = | 250 CXFA_Object* pScriptObject = |
| 251 lpScriptContext->GetVariablesThis(pOrginalObject, TRUE); | 251 lpScriptContext->GetVariablesThis(pOriginalObject, TRUE); |
| 252 if (pScriptObject) { | 252 if (pScriptObject) { |
| 253 bRet = lpScriptContext->QueryVariableHValue(ToNode(pScriptObject), | 253 bRet = lpScriptContext->QueryVariableValue(ToNode(pScriptObject), |
| 254 szPropName, hValue, TRUE); | 254 szPropName, pReturnValue, TRUE); |
| 255 } | 255 } |
| 256 if (!bRet) { | 256 if (!bRet) { |
| 257 FXJSE_Value_SetUndefined(hValue); | 257 FXJSE_Value_SetUndefined(pReturnValue); |
| 258 } | 258 } |
| 259 } | 259 } |
| 260 void CXFA_ScriptContext::NormalPropertySetter(FXJSE_HOBJECT hObject, | 260 void CXFA_ScriptContext::NormalPropertySetter(CFXJSE_Value* pOriginalValue, |
| 261 const CFX_ByteStringC& szPropName, | 261 const CFX_ByteStringC& szPropName, |
| 262 FXJSE_HVALUE hValue) { | 262 CFXJSE_Value* pReturnValue) { |
| 263 CXFA_Object* pOrginalObject = | 263 CXFA_Object* pOriginalObject = |
| 264 (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); | 264 (CXFA_Object*)FXJSE_Value_ToObject(pOriginalValue, nullptr); |
| 265 if (pOrginalObject == NULL) { | 265 if (!pOriginalObject) |
| 266 return; | 266 return; |
| 267 } | 267 |
| 268 CXFA_ScriptContext* lpScriptContext = | 268 CXFA_ScriptContext* lpScriptContext = |
| 269 (CXFA_ScriptContext*)pOrginalObject->GetDocument()->GetScriptContext(); | 269 (CXFA_ScriptContext*)pOriginalObject->GetDocument()->GetScriptContext(); |
| 270 CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOrginalObject); | 270 CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOriginalObject); |
| 271 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); | 271 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
| 272 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = XFA_GetScriptAttributeByName( | 272 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = XFA_GetScriptAttributeByName( |
| 273 pObject->GetClassID(), wsPropName.AsStringC()); | 273 pObject->GetClassID(), wsPropName.AsStringC()); |
| 274 if (lpAttributeInfo) { | 274 if (lpAttributeInfo) { |
| 275 (pObject->*(lpAttributeInfo->lpfnCallback))( | 275 (pObject->*(lpAttributeInfo->lpfnCallback))( |
| 276 hValue, TRUE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); | 276 pReturnValue, TRUE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); |
| 277 } else { | 277 } else { |
| 278 if (pObject->IsNode()) { | 278 if (pObject->IsNode()) { |
| 279 if (wsPropName.GetAt(0) == '#') { | 279 if (wsPropName.GetAt(0) == '#') { |
| 280 wsPropName = wsPropName.Right(wsPropName.GetLength() - 1); | 280 wsPropName = wsPropName.Right(wsPropName.GetLength() - 1); |
| 281 } | 281 } |
| 282 CXFA_Node* pNode = ToNode(pObject); | 282 CXFA_Node* pNode = ToNode(pObject); |
| 283 CXFA_Node* pPropOrChild = NULL; | 283 CXFA_Node* pPropOrChild = NULL; |
| 284 const XFA_ELEMENTINFO* lpElementInfo = | 284 const XFA_ELEMENTINFO* lpElementInfo = |
| 285 XFA_GetElementByName(wsPropName.AsStringC()); | 285 XFA_GetElementByName(wsPropName.AsStringC()); |
| 286 if (lpElementInfo) { | 286 if (lpElementInfo) { |
| 287 pPropOrChild = pNode->GetProperty(0, lpElementInfo->eName); | 287 pPropOrChild = pNode->GetProperty(0, lpElementInfo->eName); |
| 288 } else { | 288 } else { |
| 289 pPropOrChild = pNode->GetFirstChildByName(wsPropName.AsStringC()); | 289 pPropOrChild = pNode->GetFirstChildByName(wsPropName.AsStringC()); |
| 290 } | 290 } |
| 291 if (pPropOrChild) { | 291 if (pPropOrChild) { |
| 292 CFX_WideString wsDefaultName(L"{default}"); | 292 CFX_WideString wsDefaultName(L"{default}"); |
| 293 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = | 293 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = |
| 294 XFA_GetScriptAttributeByName(pPropOrChild->GetClassID(), | 294 XFA_GetScriptAttributeByName(pPropOrChild->GetClassID(), |
| 295 wsDefaultName.AsStringC()); | 295 wsDefaultName.AsStringC()); |
| 296 if (lpAttributeInfo) { | 296 if (lpAttributeInfo) { |
| 297 (pPropOrChild->*(lpAttributeInfo->lpfnCallback))( | 297 (pPropOrChild->*(lpAttributeInfo->lpfnCallback))( |
| 298 hValue, TRUE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); | 298 pReturnValue, TRUE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); |
| 299 return; | 299 return; |
| 300 } | 300 } |
| 301 } | 301 } |
| 302 } | 302 } |
| 303 CXFA_Object* pScriptObject = | 303 CXFA_Object* pScriptObject = |
| 304 lpScriptContext->GetVariablesThis(pOrginalObject, TRUE); | 304 lpScriptContext->GetVariablesThis(pOriginalObject, TRUE); |
| 305 if (pScriptObject) { | 305 if (pScriptObject) { |
| 306 lpScriptContext->QueryVariableHValue(ToNode(pScriptObject), szPropName, | 306 lpScriptContext->QueryVariableValue(ToNode(pScriptObject), szPropName, |
| 307 hValue, FALSE); | 307 pReturnValue, FALSE); |
| 308 } | 308 } |
| 309 } | 309 } |
| 310 } | 310 } |
| 311 int32_t CXFA_ScriptContext::NormalPropTypeGetter( | 311 int32_t CXFA_ScriptContext::NormalPropTypeGetter( |
| 312 FXJSE_HOBJECT hObject, | 312 CFXJSE_Value* pOriginalValue, |
| 313 const CFX_ByteStringC& szPropName, | 313 const CFX_ByteStringC& szPropName, |
| 314 FX_BOOL bQueryIn) { | 314 FX_BOOL bQueryIn) { |
| 315 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); | 315 CXFA_Object* pObject = |
| 316 if (pObject == NULL) { | 316 (CXFA_Object*)FXJSE_Value_ToObject(pOriginalValue, nullptr); |
| 317 if (!pObject) |
| 317 return FXJSE_ClassPropType_None; | 318 return FXJSE_ClassPropType_None; |
| 318 } | 319 |
| 319 CXFA_ScriptContext* lpScriptContext = | 320 CXFA_ScriptContext* lpScriptContext = |
| 320 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); | 321 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); |
| 321 pObject = lpScriptContext->GetVariablesThis(pObject); | 322 pObject = lpScriptContext->GetVariablesThis(pObject); |
| 322 XFA_ELEMENT objElement = pObject->GetClassID(); | 323 XFA_ELEMENT objElement = pObject->GetClassID(); |
| 323 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); | 324 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
| 324 if (XFA_GetMethodByName(objElement, wsPropName.AsStringC())) { | 325 if (XFA_GetMethodByName(objElement, wsPropName.AsStringC())) { |
| 325 return FXJSE_ClassPropType_Method; | 326 return FXJSE_ClassPropType_Method; |
| 326 } | 327 } |
| 327 if (bQueryIn && | 328 if (bQueryIn && |
| 328 !XFA_GetScriptAttributeByName(objElement, wsPropName.AsStringC())) { | 329 !XFA_GetScriptAttributeByName(objElement, wsPropName.AsStringC())) { |
| 329 return FXJSE_ClassPropType_None; | 330 return FXJSE_ClassPropType_None; |
| 330 } | 331 } |
| 331 return FXJSE_ClassPropType_Property; | 332 return FXJSE_ClassPropType_Property; |
| 332 } | 333 } |
| 333 int32_t CXFA_ScriptContext::GlobalPropTypeGetter( | 334 int32_t CXFA_ScriptContext::GlobalPropTypeGetter( |
| 334 FXJSE_HOBJECT hObject, | 335 CFXJSE_Value* pOriginalValue, |
| 335 const CFX_ByteStringC& szPropName, | 336 const CFX_ByteStringC& szPropName, |
| 336 FX_BOOL bQueryIn) { | 337 FX_BOOL bQueryIn) { |
| 337 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); | 338 CXFA_Object* pObject = |
| 338 if (pObject == NULL) { | 339 (CXFA_Object*)FXJSE_Value_ToObject(pOriginalValue, nullptr); |
| 340 if (!pObject) |
| 339 return FXJSE_ClassPropType_None; | 341 return FXJSE_ClassPropType_None; |
| 340 } | 342 |
| 341 CXFA_ScriptContext* lpScriptContext = | 343 CXFA_ScriptContext* lpScriptContext = |
| 342 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); | 344 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); |
| 343 pObject = lpScriptContext->GetVariablesThis(pObject); | 345 pObject = lpScriptContext->GetVariablesThis(pObject); |
| 344 XFA_ELEMENT objElement = pObject->GetClassID(); | 346 XFA_ELEMENT objElement = pObject->GetClassID(); |
| 345 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); | 347 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
| 346 if (XFA_GetMethodByName(objElement, wsPropName.AsStringC())) { | 348 if (XFA_GetMethodByName(objElement, wsPropName.AsStringC())) { |
| 347 return FXJSE_ClassPropType_Method; | 349 return FXJSE_ClassPropType_Method; |
| 348 } | 350 } |
| 349 return FXJSE_ClassPropType_Property; | 351 return FXJSE_ClassPropType_Property; |
| 350 } | 352 } |
| 351 void CXFA_ScriptContext::NormalMethodCall(FXJSE_HOBJECT hThis, | 353 void CXFA_ScriptContext::NormalMethodCall(CFXJSE_Value* pThis, |
| 352 const CFX_ByteStringC& szFuncName, | 354 const CFX_ByteStringC& szFuncName, |
| 353 CFXJSE_Arguments& args) { | 355 CFXJSE_Arguments& args) { |
| 354 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(hThis, NULL); | 356 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(pThis, nullptr); |
| 355 if (pObject == NULL) { | 357 if (!pObject) |
| 356 return; | 358 return; |
| 357 } | 359 |
| 358 CXFA_ScriptContext* lpScriptContext = | 360 CXFA_ScriptContext* lpScriptContext = |
| 359 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); | 361 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); |
| 360 pObject = lpScriptContext->GetVariablesThis(pObject); | 362 pObject = lpScriptContext->GetVariablesThis(pObject); |
| 361 CFX_WideString wsFunName = CFX_WideString::FromUTF8(szFuncName); | 363 CFX_WideString wsFunName = CFX_WideString::FromUTF8(szFuncName); |
| 362 const XFA_METHODINFO* lpMethodInfo = | 364 const XFA_METHODINFO* lpMethodInfo = |
| 363 XFA_GetMethodByName(pObject->GetClassID(), wsFunName.AsStringC()); | 365 XFA_GetMethodByName(pObject->GetClassID(), wsFunName.AsStringC()); |
| 364 if (NULL == lpMethodInfo) { | 366 if (!lpMethodInfo) |
| 365 return; | 367 return; |
| 366 } | 368 |
| 367 (pObject->*(lpMethodInfo->lpfnCallback))(&args); | 369 (pObject->*(lpMethodInfo->lpfnCallback))(&args); |
| 368 } | 370 } |
| 369 FX_BOOL CXFA_ScriptContext::IsStrictScopeInJavaScript() { | 371 FX_BOOL CXFA_ScriptContext::IsStrictScopeInJavaScript() { |
| 370 return m_pDocument->HasFlag(XFA_DOCFLAG_StrictScoping); | 372 return m_pDocument->HasFlag(XFA_DOCFLAG_StrictScoping); |
| 371 } | 373 } |
| 372 XFA_SCRIPTLANGTYPE CXFA_ScriptContext::GetType() { | 374 XFA_SCRIPTLANGTYPE CXFA_ScriptContext::GetType() { |
| 373 return m_eScriptType; | 375 return m_eScriptType; |
| 374 } | 376 } |
| 375 void CXFA_ScriptContext::DefineJsContext() { | 377 void CXFA_ScriptContext::DefineJsContext() { |
| 376 m_JsGlobalClass.constructor = NULL; | 378 m_JsGlobalClass.constructor = NULL; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 CXFA_Node* pTextNode = pScriptNode->GetNodeItem(XFA_NODEITEM_FirstChild); | 450 CXFA_Node* pTextNode = pScriptNode->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 449 if (!pTextNode) | 451 if (!pTextNode) |
| 450 return FALSE; | 452 return FALSE; |
| 451 | 453 |
| 452 CFX_WideStringC wsScript; | 454 CFX_WideStringC wsScript; |
| 453 if (!pTextNode->TryCData(XFA_ATTRIBUTE_Value, wsScript)) | 455 if (!pTextNode->TryCData(XFA_ATTRIBUTE_Value, wsScript)) |
| 454 return FALSE; | 456 return FALSE; |
| 455 | 457 |
| 456 CFX_ByteString btScript = | 458 CFX_ByteString btScript = |
| 457 FX_UTF8Encode(wsScript.c_str(), wsScript.GetLength()); | 459 FX_UTF8Encode(wsScript.c_str(), wsScript.GetLength()); |
| 458 FXJSE_HVALUE hRetValue = FXJSE_Value_Create(m_pIsolate); | 460 CFXJSE_Value* hRetValue = FXJSE_Value_Create(m_pIsolate); |
| 459 CXFA_Node* pThisObject = pParent->GetNodeItem(XFA_NODEITEM_Parent); | 461 CXFA_Node* pThisObject = pParent->GetNodeItem(XFA_NODEITEM_Parent); |
| 460 CFXJSE_Context* pVariablesContext = | 462 CFXJSE_Context* pVariablesContext = |
| 461 CreateVariablesContext(pScriptNode, pThisObject); | 463 CreateVariablesContext(pScriptNode, pThisObject); |
| 462 CXFA_Object* pOriginalObject = m_pThisObject; | 464 CXFA_Object* pOriginalObject = m_pThisObject; |
| 463 m_pThisObject = pThisObject; | 465 m_pThisObject = pThisObject; |
| 464 FX_BOOL bRet = | 466 FX_BOOL bRet = |
| 465 FXJSE_ExecuteScript(pVariablesContext, btScript.c_str(), hRetValue); | 467 FXJSE_ExecuteScript(pVariablesContext, btScript.c_str(), hRetValue); |
| 466 m_pThisObject = pOriginalObject; | 468 m_pThisObject = pOriginalObject; |
| 467 FXJSE_Value_Release(hRetValue); | 469 FXJSE_Value_Release(hRetValue); |
| 468 return bRet; | 470 return bRet; |
| 469 } | 471 } |
| 470 | 472 |
| 471 FX_BOOL CXFA_ScriptContext::QueryVariableHValue( | 473 FX_BOOL CXFA_ScriptContext::QueryVariableValue( |
| 472 CXFA_Node* pScriptNode, | 474 CXFA_Node* pScriptNode, |
| 473 const CFX_ByteStringC& szPropName, | 475 const CFX_ByteStringC& szPropName, |
| 474 FXJSE_HVALUE hValue, | 476 CFXJSE_Value* pValue, |
| 475 FX_BOOL bGetter) { | 477 FX_BOOL bGetter) { |
| 476 if (!pScriptNode || pScriptNode->GetClassID() != XFA_ELEMENT_Script) | 478 if (!pScriptNode || pScriptNode->GetClassID() != XFA_ELEMENT_Script) |
| 477 return FALSE; | 479 return FALSE; |
| 478 | 480 |
| 479 CXFA_Node* variablesNode = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent); | 481 CXFA_Node* variablesNode = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 480 if (!variablesNode || variablesNode->GetClassID() != XFA_ELEMENT_Variables) | 482 if (!variablesNode || variablesNode->GetClassID() != XFA_ELEMENT_Variables) |
| 481 return FALSE; | 483 return FALSE; |
| 482 | 484 |
| 483 void* lpVariables = m_mapVariableToContext.GetValueAt(pScriptNode); | 485 void* lpVariables = m_mapVariableToContext.GetValueAt(pScriptNode); |
| 484 if (!lpVariables) | 486 if (!lpVariables) |
| 485 return FALSE; | 487 return FALSE; |
| 486 | 488 |
| 487 FX_BOOL bRes = FALSE; | 489 FX_BOOL bRes = FALSE; |
| 488 CFXJSE_Context* pVariableContext = static_cast<CFXJSE_Context*>(lpVariables); | 490 CFXJSE_Context* pVariableContext = static_cast<CFXJSE_Context*>(lpVariables); |
| 489 FXJSE_HVALUE hObject = FXJSE_Context_GetGlobalObject(pVariableContext); | 491 CFXJSE_Value* pObject = FXJSE_Context_GetGlobalObject(pVariableContext); |
| 490 FXJSE_HVALUE hVariableValue = FXJSE_Value_Create(m_pIsolate); | 492 CFXJSE_Value* hVariableValue = FXJSE_Value_Create(m_pIsolate); |
| 491 if (!bGetter) { | 493 if (!bGetter) { |
| 492 FXJSE_Value_SetObjectOwnProp(hObject, szPropName, hValue); | 494 FXJSE_Value_SetObjectOwnProp(pObject, szPropName, pValue); |
| 493 bRes = TRUE; | 495 bRes = TRUE; |
| 494 } else if (FXJSE_Value_ObjectHasOwnProp(hObject, szPropName, FALSE)) { | 496 } else if (FXJSE_Value_ObjectHasOwnProp(pObject, szPropName, FALSE)) { |
| 495 FXJSE_Value_GetObjectProp(hObject, szPropName, hVariableValue); | 497 FXJSE_Value_GetObjectProp(pObject, szPropName, hVariableValue); |
| 496 if (FXJSE_Value_IsFunction(hVariableValue)) | 498 if (FXJSE_Value_IsFunction(hVariableValue)) |
| 497 FXJSE_Value_SetFunctionBind(hValue, hVariableValue, hObject); | 499 FXJSE_Value_SetFunctionBind(pValue, hVariableValue, pObject); |
| 498 else if (bGetter) | 500 else if (bGetter) |
| 499 FXJSE_Value_Set(hValue, hVariableValue); | 501 FXJSE_Value_Set(pValue, hVariableValue); |
| 500 else | 502 else |
| 501 FXJSE_Value_Set(hVariableValue, hValue); | 503 FXJSE_Value_Set(hVariableValue, pValue); |
| 502 bRes = TRUE; | 504 bRes = TRUE; |
| 503 } | 505 } |
| 504 FXJSE_Value_Release(hVariableValue); | 506 FXJSE_Value_Release(hVariableValue); |
| 505 FXJSE_Value_Release(hObject); | 507 FXJSE_Value_Release(pObject); |
| 506 return bRes; | 508 return bRes; |
| 507 } | 509 } |
| 508 | 510 |
| 509 void CXFA_ScriptContext::ReleaseVariablesMap() { | 511 void CXFA_ScriptContext::ReleaseVariablesMap() { |
| 510 FX_POSITION ps = m_mapVariableToContext.GetStartPosition(); | 512 FX_POSITION ps = m_mapVariableToContext.GetStartPosition(); |
| 511 while (ps) { | 513 while (ps) { |
| 512 CXFA_Object* pScriptNode; | 514 CXFA_Object* pScriptNode; |
| 513 CFXJSE_Context* pVariableContext = nullptr; | 515 CFXJSE_Context* pVariableContext = nullptr; |
| 514 m_mapVariableToContext.GetNextAssoc(ps, pScriptNode, pVariableContext); | 516 m_mapVariableToContext.GetNextAssoc(ps, pScriptNode, pVariableContext); |
| 515 FXJSE_HVALUE hObject = FXJSE_Context_GetGlobalObject(pVariableContext); | 517 CFXJSE_Value* pObject = FXJSE_Context_GetGlobalObject(pVariableContext); |
| 516 delete static_cast<CXFA_ThisProxy*>(FXJSE_Value_ToObject(hObject, nullptr)); | 518 delete static_cast<CXFA_ThisProxy*>(FXJSE_Value_ToObject(pObject, nullptr)); |
| 517 FXJSE_Value_Release(hObject); | 519 FXJSE_Value_Release(pObject); |
| 518 FXJSE_Context_Release(pVariableContext); | 520 FXJSE_Context_Release(pVariableContext); |
| 519 } | 521 } |
| 520 m_mapVariableToContext.RemoveAll(); | 522 m_mapVariableToContext.RemoveAll(); |
| 521 } | 523 } |
| 522 | 524 |
| 523 void CXFA_ScriptContext::DefineJsClass() { | 525 void CXFA_ScriptContext::DefineJsClass() { |
| 524 m_JsNormalClass.constructor = NULL; | 526 m_JsNormalClass.constructor = NULL; |
| 525 m_JsNormalClass.name = "XFAObject"; | 527 m_JsNormalClass.name = "XFAObject"; |
| 526 m_JsNormalClass.propNum = 0; | 528 m_JsNormalClass.propNum = 0; |
| 527 m_JsNormalClass.properties = NULL; | 529 m_JsNormalClass.properties = NULL; |
| 528 m_JsNormalClass.methNum = 0; | 530 m_JsNormalClass.methNum = 0; |
| 529 m_JsNormalClass.methods = NULL; | 531 m_JsNormalClass.methods = NULL; |
| 530 m_JsNormalClass.dynPropGetter = CXFA_ScriptContext::NormalPropertyGetter; | 532 m_JsNormalClass.dynPropGetter = CXFA_ScriptContext::NormalPropertyGetter; |
| 531 m_JsNormalClass.dynPropSetter = CXFA_ScriptContext::NormalPropertySetter; | 533 m_JsNormalClass.dynPropSetter = CXFA_ScriptContext::NormalPropertySetter; |
| 532 m_JsNormalClass.dynPropTypeGetter = CXFA_ScriptContext::NormalPropTypeGetter; | 534 m_JsNormalClass.dynPropTypeGetter = CXFA_ScriptContext::NormalPropTypeGetter; |
| 533 m_JsNormalClass.dynPropDeleter = NULL; | 535 m_JsNormalClass.dynPropDeleter = NULL; |
| 534 m_JsNormalClass.dynMethodCall = CXFA_ScriptContext::NormalMethodCall; | 536 m_JsNormalClass.dynMethodCall = CXFA_ScriptContext::NormalMethodCall; |
| 535 m_pJsClass = FXJSE_DefineClass(m_pJsContext, &m_JsNormalClass); | 537 m_pJsClass = FXJSE_DefineClass(m_pJsContext, &m_JsNormalClass); |
| 536 } | 538 } |
| 537 void CXFA_ScriptContext::RemoveBuiltInObjs(CFXJSE_Context* pContext) const { | 539 void CXFA_ScriptContext::RemoveBuiltInObjs(CFXJSE_Context* pContext) const { |
| 538 static const CFX_ByteStringC OBJ_NAME[2] = {"Number", "Date"}; | 540 static const CFX_ByteStringC OBJ_NAME[2] = {"Number", "Date"}; |
| 539 FXJSE_HVALUE hObject = FXJSE_Context_GetGlobalObject(pContext); | 541 CFXJSE_Value* pObject = FXJSE_Context_GetGlobalObject(pContext); |
| 540 FXJSE_HVALUE hProp = FXJSE_Value_Create(m_pIsolate); | 542 CFXJSE_Value* hProp = FXJSE_Value_Create(m_pIsolate); |
| 541 for (int i = 0; i < 2; ++i) { | 543 for (int i = 0; i < 2; ++i) { |
| 542 if (FXJSE_Value_GetObjectProp(hObject, OBJ_NAME[i], hProp)) | 544 if (FXJSE_Value_GetObjectProp(pObject, OBJ_NAME[i], hProp)) |
| 543 FXJSE_Value_DeleteObjectProp(hObject, OBJ_NAME[i]); | 545 FXJSE_Value_DeleteObjectProp(pObject, OBJ_NAME[i]); |
| 544 } | 546 } |
| 545 FXJSE_Value_Release(hProp); | 547 FXJSE_Value_Release(hProp); |
| 546 FXJSE_Value_Release(hObject); | 548 FXJSE_Value_Release(pObject); |
| 547 } | 549 } |
| 548 CFXJSE_Class* CXFA_ScriptContext::GetJseNormalClass() { | 550 CFXJSE_Class* CXFA_ScriptContext::GetJseNormalClass() { |
| 549 return m_pJsClass; | 551 return m_pJsClass; |
| 550 } | 552 } |
| 551 int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode, | 553 int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode, |
| 552 const CFX_WideStringC& wsExpression, | 554 const CFX_WideStringC& wsExpression, |
| 553 XFA_RESOLVENODE_RS& resolveNodeRS, | 555 XFA_RESOLVENODE_RS& resolveNodeRS, |
| 554 uint32_t dwStyles, | 556 uint32_t dwStyles, |
| 555 CXFA_Node* bindNode) { | 557 CXFA_Node* bindNode) { |
| 556 if (wsExpression.IsEmpty()) { | 558 if (wsExpression.IsEmpty()) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 } | 638 } |
| 637 rndFind.m_CurNode = findNodes[i++]; | 639 rndFind.m_CurNode = findNodes[i++]; |
| 638 rndFind.m_nLevel = nLevel; | 640 rndFind.m_nLevel = nLevel; |
| 639 rndFind.m_dwFlag = XFA_RESOVENODE_RSTYPE_Nodes; | 641 rndFind.m_dwFlag = XFA_RESOVENODE_RSTYPE_Nodes; |
| 640 nRet = m_pResolveProcessor->XFA_ResolveNodes(rndFind); | 642 nRet = m_pResolveProcessor->XFA_ResolveNodes(rndFind); |
| 641 if (nRet < 1) { | 643 if (nRet < 1) { |
| 642 continue; | 644 continue; |
| 643 } | 645 } |
| 644 if (rndFind.m_dwFlag == XFA_RESOVENODE_RSTYPE_Attribute && | 646 if (rndFind.m_dwFlag == XFA_RESOVENODE_RSTYPE_Attribute && |
| 645 rndFind.m_pScriptAttribute && nStart < wsExpression.GetLength()) { | 647 rndFind.m_pScriptAttribute && nStart < wsExpression.GetLength()) { |
| 646 FXJSE_HVALUE hValue = FXJSE_Value_Create(m_pIsolate); | 648 CFXJSE_Value* pValue = FXJSE_Value_Create(m_pIsolate); |
| 647 (rndFind.m_Nodes[0]->*(rndFind.m_pScriptAttribute->lpfnCallback))( | 649 (rndFind.m_Nodes[0]->*(rndFind.m_pScriptAttribute->lpfnCallback))( |
| 648 hValue, FALSE, | 650 pValue, FALSE, |
| 649 (XFA_ATTRIBUTE)rndFind.m_pScriptAttribute->eAttribute); | 651 (XFA_ATTRIBUTE)rndFind.m_pScriptAttribute->eAttribute); |
| 650 rndFind.m_Nodes.SetAt(0, | 652 rndFind.m_Nodes.SetAt( |
| 651 (CXFA_Object*)FXJSE_Value_ToObject(hValue, NULL)); | 653 0, (CXFA_Object*)FXJSE_Value_ToObject(pValue, nullptr)); |
| 652 FXJSE_Value_Release(hValue); | 654 FXJSE_Value_Release(pValue); |
| 653 } | 655 } |
| 654 int32_t iSize = m_upObjectArray.GetSize(); | 656 int32_t iSize = m_upObjectArray.GetSize(); |
| 655 if (iSize) { | 657 if (iSize) { |
| 656 m_upObjectArray.RemoveAt(iSize - 1); | 658 m_upObjectArray.RemoveAt(iSize - 1); |
| 657 } | 659 } |
| 658 retNodes.Append(rndFind.m_Nodes); | 660 retNodes.Append(rndFind.m_Nodes); |
| 659 rndFind.m_Nodes.RemoveAll(); | 661 rndFind.m_Nodes.RemoveAll(); |
| 660 if (bDataBind) { | 662 if (bDataBind) { |
| 661 break; | 663 break; |
| 662 } | 664 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 XFA_RESOLVENODE_BindNew)) { | 707 XFA_RESOLVENODE_BindNew)) { |
| 706 m_pResolveProcessor->XFA_ResolveNode_SetResultCreateNode( | 708 m_pResolveProcessor->XFA_ResolveNode_SetResultCreateNode( |
| 707 resolveNodeRS, rndFind.m_wsCondition); | 709 resolveNodeRS, rndFind.m_wsCondition); |
| 708 if (!bNextCreate && (dwStyles & XFA_RESOLVENODE_CreateNode)) { | 710 if (!bNextCreate && (dwStyles & XFA_RESOLVENODE_CreateNode)) { |
| 709 resolveNodeRS.dwFlags = XFA_RESOVENODE_RSTYPE_ExistNodes; | 711 resolveNodeRS.dwFlags = XFA_RESOVENODE_RSTYPE_ExistNodes; |
| 710 } | 712 } |
| 711 return resolveNodeRS.nodes.GetSize(); | 713 return resolveNodeRS.nodes.GetSize(); |
| 712 } | 714 } |
| 713 return nNodes; | 715 return nNodes; |
| 714 } | 716 } |
| 715 FXJSE_HVALUE CXFA_ScriptContext::GetJSValueFromMap(CXFA_Object* pObject) { | 717 CFXJSE_Value* CXFA_ScriptContext::GetJSValueFromMap(CXFA_Object* pObject) { |
| 716 if (!pObject) { | 718 if (!pObject) |
| 717 return NULL; | 719 return nullptr; |
| 720 if (pObject->IsNode()) |
| 721 RunVariablesScript(pObject->AsNode()); |
| 722 |
| 723 void* pValue = m_mapXFAToValue.GetValueAt(pObject); |
| 724 if (!pValue) { |
| 725 CFXJSE_Value* jsValue = FXJSE_Value_Create(m_pIsolate); |
| 726 FXJSE_Value_SetObject(jsValue, pObject, m_pJsClass); |
| 727 m_mapXFAToValue.SetAt(pObject, jsValue); |
| 728 pValue = jsValue; |
| 718 } | 729 } |
| 719 if (pObject->IsNode()) { | 730 return static_cast<CFXJSE_Value*>(pValue); |
| 720 RunVariablesScript(pObject->AsNode()); | |
| 721 } | |
| 722 void* pValue = m_mapXFAToHValue.GetValueAt(pObject); | |
| 723 if (pValue == NULL) { | |
| 724 FXJSE_HVALUE jsHvalue = FXJSE_Value_Create(m_pIsolate); | |
| 725 FXJSE_Value_SetObject(jsHvalue, pObject, m_pJsClass); | |
| 726 m_mapXFAToHValue.SetAt(pObject, jsHvalue); | |
| 727 pValue = jsHvalue; | |
| 728 } | |
| 729 return (FXJSE_HVALUE)pValue; | |
| 730 } | 731 } |
| 731 int32_t CXFA_ScriptContext::GetIndexByName(CXFA_Node* refNode) { | 732 int32_t CXFA_ScriptContext::GetIndexByName(CXFA_Node* refNode) { |
| 732 CXFA_NodeHelper* lpNodeHelper = m_pResolveProcessor->GetNodeHelper(); | 733 CXFA_NodeHelper* lpNodeHelper = m_pResolveProcessor->GetNodeHelper(); |
| 733 return lpNodeHelper->XFA_GetIndex(refNode, XFA_LOGIC_Transparent, | 734 return lpNodeHelper->XFA_GetIndex(refNode, XFA_LOGIC_Transparent, |
| 734 lpNodeHelper->XFA_NodeIsProperty(refNode), | 735 lpNodeHelper->XFA_NodeIsProperty(refNode), |
| 735 FALSE); | 736 FALSE); |
| 736 } | 737 } |
| 737 int32_t CXFA_ScriptContext::GetIndexByClassName(CXFA_Node* refNode) { | 738 int32_t CXFA_ScriptContext::GetIndexByClassName(CXFA_Node* refNode) { |
| 738 CXFA_NodeHelper* lpNodeHelper = m_pResolveProcessor->GetNodeHelper(); | 739 CXFA_NodeHelper* lpNodeHelper = m_pResolveProcessor->GetNodeHelper(); |
| 739 return lpNodeHelper->XFA_GetIndex(refNode, XFA_LOGIC_Transparent, | 740 return lpNodeHelper->XFA_GetIndex(refNode, XFA_LOGIC_Transparent, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 758 } | 759 } |
| 759 } | 760 } |
| 760 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { | 761 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { |
| 761 if (!m_pScriptNodeArray) { | 762 if (!m_pScriptNodeArray) { |
| 762 return; | 763 return; |
| 763 } | 764 } |
| 764 if (m_pScriptNodeArray->Find(pNode) == -1) { | 765 if (m_pScriptNodeArray->Find(pNode) == -1) { |
| 765 m_pScriptNodeArray->Add(pNode); | 766 m_pScriptNodeArray->Add(pNode); |
| 766 } | 767 } |
| 767 } | 768 } |
| OLD | NEW |