| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyrightdd | 8 * * Redistributions of source code must retain the above copyrightdd |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. | 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
| 17 * | 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | |
| 31 /** | 30 /** |
| 32 * @constructor | 31 * @unrestricted |
| 33 * @param {function(string, *)} eventHandler | |
| 34 * @extends {WebInspector.Object} | |
| 35 */ | 32 */ |
| 36 WebInspector.HeapSnapshotWorkerProxy = function(eventHandler) | 33 WebInspector.HeapSnapshotWorkerProxy = class extends WebInspector.Object { |
| 37 { | 34 /** |
| 35 * @param {function(string, *)} eventHandler |
| 36 */ |
| 37 constructor(eventHandler) { |
| 38 super(); |
| 38 this._eventHandler = eventHandler; | 39 this._eventHandler = eventHandler; |
| 39 this._nextObjectId = 1; | 40 this._nextObjectId = 1; |
| 40 this._nextCallId = 1; | 41 this._nextCallId = 1; |
| 41 /** @type {!Map<number, function(*)>} */ | 42 /** @type {!Map<number, function(*)>} */ |
| 42 this._callbacks = new Map(); | 43 this._callbacks = new Map(); |
| 43 /** @type {!Set<number>} */ | 44 /** @type {!Set<number>} */ |
| 44 this._previousCallbacks = new Set(); | 45 this._previousCallbacks = new Set(); |
| 45 this._worker = new WebInspector.Worker("heap_snapshot_worker"); | 46 this._worker = new WebInspector.Worker('heap_snapshot_worker'); |
| 46 this._worker.onmessage = this._messageReceived.bind(this); | 47 this._worker.onmessage = this._messageReceived.bind(this); |
| 48 } |
| 49 |
| 50 /** |
| 51 * @param {number} profileUid |
| 52 * @param {function(!WebInspector.HeapSnapshotProxy)} snapshotReceivedCallback |
| 53 * @return {!WebInspector.HeapSnapshotLoaderProxy} |
| 54 */ |
| 55 createLoader(profileUid, snapshotReceivedCallback) { |
| 56 var objectId = this._nextObjectId++; |
| 57 var proxy = new WebInspector.HeapSnapshotLoaderProxy(this, objectId, profile
Uid, snapshotReceivedCallback); |
| 58 this._postMessage({ |
| 59 callId: this._nextCallId++, |
| 60 disposition: 'create', |
| 61 objectId: objectId, |
| 62 methodName: 'WebInspector.HeapSnapshotLoader' |
| 63 }); |
| 64 return proxy; |
| 65 } |
| 66 |
| 67 dispose() { |
| 68 this._worker.terminate(); |
| 69 if (this._interval) |
| 70 clearInterval(this._interval); |
| 71 } |
| 72 |
| 73 disposeObject(objectId) { |
| 74 this._postMessage({callId: this._nextCallId++, disposition: 'dispose', objec
tId: objectId}); |
| 75 } |
| 76 |
| 77 evaluateForTest(script, callback) { |
| 78 var callId = this._nextCallId++; |
| 79 this._callbacks.set(callId, callback); |
| 80 this._postMessage({callId: callId, disposition: 'evaluateForTest', source: s
cript}); |
| 81 } |
| 82 |
| 83 /** |
| 84 * @param {?function(...?)} callback |
| 85 * @param {string} objectId |
| 86 * @param {string} methodName |
| 87 * @param {function(new:T, ...?)} proxyConstructor |
| 88 * @return {?Object} |
| 89 * @template T |
| 90 */ |
| 91 callFactoryMethod(callback, objectId, methodName, proxyConstructor) { |
| 92 var callId = this._nextCallId++; |
| 93 var methodArguments = Array.prototype.slice.call(arguments, 4); |
| 94 var newObjectId = this._nextObjectId++; |
| 95 |
| 96 /** |
| 97 * @this {WebInspector.HeapSnapshotWorkerProxy} |
| 98 */ |
| 99 function wrapCallback(remoteResult) { |
| 100 callback(remoteResult ? new proxyConstructor(this, newObjectId) : null); |
| 101 } |
| 102 |
| 103 if (callback) { |
| 104 this._callbacks.set(callId, wrapCallback.bind(this)); |
| 105 this._postMessage({ |
| 106 callId: callId, |
| 107 disposition: 'factory', |
| 108 objectId: objectId, |
| 109 methodName: methodName, |
| 110 methodArguments: methodArguments, |
| 111 newObjectId: newObjectId |
| 112 }); |
| 113 return null; |
| 114 } else { |
| 115 this._postMessage({ |
| 116 callId: callId, |
| 117 disposition: 'factory', |
| 118 objectId: objectId, |
| 119 methodName: methodName, |
| 120 methodArguments: methodArguments, |
| 121 newObjectId: newObjectId |
| 122 }); |
| 123 return new proxyConstructor(this, newObjectId); |
| 124 } |
| 125 } |
| 126 |
| 127 /** |
| 128 * @param {function(*)} callback |
| 129 * @param {string} objectId |
| 130 * @param {string} methodName |
| 131 */ |
| 132 callMethod(callback, objectId, methodName) { |
| 133 var callId = this._nextCallId++; |
| 134 var methodArguments = Array.prototype.slice.call(arguments, 3); |
| 135 if (callback) |
| 136 this._callbacks.set(callId, callback); |
| 137 this._postMessage({ |
| 138 callId: callId, |
| 139 disposition: 'method', |
| 140 objectId: objectId, |
| 141 methodName: methodName, |
| 142 methodArguments: methodArguments |
| 143 }); |
| 144 } |
| 145 |
| 146 startCheckingForLongRunningCalls() { |
| 147 if (this._interval) |
| 148 return; |
| 149 this._checkLongRunningCalls(); |
| 150 this._interval = setInterval(this._checkLongRunningCalls.bind(this), 300); |
| 151 } |
| 152 |
| 153 _checkLongRunningCalls() { |
| 154 for (var callId of this._previousCallbacks) |
| 155 if (!this._callbacks.has(callId)) |
| 156 this._previousCallbacks.delete(callId); |
| 157 var hasLongRunningCalls = !!this._previousCallbacks.size; |
| 158 this.dispatchEventToListeners('wait', hasLongRunningCalls); |
| 159 for (var callId of this._callbacks.keysArray()) |
| 160 this._previousCallbacks.add(callId); |
| 161 } |
| 162 |
| 163 /** |
| 164 * @param {!MessageEvent} event |
| 165 */ |
| 166 _messageReceived(event) { |
| 167 var data = event.data; |
| 168 if (data.eventName) { |
| 169 if (this._eventHandler) |
| 170 this._eventHandler(data.eventName, data.data); |
| 171 return; |
| 172 } |
| 173 if (data.error) { |
| 174 if (data.errorMethodName) |
| 175 WebInspector.console.error(WebInspector.UIString( |
| 176 'An error occurred when a call to method \'%s\' was requested', data
.errorMethodName)); |
| 177 WebInspector.console.error(data['errorCallStack']); |
| 178 this._callbacks.delete(data.callId); |
| 179 return; |
| 180 } |
| 181 if (!this._callbacks.has(data.callId)) |
| 182 return; |
| 183 var callback = this._callbacks.get(data.callId); |
| 184 this._callbacks.delete(data.callId); |
| 185 callback(data.result); |
| 186 } |
| 187 |
| 188 _postMessage(message) { |
| 189 this._worker.postMessage(message); |
| 190 } |
| 47 }; | 191 }; |
| 48 | 192 |
| 49 WebInspector.HeapSnapshotWorkerProxy.prototype = { | 193 /** |
| 194 * @unrestricted |
| 195 */ |
| 196 WebInspector.HeapSnapshotProxyObject = class { |
| 197 /** |
| 198 * @param {!WebInspector.HeapSnapshotWorkerProxy} worker |
| 199 * @param {number} objectId |
| 200 */ |
| 201 constructor(worker, objectId) { |
| 202 this._worker = worker; |
| 203 this._objectId = objectId; |
| 204 } |
| 205 |
| 206 /** |
| 207 * @param {string} workerMethodName |
| 208 * @param {!Array.<*>} args |
| 209 */ |
| 210 _callWorker(workerMethodName, args) { |
| 211 args.splice(1, 0, this._objectId); |
| 212 return this._worker[workerMethodName].apply(this._worker, args); |
| 213 } |
| 214 |
| 215 dispose() { |
| 216 this._worker.disposeObject(this._objectId); |
| 217 } |
| 218 |
| 219 disposeWorker() { |
| 220 this._worker.dispose(); |
| 221 } |
| 222 |
| 223 /** |
| 224 * @param {?function(...?)} callback |
| 225 * @param {string} methodName |
| 226 * @param {function (new:T, ...?)} proxyConstructor |
| 227 * @param {...*} var_args |
| 228 * @return {!T} |
| 229 * @template T |
| 230 */ |
| 231 callFactoryMethod(callback, methodName, proxyConstructor, var_args) { |
| 232 return this._callWorker('callFactoryMethod', Array.prototype.slice.call(argu
ments, 0)); |
| 233 } |
| 234 |
| 235 /** |
| 236 * @param {function(T)|undefined} callback |
| 237 * @param {string} methodName |
| 238 * @param {...*} var_args |
| 239 * @return {*} |
| 240 * @template T |
| 241 */ |
| 242 callMethod(callback, methodName, var_args) { |
| 243 return this._callWorker('callMethod', Array.prototype.slice.call(arguments,
0)); |
| 244 } |
| 245 |
| 246 /** |
| 247 * @param {string} methodName |
| 248 * @param {...*} var_args |
| 249 * @return {!Promise.<?T>} |
| 250 * @template T |
| 251 */ |
| 252 _callMethodPromise(methodName, var_args) { |
| 50 /** | 253 /** |
| 51 * @param {number} profileUid | 254 * @param {!Array.<*>} args |
| 52 * @param {function(!WebInspector.HeapSnapshotProxy)} snapshotReceivedCallba
ck | 255 * @param {function(?T)} fulfill |
| 53 * @return {!WebInspector.HeapSnapshotLoaderProxy} | 256 * @this {WebInspector.HeapSnapshotProxyObject} |
| 54 */ | |
| 55 createLoader: function(profileUid, snapshotReceivedCallback) | |
| 56 { | |
| 57 var objectId = this._nextObjectId++; | |
| 58 var proxy = new WebInspector.HeapSnapshotLoaderProxy(this, objectId, pro
fileUid, snapshotReceivedCallback); | |
| 59 this._postMessage({callId: this._nextCallId++, disposition: "create", ob
jectId: objectId, methodName: "WebInspector.HeapSnapshotLoader"}); | |
| 60 return proxy; | |
| 61 }, | |
| 62 | |
| 63 dispose: function() | |
| 64 { | |
| 65 this._worker.terminate(); | |
| 66 if (this._interval) | |
| 67 clearInterval(this._interval); | |
| 68 }, | |
| 69 | |
| 70 disposeObject: function(objectId) | |
| 71 { | |
| 72 this._postMessage({callId: this._nextCallId++, disposition: "dispose", o
bjectId: objectId}); | |
| 73 }, | |
| 74 | |
| 75 evaluateForTest: function(script, callback) | |
| 76 { | |
| 77 var callId = this._nextCallId++; | |
| 78 this._callbacks.set(callId, callback); | |
| 79 this._postMessage({callId: callId, disposition: "evaluateForTest", sourc
e: script}); | |
| 80 }, | |
| 81 | |
| 82 /** | |
| 83 * @param {?function(...?)} callback | |
| 84 * @param {string} objectId | |
| 85 * @param {string} methodName | |
| 86 * @param {function(new:T, ...?)} proxyConstructor | |
| 87 * @return {?Object} | |
| 88 * @template T | 257 * @template T |
| 89 */ | 258 */ |
| 90 callFactoryMethod: function(callback, objectId, methodName, proxyConstructor
) | 259 function action(args, fulfill) { |
| 91 { | 260 this._callWorker('callMethod', [fulfill].concat(args)); |
| 92 var callId = this._nextCallId++; | 261 } |
| 93 var methodArguments = Array.prototype.slice.call(arguments, 4); | 262 return new Promise(action.bind(this, Array.prototype.slice.call(arguments)))
; |
| 94 var newObjectId = this._nextObjectId++; | 263 } |
| 95 | |
| 96 /** | |
| 97 * @this {WebInspector.HeapSnapshotWorkerProxy} | |
| 98 */ | |
| 99 function wrapCallback(remoteResult) | |
| 100 { | |
| 101 callback(remoteResult ? new proxyConstructor(this, newObjectId) : nu
ll); | |
| 102 } | |
| 103 | |
| 104 if (callback) { | |
| 105 this._callbacks.set(callId, wrapCallback.bind(this)); | |
| 106 this._postMessage({callId: callId, disposition: "factory", objectId:
objectId, methodName: methodName, methodArguments: methodArguments, newObjectId
: newObjectId}); | |
| 107 return null; | |
| 108 } else { | |
| 109 this._postMessage({callId: callId, disposition: "factory", objectId:
objectId, methodName: methodName, methodArguments: methodArguments, newObjectId
: newObjectId}); | |
| 110 return new proxyConstructor(this, newObjectId); | |
| 111 } | |
| 112 }, | |
| 113 | |
| 114 /** | |
| 115 * @param {function(*)} callback | |
| 116 * @param {string} objectId | |
| 117 * @param {string} methodName | |
| 118 */ | |
| 119 callMethod: function(callback, objectId, methodName) | |
| 120 { | |
| 121 var callId = this._nextCallId++; | |
| 122 var methodArguments = Array.prototype.slice.call(arguments, 3); | |
| 123 if (callback) | |
| 124 this._callbacks.set(callId, callback); | |
| 125 this._postMessage({callId: callId, disposition: "method", objectId: obje
ctId, methodName: methodName, methodArguments: methodArguments}); | |
| 126 }, | |
| 127 | |
| 128 startCheckingForLongRunningCalls: function() | |
| 129 { | |
| 130 if (this._interval) | |
| 131 return; | |
| 132 this._checkLongRunningCalls(); | |
| 133 this._interval = setInterval(this._checkLongRunningCalls.bind(this), 300
); | |
| 134 }, | |
| 135 | |
| 136 _checkLongRunningCalls: function() | |
| 137 { | |
| 138 for (var callId of this._previousCallbacks) | |
| 139 if (!this._callbacks.has(callId)) | |
| 140 this._previousCallbacks.delete(callId); | |
| 141 var hasLongRunningCalls = !!this._previousCallbacks.size; | |
| 142 this.dispatchEventToListeners("wait", hasLongRunningCalls); | |
| 143 for (var callId of this._callbacks.keysArray()) | |
| 144 this._previousCallbacks.add(callId); | |
| 145 }, | |
| 146 | |
| 147 /** | |
| 148 * @param {!MessageEvent} event | |
| 149 */ | |
| 150 _messageReceived: function(event) | |
| 151 { | |
| 152 var data = event.data; | |
| 153 if (data.eventName) { | |
| 154 if (this._eventHandler) | |
| 155 this._eventHandler(data.eventName, data.data); | |
| 156 return; | |
| 157 } | |
| 158 if (data.error) { | |
| 159 if (data.errorMethodName) | |
| 160 WebInspector.console.error(WebInspector.UIString("An error occur
red when a call to method '%s' was requested", data.errorMethodName)); | |
| 161 WebInspector.console.error(data["errorCallStack"]); | |
| 162 this._callbacks.delete(data.callId); | |
| 163 return; | |
| 164 } | |
| 165 if (!this._callbacks.has(data.callId)) | |
| 166 return; | |
| 167 var callback = this._callbacks.get(data.callId); | |
| 168 this._callbacks.delete(data.callId); | |
| 169 callback(data.result); | |
| 170 }, | |
| 171 | |
| 172 _postMessage: function(message) | |
| 173 { | |
| 174 this._worker.postMessage(message); | |
| 175 }, | |
| 176 | |
| 177 __proto__: WebInspector.Object.prototype | |
| 178 }; | 264 }; |
| 179 | 265 |
| 180 | |
| 181 /** | 266 /** |
| 182 * @constructor | 267 * @implements {WebInspector.OutputStream} |
| 183 * @param {!WebInspector.HeapSnapshotWorkerProxy} worker | 268 * @unrestricted |
| 184 * @param {number} objectId | |
| 185 */ | 269 */ |
| 186 WebInspector.HeapSnapshotProxyObject = function(worker, objectId) | 270 WebInspector.HeapSnapshotLoaderProxy = class extends WebInspector.HeapSnapshotPr
oxyObject { |
| 187 { | 271 /** |
| 188 this._worker = worker; | 272 * @param {!WebInspector.HeapSnapshotWorkerProxy} worker |
| 189 this._objectId = objectId; | 273 * @param {number} objectId |
| 190 }; | 274 * @param {number} profileUid |
| 191 | 275 * @param {function(!WebInspector.HeapSnapshotProxy)} snapshotReceivedCallback |
| 192 WebInspector.HeapSnapshotProxyObject.prototype = { | 276 */ |
| 193 /** | 277 constructor(worker, objectId, profileUid, snapshotReceivedCallback) { |
| 194 * @param {string} workerMethodName | 278 super(worker, objectId); |
| 195 * @param {!Array.<*>} args | |
| 196 */ | |
| 197 _callWorker: function(workerMethodName, args) | |
| 198 { | |
| 199 args.splice(1, 0, this._objectId); | |
| 200 return this._worker[workerMethodName].apply(this._worker, args); | |
| 201 }, | |
| 202 | |
| 203 dispose: function() | |
| 204 { | |
| 205 this._worker.disposeObject(this._objectId); | |
| 206 }, | |
| 207 | |
| 208 disposeWorker: function() | |
| 209 { | |
| 210 this._worker.dispose(); | |
| 211 }, | |
| 212 | |
| 213 /** | |
| 214 * @param {?function(...?)} callback | |
| 215 * @param {string} methodName | |
| 216 * @param {function (new:T, ...?)} proxyConstructor | |
| 217 * @param {...*} var_args | |
| 218 * @return {!T} | |
| 219 * @template T | |
| 220 */ | |
| 221 callFactoryMethod: function(callback, methodName, proxyConstructor, var_args
) | |
| 222 { | |
| 223 return this._callWorker("callFactoryMethod", Array.prototype.slice.call(
arguments, 0)); | |
| 224 }, | |
| 225 | |
| 226 /** | |
| 227 * @param {function(T)|undefined} callback | |
| 228 * @param {string} methodName | |
| 229 * @param {...*} var_args | |
| 230 * @return {*} | |
| 231 * @template T | |
| 232 */ | |
| 233 callMethod: function(callback, methodName, var_args) | |
| 234 { | |
| 235 return this._callWorker("callMethod", Array.prototype.slice.call(argumen
ts, 0)); | |
| 236 }, | |
| 237 | |
| 238 /** | |
| 239 * @param {string} methodName | |
| 240 * @param {...*} var_args | |
| 241 * @return {!Promise.<?T>} | |
| 242 * @template T | |
| 243 */ | |
| 244 _callMethodPromise: function(methodName, var_args) | |
| 245 { | |
| 246 /** | |
| 247 * @param {!Array.<*>} args | |
| 248 * @param {function(?T)} fulfill | |
| 249 * @this {WebInspector.HeapSnapshotProxyObject} | |
| 250 * @template T | |
| 251 */ | |
| 252 function action(args, fulfill) | |
| 253 { | |
| 254 this._callWorker("callMethod", [fulfill].concat(args)); | |
| 255 } | |
| 256 return new Promise(action.bind(this, Array.prototype.slice.call(argument
s))); | |
| 257 } | |
| 258 }; | |
| 259 | |
| 260 /** | |
| 261 * @constructor | |
| 262 * @extends {WebInspector.HeapSnapshotProxyObject} | |
| 263 * @implements {WebInspector.OutputStream} | |
| 264 * @param {!WebInspector.HeapSnapshotWorkerProxy} worker | |
| 265 * @param {number} objectId | |
| 266 * @param {number} profileUid | |
| 267 * @param {function(!WebInspector.HeapSnapshotProxy)} snapshotReceivedCallback | |
| 268 */ | |
| 269 WebInspector.HeapSnapshotLoaderProxy = function(worker, objectId, profileUid, sn
apshotReceivedCallback) | |
| 270 { | |
| 271 WebInspector.HeapSnapshotProxyObject.call(this, worker, objectId); | |
| 272 this._profileUid = profileUid; | 279 this._profileUid = profileUid; |
| 273 this._snapshotReceivedCallback = snapshotReceivedCallback; | 280 this._snapshotReceivedCallback = snapshotReceivedCallback; |
| 281 } |
| 282 |
| 283 /** |
| 284 * @override |
| 285 * @param {string} chunk |
| 286 * @param {function(!WebInspector.OutputStream)=} callback |
| 287 */ |
| 288 write(chunk, callback) { |
| 289 this.callMethod(callback, 'write', chunk); |
| 290 } |
| 291 |
| 292 /** |
| 293 * @override |
| 294 * @param {function()=} callback |
| 295 */ |
| 296 close(callback) { |
| 297 /** |
| 298 * @this {WebInspector.HeapSnapshotLoaderProxy} |
| 299 */ |
| 300 function buildSnapshot() { |
| 301 if (callback) |
| 302 callback(); |
| 303 this.callFactoryMethod(updateStaticData.bind(this), 'buildSnapshot', WebIn
spector.HeapSnapshotProxy); |
| 304 } |
| 305 |
| 306 /** |
| 307 * @param {!WebInspector.HeapSnapshotProxy} snapshotProxy |
| 308 * @this {WebInspector.HeapSnapshotLoaderProxy} |
| 309 */ |
| 310 function updateStaticData(snapshotProxy) { |
| 311 this.dispose(); |
| 312 snapshotProxy.setProfileUid(this._profileUid); |
| 313 snapshotProxy.updateStaticData(this._snapshotReceivedCallback.bind(this)); |
| 314 } |
| 315 |
| 316 this.callMethod(buildSnapshot.bind(this), 'close'); |
| 317 } |
| 274 }; | 318 }; |
| 275 | 319 |
| 276 WebInspector.HeapSnapshotLoaderProxy.prototype = { | |
| 277 /** | |
| 278 * @override | |
| 279 * @param {string} chunk | |
| 280 * @param {function(!WebInspector.OutputStream)=} callback | |
| 281 */ | |
| 282 write: function(chunk, callback) | |
| 283 { | |
| 284 this.callMethod(callback, "write", chunk); | |
| 285 }, | |
| 286 | |
| 287 /** | |
| 288 * @override | |
| 289 * @param {function()=} callback | |
| 290 */ | |
| 291 close: function(callback) | |
| 292 { | |
| 293 /** | |
| 294 * @this {WebInspector.HeapSnapshotLoaderProxy} | |
| 295 */ | |
| 296 function buildSnapshot() | |
| 297 { | |
| 298 if (callback) | |
| 299 callback(); | |
| 300 this.callFactoryMethod(updateStaticData.bind(this), "buildSnapshot",
WebInspector.HeapSnapshotProxy); | |
| 301 } | |
| 302 | |
| 303 /** | |
| 304 * @param {!WebInspector.HeapSnapshotProxy} snapshotProxy | |
| 305 * @this {WebInspector.HeapSnapshotLoaderProxy} | |
| 306 */ | |
| 307 function updateStaticData(snapshotProxy) | |
| 308 { | |
| 309 this.dispose(); | |
| 310 snapshotProxy.setProfileUid(this._profileUid); | |
| 311 snapshotProxy.updateStaticData(this._snapshotReceivedCallback.bind(t
his)); | |
| 312 } | |
| 313 | |
| 314 this.callMethod(buildSnapshot.bind(this), "close"); | |
| 315 }, | |
| 316 | |
| 317 __proto__: WebInspector.HeapSnapshotProxyObject.prototype | |
| 318 }; | |
| 319 | |
| 320 | |
| 321 /** | 320 /** |
| 322 * @constructor | 321 * @unrestricted |
| 323 * @extends {WebInspector.HeapSnapshotProxyObject} | |
| 324 * @param {!WebInspector.HeapSnapshotWorkerProxy} worker | |
| 325 * @param {number} objectId | |
| 326 */ | 322 */ |
| 327 WebInspector.HeapSnapshotProxy = function(worker, objectId) | 323 WebInspector.HeapSnapshotProxy = class extends WebInspector.HeapSnapshotProxyObj
ect { |
| 328 { | 324 /** |
| 329 WebInspector.HeapSnapshotProxyObject.call(this, worker, objectId); | 325 * @param {!WebInspector.HeapSnapshotWorkerProxy} worker |
| 326 * @param {number} objectId |
| 327 */ |
| 328 constructor(worker, objectId) { |
| 329 super(worker, objectId); |
| 330 /** @type {?WebInspector.HeapSnapshotCommon.StaticData} */ | 330 /** @type {?WebInspector.HeapSnapshotCommon.StaticData} */ |
| 331 this._staticData = null; | 331 this._staticData = null; |
| 332 } |
| 333 |
| 334 /** |
| 335 * @param {!WebInspector.HeapSnapshotCommon.SearchConfig} searchConfig |
| 336 * @param {!WebInspector.HeapSnapshotCommon.NodeFilter} filter |
| 337 * @return {!Promise<!Array<number>>} |
| 338 */ |
| 339 search(searchConfig, filter) { |
| 340 return this._callMethodPromise('search', searchConfig, filter); |
| 341 } |
| 342 |
| 343 /** |
| 344 * @param {!WebInspector.HeapSnapshotCommon.NodeFilter} filter |
| 345 * @param {function(!Object.<string, !WebInspector.HeapSnapshotCommon.Aggregat
e>)} callback |
| 346 */ |
| 347 aggregatesWithFilter(filter, callback) { |
| 348 this.callMethod(callback, 'aggregatesWithFilter', filter); |
| 349 } |
| 350 |
| 351 aggregatesForDiff(callback) { |
| 352 this.callMethod(callback, 'aggregatesForDiff'); |
| 353 } |
| 354 |
| 355 calculateSnapshotDiff(baseSnapshotId, baseSnapshotAggregates, callback) { |
| 356 this.callMethod(callback, 'calculateSnapshotDiff', baseSnapshotId, baseSnaps
hotAggregates); |
| 357 } |
| 358 |
| 359 /** |
| 360 * @param {number} snapshotObjectId |
| 361 * @return {!Promise<?string>} |
| 362 */ |
| 363 nodeClassName(snapshotObjectId) { |
| 364 return this._callMethodPromise('nodeClassName', snapshotObjectId); |
| 365 } |
| 366 |
| 367 /** |
| 368 * @param {number} nodeIndex |
| 369 * @return {!WebInspector.HeapSnapshotProviderProxy} |
| 370 */ |
| 371 createEdgesProvider(nodeIndex) { |
| 372 return this.callFactoryMethod(null, 'createEdgesProvider', WebInspector.Heap
SnapshotProviderProxy, nodeIndex); |
| 373 } |
| 374 |
| 375 /** |
| 376 * @param {number} nodeIndex |
| 377 * @return {!WebInspector.HeapSnapshotProviderProxy} |
| 378 */ |
| 379 createRetainingEdgesProvider(nodeIndex) { |
| 380 return this.callFactoryMethod( |
| 381 null, 'createRetainingEdgesProvider', WebInspector.HeapSnapshotProviderP
roxy, nodeIndex); |
| 382 } |
| 383 |
| 384 /** |
| 385 * @param {string} baseSnapshotId |
| 386 * @param {string} className |
| 387 * @return {?WebInspector.HeapSnapshotProviderProxy} |
| 388 */ |
| 389 createAddedNodesProvider(baseSnapshotId, className) { |
| 390 return this.callFactoryMethod( |
| 391 null, 'createAddedNodesProvider', WebInspector.HeapSnapshotProviderProxy
, baseSnapshotId, className); |
| 392 } |
| 393 |
| 394 /** |
| 395 * @param {!Array.<number>} nodeIndexes |
| 396 * @return {?WebInspector.HeapSnapshotProviderProxy} |
| 397 */ |
| 398 createDeletedNodesProvider(nodeIndexes) { |
| 399 return this.callFactoryMethod( |
| 400 null, 'createDeletedNodesProvider', WebInspector.HeapSnapshotProviderPro
xy, nodeIndexes); |
| 401 } |
| 402 |
| 403 /** |
| 404 * @param {function(*):boolean} filter |
| 405 * @return {?WebInspector.HeapSnapshotProviderProxy} |
| 406 */ |
| 407 createNodesProvider(filter) { |
| 408 return this.callFactoryMethod(null, 'createNodesProvider', WebInspector.Heap
SnapshotProviderProxy, filter); |
| 409 } |
| 410 |
| 411 /** |
| 412 * @param {string} className |
| 413 * @param {!WebInspector.HeapSnapshotCommon.NodeFilter} nodeFilter |
| 414 * @return {?WebInspector.HeapSnapshotProviderProxy} |
| 415 */ |
| 416 createNodesProviderForClass(className, nodeFilter) { |
| 417 return this.callFactoryMethod( |
| 418 null, 'createNodesProviderForClass', WebInspector.HeapSnapshotProviderPr
oxy, className, nodeFilter); |
| 419 } |
| 420 |
| 421 allocationTracesTops(callback) { |
| 422 this.callMethod(callback, 'allocationTracesTops'); |
| 423 } |
| 424 |
| 425 /** |
| 426 * @param {number} nodeId |
| 427 * @param {function(!WebInspector.HeapSnapshotCommon.AllocationNodeCallers)} c
allback |
| 428 */ |
| 429 allocationNodeCallers(nodeId, callback) { |
| 430 this.callMethod(callback, 'allocationNodeCallers', nodeId); |
| 431 } |
| 432 |
| 433 /** |
| 434 * @param {number} nodeIndex |
| 435 * @param {function(?Array.<!WebInspector.HeapSnapshotCommon.AllocationStackFr
ame>)} callback |
| 436 */ |
| 437 allocationStack(nodeIndex, callback) { |
| 438 this.callMethod(callback, 'allocationStack', nodeIndex); |
| 439 } |
| 440 |
| 441 /** |
| 442 * @override |
| 443 */ |
| 444 dispose() { |
| 445 throw new Error('Should never be called'); |
| 446 } |
| 447 |
| 448 get nodeCount() { |
| 449 return this._staticData.nodeCount; |
| 450 } |
| 451 |
| 452 get rootNodeIndex() { |
| 453 return this._staticData.rootNodeIndex; |
| 454 } |
| 455 |
| 456 updateStaticData(callback) { |
| 457 /** |
| 458 * @param {!WebInspector.HeapSnapshotCommon.StaticData} staticData |
| 459 * @this {WebInspector.HeapSnapshotProxy} |
| 460 */ |
| 461 function dataReceived(staticData) { |
| 462 this._staticData = staticData; |
| 463 callback(this); |
| 464 } |
| 465 this.callMethod(dataReceived.bind(this), 'updateStaticData'); |
| 466 } |
| 467 |
| 468 /** |
| 469 * @return {!Promise.<!WebInspector.HeapSnapshotCommon.Statistics>} |
| 470 */ |
| 471 getStatistics() { |
| 472 return this._callMethodPromise('getStatistics'); |
| 473 } |
| 474 |
| 475 /** |
| 476 * @return {!Promise.<?WebInspector.HeapSnapshotCommon.Samples>} |
| 477 */ |
| 478 getSamples() { |
| 479 return this._callMethodPromise('getSamples'); |
| 480 } |
| 481 |
| 482 get totalSize() { |
| 483 return this._staticData.totalSize; |
| 484 } |
| 485 |
| 486 get uid() { |
| 487 return this._profileUid; |
| 488 } |
| 489 |
| 490 setProfileUid(profileUid) { |
| 491 this._profileUid = profileUid; |
| 492 } |
| 493 |
| 494 /** |
| 495 * @return {number} |
| 496 */ |
| 497 maxJSObjectId() { |
| 498 return this._staticData.maxJSObjectId; |
| 499 } |
| 332 }; | 500 }; |
| 333 | 501 |
| 334 WebInspector.HeapSnapshotProxy.prototype = { | 502 /** |
| 335 /** | 503 * @implements {WebInspector.HeapSnapshotGridNode.ChildrenProvider} |
| 336 * @param {!WebInspector.HeapSnapshotCommon.SearchConfig} searchConfig | 504 * @unrestricted |
| 337 * @param {!WebInspector.HeapSnapshotCommon.NodeFilter} filter | 505 */ |
| 338 * @return {!Promise<!Array<number>>} | 506 WebInspector.HeapSnapshotProviderProxy = class extends WebInspector.HeapSnapshot
ProxyObject { |
| 339 */ | 507 /** |
| 340 search: function(searchConfig, filter) | 508 * @param {!WebInspector.HeapSnapshotWorkerProxy} worker |
| 341 { | 509 * @param {number} objectId |
| 342 return this._callMethodPromise("search", searchConfig, filter); | 510 */ |
| 343 }, | 511 constructor(worker, objectId) { |
| 344 | 512 super(worker, objectId); |
| 345 /** | 513 } |
| 346 * @param {!WebInspector.HeapSnapshotCommon.NodeFilter} filter | 514 |
| 347 * @param {function(!Object.<string, !WebInspector.HeapSnapshotCommon.Aggreg
ate>)} callback | 515 /** |
| 348 */ | 516 * @override |
| 349 aggregatesWithFilter: function(filter, callback) | 517 * @param {number} snapshotObjectId |
| 350 { | 518 * @return {!Promise<number>} |
| 351 this.callMethod(callback, "aggregatesWithFilter", filter); | 519 */ |
| 352 }, | 520 nodePosition(snapshotObjectId) { |
| 353 | 521 return this._callMethodPromise('nodePosition', snapshotObjectId); |
| 354 aggregatesForDiff: function(callback) | 522 } |
| 355 { | 523 |
| 356 this.callMethod(callback, "aggregatesForDiff"); | 524 /** |
| 357 }, | 525 * @override |
| 358 | 526 * @param {function(boolean)} callback |
| 359 calculateSnapshotDiff: function(baseSnapshotId, baseSnapshotAggregates, call
back) | 527 */ |
| 360 { | 528 isEmpty(callback) { |
| 361 this.callMethod(callback, "calculateSnapshotDiff", baseSnapshotId, baseS
napshotAggregates); | 529 this.callMethod(callback, 'isEmpty'); |
| 362 }, | 530 } |
| 363 | 531 |
| 364 /** | 532 /** |
| 365 * @param {number} snapshotObjectId | 533 * @override |
| 366 * @return {!Promise<?string>} | 534 * @param {number} startPosition |
| 367 */ | 535 * @param {number} endPosition |
| 368 nodeClassName: function(snapshotObjectId) | 536 * @param {function(!WebInspector.HeapSnapshotCommon.ItemsRange)} callback |
| 369 { | 537 */ |
| 370 return this._callMethodPromise("nodeClassName", snapshotObjectId); | 538 serializeItemsRange(startPosition, endPosition, callback) { |
| 371 }, | 539 this.callMethod(callback, 'serializeItemsRange', startPosition, endPosition)
; |
| 372 | 540 } |
| 373 /** | 541 |
| 374 * @param {number} nodeIndex | 542 /** |
| 375 * @return {!WebInspector.HeapSnapshotProviderProxy} | 543 * @override |
| 376 */ | 544 * @param {!WebInspector.HeapSnapshotCommon.ComparatorConfig} comparator |
| 377 createEdgesProvider: function(nodeIndex) | 545 * @return {!Promise<?>} |
| 378 { | 546 */ |
| 379 return this.callFactoryMethod(null, "createEdgesProvider", WebInspector.
HeapSnapshotProviderProxy, nodeIndex); | 547 sortAndRewind(comparator) { |
| 380 }, | 548 return this._callMethodPromise('sortAndRewind', comparator); |
| 381 | 549 } |
| 382 /** | |
| 383 * @param {number} nodeIndex | |
| 384 * @return {!WebInspector.HeapSnapshotProviderProxy} | |
| 385 */ | |
| 386 createRetainingEdgesProvider: function(nodeIndex) | |
| 387 { | |
| 388 return this.callFactoryMethod(null, "createRetainingEdgesProvider", WebI
nspector.HeapSnapshotProviderProxy, nodeIndex); | |
| 389 }, | |
| 390 | |
| 391 /** | |
| 392 * @param {string} baseSnapshotId | |
| 393 * @param {string} className | |
| 394 * @return {?WebInspector.HeapSnapshotProviderProxy} | |
| 395 */ | |
| 396 createAddedNodesProvider: function(baseSnapshotId, className) | |
| 397 { | |
| 398 return this.callFactoryMethod(null, "createAddedNodesProvider", WebInspe
ctor.HeapSnapshotProviderProxy, baseSnapshotId, className); | |
| 399 }, | |
| 400 | |
| 401 /** | |
| 402 * @param {!Array.<number>} nodeIndexes | |
| 403 * @return {?WebInspector.HeapSnapshotProviderProxy} | |
| 404 */ | |
| 405 createDeletedNodesProvider: function(nodeIndexes) | |
| 406 { | |
| 407 return this.callFactoryMethod(null, "createDeletedNodesProvider", WebIns
pector.HeapSnapshotProviderProxy, nodeIndexes); | |
| 408 }, | |
| 409 | |
| 410 /** | |
| 411 * @param {function(*):boolean} filter | |
| 412 * @return {?WebInspector.HeapSnapshotProviderProxy} | |
| 413 */ | |
| 414 createNodesProvider: function(filter) | |
| 415 { | |
| 416 return this.callFactoryMethod(null, "createNodesProvider", WebInspector.
HeapSnapshotProviderProxy, filter); | |
| 417 }, | |
| 418 | |
| 419 /** | |
| 420 * @param {string} className | |
| 421 * @param {!WebInspector.HeapSnapshotCommon.NodeFilter} nodeFilter | |
| 422 * @return {?WebInspector.HeapSnapshotProviderProxy} | |
| 423 */ | |
| 424 createNodesProviderForClass: function(className, nodeFilter) | |
| 425 { | |
| 426 return this.callFactoryMethod(null, "createNodesProviderForClass", WebIn
spector.HeapSnapshotProviderProxy, className, nodeFilter); | |
| 427 }, | |
| 428 | |
| 429 allocationTracesTops: function(callback) | |
| 430 { | |
| 431 this.callMethod(callback, "allocationTracesTops"); | |
| 432 }, | |
| 433 | |
| 434 /** | |
| 435 * @param {number} nodeId | |
| 436 * @param {function(!WebInspector.HeapSnapshotCommon.AllocationNodeCallers)}
callback | |
| 437 */ | |
| 438 allocationNodeCallers: function(nodeId, callback) | |
| 439 { | |
| 440 this.callMethod(callback, "allocationNodeCallers", nodeId); | |
| 441 }, | |
| 442 | |
| 443 /** | |
| 444 * @param {number} nodeIndex | |
| 445 * @param {function(?Array.<!WebInspector.HeapSnapshotCommon.AllocationStack
Frame>)} callback | |
| 446 */ | |
| 447 allocationStack: function(nodeIndex, callback) | |
| 448 { | |
| 449 this.callMethod(callback, "allocationStack", nodeIndex); | |
| 450 }, | |
| 451 | |
| 452 dispose: function() | |
| 453 { | |
| 454 throw new Error("Should never be called"); | |
| 455 }, | |
| 456 | |
| 457 get nodeCount() | |
| 458 { | |
| 459 return this._staticData.nodeCount; | |
| 460 }, | |
| 461 | |
| 462 get rootNodeIndex() | |
| 463 { | |
| 464 return this._staticData.rootNodeIndex; | |
| 465 }, | |
| 466 | |
| 467 updateStaticData: function(callback) | |
| 468 { | |
| 469 /** | |
| 470 * @param {!WebInspector.HeapSnapshotCommon.StaticData} staticData | |
| 471 * @this {WebInspector.HeapSnapshotProxy} | |
| 472 */ | |
| 473 function dataReceived(staticData) | |
| 474 { | |
| 475 this._staticData = staticData; | |
| 476 callback(this); | |
| 477 } | |
| 478 this.callMethod(dataReceived.bind(this), "updateStaticData"); | |
| 479 }, | |
| 480 | |
| 481 /** | |
| 482 * @return {!Promise.<!WebInspector.HeapSnapshotCommon.Statistics>} | |
| 483 */ | |
| 484 getStatistics: function() | |
| 485 { | |
| 486 return this._callMethodPromise("getStatistics"); | |
| 487 }, | |
| 488 | |
| 489 /** | |
| 490 * @return {!Promise.<?WebInspector.HeapSnapshotCommon.Samples>} | |
| 491 */ | |
| 492 getSamples: function() | |
| 493 { | |
| 494 return this._callMethodPromise("getSamples"); | |
| 495 }, | |
| 496 | |
| 497 get totalSize() | |
| 498 { | |
| 499 return this._staticData.totalSize; | |
| 500 }, | |
| 501 | |
| 502 get uid() | |
| 503 { | |
| 504 return this._profileUid; | |
| 505 }, | |
| 506 | |
| 507 setProfileUid: function(profileUid) | |
| 508 { | |
| 509 this._profileUid = profileUid; | |
| 510 }, | |
| 511 | |
| 512 /** | |
| 513 * @return {number} | |
| 514 */ | |
| 515 maxJSObjectId: function() | |
| 516 { | |
| 517 return this._staticData.maxJSObjectId; | |
| 518 }, | |
| 519 | |
| 520 __proto__: WebInspector.HeapSnapshotProxyObject.prototype | |
| 521 }; | 550 }; |
| 522 | |
| 523 | |
| 524 /** | |
| 525 * @constructor | |
| 526 * @extends {WebInspector.HeapSnapshotProxyObject} | |
| 527 * @implements {WebInspector.HeapSnapshotGridNode.ChildrenProvider} | |
| 528 * @param {!WebInspector.HeapSnapshotWorkerProxy} worker | |
| 529 * @param {number} objectId | |
| 530 */ | |
| 531 WebInspector.HeapSnapshotProviderProxy = function(worker, objectId) | |
| 532 { | |
| 533 WebInspector.HeapSnapshotProxyObject.call(this, worker, objectId); | |
| 534 }; | |
| 535 | |
| 536 WebInspector.HeapSnapshotProviderProxy.prototype = { | |
| 537 /** | |
| 538 * @override | |
| 539 * @param {number} snapshotObjectId | |
| 540 * @return {!Promise<number>} | |
| 541 */ | |
| 542 nodePosition: function(snapshotObjectId) | |
| 543 { | |
| 544 return this._callMethodPromise("nodePosition", snapshotObjectId); | |
| 545 }, | |
| 546 | |
| 547 /** | |
| 548 * @override | |
| 549 * @param {function(boolean)} callback | |
| 550 */ | |
| 551 isEmpty: function(callback) | |
| 552 { | |
| 553 this.callMethod(callback, "isEmpty"); | |
| 554 }, | |
| 555 | |
| 556 /** | |
| 557 * @override | |
| 558 * @param {number} startPosition | |
| 559 * @param {number} endPosition | |
| 560 * @param {function(!WebInspector.HeapSnapshotCommon.ItemsRange)} callback | |
| 561 */ | |
| 562 serializeItemsRange: function(startPosition, endPosition, callback) | |
| 563 { | |
| 564 this.callMethod(callback, "serializeItemsRange", startPosition, endPosit
ion); | |
| 565 }, | |
| 566 | |
| 567 /** | |
| 568 * @override | |
| 569 * @param {!WebInspector.HeapSnapshotCommon.ComparatorConfig} comparator | |
| 570 * @return {!Promise<?>} | |
| 571 */ | |
| 572 sortAndRewind: function(comparator) | |
| 573 { | |
| 574 return this._callMethodPromise("sortAndRewind", comparator); | |
| 575 }, | |
| 576 | |
| 577 __proto__: WebInspector.HeapSnapshotProxyObject.prototype | |
| 578 }; | |
| OLD | NEW |