Bug 1149294 - Part 2: expose ChromeUtils and HeapSnapshot to workers; r=bholley

This commit is contained in:
Nick Fitzgerald 2015-06-17 11:12:23 -07:00
parent 870beaf40d
commit 004aacf74b
5 changed files with 91 additions and 2 deletions

View File

@ -7,7 +7,7 @@
/**
* A collection of static utility methods that are only exposed to Chrome.
*/
[ChromeOnly, Exposed=(Window,System)]
[ChromeOnly, Exposed=(Window,System,Worker)]
interface ChromeUtils {
/**
* Serialize a snapshot of the heap graph, as seen by |JS::ubi::Node| and

View File

@ -7,6 +7,6 @@
/**
* A HeapSnapshot represents a snapshot of the heap graph
*/
[ChromeOnly, Exposed=(Window,System)]
[ChromeOnly, Exposed=(Window,System,Worker)]
interface HeapSnapshot {
};

View File

@ -0,0 +1,44 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
console.log("Initializing worker.");
self.onmessage = e => {
console.log("Starting test.");
try {
const { filePath } = e.data;
ok(ChromeUtils, "Should have access to ChromeUtils");
ok(HeapSnapshot, "Should have access to HeapSnapshot");
ChromeUtils.saveHeapSnapshot(filePath, { globals: [this] });
ok(true, "Should be able to save a snapshot.");
const snapshot = ChromeUtils.readHeapSnapshot(filePath);
ok(snapshot, "Should be able to read a heap snapshot");
ok(snapshot instanceof HeapSnapshot, "Should be an instanceof HeapSnapshot");
} catch (e) {
ok(false, "Unexpected error inside worker:\n" + e.toString() + "\n" + e.stack);
} finally {
done();
}
};
// Proxy assertions to the main thread.
function ok(val, msg) {
console.log("ok(" + !!val + ", \"" + msg + "\")");
self.postMessage({
type: "assertion",
passed: !!val,
msg,
stack: Error().stack
});
}
// Tell the main thread we are done with the tests.
function done() {
console.log("done()");
self.postMessage({
type: "done"
});
}

View File

@ -0,0 +1,43 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Test that we can read core dumps into HeapSnapshot instances in a worker.
add_task(function* () {
const filePath = getFilePath("core-dump.tmp", true, true);
ok(filePath, "Should get a file path");
const worker = new ChromeWorker("resource://test/heap-snapshot-worker.js");
worker.postMessage({ filePath });
let assertionCount = 0;
worker.onmessage = e => {
if (e.data.type !== "assertion") {
return;
}
ok(e.data.passed, e.data.msg + "\n" + e.data.stack);
assertionCount++;
};
yield waitForDone(worker);
ok(assertionCount > 0);
worker.terminate();
});
function waitForDone(w) {
return new Promise((resolve, reject) => {
worker.onerror = e => {
reject();
ok(false, "Error in worker: " + e);
};
w.addEventListener("message", function listener(e) {
if (e.data.type === "done") {
w.removeEventListener("message", listener, false);
resolve();
}
}, false);
});
}

View File

@ -17,6 +17,7 @@ support-files =
sourcemapped.js
testactors.js
tracerlocations.js
heap-snapshot-worker.js
hello-actor.js
setBreakpoint-on-column.js
setBreakpoint-on-column-in-gcd-script.js
@ -42,6 +43,7 @@ support-files =
[test_nsjsinspector.js]
[test_SaveHeapSnapshot.js]
[test_ReadHeapSnapshot.js]
[test_ReadHeapSnapshot_worker.js]
[test_dbgactor.js]
[test_dbgglobal.js]
[test_dbgclient_debuggerstatement.js]