From: Gabriel Ivăncescu gabrielopcode@gmail.com
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/jscript/array.c | 14 ++++++++++---- dlls/mshtml/tests/es5.js | 7 +++++++ 2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/dlls/jscript/array.c b/dlls/jscript/array.c index 48f665da576..f86a9323aa8 100644 --- a/dlls/jscript/array.c +++ b/dlls/jscript/array.c @@ -1330,9 +1330,9 @@ static HRESULT Array_map(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned { jsval_t context_this = jsval_undefined(); jsval_t callback_args[3], mapped_value; + UINT32 length, new_len, k; jsdisp_t *jsthis, *array; IDispatch *callback; - UINT32 length, k; HRESULT hres;
TRACE("\n"); @@ -1358,10 +1358,13 @@ static HRESULT Array_map(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned if(FAILED(hres)) goto done;
+ new_len = 0; for(k = 0; k < length; k++) { hres = jsdisp_get_idx(jsthis, k, &callback_args[0]); - if(hres == DISP_E_UNKNOWNNAME) + if(hres == DISP_E_UNKNOWNNAME) { + hres = S_OK; continue; + } if(FAILED(hres)) break;
@@ -1375,12 +1378,15 @@ static HRESULT Array_map(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned hres = jsdisp_propput_idx(array, k, mapped_value); if(FAILED(hres)) break; + new_len = k + 1; }
- if(SUCCEEDED(hres) && r) + if(SUCCEEDED(hres) && r) { + array_from_jsdisp(array)->length = new_len; *r = jsval_obj(array); - else + }else { jsdisp_release(array); + } done: jsdisp_release(jsthis); return hres; diff --git a/dlls/mshtml/tests/es5.js b/dlls/mshtml/tests/es5.js index 7e2f66daabf..fbcb1b42f3e 100644 --- a/dlls/mshtml/tests/es5.js +++ b/dlls/mshtml/tests/es5.js @@ -431,6 +431,13 @@ sync_test("array_map", function() { [1,2].map(function() { ok(this.valueOf() === 137, "this.valueOf() = " + this.valueOf()); }, 137); + + r = [1,,2,].map(function(x) { return "" + x; }); + ok(r.length === 3, "[1,,2,].map length = " + r.length); + ok(r[0] === "1", "[1,,2,].map[0] = " + r[0]); + ok(r[2] === "2", "[1,,2,].map[2] = " + r[2]); + ok(!("1" in r), "[1,,2,].map[1] exists"); + ok(!("3" in r), "[1,,2,].map[3] exists"); });
sync_test("array_sort", function() {