Chromium Code Reviews| 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 = (CXFA_Object*)FXJSE_Value_ToObject(hObject); | 105 CXFA_Object* lpOrginalNode = (CXFA_Object*)FXJSE_Value_ToObject(pObject); |
| 105 CXFA_Document* pDoc = lpOrginalNode->GetDocument(); | 106 CXFA_Document* pDoc = lpOrginalNode->GetDocument(); |
| 106 CXFA_ScriptContext* lpScriptContext = | 107 CXFA_ScriptContext* lpScriptContext = |
| 107 (CXFA_ScriptContext*)pDoc->GetScriptContext(); | 108 (CXFA_ScriptContext*)pDoc->GetScriptContext(); |
| 108 CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(lpOrginalNode); | 109 CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(lpOrginalNode); |
| 109 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); | 110 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
| 110 uint32_t dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings | | 111 uint32_t dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings | |
| 111 XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | | 112 XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | |
| 112 XFA_RESOLVENODE_Attributes; | 113 XFA_RESOLVENODE_Attributes; |
| 113 CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject()); | 114 CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject()); |
| 114 if (lpOrginalNode->GetObjectType() == XFA_OBJECTTYPE_VariablesThis) { | 115 if (lpOrginalNode->GetObjectType() == XFA_OBJECTTYPE_VariablesThis) { |
| 115 pRefNode = ToNode(lpCurNode); | 116 pRefNode = ToNode(lpCurNode); |
| 116 } | 117 } |
| 117 if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringC(), hValue, | 118 if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringC(), pValue, |
| 118 dwFlag, TRUE)) { | 119 dwFlag, TRUE)) { |
| 119 return; | 120 return; |
| 120 } | 121 } |
| 121 if (lpOrginalNode->GetObjectType() == XFA_OBJECTTYPE_VariablesThis) { | 122 if (lpOrginalNode->GetObjectType() == XFA_OBJECTTYPE_VariablesThis) { |
| 122 if (FXJSE_Value_IsUndefined(hValue)) { | 123 if (FXJSE_Value_IsUndefined(pValue)) { |
| 123 FXJSE_Value_SetObjectOwnProp(hObject, szPropName, hValue); | 124 FXJSE_Value_SetObjectOwnProp(pObject, szPropName, pValue); |
| 124 return; | 125 return; |
| 125 } | 126 } |
| 126 } | 127 } |
| 127 CXFA_FFNotify* pNotify = pDoc->GetNotify(); | 128 CXFA_FFNotify* pNotify = pDoc->GetNotify(); |
| 128 if (!pNotify) { | 129 if (!pNotify) { |
| 129 return; | 130 return; |
| 130 } | 131 } |
| 131 pNotify->GetDocProvider()->SetGlobalProperty(pNotify->GetHDOC(), szPropName, | 132 pNotify->GetDocProvider()->SetGlobalProperty(pNotify->GetHDOC(), szPropName, |
| 132 hValue); | 133 pValue); |
| 133 } | 134 } |
| 134 FX_BOOL CXFA_ScriptContext::QueryNodeByFlag(CXFA_Node* refNode, | 135 FX_BOOL CXFA_ScriptContext::QueryNodeByFlag(CXFA_Node* refNode, |
| 135 const CFX_WideStringC& propname, | 136 const CFX_WideStringC& propname, |
| 136 FXJSE_HVALUE hValue, | 137 CFXJSE_Value* pValue, |
| 137 uint32_t dwFlag, | 138 uint32_t dwFlag, |
| 138 FX_BOOL bSetting) { | 139 FX_BOOL bSetting) { |
| 139 if (!refNode) | 140 if (!refNode) |
| 140 return false; | 141 return false; |
| 141 XFA_RESOLVENODE_RS resolveRs; | 142 XFA_RESOLVENODE_RS resolveRs; |
| 142 if (ResolveObjects(refNode, propname, resolveRs, dwFlag) <= 0) | 143 if (ResolveObjects(refNode, propname, resolveRs, dwFlag) <= 0) |
| 143 return false; | 144 return false; |
| 144 if (resolveRs.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { | 145 if (resolveRs.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { |
| 145 FXJSE_HVALUE pValue = GetJSValueFromMap(resolveRs.nodes[0]); | 146 CFXJSE_Value* pValue = GetJSValueFromMap(resolveRs.nodes[0]); |
| 146 FXJSE_Value_Set(hValue, pValue); | 147 FXJSE_Value_Set(pValue, pValue); |
| 147 return true; | 148 return true; |
| 148 } | 149 } |
| 149 if (resolveRs.dwFlags == XFA_RESOVENODE_RSTYPE_Attribute) { | 150 if (resolveRs.dwFlags == XFA_RESOVENODE_RSTYPE_Attribute) { |
| 150 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = resolveRs.pScriptAttribute; | 151 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = resolveRs.pScriptAttribute; |
| 151 if (lpAttributeInfo) { | 152 if (lpAttributeInfo) { |
| 152 (resolveRs.nodes[0]->*(lpAttributeInfo->lpfnCallback))( | 153 (resolveRs.nodes[0]->*(lpAttributeInfo->lpfnCallback))( |
| 153 hValue, bSetting, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); | 154 pValue, bSetting, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); |
| 154 } | 155 } |
| 155 } | 156 } |
| 156 return true; | 157 return true; |
| 157 } | 158 } |
| 158 void CXFA_ScriptContext::GlobalPropertyGetter(FXJSE_HOBJECT hObject, | 159 void CXFA_ScriptContext::GlobalPropertyGetter(CFXJSE_Value* pObject, |
| 159 const CFX_ByteStringC& szPropName, | 160 const CFX_ByteStringC& szPropName, |
| 160 FXJSE_HVALUE hValue) { | 161 CFXJSE_Value* pValue) { |
| 161 CXFA_Object* pOrginalObject = (CXFA_Object*)FXJSE_Value_ToObject(hObject); | 162 CXFA_Object* pOriginalObject = (CXFA_Object*)FXJSE_Value_ToObject(pObject); |
| 162 CXFA_Document* pDoc = pOrginalObject->GetDocument(); | 163 CXFA_Document* pDoc = pOriginalObject->GetDocument(); |
| 163 CXFA_ScriptContext* lpScriptContext = | 164 CXFA_ScriptContext* lpScriptContext = |
| 164 (CXFA_ScriptContext*)pDoc->GetScriptContext(); | 165 (CXFA_ScriptContext*)pDoc->GetScriptContext(); |
| 165 CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(pOrginalObject); | 166 CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(pOriginalObject); |
| 166 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); | 167 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
| 167 if (lpScriptContext->GetType() == XFA_SCRIPTLANGTYPE_Formcalc) { | 168 if (lpScriptContext->GetType() == XFA_SCRIPTLANGTYPE_Formcalc) { |
| 168 if (szPropName == FOXIT_XFA_FM2JS_FORMCALC_RUNTIME) { | 169 if (szPropName == FOXIT_XFA_FM2JS_FORMCALC_RUNTIME) { |
| 169 XFA_FM2JS_GlobalPropertyGetter(lpScriptContext->m_hFM2JSContext, hValue); | 170 XFA_FM2JS_GlobalPropertyGetter(lpScriptContext->m_hFM2JSContext, pValue); |
| 170 return; | 171 return; |
| 171 } | 172 } |
| 172 XFA_HashCode uHashCode = static_cast<XFA_HashCode>( | 173 XFA_HashCode uHashCode = static_cast<XFA_HashCode>( |
| 173 FX_HashCode_GetW(wsPropName.AsStringC(), false)); | 174 FX_HashCode_GetW(wsPropName.AsStringC(), false)); |
| 174 if (uHashCode != XFA_HASHCODE_Layout) { | 175 if (uHashCode != XFA_HASHCODE_Layout) { |
| 175 CXFA_Object* pObject = | 176 CXFA_Object* pObject = |
| 176 lpScriptContext->GetDocument()->GetXFAObject(uHashCode); | 177 lpScriptContext->GetDocument()->GetXFAObject(uHashCode); |
| 177 if (pObject) { | 178 if (pObject) { |
| 178 FXJSE_Value_Set(hValue, lpScriptContext->GetJSValueFromMap(pObject)); | 179 FXJSE_Value_Set(pValue, lpScriptContext->GetJSValueFromMap(pObject)); |
| 179 return; | 180 return; |
| 180 } | 181 } |
| 181 } | 182 } |
| 182 } | 183 } |
| 183 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | | 184 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | |
| 184 XFA_RESOLVENODE_Attributes; | 185 XFA_RESOLVENODE_Attributes; |
| 185 CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject()); | 186 CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject()); |
| 186 if (pOrginalObject->GetObjectType() == XFA_OBJECTTYPE_VariablesThis) { | 187 if (pOriginalObject->GetObjectType() == XFA_OBJECTTYPE_VariablesThis) { |
| 187 pRefNode = ToNode(lpCurNode); | 188 pRefNode = ToNode(lpCurNode); |
| 188 } | 189 } |
| 189 if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringC(), hValue, | 190 if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringC(), pValue, |
| 190 dwFlag, FALSE)) { | 191 dwFlag, FALSE)) { |
| 191 return; | 192 return; |
| 192 } | 193 } |
| 193 dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; | 194 dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; |
| 194 if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringC(), hValue, | 195 if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringC(), pValue, |
| 195 dwFlag, FALSE)) { | 196 dwFlag, FALSE)) { |
| 196 return; | 197 return; |
| 197 } | 198 } |
| 198 CXFA_Object* pScriptObject = | 199 CXFA_Object* pScriptObject = |
| 199 lpScriptContext->GetVariablesThis(pOrginalObject, TRUE); | 200 lpScriptContext->GetVariablesThis(pOriginalObject, TRUE); |
| 200 if (pScriptObject && | 201 if (pScriptObject && |
| 201 lpScriptContext->QueryVariableHValue(pScriptObject->AsNode(), szPropName, | 202 lpScriptContext->QueryVariableValue(pScriptObject->AsNode(), szPropName, |
| 202 hValue, TRUE)) { | 203 pValue, TRUE)) { |
| 203 return; | 204 return; |
| 204 } | 205 } |
| 205 CXFA_FFNotify* pNotify = pDoc->GetNotify(); | 206 CXFA_FFNotify* pNotify = pDoc->GetNotify(); |
| 206 if (!pNotify) { | 207 if (!pNotify) { |
| 207 return; | 208 return; |
| 208 } | 209 } |
| 209 pNotify->GetDocProvider()->GetGlobalProperty(pNotify->GetHDOC(), szPropName, | 210 pNotify->GetDocProvider()->GetGlobalProperty(pNotify->GetHDOC(), szPropName, |
| 210 hValue); | 211 pValue); |
| 211 } | 212 } |
| 212 void CXFA_ScriptContext::NormalPropertyGetter(FXJSE_HOBJECT hObject, | 213 void CXFA_ScriptContext::NormalPropertyGetter(CFXJSE_Value* pOriginalValue, |
| 213 const CFX_ByteStringC& szPropName, | 214 const CFX_ByteStringC& szPropName, |
| 214 FXJSE_HVALUE hValue) { | 215 CFXJSE_Value* pReturnValue) { |
| 215 CXFA_Object* pOrginalObject = (CXFA_Object*)FXJSE_Value_ToObject(hObject); | 216 CXFA_Object* pOriginalObject = |
| 216 if (pOrginalObject == NULL) { | 217 (CXFA_Object*)FXJSE_Value_ToObject(pOriginalValue); |
| 217 FXJSE_Value_SetUndefined(hValue); | 218 if (!pOriginalObject) { |
| 219 FXJSE_Value_SetUndefined(pReturnValue); | |
| 218 return; | 220 return; |
| 219 } | 221 } |
| 220 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); | 222 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
| 221 CXFA_ScriptContext* lpScriptContext = | 223 CXFA_ScriptContext* lpScriptContext = |
| 222 (CXFA_ScriptContext*)pOrginalObject->GetDocument()->GetScriptContext(); | 224 (CXFA_ScriptContext*)pOriginalObject->GetDocument()->GetScriptContext(); |
|
Tom Sepez
2016/05/26 15:51:57
nice.
| |
| 223 CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOrginalObject); | 225 CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOriginalObject); |
| 224 if (wsPropName == FX_WSTRC(L"xfa")) { | 226 if (wsPropName == FX_WSTRC(L"xfa")) { |
| 225 FXJSE_HVALUE pValue = lpScriptContext->GetJSValueFromMap( | 227 CFXJSE_Value* pValue = lpScriptContext->GetJSValueFromMap( |
| 226 lpScriptContext->GetDocument()->GetRoot()); | 228 lpScriptContext->GetDocument()->GetRoot()); |
| 227 FXJSE_Value_Set(hValue, pValue); | 229 FXJSE_Value_Set(pReturnValue, pValue); |
| 228 return; | 230 return; |
| 229 } | 231 } |
| 230 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | | 232 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | |
| 231 XFA_RESOLVENODE_Attributes; | 233 XFA_RESOLVENODE_Attributes; |
| 232 FX_BOOL bRet = lpScriptContext->QueryNodeByFlag( | 234 FX_BOOL bRet = lpScriptContext->QueryNodeByFlag( |
| 233 ToNode(pObject), wsPropName.AsStringC(), hValue, dwFlag, FALSE); | 235 ToNode(pObject), wsPropName.AsStringC(), pReturnValue, dwFlag, FALSE); |
| 234 if (bRet) { | 236 if (bRet) { |
| 235 return; | 237 return; |
| 236 } | 238 } |
| 237 if (pObject == lpScriptContext->GetThisObject() || | 239 if (pObject == lpScriptContext->GetThisObject() || |
| 238 (lpScriptContext->GetType() == XFA_SCRIPTLANGTYPE_Javascript && | 240 (lpScriptContext->GetType() == XFA_SCRIPTLANGTYPE_Javascript && |
| 239 !lpScriptContext->IsStrictScopeInJavaScript())) { | 241 !lpScriptContext->IsStrictScopeInJavaScript())) { |
| 240 dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; | 242 dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; |
| 241 bRet = lpScriptContext->QueryNodeByFlag( | 243 bRet = lpScriptContext->QueryNodeByFlag( |
| 242 ToNode(pObject), wsPropName.AsStringC(), hValue, dwFlag, FALSE); | 244 ToNode(pObject), wsPropName.AsStringC(), pReturnValue, dwFlag, FALSE); |
| 243 } | 245 } |
| 244 if (bRet) { | 246 if (bRet) { |
| 245 return; | 247 return; |
| 246 } | 248 } |
| 247 CXFA_Object* pScriptObject = | 249 CXFA_Object* pScriptObject = |
| 248 lpScriptContext->GetVariablesThis(pOrginalObject, TRUE); | 250 lpScriptContext->GetVariablesThis(pOriginalObject, TRUE); |
| 249 if (pScriptObject) { | 251 if (pScriptObject) { |
| 250 bRet = lpScriptContext->QueryVariableHValue(ToNode(pScriptObject), | 252 bRet = lpScriptContext->QueryVariableValue(ToNode(pScriptObject), |
| 251 szPropName, hValue, TRUE); | 253 szPropName, pReturnValue, TRUE); |
| 252 } | 254 } |
| 253 if (!bRet) { | 255 if (!bRet) { |
| 254 FXJSE_Value_SetUndefined(hValue); | 256 FXJSE_Value_SetUndefined(pReturnValue); |
| 255 } | 257 } |
| 256 } | 258 } |
| 257 void CXFA_ScriptContext::NormalPropertySetter(FXJSE_HOBJECT hObject, | 259 void CXFA_ScriptContext::NormalPropertySetter(CFXJSE_Value* pOriginalValue, |
| 258 const CFX_ByteStringC& szPropName, | 260 const CFX_ByteStringC& szPropName, |
| 259 FXJSE_HVALUE hValue) { | 261 CFXJSE_Value* pReturnValue) { |
| 260 CXFA_Object* pOrginalObject = (CXFA_Object*)FXJSE_Value_ToObject(hObject); | 262 CXFA_Object* pOriginalObject = |
| 261 if (pOrginalObject == NULL) { | 263 (CXFA_Object*)FXJSE_Value_ToObject(pOriginalValue); |
| 264 if (!pOriginalObject) | |
| 262 return; | 265 return; |
| 263 } | 266 |
| 264 CXFA_ScriptContext* lpScriptContext = | 267 CXFA_ScriptContext* lpScriptContext = |
| 265 (CXFA_ScriptContext*)pOrginalObject->GetDocument()->GetScriptContext(); | 268 (CXFA_ScriptContext*)pOriginalObject->GetDocument()->GetScriptContext(); |
| 266 CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOrginalObject); | 269 CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOriginalObject); |
| 267 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); | 270 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
| 268 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = XFA_GetScriptAttributeByName( | 271 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = XFA_GetScriptAttributeByName( |
| 269 pObject->GetClassID(), wsPropName.AsStringC()); | 272 pObject->GetClassID(), wsPropName.AsStringC()); |
| 270 if (lpAttributeInfo) { | 273 if (lpAttributeInfo) { |
| 271 (pObject->*(lpAttributeInfo->lpfnCallback))( | 274 (pObject->*(lpAttributeInfo->lpfnCallback))( |
| 272 hValue, TRUE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); | 275 pReturnValue, TRUE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); |
| 273 } else { | 276 } else { |
| 274 if (pObject->IsNode()) { | 277 if (pObject->IsNode()) { |
| 275 if (wsPropName.GetAt(0) == '#') { | 278 if (wsPropName.GetAt(0) == '#') { |
| 276 wsPropName = wsPropName.Right(wsPropName.GetLength() - 1); | 279 wsPropName = wsPropName.Right(wsPropName.GetLength() - 1); |
| 277 } | 280 } |
| 278 CXFA_Node* pNode = ToNode(pObject); | 281 CXFA_Node* pNode = ToNode(pObject); |
| 279 CXFA_Node* pPropOrChild = NULL; | 282 CXFA_Node* pPropOrChild = NULL; |
| 280 const XFA_ELEMENTINFO* lpElementInfo = | 283 const XFA_ELEMENTINFO* lpElementInfo = |
| 281 XFA_GetElementByName(wsPropName.AsStringC()); | 284 XFA_GetElementByName(wsPropName.AsStringC()); |
| 282 if (lpElementInfo) { | 285 if (lpElementInfo) { |
| 283 pPropOrChild = pNode->GetProperty(0, lpElementInfo->eName); | 286 pPropOrChild = pNode->GetProperty(0, lpElementInfo->eName); |
| 284 } else { | 287 } else { |
| 285 pPropOrChild = pNode->GetFirstChildByName(wsPropName.AsStringC()); | 288 pPropOrChild = pNode->GetFirstChildByName(wsPropName.AsStringC()); |
| 286 } | 289 } |
| 287 if (pPropOrChild) { | 290 if (pPropOrChild) { |
| 288 CFX_WideString wsDefaultName(L"{default}"); | 291 CFX_WideString wsDefaultName(L"{default}"); |
| 289 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = | 292 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = |
| 290 XFA_GetScriptAttributeByName(pPropOrChild->GetClassID(), | 293 XFA_GetScriptAttributeByName(pPropOrChild->GetClassID(), |
| 291 wsDefaultName.AsStringC()); | 294 wsDefaultName.AsStringC()); |
| 292 if (lpAttributeInfo) { | 295 if (lpAttributeInfo) { |
| 293 (pPropOrChild->*(lpAttributeInfo->lpfnCallback))( | 296 (pPropOrChild->*(lpAttributeInfo->lpfnCallback))( |
| 294 hValue, TRUE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); | 297 pReturnValue, TRUE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); |
| 295 return; | 298 return; |
| 296 } | 299 } |
| 297 } | 300 } |
| 298 } | 301 } |
| 299 CXFA_Object* pScriptObject = | 302 CXFA_Object* pScriptObject = |
| 300 lpScriptContext->GetVariablesThis(pOrginalObject, TRUE); | 303 lpScriptContext->GetVariablesThis(pOriginalObject, TRUE); |
| 301 if (pScriptObject) { | 304 if (pScriptObject) { |
| 302 lpScriptContext->QueryVariableHValue(ToNode(pScriptObject), szPropName, | 305 lpScriptContext->QueryVariableValue(ToNode(pScriptObject), szPropName, |
| 303 hValue, FALSE); | 306 pReturnValue, FALSE); |
| 304 } | 307 } |
| 305 } | 308 } |
| 306 } | 309 } |
| 307 int32_t CXFA_ScriptContext::NormalPropTypeGetter( | 310 int32_t CXFA_ScriptContext::NormalPropTypeGetter( |
| 308 FXJSE_HOBJECT hObject, | 311 CFXJSE_Value* pOriginalValue, |
| 309 const CFX_ByteStringC& szPropName, | 312 const CFX_ByteStringC& szPropName, |
| 310 FX_BOOL bQueryIn) { | 313 FX_BOOL bQueryIn) { |
| 311 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(hObject); | 314 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(pOriginalValue); |
| 312 if (pObject == NULL) { | 315 if (!pObject) |
| 313 return FXJSE_ClassPropType_None; | 316 return FXJSE_ClassPropType_None; |
| 314 } | 317 |
| 315 CXFA_ScriptContext* lpScriptContext = | 318 CXFA_ScriptContext* lpScriptContext = |
| 316 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); | 319 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); |
| 317 pObject = lpScriptContext->GetVariablesThis(pObject); | 320 pObject = lpScriptContext->GetVariablesThis(pObject); |
| 318 XFA_ELEMENT objElement = pObject->GetClassID(); | 321 XFA_ELEMENT objElement = pObject->GetClassID(); |
| 319 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); | 322 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
| 320 if (XFA_GetMethodByName(objElement, wsPropName.AsStringC())) { | 323 if (XFA_GetMethodByName(objElement, wsPropName.AsStringC())) { |
| 321 return FXJSE_ClassPropType_Method; | 324 return FXJSE_ClassPropType_Method; |
| 322 } | 325 } |
| 323 if (bQueryIn && | 326 if (bQueryIn && |
| 324 !XFA_GetScriptAttributeByName(objElement, wsPropName.AsStringC())) { | 327 !XFA_GetScriptAttributeByName(objElement, wsPropName.AsStringC())) { |
| 325 return FXJSE_ClassPropType_None; | 328 return FXJSE_ClassPropType_None; |
| 326 } | 329 } |
| 327 return FXJSE_ClassPropType_Property; | 330 return FXJSE_ClassPropType_Property; |
| 328 } | 331 } |
| 329 int32_t CXFA_ScriptContext::GlobalPropTypeGetter( | 332 int32_t CXFA_ScriptContext::GlobalPropTypeGetter( |
| 330 FXJSE_HOBJECT hObject, | 333 CFXJSE_Value* pOriginalValue, |
| 331 const CFX_ByteStringC& szPropName, | 334 const CFX_ByteStringC& szPropName, |
| 332 FX_BOOL bQueryIn) { | 335 FX_BOOL bQueryIn) { |
| 333 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(hObject); | 336 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(pOriginalValue); |
| 334 if (pObject == NULL) { | 337 if (!pObject) |
| 335 return FXJSE_ClassPropType_None; | 338 return FXJSE_ClassPropType_None; |
| 336 } | 339 |
| 337 CXFA_ScriptContext* lpScriptContext = | 340 CXFA_ScriptContext* lpScriptContext = |
| 338 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); | 341 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); |
| 339 pObject = lpScriptContext->GetVariablesThis(pObject); | 342 pObject = lpScriptContext->GetVariablesThis(pObject); |
| 340 XFA_ELEMENT objElement = pObject->GetClassID(); | 343 XFA_ELEMENT objElement = pObject->GetClassID(); |
| 341 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); | 344 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
| 342 if (XFA_GetMethodByName(objElement, wsPropName.AsStringC())) { | 345 if (XFA_GetMethodByName(objElement, wsPropName.AsStringC())) { |
| 343 return FXJSE_ClassPropType_Method; | 346 return FXJSE_ClassPropType_Method; |
| 344 } | 347 } |
| 345 return FXJSE_ClassPropType_Property; | 348 return FXJSE_ClassPropType_Property; |
| 346 } | 349 } |
| 347 void CXFA_ScriptContext::NormalMethodCall(FXJSE_HOBJECT hThis, | 350 void CXFA_ScriptContext::NormalMethodCall(CFXJSE_Value* pThis, |
| 348 const CFX_ByteStringC& szFuncName, | 351 const CFX_ByteStringC& szFuncName, |
| 349 CFXJSE_Arguments& args) { | 352 CFXJSE_Arguments& args) { |
| 350 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(hThis); | 353 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(pThis); |
| 351 if (pObject == NULL) { | 354 if (!pObject) |
| 352 return; | 355 return; |
| 353 } | 356 |
| 354 CXFA_ScriptContext* lpScriptContext = | 357 CXFA_ScriptContext* lpScriptContext = |
| 355 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); | 358 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); |
| 356 pObject = lpScriptContext->GetVariablesThis(pObject); | 359 pObject = lpScriptContext->GetVariablesThis(pObject); |
| 357 CFX_WideString wsFunName = CFX_WideString::FromUTF8(szFuncName); | 360 CFX_WideString wsFunName = CFX_WideString::FromUTF8(szFuncName); |
| 358 const XFA_METHODINFO* lpMethodInfo = | 361 const XFA_METHODINFO* lpMethodInfo = |
| 359 XFA_GetMethodByName(pObject->GetClassID(), wsFunName.AsStringC()); | 362 XFA_GetMethodByName(pObject->GetClassID(), wsFunName.AsStringC()); |
| 360 if (NULL == lpMethodInfo) { | 363 if (!lpMethodInfo) |
| 361 return; | 364 return; |
| 362 } | 365 |
| 363 (pObject->*(lpMethodInfo->lpfnCallback))(&args); | 366 (pObject->*(lpMethodInfo->lpfnCallback))(&args); |
| 364 } | 367 } |
| 365 FX_BOOL CXFA_ScriptContext::IsStrictScopeInJavaScript() { | 368 FX_BOOL CXFA_ScriptContext::IsStrictScopeInJavaScript() { |
| 366 return m_pDocument->HasFlag(XFA_DOCFLAG_StrictScoping); | 369 return m_pDocument->HasFlag(XFA_DOCFLAG_StrictScoping); |
| 367 } | 370 } |
| 368 XFA_SCRIPTLANGTYPE CXFA_ScriptContext::GetType() { | 371 XFA_SCRIPTLANGTYPE CXFA_ScriptContext::GetType() { |
| 369 return m_eScriptType; | 372 return m_eScriptType; |
| 370 } | 373 } |
| 371 void CXFA_ScriptContext::DefineJsContext() { | 374 void CXFA_ScriptContext::DefineJsContext() { |
| 372 m_JsGlobalClass.constructor = NULL; | 375 m_JsGlobalClass.constructor = NULL; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 444 CXFA_Node* pTextNode = pScriptNode->GetNodeItem(XFA_NODEITEM_FirstChild); | 447 CXFA_Node* pTextNode = pScriptNode->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 445 if (!pTextNode) | 448 if (!pTextNode) |
| 446 return FALSE; | 449 return FALSE; |
| 447 | 450 |
| 448 CFX_WideStringC wsScript; | 451 CFX_WideStringC wsScript; |
| 449 if (!pTextNode->TryCData(XFA_ATTRIBUTE_Value, wsScript)) | 452 if (!pTextNode->TryCData(XFA_ATTRIBUTE_Value, wsScript)) |
| 450 return FALSE; | 453 return FALSE; |
| 451 | 454 |
| 452 CFX_ByteString btScript = | 455 CFX_ByteString btScript = |
| 453 FX_UTF8Encode(wsScript.c_str(), wsScript.GetLength()); | 456 FX_UTF8Encode(wsScript.c_str(), wsScript.GetLength()); |
| 454 FXJSE_HVALUE hRetValue = FXJSE_Value_Create(m_pIsolate); | 457 CFXJSE_Value* hRetValue = FXJSE_Value_Create(m_pIsolate); |
| 455 CXFA_Node* pThisObject = pParent->GetNodeItem(XFA_NODEITEM_Parent); | 458 CXFA_Node* pThisObject = pParent->GetNodeItem(XFA_NODEITEM_Parent); |
| 456 CFXJSE_Context* pVariablesContext = | 459 CFXJSE_Context* pVariablesContext = |
| 457 CreateVariablesContext(pScriptNode, pThisObject); | 460 CreateVariablesContext(pScriptNode, pThisObject); |
| 458 CXFA_Object* pOriginalObject = m_pThisObject; | 461 CXFA_Object* pOriginalObject = m_pThisObject; |
| 459 m_pThisObject = pThisObject; | 462 m_pThisObject = pThisObject; |
| 460 FX_BOOL bRet = | 463 FX_BOOL bRet = |
| 461 FXJSE_ExecuteScript(pVariablesContext, btScript.c_str(), hRetValue); | 464 FXJSE_ExecuteScript(pVariablesContext, btScript.c_str(), hRetValue); |
| 462 m_pThisObject = pOriginalObject; | 465 m_pThisObject = pOriginalObject; |
| 463 FXJSE_Value_Release(hRetValue); | 466 FXJSE_Value_Release(hRetValue); |
| 464 return bRet; | 467 return bRet; |
| 465 } | 468 } |
| 466 | 469 |
| 467 FX_BOOL CXFA_ScriptContext::QueryVariableHValue( | 470 FX_BOOL CXFA_ScriptContext::QueryVariableValue( |
| 468 CXFA_Node* pScriptNode, | 471 CXFA_Node* pScriptNode, |
| 469 const CFX_ByteStringC& szPropName, | 472 const CFX_ByteStringC& szPropName, |
| 470 FXJSE_HVALUE hValue, | 473 CFXJSE_Value* pValue, |
| 471 FX_BOOL bGetter) { | 474 FX_BOOL bGetter) { |
| 472 if (!pScriptNode || pScriptNode->GetClassID() != XFA_ELEMENT_Script) | 475 if (!pScriptNode || pScriptNode->GetClassID() != XFA_ELEMENT_Script) |
| 473 return FALSE; | 476 return FALSE; |
| 474 | 477 |
| 475 CXFA_Node* variablesNode = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent); | 478 CXFA_Node* variablesNode = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 476 if (!variablesNode || variablesNode->GetClassID() != XFA_ELEMENT_Variables) | 479 if (!variablesNode || variablesNode->GetClassID() != XFA_ELEMENT_Variables) |
| 477 return FALSE; | 480 return FALSE; |
| 478 | 481 |
| 479 void* lpVariables = m_mapVariableToContext.GetValueAt(pScriptNode); | 482 void* lpVariables = m_mapVariableToContext.GetValueAt(pScriptNode); |
| 480 if (!lpVariables) | 483 if (!lpVariables) |
| 481 return FALSE; | 484 return FALSE; |
| 482 | 485 |
| 483 FX_BOOL bRes = FALSE; | 486 FX_BOOL bRes = FALSE; |
| 484 CFXJSE_Context* pVariableContext = static_cast<CFXJSE_Context*>(lpVariables); | 487 CFXJSE_Context* pVariableContext = static_cast<CFXJSE_Context*>(lpVariables); |
| 485 FXJSE_HVALUE hObject = FXJSE_Context_GetGlobalObject(pVariableContext); | 488 CFXJSE_Value* pObject = FXJSE_Context_GetGlobalObject(pVariableContext); |
| 486 FXJSE_HVALUE hVariableValue = FXJSE_Value_Create(m_pIsolate); | 489 CFXJSE_Value* hVariableValue = FXJSE_Value_Create(m_pIsolate); |
| 487 if (!bGetter) { | 490 if (!bGetter) { |
| 488 FXJSE_Value_SetObjectOwnProp(hObject, szPropName, hValue); | 491 FXJSE_Value_SetObjectOwnProp(pObject, szPropName, pValue); |
| 489 bRes = TRUE; | 492 bRes = TRUE; |
| 490 } else if (FXJSE_Value_ObjectHasOwnProp(hObject, szPropName, FALSE)) { | 493 } else if (FXJSE_Value_ObjectHasOwnProp(pObject, szPropName, FALSE)) { |
| 491 FXJSE_Value_GetObjectProp(hObject, szPropName, hVariableValue); | 494 FXJSE_Value_GetObjectProp(pObject, szPropName, hVariableValue); |
| 492 if (FXJSE_Value_IsFunction(hVariableValue)) | 495 if (FXJSE_Value_IsFunction(hVariableValue)) |
| 493 FXJSE_Value_SetFunctionBind(hValue, hVariableValue, hObject); | 496 FXJSE_Value_SetFunctionBind(pValue, hVariableValue, pObject); |
| 494 else if (bGetter) | 497 else if (bGetter) |
| 495 FXJSE_Value_Set(hValue, hVariableValue); | 498 FXJSE_Value_Set(pValue, hVariableValue); |
| 496 else | 499 else |
| 497 FXJSE_Value_Set(hVariableValue, hValue); | 500 FXJSE_Value_Set(hVariableValue, pValue); |
| 498 bRes = TRUE; | 501 bRes = TRUE; |
| 499 } | 502 } |
| 500 FXJSE_Value_Release(hVariableValue); | 503 FXJSE_Value_Release(hVariableValue); |
| 501 FXJSE_Value_Release(hObject); | 504 FXJSE_Value_Release(pObject); |
| 502 return bRes; | 505 return bRes; |
| 503 } | 506 } |
| 504 | 507 |
| 505 void CXFA_ScriptContext::ReleaseVariablesMap() { | 508 void CXFA_ScriptContext::ReleaseVariablesMap() { |
| 506 FX_POSITION ps = m_mapVariableToContext.GetStartPosition(); | 509 FX_POSITION ps = m_mapVariableToContext.GetStartPosition(); |
| 507 while (ps) { | 510 while (ps) { |
| 508 CXFA_Object* pScriptNode; | 511 CXFA_Object* pScriptNode; |
| 509 CFXJSE_Context* pVariableContext = nullptr; | 512 CFXJSE_Context* pVariableContext = nullptr; |
| 510 m_mapVariableToContext.GetNextAssoc(ps, pScriptNode, pVariableContext); | 513 m_mapVariableToContext.GetNextAssoc(ps, pScriptNode, pVariableContext); |
| 511 FXJSE_HVALUE hObject = FXJSE_Context_GetGlobalObject(pVariableContext); | 514 CFXJSE_Value* pObject = FXJSE_Context_GetGlobalObject(pVariableContext); |
| 512 delete static_cast<CXFA_ThisProxy*>(FXJSE_Value_ToObject(hObject)); | 515 delete static_cast<CXFA_ThisProxy*>(FXJSE_Value_ToObject(pObject)); |
| 513 FXJSE_Value_Release(hObject); | 516 FXJSE_Value_Release(pObject); |
| 514 FXJSE_Context_Release(pVariableContext); | 517 FXJSE_Context_Release(pVariableContext); |
| 515 } | 518 } |
| 516 m_mapVariableToContext.RemoveAll(); | 519 m_mapVariableToContext.RemoveAll(); |
| 517 } | 520 } |
| 518 | 521 |
| 519 void CXFA_ScriptContext::DefineJsClass() { | 522 void CXFA_ScriptContext::DefineJsClass() { |
| 520 m_JsNormalClass.constructor = NULL; | 523 m_JsNormalClass.constructor = NULL; |
| 521 m_JsNormalClass.name = "XFAObject"; | 524 m_JsNormalClass.name = "XFAObject"; |
| 522 m_JsNormalClass.propNum = 0; | 525 m_JsNormalClass.propNum = 0; |
| 523 m_JsNormalClass.properties = NULL; | 526 m_JsNormalClass.properties = NULL; |
| 524 m_JsNormalClass.methNum = 0; | 527 m_JsNormalClass.methNum = 0; |
| 525 m_JsNormalClass.methods = NULL; | 528 m_JsNormalClass.methods = NULL; |
| 526 m_JsNormalClass.dynPropGetter = CXFA_ScriptContext::NormalPropertyGetter; | 529 m_JsNormalClass.dynPropGetter = CXFA_ScriptContext::NormalPropertyGetter; |
| 527 m_JsNormalClass.dynPropSetter = CXFA_ScriptContext::NormalPropertySetter; | 530 m_JsNormalClass.dynPropSetter = CXFA_ScriptContext::NormalPropertySetter; |
| 528 m_JsNormalClass.dynPropTypeGetter = CXFA_ScriptContext::NormalPropTypeGetter; | 531 m_JsNormalClass.dynPropTypeGetter = CXFA_ScriptContext::NormalPropTypeGetter; |
| 529 m_JsNormalClass.dynPropDeleter = NULL; | 532 m_JsNormalClass.dynPropDeleter = NULL; |
| 530 m_JsNormalClass.dynMethodCall = CXFA_ScriptContext::NormalMethodCall; | 533 m_JsNormalClass.dynMethodCall = CXFA_ScriptContext::NormalMethodCall; |
| 531 m_pJsClass = FXJSE_DefineClass(m_pJsContext, &m_JsNormalClass); | 534 m_pJsClass = FXJSE_DefineClass(m_pJsContext, &m_JsNormalClass); |
| 532 } | 535 } |
| 533 void CXFA_ScriptContext::RemoveBuiltInObjs(CFXJSE_Context* pContext) const { | 536 void CXFA_ScriptContext::RemoveBuiltInObjs(CFXJSE_Context* pContext) const { |
| 534 static const CFX_ByteStringC OBJ_NAME[2] = {"Number", "Date"}; | 537 static const CFX_ByteStringC OBJ_NAME[2] = {"Number", "Date"}; |
| 535 FXJSE_HVALUE hObject = FXJSE_Context_GetGlobalObject(pContext); | 538 CFXJSE_Value* pObject = FXJSE_Context_GetGlobalObject(pContext); |
| 536 FXJSE_HVALUE hProp = FXJSE_Value_Create(m_pIsolate); | 539 CFXJSE_Value* hProp = FXJSE_Value_Create(m_pIsolate); |
| 537 for (int i = 0; i < 2; ++i) { | 540 for (int i = 0; i < 2; ++i) { |
| 538 if (FXJSE_Value_GetObjectProp(hObject, OBJ_NAME[i], hProp)) | 541 if (FXJSE_Value_GetObjectProp(pObject, OBJ_NAME[i], hProp)) |
| 539 FXJSE_Value_DeleteObjectProp(hObject, OBJ_NAME[i]); | 542 FXJSE_Value_DeleteObjectProp(pObject, OBJ_NAME[i]); |
| 540 } | 543 } |
| 541 FXJSE_Value_Release(hProp); | 544 FXJSE_Value_Release(hProp); |
| 542 FXJSE_Value_Release(hObject); | 545 FXJSE_Value_Release(pObject); |
| 543 } | 546 } |
| 544 CFXJSE_Class* CXFA_ScriptContext::GetJseNormalClass() { | 547 CFXJSE_Class* CXFA_ScriptContext::GetJseNormalClass() { |
| 545 return m_pJsClass; | 548 return m_pJsClass; |
| 546 } | 549 } |
| 547 int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode, | 550 int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode, |
| 548 const CFX_WideStringC& wsExpression, | 551 const CFX_WideStringC& wsExpression, |
| 549 XFA_RESOLVENODE_RS& resolveNodeRS, | 552 XFA_RESOLVENODE_RS& resolveNodeRS, |
| 550 uint32_t dwStyles, | 553 uint32_t dwStyles, |
| 551 CXFA_Node* bindNode) { | 554 CXFA_Node* bindNode) { |
| 552 if (wsExpression.IsEmpty()) { | 555 if (wsExpression.IsEmpty()) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 632 } | 635 } |
| 633 rndFind.m_CurNode = findNodes[i++]; | 636 rndFind.m_CurNode = findNodes[i++]; |
| 634 rndFind.m_nLevel = nLevel; | 637 rndFind.m_nLevel = nLevel; |
| 635 rndFind.m_dwFlag = XFA_RESOVENODE_RSTYPE_Nodes; | 638 rndFind.m_dwFlag = XFA_RESOVENODE_RSTYPE_Nodes; |
| 636 nRet = m_pResolveProcessor->XFA_ResolveNodes(rndFind); | 639 nRet = m_pResolveProcessor->XFA_ResolveNodes(rndFind); |
| 637 if (nRet < 1) { | 640 if (nRet < 1) { |
| 638 continue; | 641 continue; |
| 639 } | 642 } |
| 640 if (rndFind.m_dwFlag == XFA_RESOVENODE_RSTYPE_Attribute && | 643 if (rndFind.m_dwFlag == XFA_RESOVENODE_RSTYPE_Attribute && |
| 641 rndFind.m_pScriptAttribute && nStart < wsExpression.GetLength()) { | 644 rndFind.m_pScriptAttribute && nStart < wsExpression.GetLength()) { |
| 642 FXJSE_HVALUE hValue = FXJSE_Value_Create(m_pIsolate); | 645 CFXJSE_Value* pValue = FXJSE_Value_Create(m_pIsolate); |
| 643 (rndFind.m_Nodes[0]->*(rndFind.m_pScriptAttribute->lpfnCallback))( | 646 (rndFind.m_Nodes[0]->*(rndFind.m_pScriptAttribute->lpfnCallback))( |
| 644 hValue, FALSE, | 647 pValue, FALSE, |
| 645 (XFA_ATTRIBUTE)rndFind.m_pScriptAttribute->eAttribute); | 648 (XFA_ATTRIBUTE)rndFind.m_pScriptAttribute->eAttribute); |
| 646 rndFind.m_Nodes.SetAt(0, (CXFA_Object*)FXJSE_Value_ToObject(hValue)); | 649 rndFind.m_Nodes.SetAt(0, (CXFA_Object*)FXJSE_Value_ToObject(pValue)); |
| 647 FXJSE_Value_Release(hValue); | 650 FXJSE_Value_Release(pValue); |
| 648 } | 651 } |
| 649 int32_t iSize = m_upObjectArray.GetSize(); | 652 int32_t iSize = m_upObjectArray.GetSize(); |
| 650 if (iSize) { | 653 if (iSize) { |
| 651 m_upObjectArray.RemoveAt(iSize - 1); | 654 m_upObjectArray.RemoveAt(iSize - 1); |
| 652 } | 655 } |
| 653 retNodes.Append(rndFind.m_Nodes); | 656 retNodes.Append(rndFind.m_Nodes); |
| 654 rndFind.m_Nodes.RemoveAll(); | 657 rndFind.m_Nodes.RemoveAll(); |
| 655 if (bDataBind) { | 658 if (bDataBind) { |
| 656 break; | 659 break; |
| 657 } | 660 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 700 XFA_RESOLVENODE_BindNew)) { | 703 XFA_RESOLVENODE_BindNew)) { |
| 701 m_pResolveProcessor->XFA_ResolveNode_SetResultCreateNode( | 704 m_pResolveProcessor->XFA_ResolveNode_SetResultCreateNode( |
| 702 resolveNodeRS, rndFind.m_wsCondition); | 705 resolveNodeRS, rndFind.m_wsCondition); |
| 703 if (!bNextCreate && (dwStyles & XFA_RESOLVENODE_CreateNode)) { | 706 if (!bNextCreate && (dwStyles & XFA_RESOLVENODE_CreateNode)) { |
| 704 resolveNodeRS.dwFlags = XFA_RESOVENODE_RSTYPE_ExistNodes; | 707 resolveNodeRS.dwFlags = XFA_RESOVENODE_RSTYPE_ExistNodes; |
| 705 } | 708 } |
| 706 return resolveNodeRS.nodes.GetSize(); | 709 return resolveNodeRS.nodes.GetSize(); |
| 707 } | 710 } |
| 708 return nNodes; | 711 return nNodes; |
| 709 } | 712 } |
| 710 FXJSE_HVALUE CXFA_ScriptContext::GetJSValueFromMap(CXFA_Object* pObject) { | 713 CFXJSE_Value* CXFA_ScriptContext::GetJSValueFromMap(CXFA_Object* pObject) { |
| 711 if (!pObject) { | 714 if (!pObject) |
| 712 return NULL; | 715 return nullptr; |
| 716 if (pObject->IsNode()) | |
| 717 RunVariablesScript(pObject->AsNode()); | |
| 718 | |
| 719 void* pValue = m_mapXFAToValue.GetValueAt(pObject); | |
| 720 if (!pValue) { | |
| 721 CFXJSE_Value* jsValue = FXJSE_Value_Create(m_pIsolate); | |
| 722 FXJSE_Value_SetObject(jsValue, pObject, m_pJsClass); | |
| 723 m_mapXFAToValue.SetAt(pObject, jsValue); | |
| 724 pValue = jsValue; | |
| 713 } | 725 } |
| 714 if (pObject->IsNode()) { | 726 return static_cast<CFXJSE_Value*>(pValue); |
| 715 RunVariablesScript(pObject->AsNode()); | |
| 716 } | |
| 717 void* pValue = m_mapXFAToHValue.GetValueAt(pObject); | |
| 718 if (pValue == NULL) { | |
| 719 FXJSE_HVALUE jsHvalue = FXJSE_Value_Create(m_pIsolate); | |
| 720 FXJSE_Value_SetObject(jsHvalue, pObject, m_pJsClass); | |
| 721 m_mapXFAToHValue.SetAt(pObject, jsHvalue); | |
| 722 pValue = jsHvalue; | |
| 723 } | |
| 724 return (FXJSE_HVALUE)pValue; | |
| 725 } | 727 } |
| 726 int32_t CXFA_ScriptContext::GetIndexByName(CXFA_Node* refNode) { | 728 int32_t CXFA_ScriptContext::GetIndexByName(CXFA_Node* refNode) { |
| 727 CXFA_NodeHelper* lpNodeHelper = m_pResolveProcessor->GetNodeHelper(); | 729 CXFA_NodeHelper* lpNodeHelper = m_pResolveProcessor->GetNodeHelper(); |
| 728 return lpNodeHelper->XFA_GetIndex(refNode, XFA_LOGIC_Transparent, | 730 return lpNodeHelper->XFA_GetIndex(refNode, XFA_LOGIC_Transparent, |
| 729 lpNodeHelper->XFA_NodeIsProperty(refNode), | 731 lpNodeHelper->XFA_NodeIsProperty(refNode), |
| 730 FALSE); | 732 FALSE); |
| 731 } | 733 } |
| 732 int32_t CXFA_ScriptContext::GetIndexByClassName(CXFA_Node* refNode) { | 734 int32_t CXFA_ScriptContext::GetIndexByClassName(CXFA_Node* refNode) { |
| 733 CXFA_NodeHelper* lpNodeHelper = m_pResolveProcessor->GetNodeHelper(); | 735 CXFA_NodeHelper* lpNodeHelper = m_pResolveProcessor->GetNodeHelper(); |
| 734 return lpNodeHelper->XFA_GetIndex(refNode, XFA_LOGIC_Transparent, | 736 return lpNodeHelper->XFA_GetIndex(refNode, XFA_LOGIC_Transparent, |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 753 } | 755 } |
| 754 } | 756 } |
| 755 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { | 757 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { |
| 756 if (!m_pScriptNodeArray) { | 758 if (!m_pScriptNodeArray) { |
| 757 return; | 759 return; |
| 758 } | 760 } |
| 759 if (m_pScriptNodeArray->Find(pNode) == -1) { | 761 if (m_pScriptNodeArray->Find(pNode) == -1) { |
| 760 m_pScriptNodeArray->Add(pNode); | 762 m_pScriptNodeArray->Add(pNode); |
| 761 } | 763 } |
| 762 } | 764 } |
| OLD | NEW |