Piotr Caban : jscript: Fix jsdisp_propget_idx implementation.
Alexandre Julliard
julliard at winehq.org
Mon Jan 25 11:21:09 CST 2010
Module: wine
Branch: master
Commit: 352ae8b480050456be18b4e81a68db7b2c816365
URL: http://source.winehq.org/git/wine.git/?a=commit;h=352ae8b480050456be18b4e81a68db7b2c816365
Author: Piotr Caban <piotr at codeweavers.com>
Date: Mon Jan 25 03:49:49 2010 +0100
jscript: Fix jsdisp_propget_idx implementation.
---
dlls/jscript/array.c | 34 ++++++++++++++++++++--------------
dlls/jscript/dispex.c | 20 ++++++++++++++++----
dlls/jscript/function.c | 6 ++++--
dlls/jscript/jscript.h | 2 +-
4 files changed, 41 insertions(+), 21 deletions(-)
diff --git a/dlls/jscript/array.c b/dlls/jscript/array.c
index 1ced39e..1268d59 100644
--- a/dlls/jscript/array.c
+++ b/dlls/jscript/array.c
@@ -166,7 +166,7 @@ static HRESULT concat_array(DispatchEx *array, ArrayInstance *obj, DWORD *len,
HRESULT hres;
for(i=0; i < obj->length; i++) {
- hres = jsdisp_propget_idx(&obj->dispex, i, &var, ei, caller);
+ hres = jsdisp_get_idx(&obj->dispex, i, &var, ei, caller);
if(hres == DISP_E_UNKNOWNNAME)
continue;
if(FAILED(hres))
@@ -267,8 +267,11 @@ static HRESULT array_join(script_ctx_t *ctx, DispatchEx *array, DWORD length, co
return E_OUTOFMEMORY;
for(i=0; i < length; i++) {
- hres = jsdisp_propget_idx(array, i, &var, ei, caller);
- if(FAILED(hres))
+ hres = jsdisp_get_idx(array, i, &var, ei, caller);
+ if(hres == DISP_E_UNKNOWNNAME) {
+ hres = S_OK;
+ continue;
+ } else if(FAILED(hres))
break;
if(V_VT(&var) != VT_EMPTY && V_VT(&var) != VT_NULL)
@@ -397,7 +400,7 @@ static HRESULT Array_pop(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPARA
}
length--;
- hres = jsdisp_propget_idx(jsthis, length, &val, ei, caller);
+ hres = jsdisp_get_idx(jsthis, length, &val, ei, caller);
if(SUCCEEDED(hres)) {
hres = jsdisp_delete_idx(jsthis, length);
} else if(hres == DISP_E_UNKNOWNNAME) {
@@ -472,11 +475,11 @@ static HRESULT Array_reverse(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISP
for(k=0; k<length/2; k++) {
l = length-k-1;
- hres1 = jsdisp_propget_idx(jsthis, k, &v1, ei, sp);
+ hres1 = jsdisp_get_idx(jsthis, k, &v1, ei, sp);
if(FAILED(hres1) && hres1!=DISP_E_UNKNOWNNAME)
return hres1;
- hres2 = jsdisp_propget_idx(jsthis, l, &v2, ei, sp);
+ hres2 = jsdisp_get_idx(jsthis, l, &v2, ei, sp);
if(FAILED(hres2) && hres2!=DISP_E_UNKNOWNNAME) {
VariantClear(&v1);
return hres2;
@@ -540,14 +543,14 @@ static HRESULT Array_shift(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPA
return S_OK;
}
- hres = jsdisp_propget_idx(jsthis, 0, &ret, ei, caller);
+ hres = jsdisp_get_idx(jsthis, 0, &ret, ei, caller);
if(hres == DISP_E_UNKNOWNNAME) {
V_VT(&ret) = VT_EMPTY;
hres = S_OK;
}
for(i=1; SUCCEEDED(hres) && i<length; i++) {
- hres = jsdisp_propget_idx(jsthis, i, &v, ei, caller);
+ hres = jsdisp_get_idx(jsthis, i, &v, ei, caller);
if(hres == DISP_E_UNKNOWNNAME)
hres = jsdisp_delete_idx(jsthis, i-1);
else if(SUCCEEDED(hres))
@@ -622,7 +625,7 @@ static HRESULT Array_slice(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPA
return hres;
for(idx=start; idx<end; idx++) {
- hres = jsdisp_propget_idx(jsthis, idx, &v, ei, sp);
+ hres = jsdisp_get_idx(jsthis, idx, &v, ei, sp);
if(hres == DISP_E_UNKNOWNNAME)
continue;
@@ -755,8 +758,11 @@ static HRESULT Array_sort(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPAR
vtab = heap_alloc_zero(length * sizeof(VARIANT));
if(vtab) {
for(i=0; i<length; i++) {
- hres = jsdisp_propget_idx(jsthis, i, vtab+i, ei, caller);
- if(FAILED(hres) && hres != DISP_E_UNKNOWNNAME) {
+ hres = jsdisp_get_idx(jsthis, i, vtab+i, ei, caller);
+ if(hres == DISP_E_UNKNOWNNAME) {
+ V_VT(vtab+i) = VT_EMPTY;
+ hres = S_OK;
+ } else if(FAILED(hres)) {
WARN("Could not get elem %d: %08x\n", i, hres);
break;
}
@@ -908,7 +914,7 @@ static HRESULT Array_splice(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPP
return hres;
for(i=0; SUCCEEDED(hres) && i < delete_cnt; i++) {
- hres = jsdisp_propget_idx(jsthis, start+i, &v, ei, caller);
+ hres = jsdisp_get_idx(jsthis, start+i, &v, ei, caller);
if(hres == DISP_E_UNKNOWNNAME)
hres = S_OK;
else if(SUCCEEDED(hres))
@@ -925,7 +931,7 @@ static HRESULT Array_splice(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPP
if(add_args < delete_cnt) {
for(i = start; SUCCEEDED(hres) && i < length-delete_cnt; i++) {
- hres = jsdisp_propget_idx(jsthis, i+delete_cnt, &v, ei, caller);
+ hres = jsdisp_get_idx(jsthis, i+delete_cnt, &v, ei, caller);
if(hres == DISP_E_UNKNOWNNAME)
hres = jsdisp_delete_idx(jsthis, i+add_args);
else if(SUCCEEDED(hres))
@@ -936,7 +942,7 @@ static HRESULT Array_splice(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPP
hres = jsdisp_delete_idx(jsthis, i-1);
}else if(add_args > delete_cnt) {
for(i=length-delete_cnt; SUCCEEDED(hres) && i != start; i--) {
- hres = jsdisp_propget_idx(jsthis, i+delete_cnt-1, &v, ei, caller);
+ hres = jsdisp_get_idx(jsthis, i+delete_cnt-1, &v, ei, caller);
if(hres == DISP_E_UNKNOWNNAME)
hres = jsdisp_delete_idx(jsthis, i+add_args-1);
else if(SUCCEEDED(hres))
diff --git a/dlls/jscript/dispex.c b/dlls/jscript/dispex.c
index 1b52ba4..492623e 100644
--- a/dlls/jscript/dispex.c
+++ b/dlls/jscript/dispex.c
@@ -1003,14 +1003,26 @@ HRESULT jsdisp_propget_name(DispatchEx *obj, const WCHAR *name, VARIANT *var, js
return prop_get(obj, prop, &dp, var, ei, caller);
}
-HRESULT jsdisp_propget_idx(DispatchEx *obj, DWORD idx, VARIANT *var, jsexcept_t *ei, IServiceProvider *caller)
+HRESULT jsdisp_get_idx(DispatchEx *obj, DWORD idx, VARIANT *var, jsexcept_t *ei, IServiceProvider *caller)
{
- WCHAR buf[12];
+ WCHAR name[12];
+ DISPPARAMS dp = {NULL, NULL, 0, 0};
+ dispex_prop_t *prop;
+ HRESULT hres;
static const WCHAR formatW[] = {'%','d',0};
- sprintfW(buf, formatW, idx);
- return jsdisp_propget_name(obj, buf, var, ei, caller);
+ sprintfW(name, formatW, idx);
+
+ hres = find_prop_name_prot(obj, name, FALSE, &prop);
+ if(FAILED(hres))
+ return hres;
+
+ V_VT(var) = VT_EMPTY;
+ if(!prop)
+ return DISP_E_UNKNOWNNAME;
+
+ return prop_get(obj, prop, &dp, var, ei, caller);
}
HRESULT jsdisp_propget(DispatchEx *jsdisp, DISPID id, VARIANT *val, jsexcept_t *ei, IServiceProvider *caller)
diff --git a/dlls/jscript/function.c b/dlls/jscript/function.c
index d25fd0f..c7494cf 100644
--- a/dlls/jscript/function.c
+++ b/dlls/jscript/function.c
@@ -374,8 +374,10 @@ static HRESULT array_to_args(script_ctx_t *ctx, DispatchEx *arg_array, jsexcept_
return E_OUTOFMEMORY;
for(i=0; i<length; i++) {
- hres = jsdisp_propget_idx(arg_array, i, argv+i, ei, caller);
- if(FAILED(hres)) {
+ hres = jsdisp_get_idx(arg_array, i, argv+i, ei, caller);
+ if(hres == DISP_E_UNKNOWNNAME)
+ V_VT(argv+i) = VT_EMPTY;
+ else if(FAILED(hres)) {
while(i--)
VariantClear(argv+i);
heap_free(argv);
diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h
index 95f5028..0068827 100644
--- a/dlls/jscript/jscript.h
+++ b/dlls/jscript/jscript.h
@@ -205,7 +205,7 @@ HRESULT jsdisp_propget(DispatchEx*,DISPID,VARIANT*,jsexcept_t*,IServiceProvider*
HRESULT jsdisp_propput_name(DispatchEx*,const WCHAR*,VARIANT*,jsexcept_t*,IServiceProvider*);
HRESULT jsdisp_propput_idx(DispatchEx*,DWORD,VARIANT*,jsexcept_t*,IServiceProvider*);
HRESULT jsdisp_propget_name(DispatchEx*,LPCWSTR,VARIANT*,jsexcept_t*,IServiceProvider*);
-HRESULT jsdisp_propget_idx(DispatchEx*,DWORD,VARIANT*,jsexcept_t*,IServiceProvider*);
+HRESULT jsdisp_get_idx(DispatchEx*,DWORD,VARIANT*,jsexcept_t*,IServiceProvider*);
HRESULT jsdisp_get_id(DispatchEx*,const WCHAR*,DWORD,DISPID*);
HRESULT jsdisp_delete_idx(DispatchEx*,DWORD);
More information about the wine-cvs
mailing list