Module: wine Branch: master Commit: 16271ac208ea82cde1777a72d412fad407906309 URL: https://gitlab.winehq.org/wine/wine/-/commit/16271ac208ea82cde1777a72d412fad...
Author: Jacek Caban jacek@codeweavers.com Date: Wed May 29 23:33:24 2024 +0200
mshtml: Factor out alloc_dynamic_prop.
---
dlls/mshtml/dispex.c | 70 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 27 deletions(-)
diff --git a/dlls/mshtml/dispex.c b/dlls/mshtml/dispex.c index 07c26e2e762..3c5f00e35b7 100644 --- a/dlls/mshtml/dispex.c +++ b/dlls/mshtml/dispex.c @@ -646,33 +646,16 @@ static inline dispex_dynamic_data_t *get_dynamic_data(DispatchEx *This) return This->dynamic_data; }
-static HRESULT get_dynamic_prop(DispatchEx *This, const WCHAR *name, DWORD flags, dynamic_prop_t **ret) +static HRESULT alloc_dynamic_prop(DispatchEx *This, const WCHAR *name, dynamic_prop_t *prop, dynamic_prop_t **ret) { - const BOOL alloc = flags & fdexNameEnsure; - dispex_dynamic_data_t *data; - dynamic_prop_t *prop; - - data = get_dynamic_data(This); - if(!data) - return E_OUTOFMEMORY; + dispex_dynamic_data_t *data = This->dynamic_data;
- for(prop = data->props; prop < data->props+data->prop_cnt; prop++) { - if(flags & fdexNameCaseInsensitive ? !wcsicmp(prop->name, name) : !wcscmp(prop->name, name)) { - if(prop->flags & DYNPROP_DELETED) { - if(!alloc) - return DISP_E_UNKNOWNNAME; - prop->flags &= ~DYNPROP_DELETED; - } - *ret = prop; - return S_OK; - } + if(prop) { + prop->flags &= ~DYNPROP_DELETED; + *ret = prop; + return S_OK; }
- if(!alloc) - return DISP_E_UNKNOWNNAME; - - TRACE("creating dynamic prop %s\n", debugstr_w(name)); - if(!data->buf_size) { data->props = malloc(sizeof(dynamic_prop_t) * 4); if(!data->props) @@ -702,6 +685,35 @@ static HRESULT get_dynamic_prop(DispatchEx *This, const WCHAR *name, DWORD flags return S_OK; }
+static HRESULT get_dynamic_prop(DispatchEx *This, const WCHAR *name, DWORD flags, dynamic_prop_t **ret) +{ + const BOOL alloc = flags & fdexNameEnsure; + dispex_dynamic_data_t *data; + dynamic_prop_t *prop; + + data = get_dynamic_data(This); + if(!data) + return E_OUTOFMEMORY; + + for(prop = data->props; prop < data->props+data->prop_cnt; prop++) { + if(flags & fdexNameCaseInsensitive ? !wcsicmp(prop->name, name) : !wcscmp(prop->name, name)) { + *ret = prop; + if(prop->flags & DYNPROP_DELETED) { + if(!alloc) + return DISP_E_UNKNOWNNAME; + prop->flags &= ~DYNPROP_DELETED; + } + return S_OK; + } + } + + if(!alloc) + return DISP_E_UNKNOWNNAME; + + TRACE("creating dynamic prop %s\n", debugstr_w(name)); + return alloc_dynamic_prop(This, name, NULL, ret); +} + HRESULT dispex_get_dprop_ref(DispatchEx *This, const WCHAR *name, BOOL alloc, VARIANT **ret) { dynamic_prop_t *prop; @@ -1662,7 +1674,7 @@ static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember, static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid) { DispatchEx *This = impl_from_IDispatchEx(iface); - dynamic_prop_t *dprop; + dynamic_prop_t *dprop = NULL; HRESULT hres;
TRACE("%s (%p)->(%s %lx %p)\n", This->info->desc->name, This, debugstr_w(bstrName), grfdex, pid); @@ -1677,9 +1689,13 @@ static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DW if(hres != DISP_E_UNKNOWNNAME) return hres;
- hres = get_dynamic_prop(This, bstrName, grfdex, &dprop); - if(FAILED(hres)) - return hres; + hres = get_dynamic_prop(This, bstrName, grfdex & ~fdexNameEnsure, &dprop); + if(FAILED(hres)) { + if(grfdex & fdexNameEnsure) + hres = alloc_dynamic_prop(This, bstrName, dprop, &dprop); + if(FAILED(hres)) + return hres; + }
*pid = DISPID_DYNPROP_0 + (dprop - This->dynamic_data->props); return S_OK;