Bug 941649 - Part 2: Add a workerThreadCount shell testing function. (r=luke)

This commit is contained in:
Shu-yu Guo 2013-11-27 20:08:46 -08:00
parent 2e59abbcd1
commit 790bd61f01
3 changed files with 22 additions and 2 deletions

View File

@ -115,6 +115,14 @@ GetBuildConfiguration(JSContext *cx, unsigned argc, jsval *vp)
if (!JS_SetProperty(cx, info, "threadsafe", value))
return false;
#ifdef JS_WORKER_THREADS
value = BooleanValue(true);
#else
value = BooleanValue(false);
#endif
if (!JS_SetProperty(cx, info, "worker-threads", value))
return false;
#ifdef JS_MORE_DETERMINISTIC
value = BooleanValue(true);
#else
@ -1361,6 +1369,14 @@ Neuter(JSContext *cx, unsigned argc, jsval *vp)
return true;
}
static bool
WorkerThreadCount(JSContext *cx, unsigned argc, jsval *vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
args.rval().setNumber(static_cast<double>(cx->runtime()->helperThreadCount()));
return true;
}
static const JSFunctionSpecWithHelp TestingFunctions[] = {
JS_FN_HELP("gc", ::GC, 0, 0,
"gc([obj] | 'compartment')",
@ -1580,6 +1596,10 @@ static const JSFunctionSpecWithHelp TestingFunctions[] = {
"neuter(buffer)",
" Neuter the given ArrayBuffer object as if it had been transferred to a WebWorker."),
JS_FN_HELP("workerThreadCount", WorkerThreadCount, 0, 0,
"workerThreadCount()",
" Returns the number of worker threads available for off-main-thread tasks."),
JS_FS_HELP_END
};

View File

@ -5,7 +5,7 @@
load(libdir + 'asserts.js');
if (!getBuildConfiguration().threadsafe)
if (workerThreadCount() === 0)
quit(0);
offThreadCompileScript('Math.sin(Math.PI/2)');

View File

@ -1,6 +1,6 @@
// We still get onNewScript notifications for code compiled off the main thread.
if (!getBuildConfiguration().threadsafe)
if (workerThreadCount() === 0)
quit(0);
var g = newGlobal();