Commit 40b36d42 authored by Gabriel Ivăncescu's avatar Gabriel Ivăncescu Committed by Alexandre Julliard

jscript: Fix Array.map when last element doesn't exist.

parent 75635053
...@@ -1354,14 +1354,16 @@ static HRESULT Array_map(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned ...@@ -1354,14 +1354,16 @@ static HRESULT Array_map(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned
if(argc > 1) if(argc > 1)
context_this = argv[1]; context_this = argv[1];
hres = create_array(ctx, length, &array); hres = create_array(ctx, 0, &array);
if(FAILED(hres)) if(FAILED(hres))
goto done; goto done;
for(k = 0; k < length; k++) { for(k = 0; k < length; k++) {
hres = jsdisp_get_idx(jsthis, k, &callback_args[0]); hres = jsdisp_get_idx(jsthis, k, &callback_args[0]);
if(hres == DISP_E_UNKNOWNNAME) if(hres == DISP_E_UNKNOWNNAME) {
hres = S_OK;
continue; continue;
}
if(FAILED(hres)) if(FAILED(hres))
break; break;
......
...@@ -431,6 +431,13 @@ sync_test("array_map", function() { ...@@ -431,6 +431,13 @@ sync_test("array_map", function() {
[1,2].map(function() { [1,2].map(function() {
ok(this.valueOf() === 137, "this.valueOf() = " + this.valueOf()); ok(this.valueOf() === 137, "this.valueOf() = " + this.valueOf());
}, 137); }, 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() { sync_test("array_sort", function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment