Index: Source/devtools/front_end/profiler/HeapSnapshotProxy.js |
diff --git a/Source/devtools/front_end/profiler/HeapSnapshotProxy.js b/Source/devtools/front_end/profiler/HeapSnapshotProxy.js |
index 5f0324eb7e9091febe46a339f13a2dc9d72f2662..d740895d6892d48f90298decdd022f72e226955d 100644 |
--- a/Source/devtools/front_end/profiler/HeapSnapshotProxy.js |
+++ b/Source/devtools/front_end/profiler/HeapSnapshotProxy.js |
@@ -40,12 +40,24 @@ WebInspector.HeapSnapshotWorkerProxy = function(eventHandler) |
this._nextCallId = 1; |
this._callbacks = []; |
this._previousCallbacks = []; |
- this._worker = Runtime.startWorker("heap_snapshot_worker"); |
- this._worker.onmessage = this._messageReceived.bind(this); |
+ this._pendingWorkerPromise = WorkerRuntime.startWorker("heap_snapshot_worker").then(this._init.bind(this)); |
} |
WebInspector.HeapSnapshotWorkerProxy.prototype = { |
/** |
+ * @param {!Worker} worker |
+ */ |
+ _init: function(worker) |
+ { |
+ this._worker = worker; |
+ if (this._disposed) { |
+ this.dispose(); |
+ return; |
+ } |
+ this._worker.onmessage = this._messageReceived.bind(this); |
+ }, |
+ |
+ /** |
* @param {number} profileUid |
* @param {function(!WebInspector.HeapSnapshotProxy)} snapshotReceivedCallback |
* @return {!WebInspector.HeapSnapshotLoaderProxy} |
@@ -60,7 +72,9 @@ WebInspector.HeapSnapshotWorkerProxy.prototype = { |
dispose: function() |
{ |
- this._worker.terminate(); |
+ this._disposed = true; |
+ if (this._worker) |
+ this._worker.terminate(); |
if (this._interval) |
clearInterval(this._interval); |
}, |
@@ -171,9 +185,22 @@ WebInspector.HeapSnapshotWorkerProxy.prototype = { |
callback(data.result); |
}, |
+ /** |
+ * @param {!Object} message |
+ */ |
_postMessage: function(message) |
{ |
- this._worker.postMessage(message); |
+ this._pendingWorkerPromise.then(postMessage.bind(this)); |
+ |
+ /** |
+ * @this {WebInspector.HeapSnapshotWorkerProxy} |
+ */ |
+ function postMessage() |
+ { |
+ if (this._disposed) |
+ return; |
+ this._worker.postMessage(message); |
+ } |
}, |
__proto__: WebInspector.Object.prototype |
@@ -445,7 +472,7 @@ WebInspector.HeapSnapshotProxy.prototype = { |
}, |
/** |
- * @param {!function(!WebInspector.HeapSnapshotCommon.Statistics):void} callback |
+ * @param {function(!WebInspector.HeapSnapshotCommon.Statistics):void} callback |
*/ |
getStatistics: function(callback) |
{ |