From ed674d63a4ec07e07a36e0bead84d7ac9bf6c9a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Iv=C4=83ncescu?= Date: Tue, 17 Oct 2023 16:18:54 +0300 Subject: [PATCH] jscript: Fix Array.reduce when last element doesn't exist. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gabriel Ivăncescu --- dlls/jscript/array.c | 4 +++- dlls/mshtml/tests/es5.js | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/dlls/jscript/array.c b/dlls/jscript/array.c index c673b82fed2..36f45120055 100644 --- a/dlls/jscript/array.c +++ b/dlls/jscript/array.c @@ -1422,8 +1422,10 @@ static HRESULT Array_reduce(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsign for(k = 0; k < length; k++) { hres = jsdisp_get_idx(jsthis, k, &callback_args[1]); - if(hres == DISP_E_UNKNOWNNAME) + if(hres == DISP_E_UNKNOWNNAME) { + hres = S_OK; continue; + } if(FAILED(hres)) break; diff --git a/dlls/mshtml/tests/es5.js b/dlls/mshtml/tests/es5.js index fbcb1b42f3e..b6ce7be3c54 100644 --- a/dlls/mshtml/tests/es5.js +++ b/dlls/mshtml/tests/es5.js @@ -1336,6 +1336,9 @@ sync_test("reduce", function() { r = [1,2,3].reduce(function(a, value) { return a + value; }, "str"); ok(r === "str123", "reduce() returned " + r); + r = [1,2,].reduce(function(a, value) { return a + value; }, "str"); + ok(r === "str12", "reduce() returned " + r); + array = [1,2,3]; r = array.reduce(function(a, value, index, src) { ok(src === array, "src != array");