Bug 870043 - Add a way to simulate the JSRuntime activity callback from xpcshell. r=mrbkap
The JS engine fires this callback when the request count drops to zero, and we use it determine when we should hibernate the watchdog thread. But since the request count never drops to zero for nested event loops, the watchdog never runs in those cases. And since our xpcshell harness runs tests in a nested event loop, this means we can't test watchdog hibernation from xpcshell. And we don't want to test it in mochitests, because the non-determinism of timer CCs and GCs are likely to be problematic. Really, we should consider finding a way to integrate nested event loops into the activity callback mechanism, and should probably get a bug on file. But such a task is out of scope for this bug, so we just add a way to fake it.
This commit is contained in:
@@ -861,6 +861,19 @@ SetOperationCallback(JSContext *cx, unsigned argc, jsval *vp)
|
||||
return true;
|
||||
}
|
||||
|
||||
static JSBool
|
||||
SimulateActivityCallback(JSContext *cx, unsigned argc, jsval *vp)
|
||||
{
|
||||
// Sanity-check args.
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||
if (args.length() != 1 || !args[0].isBoolean()) {
|
||||
JS_ReportError(cx, "Wrong number of arguments");
|
||||
return false;
|
||||
}
|
||||
xpc::SimulateActivityCallback(args[0].toBoolean());
|
||||
return true;
|
||||
}
|
||||
|
||||
static const JSFunctionSpec glob_functions[] = {
|
||||
JS_FS("print", Print, 0,0),
|
||||
JS_FS("readline", ReadLine, 1,0),
|
||||
@@ -886,6 +899,7 @@ static const JSFunctionSpec glob_functions[] = {
|
||||
JS_FS("Blob", Blob, 2,JSFUN_CONSTRUCTOR),
|
||||
JS_FS("File", File, 2,JSFUN_CONSTRUCTOR),
|
||||
JS_FS("setOperationCallback", SetOperationCallback, 1,0),
|
||||
JS_FS("simulateActivityCallback", SimulateActivityCallback, 1,0),
|
||||
JS_FS_END
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user