Commit 8cb5d741 authored by Gabriel Ivăncescu's avatar Gabriel Ivăncescu Committed by Alexandre Julliard

jscript: Pass correct 'this' to callbacks called by builtins.

parent da842966
......@@ -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);
......
......@@ -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);
......
......@@ -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);
});
......
......@@ -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() {
......
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