Module: wine Branch: master Commit: 8cb5d74125329a10d79da8ffa129e183c282a6ed URL: https://gitlab.winehq.org/wine/wine/-/commit/8cb5d74125329a10d79da8ffa129e18...
Author: Gabriel Ivăncescu gabrielopcode@gmail.com Date: Tue Nov 22 18:53:20 2022 +0200
jscript: Pass correct 'this' to callbacks called by builtins.
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com
---
dlls/jscript/array.c | 43 ++++++--------------------------------- dlls/jscript/set.c | 7 +------ dlls/mshtml/tests/documentmode.js | 6 ++++-- dlls/mshtml/tests/es5.js | 10 +++++++++ 4 files changed, 21 insertions(+), 45 deletions(-)
diff --git a/dlls/jscript/array.c b/dlls/jscript/array.c index 27d85fdb22b..341505a335c 100644 --- a/dlls/jscript/array.c +++ b/dlls/jscript/array.c @@ -1048,14 +1048,8 @@ static HRESULT Array_every(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigne } callback = get_object(argv[0]);
- if(argc > 1 && !is_undefined(argv[1])) { - if(!is_object_instance(argv[1])) { - FIXME("Unsupported context this %s\n", debugstr_jsval(argv[1])); - hres = E_NOTIMPL; - goto done; - } + if(argc > 1) context_this = argv[1]; - }
for(i = 0; i < length; i++) { hres = jsdisp_get_idx(jsthis, i, &value); @@ -1115,14 +1109,8 @@ static HRESULT Array_filter(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsign } callback = get_object(argv[0]);
- if(argc > 1 && !is_undefined(argv[1])) { - if(!is_object_instance(argv[1])) { - FIXME("Unsupported context this %s\n", debugstr_jsval(argv[1])); - hres = E_NOTIMPL; - goto done; - } + if(argc > 1) context_this = argv[1]; - }
hres = create_array(ctx, 0, &arr); if(FAILED(hres)) @@ -1189,14 +1177,8 @@ static HRESULT Array_forEach(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsig } callback = get_object(argv[0]);
- if(argc > 1 && !is_undefined(argv[1])) { - if(!is_object_instance(argv[1])) { - FIXME("Unsupported context this %s\n", debugstr_jsval(argv[1])); - hres = E_NOTIMPL; - goto done; - } + if(argc > 1) context_this = argv[1]; - }
for(i = 0; i < length; i++) { hres = jsdisp_get_idx(jsthis, i, &value); @@ -1367,15 +1349,8 @@ static HRESULT Array_map(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned } callback = get_object(argv[0]);
- if(argc > 1) { - if(is_object_instance(argv[1])) { - context_this = argv[1]; - }else if(!is_undefined(argv[1])) { - FIXME("Unsupported context this %s\n", debugstr_jsval(argv[1])); - hres = E_NOTIMPL; - goto done; - } - } + if(argc > 1) + context_this = argv[1];
hres = create_array(ctx, length, &array); if(FAILED(hres)) @@ -1505,14 +1480,8 @@ static HRESULT Array_some(script_ctx_t *ctx, jsval_t vthis, WORD flags, unsigned } callback = get_object(argv[0]);
- if(argc > 1 && !is_undefined(argv[1])) { - if(!is_object_instance(argv[1])) { - FIXME("Unsupported context this %s\n", debugstr_jsval(argv[1])); - hres = E_NOTIMPL; - goto done; - } + if(argc > 1) context_this = argv[1]; - }
for(i = 0; i < length; i++) { hres = jsdisp_get_idx(jsthis, i, &value); diff --git a/dlls/jscript/set.c b/dlls/jscript/set.c index 889b744b385..4e2c1ffb33f 100644 --- a/dlls/jscript/set.c +++ b/dlls/jscript/set.c @@ -192,13 +192,8 @@ static HRESULT iterate_map(MapInstance *map, script_ctx_t *ctx, unsigned argc, j return E_FAIL; }
- if(argc > 1 && !is_undefined(argv[1])) { - if(!is_object_instance(argv[1])) { - FIXME("Unsupported context this %s\n", debugstr_jsval(argv[1])); - return E_NOTIMPL; - } + if(argc > 1) context_this = argv[1]; - }
while(iter) { struct jsval_map_entry *entry = LIST_ENTRY(iter, struct jsval_map_entry, list_entry); diff --git a/dlls/mshtml/tests/documentmode.js b/dlls/mshtml/tests/documentmode.js index 157a7337c04..f968fae00df 100644 --- a/dlls/mshtml/tests/documentmode.js +++ b/dlls/mshtml/tests/documentmode.js @@ -1293,7 +1293,8 @@ sync_test("set_obj", function() { r++; s.clear(); ok(s.size === 0, "size = " + s.size); - }); + ok(this.valueOf() === 42, "this.valueOf() = " + this.valueOf()); + }, 42); ok(r === 1, "r = " + r); });
@@ -1447,7 +1448,8 @@ sync_test("map_obj", function() { r++; s.clear(); ok(s.size === 0, "size = " + s.size); - }); + ok(this.valueOf() === 42, "this.valueOf() = " + this.valueOf()); + }, 42); ok(r === 1, "r = " + r); });
diff --git a/dlls/mshtml/tests/es5.js b/dlls/mshtml/tests/es5.js index e22f610e197..93ede87eeb0 100644 --- a/dlls/mshtml/tests/es5.js +++ b/dlls/mshtml/tests/es5.js @@ -280,6 +280,8 @@ sync_test("filter", function() { test(["a","b"], function(v) { if(v === "b") delete arr[0]; return typeof v === "string"; }); test(["b"], function(v) { if(arr[arr.length - 1] !== "c") arr.push("c"); return typeof v === "string"; }); test([true,"b",42,Math,arr[9],"c"], function(v) { return v; }, Object); + + [0].filter(function() { ok(this.valueOf() === "wine", "this.valueOf() = " + this.valueOf()); return true; }, "wine"); });
sync_test("every & some", function() { @@ -314,6 +316,9 @@ sync_test("every & some", function() { test(false, false, function(v) { return v; }); arr.push(1); test(false, true, function(v) { return v; }); + + [0].every(function() { ok(this.valueOf() === 42, "this.valueOf() = " + this.valueOf()); return true; }, 42); + [0].some(function() { ok(this.valueOf() === 137, "this.valueOf() = " + this.valueOf()); return false; }, 137); });
sync_test("forEach", function() { @@ -347,6 +352,8 @@ sync_test("forEach", function() { ok(array === a, "array != a"); ok(this === o, "this != o"); }, o); + + a.forEach(function() { ok(this.valueOf() === "foobar", "this.valueOf() = " + this.valueOf()); }, "foobar"); });
sync_test("isArray", function() { @@ -412,6 +419,9 @@ sync_test("array_map", function() { [1,2].map(function() { ok(this === window, "this != window"); }, undefined); + [1,2].map(function() { + ok(this.valueOf() === 137, "this.valueOf() = " + this.valueOf()); + }, 137); });
sync_test("array_sort", function() {