Asynchronous step function that does not modify this value #236
Comments
What does |
The let x = async_test(function(t) {
setTimeout(t.step_func(function() {
console.log(this === x); // true
console.log(this === t); // true
t.done();
}));
}, "Title"); |
You could change Something like: (untested) Test.prototype.step_func = function(func, this_obj)
{
var test_this = this;
var has_explicit_this_obj = arguments.length > 1;
return function()
{
var func_this = has_explicit_this_obj ? this_obj : this;
return test_this.step.apply(test_this, [func, func_this].concat(
Array.prototype.slice.call(arguments)));
};
}; I wasn't sure if anything relied on this behavior (I only just started using testharness.js today). |
I have no idea! I'm wondering if we can get away with that. :) |
Do you have a way of running all (or a large portion of) the tests? I'm afraid if I do it I won't be able to test enough of the tests to guarantee there will be no regressions. |
I can, though it takes a while. Probably easier when I'm not travelling and using my laptop. :) |
I'm a little concerned about changing this; would using |
|
This issue has been moved to web-platform-tests/wpt#7182; please continue all discussion there. |
When attempting to write an async test,
t.step_func
is useful for wrapping a callback function, however it modifies thethis
value within the callback. I'd like to add a variant that doesn't modify the this value,t.step_func_unmodified_this
.Implementation (simplified)
Docs
For asynchronous callbacks where the
this
value is significant,step_func_unmodified_this
can be used. For example:Currently the above test would need to be written something like:
Which is quite obtuse, and requires using a different name for
this
even thoughthis
is what is being tested.The text was updated successfully, but these errors were encountered: