From c4fd5c183142aef5ae93b918b65a0bf01d2a0a1e Mon Sep 17 00:00:00 2001 From: Jun Fang Date: Wed, 20 Jan 2016 10:40:58 +0800 Subject: Remove dubious cast in CXFA_ScriptContext::AddJSBuiltinObject() BUG=pdfium:354 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1580773002 . --- xfa/src/fxfa/src/common/xfa_script.h | 1 - xfa/src/fxfa/src/parser/xfa_object_imp.cpp | 7 +-- xfa/src/fxfa/src/parser/xfa_script_imp.cpp | 89 +++++------------------------- xfa/src/fxfa/src/parser/xfa_script_imp.h | 6 +- 4 files changed, 16 insertions(+), 87 deletions(-) (limited to 'xfa') diff --git a/xfa/src/fxfa/src/common/xfa_script.h b/xfa/src/fxfa/src/common/xfa_script.h index 3bddc8bac9..69f69796e8 100644 --- a/xfa/src/fxfa/src/common/xfa_script.h +++ b/xfa/src/fxfa/src/common/xfa_script.h @@ -102,7 +102,6 @@ class IXFA_ScriptContext { virtual void AddNodesOfRunScript(CXFA_Node* pNode) = 0; virtual FXJSE_HCLASS GetJseNormalClass() = 0; virtual XFA_SCRIPTLANGTYPE GetType() = 0; - virtual void AddJSBuiltinObject(XFA_LPCJSBUILTININFO pBuitinObject) = 0; virtual void SetRunAtType(XFA_ATTRIBUTEENUM eRunAt) = 0; virtual FX_BOOL IsRunAtClient() = 0; }; diff --git a/xfa/src/fxfa/src/parser/xfa_object_imp.cpp b/xfa/src/fxfa/src/parser/xfa_object_imp.cpp index be2bed9334..86c267bcc3 100644 --- a/xfa/src/fxfa/src/parser/xfa_object_imp.cpp +++ b/xfa/src/fxfa/src/parser/xfa_object_imp.cpp @@ -3967,13 +3967,8 @@ FX_BOOL CXFA_Node::SetCData(XFA_ATTRIBUTE eAttr, SetUserData(pKey, pClone, &deleteWideStringCallBack); } else { SetMapModuleString(pKey, wsValue); - if (eAttr == XFA_ATTRIBUTE_Name) { + if (eAttr == XFA_ATTRIBUTE_Name) UpdateNameHash(); - if (XFA_LPCJSBUILTININFO pBuiltin = - XFA_GetJSBuiltinByHash(m_dwNameHash)) { - m_pDocument->GetScriptContext()->AddJSBuiltinObject(pBuiltin); - } - } } OnChanged(eAttr, (void*)(const FX_WCHAR*)wsValue, bNotify, bScriptModify); if (IsNeedSavingXMLNode() && eAttr != XFA_ATTRIBUTE_QualifiedName && diff --git a/xfa/src/fxfa/src/parser/xfa_script_imp.cpp b/xfa/src/fxfa/src/parser/xfa_script_imp.cpp index 9f4f0232ef..0db550b7fe 100644 --- a/xfa/src/fxfa/src/parser/xfa_script_imp.cpp +++ b/xfa/src/fxfa/src/parser/xfa_script_imp.cpp @@ -60,18 +60,6 @@ CXFA_ScriptContext::~CXFA_ScriptContext() { delete ((CXFA_NodeList*)m_CacheListArray[i]); } m_CacheListArray.RemoveAll(); - if (m_dwBuiltInInFlags & XFA_JSBUILTIN_HasCount) { - FX_POSITION ps = m_JSBuiltInObjects.GetStartPosition(); - while (ps) { - CFX_ByteString bsKey; - void* pValue = NULL; - m_JSBuiltInObjects.GetNextAssoc(ps, bsKey, pValue); - if (pValue) { - FXJSE_Value_Release((FXJSE_HVALUE)pValue); - } - } - m_JSBuiltInObjects.RemoveAll(); - } } void CXFA_ScriptContext::Initialize(FXJSE_HRUNTIME hRuntime) { m_hJsRuntime = hRuntime; @@ -105,28 +93,6 @@ FX_BOOL CXFA_ScriptContext::RunScript(XFA_SCRIPTLANGTYPE eScriptType, btScript = FX_UTF8Encode(wsJavaScript.GetBuffer(), wsJavaScript.GetLength()); } else { - if ((m_dwBuiltInInFlags & XFA_JSBUILTIN_Initialized) == 0) { - m_dwBuiltInInFlags = XFA_JSBUILTIN_Initialized; - FX_POSITION ps = m_JSBuiltInObjects.GetStartPosition(); - if (ps) { - FXJSE_HVALUE hObject = FXJSE_Context_GetGlobalObject(m_hJsContext); - while (ps) { - CFX_ByteString bsKey; - void* pValue; - m_JSBuiltInObjects.GetNextAssoc(ps, bsKey, pValue); - FXJSE_HVALUE hProp = FXJSE_Value_Create(m_hJsRuntime); - if (FXJSE_Value_GetObjectProp(hObject, bsKey, hProp)) { - m_JSBuiltInObjects.SetAt(bsKey, hProp); - FXJSE_Value_DeleteObjectProp(hObject, bsKey); - m_dwBuiltInInFlags |= XFA_JSBUILTIN_HasCount; - } else { - m_JSBuiltInObjects.RemoveKey(bsKey); - FXJSE_Value_Release(hProp); - } - } - FXJSE_Value_Release(hObject); - } - } btScript = FX_UTF8Encode(wsScript.GetPtr(), wsScript.GetLength()); } CXFA_Object* pOriginalObject = m_pThisObject; @@ -244,9 +210,6 @@ void CXFA_ScriptContext::GlobalPropertyGetter(FXJSE_HOBJECT hObject, szPropName, hValue, TRUE)) { return; } - if (lpScriptContext->QueryBuiltinHValue(szPropName, hValue)) { - return; - } IXFA_Notify* pNotify = pDoc->GetNotify(); if (!pNotify) { return; @@ -432,6 +395,7 @@ void CXFA_ScriptContext::DefineJsContext() { m_JsGlobalClass.dynMethodCall = CXFA_ScriptContext::NormalMethodCall; m_hJsContext = FXJSE_Context_Create(m_hJsRuntime, &m_JsGlobalClass, m_pDocument->GetRoot()); + RemoveBuiltInObjs(m_hJsContext); FXJSE_Context_EnableCompatibleMode( m_hJsContext, FXJSE_COMPATIBLEMODEFLAG_CONSTRUCTOREXTRAMETHODS); } @@ -461,6 +425,7 @@ FXJSE_HCONTEXT CXFA_ScriptContext::CreateVariablesContext( CXFA_ThisProxy* lpVariableNode = new CXFA_ThisProxy(pSubform, pScriptNode); FXJSE_HCONTEXT hVariablesContext = FXJSE_Context_Create( m_hJsRuntime, &m_JsGlobalVariablesClass, (CXFA_Object*)lpVariableNode); + RemoveBuiltInObjs(hVariablesContext); FXJSE_Context_EnableCompatibleMode( hVariablesContext, FXJSE_COMPATIBLEMODEFLAG_CONSTRUCTOREXTRAMETHODS); m_mapVariableToHValue.SetAt(pScriptNode, hVariablesContext); @@ -546,17 +511,6 @@ FX_BOOL CXFA_ScriptContext::QueryVariableHValue( } return bRes; } -FX_BOOL CXFA_ScriptContext::QueryBuiltinHValue( - const CFX_ByteStringC& szPropName, - FXJSE_HVALUE hValue) { - void* pBuiltin = NULL; - if ((m_dwBuiltInInFlags & XFA_JSBUILTIN_HasCount) && - m_JSBuiltInObjects.Lookup(szPropName, pBuiltin)) { - FXJSE_Value_Set(hValue, (FXJSE_HVALUE)pBuiltin); - return TRUE; - } - return FALSE; -} void CXFA_ScriptContext::ReleaseVariablesMap() { FX_POSITION ps = m_mapVariableToHValue.GetStartPosition(); while (ps) { @@ -589,16 +543,20 @@ void CXFA_ScriptContext::DefineJsClass() { m_JsNormalClass.dynMethodCall = CXFA_ScriptContext::NormalMethodCall; m_hJsClass = FXJSE_DefineClass(m_hJsContext, &m_JsNormalClass); } +void CXFA_ScriptContext::RemoveBuiltInObjs(FXJSE_HCONTEXT jsContext) const { + static const CFX_ByteStringC OBJ_NAME[2] = {"Number", "Date"}; + FXJSE_HVALUE hObject = FXJSE_Context_GetGlobalObject(jsContext); + FXJSE_HVALUE hProp = FXJSE_Value_Create(m_hJsRuntime); + for (int i = 0; i < 2; ++i) { + if (FXJSE_Value_GetObjectProp(hObject, OBJ_NAME[i], hProp)) + FXJSE_Value_DeleteObjectProp(hObject, OBJ_NAME[i]); + } + FXJSE_Value_Release(hProp); + FXJSE_Value_Release(hObject); +} FXJSE_HCLASS CXFA_ScriptContext::GetJseNormalClass() { return m_hJsClass; } -void CXFA_ScriptContext::AddJSBuiltinObject( - XFA_LPCJSBUILTININFO pBuitinObject) { - if (m_dwBuiltInInFlags & XFA_JSBUILTIN_Initialized) { - return; - } - m_JSBuiltInObjects.SetAt(pBuitinObject->pName, (void*)pBuitinObject); -} int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode, const CFX_WideStringC& wsExpression, XFA_RESOLVENODE_RS& resolveNodeRS, @@ -824,24 +782,3 @@ void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { IXFA_ScriptContext* XFA_ScriptContext_Create(CXFA_Document* pDocument) { return new CXFA_ScriptContext(pDocument); } -static const XFA_JSBUILTININFO gs_JSBUILTINData[] = { - {0x8108b9a9, "Number"}, - {0xe07e3fbe, "Date"}, -}; -const int32_t g_iJSBuiltinCount = - sizeof(XFA_JSBUILTININFO) / sizeof(XFA_JSBUILTININFO); -XFA_LPCJSBUILTININFO XFA_GetJSBuiltinByHash(uint32_t uHashCode) { - int32_t iStart = 0, iEnd = g_iJSBuiltinCount - 1, iMid; - do { - iMid = (iStart + iEnd) / 2; - XFA_LPCJSBUILTININFO pInfo = gs_JSBUILTINData + iMid; - if (uHashCode == pInfo->uUnicodeHash) { - return pInfo; - } else if (uHashCode < pInfo->uUnicodeHash) { - iEnd = iMid - 1; - } else { - iStart = iMid + 1; - } - } while (iStart <= iEnd); - return NULL; -} diff --git a/xfa/src/fxfa/src/parser/xfa_script_imp.h b/xfa/src/fxfa/src/parser/xfa_script_imp.h index 9a1ed6daf2..0075c3f68c 100644 --- a/xfa/src/fxfa/src/parser/xfa_script_imp.h +++ b/xfa/src/fxfa/src/parser/xfa_script_imp.h @@ -7,8 +7,7 @@ #ifndef _FXFA_SCRIPT_IMP_H #define _FXFA_SCRIPT_IMP_H #define XFA_RESOLVENODE_TagName 0x0002 -#define XFA_JSBUILTIN_Initialized 0x0001 -#define XFA_JSBUILTIN_HasCount 0x0002 + class CXFA_ResolveProcessor; class CXFA_ScriptContext : public IXFA_ScriptContext { public: @@ -45,7 +44,6 @@ class CXFA_ScriptContext : public IXFA_ScriptContext { virtual void AddNodesOfRunScript(CXFA_Node* pNode); virtual FXJSE_HCLASS GetJseNormalClass(); - virtual void AddJSBuiltinObject(XFA_LPCJSBUILTININFO pBuitinObject); virtual void SetRunAtType(XFA_ATTRIBUTEENUM eRunAt) { m_eRunAtType = eRunAt; } virtual FX_BOOL IsRunAtClient() { return m_eRunAtType != XFA_ATTRIBUTEENUM_Server; @@ -96,6 +94,7 @@ class CXFA_ScriptContext : public IXFA_ScriptContext { FXJSE_HCONTEXT CreateVariablesContext(CXFA_Node* pScriptNode, CXFA_Node* pSubform); void DefineJsClass(); + void RemoveBuiltInObjs(FXJSE_HCONTEXT jsContext) const; CXFA_Document* m_pDocument; FXJSE_HCONTEXT m_hJsContext; @@ -114,7 +113,6 @@ class CXFA_ScriptContext : public IXFA_ScriptContext { CXFA_ResolveProcessor* m_pResolveProcessor; XFA_HFM2JSCONTEXT m_hFM2JSContext; CXFA_Object* m_pThisObject; - CFX_CMapByteStringToPtr m_JSBuiltInObjects; FX_DWORD m_dwBuiltInInFlags; XFA_ATTRIBUTEENUM m_eRunAtType; }; -- cgit v1.2.3