heap-snapshot-worker.js (1261B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 /* eslint-env worker */ 5 6 "use strict"; 7 8 console.log("Initializing worker."); 9 10 self.onmessage = () => { 11 console.log("Starting test."); 12 try { 13 ok(ChromeUtils, "Should have access to ChromeUtils in a worker."); 14 ok(HeapSnapshot, "Should have access to HeapSnapshot in a worker."); 15 16 const filePath = ChromeUtils.saveHeapSnapshot({ globals: [this] }); 17 ok(true, "Should be able to save a snapshot."); 18 19 const snapshot = ChromeUtils.readHeapSnapshot(filePath); 20 ok(snapshot, "Should be able to read a heap snapshot"); 21 ok( 22 HeapSnapshot.isInstance(snapshot), 23 "Should be an instanceof HeapSnapshot" 24 ); 25 } catch (e) { 26 ok( 27 false, 28 "Unexpected error inside worker:\n" + e.toString() + "\n" + e.stack 29 ); 30 } finally { 31 done(); 32 } 33 }; 34 35 // Proxy assertions to the main thread. 36 function ok(val, msg) { 37 console.log("ok(" + !!val + ', "' + msg + '")'); 38 self.postMessage({ 39 type: "assertion", 40 passed: !!val, 41 msg, 42 stack: Error().stack, 43 }); 44 } 45 46 // Tell the main thread we are done with the tests. 47 function done() { 48 console.log("done()"); 49 self.postMessage({ 50 type: "done", 51 }); 52 }