moved to root
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Apple Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
WI.FormatterWorkerProxy = class FormatterWorkerProxy
|
||||
{
|
||||
constructor()
|
||||
{
|
||||
this._formatterWorker = new Worker("Workers/Formatter/FormatterWorker.js");
|
||||
this._formatterWorker.addEventListener("message", this._handleMessage.bind(this));
|
||||
|
||||
this._nextCallId = 1;
|
||||
this._callbacks = new Map;
|
||||
}
|
||||
|
||||
// Static
|
||||
|
||||
static singleton()
|
||||
{
|
||||
if (!FormatterWorkerProxy.instance)
|
||||
FormatterWorkerProxy.instance = new FormatterWorkerProxy;
|
||||
return FormatterWorkerProxy.instance;
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
formatJavaScript(sourceText, isModule, indentString, includeSourceMapData)
|
||||
{
|
||||
this.performAction("formatJavaScript", ...arguments);
|
||||
}
|
||||
|
||||
formatCSS(sourceText, indentString, includeSourceMapData)
|
||||
{
|
||||
this.performAction("formatCSS", ...arguments);
|
||||
}
|
||||
|
||||
formatHTML(sourceText, indentString, includeSourceMapData)
|
||||
{
|
||||
this.performAction("formatHTML", ...arguments);
|
||||
}
|
||||
|
||||
formatXML(sourceText, indentString, includeSourceMapData)
|
||||
{
|
||||
this.performAction("formatXML", ...arguments);
|
||||
}
|
||||
|
||||
// Public
|
||||
|
||||
performAction(actionName)
|
||||
{
|
||||
let callId = this._nextCallId++;
|
||||
let callback = arguments[arguments.length - 1];
|
||||
let actionArguments = Array.prototype.slice.call(arguments, 1, arguments.length - 1);
|
||||
|
||||
console.assert(typeof actionName === "string", "performAction should always have an actionName");
|
||||
console.assert(typeof callback === "function", "performAction should always have a callback");
|
||||
|
||||
this._callbacks.set(callId, callback);
|
||||
this._postMessage({callId, actionName, actionArguments});
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
_postMessage()
|
||||
{
|
||||
this._formatterWorker.postMessage(...arguments);
|
||||
}
|
||||
|
||||
_handleMessage(event)
|
||||
{
|
||||
let data = event.data;
|
||||
|
||||
// Action response.
|
||||
if (data.callId) {
|
||||
let callback = this._callbacks.get(data.callId);
|
||||
this._callbacks.delete(data.callId);
|
||||
callback(data.result);
|
||||
return;
|
||||
}
|
||||
|
||||
console.error("Unexpected FormatterWorker message", data);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Apple Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
WI.HeapSnapshotDiffProxy = class HeapSnapshotDiffProxy extends WI.Object
|
||||
{
|
||||
constructor(snapshotDiffObjectId, snapshot1, snapshot2, totalSize, totalObjectCount, categories)
|
||||
{
|
||||
super();
|
||||
|
||||
this._proxyObjectId = snapshotDiffObjectId;
|
||||
|
||||
console.assert(snapshot1 instanceof WI.HeapSnapshotProxy);
|
||||
console.assert(snapshot2 instanceof WI.HeapSnapshotProxy);
|
||||
|
||||
this._snapshot1 = snapshot1;
|
||||
this._snapshot2 = snapshot2;
|
||||
this._totalSize = totalSize;
|
||||
this._totalObjectCount = totalObjectCount;
|
||||
this._categories = Map.fromObject(categories);
|
||||
}
|
||||
|
||||
// Static
|
||||
|
||||
static deserialize(objectId, serializedSnapshotDiff)
|
||||
{
|
||||
let {snapshot1: serializedSnapshot1, snapshot2: serializedSnapshot2, totalSize, totalObjectCount, categories} = serializedSnapshotDiff;
|
||||
// FIXME: The objectId for these snapshots is the snapshotDiff's objectId. Currently these
|
||||
// snapshots are only used for static data so the proxing doesn't matter. However,
|
||||
// should we serialize the objectId with the snapshot so we have the right objectId?
|
||||
let snapshot1 = WI.HeapSnapshotProxy.deserialize(objectId, serializedSnapshot1);
|
||||
let snapshot2 = WI.HeapSnapshotProxy.deserialize(objectId, serializedSnapshot2);
|
||||
return new WI.HeapSnapshotDiffProxy(objectId, snapshot1, snapshot2, totalSize, totalObjectCount, categories);
|
||||
}
|
||||
|
||||
// Public
|
||||
|
||||
get snapshot1() { return this._snapshot1; }
|
||||
get snapshot2() { return this._snapshot2; }
|
||||
get totalSize() { return this._totalSize; }
|
||||
get totalObjectCount() { return this._totalObjectCount; }
|
||||
get categories() { return this._categories; }
|
||||
get invalid() { return this._snapshot1.invalid || this._snapshot2.invalid; }
|
||||
|
||||
updateForCollectionEvent(event)
|
||||
{
|
||||
console.assert(!this.invalid);
|
||||
if (!event.data.affectedSnapshots.includes(this._snapshot2._identifier))
|
||||
return;
|
||||
|
||||
this.update(() => {
|
||||
this.dispatchEventToListeners(WI.HeapSnapshotProxy.Event.CollectedNodes, event.data);
|
||||
});
|
||||
}
|
||||
|
||||
allocationBucketCounts(bucketSizes, callback)
|
||||
{
|
||||
console.assert(!this.invalid);
|
||||
WI.HeapSnapshotWorkerProxy.singleton().callMethod(this._proxyObjectId, "allocationBucketCounts", bucketSizes, callback);
|
||||
}
|
||||
|
||||
instancesWithClassName(className, callback)
|
||||
{
|
||||
console.assert(!this.invalid);
|
||||
WI.HeapSnapshotWorkerProxy.singleton().callMethod(this._proxyObjectId, "instancesWithClassName", className, (serializedNodes) => {
|
||||
callback(serializedNodes.map(WI.HeapSnapshotNodeProxy.deserialize.bind(null, this._proxyObjectId)));
|
||||
});
|
||||
}
|
||||
|
||||
update(callback)
|
||||
{
|
||||
console.assert(!this.invalid);
|
||||
WI.HeapSnapshotWorkerProxy.singleton().callMethod(this._proxyObjectId, "update", ({liveSize, categories}) => {
|
||||
this._categories = Map.fromObject(categories);
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
nodeWithIdentifier(nodeIdentifier, callback)
|
||||
{
|
||||
console.assert(!this.invalid);
|
||||
WI.HeapSnapshotWorkerProxy.singleton().callMethod(this._proxyObjectId, "nodeWithIdentifier", nodeIdentifier, (serializedNode) => {
|
||||
callback(WI.HeapSnapshotNodeProxy.deserialize(this._proxyObjectId, serializedNode));
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Apple Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
// Directed edge between two HeapSnapshotNodes 'from' and 'to'.
|
||||
|
||||
WI.HeapSnapshotEdgeProxy = class HeapSnapshotEdgeProxy
|
||||
{
|
||||
constructor(objectId, fromIdentifier, toIdentifier, type, data)
|
||||
{
|
||||
this._proxyObjectId = objectId;
|
||||
|
||||
console.assert(type in WI.HeapSnapshotEdgeProxy.EdgeType);
|
||||
|
||||
this.fromIdentifier = fromIdentifier;
|
||||
this.toIdentifier = toIdentifier;
|
||||
this.type = type;
|
||||
this.data = data;
|
||||
|
||||
this.from = null;
|
||||
this.to = null;
|
||||
}
|
||||
|
||||
isPrivateSymbol()
|
||||
{
|
||||
if (WI.settings.engineeringShowPrivateSymbolsInHeapSnapshot.value)
|
||||
return false;
|
||||
|
||||
return typeof this.data === "string" && this.data.startsWith("PrivateSymbol");
|
||||
}
|
||||
|
||||
// Static
|
||||
|
||||
static deserialize(objectId, serializedEdge)
|
||||
{
|
||||
let {from, to, type, data} = serializedEdge;
|
||||
return new WI.HeapSnapshotEdgeProxy(objectId, from, to, type, data);
|
||||
}
|
||||
};
|
||||
|
||||
WI.HeapSnapshotEdgeProxy.EdgeType = {
|
||||
Internal: "Internal", // No data.
|
||||
Property: "Property", // data is string property name.
|
||||
Index: "Index", // data is numeric index.
|
||||
Variable: "Variable", // data is string variable name.
|
||||
};
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Apple Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
WI.HeapSnapshotNodeProxy = class HeapSnapshotNodeProxy
|
||||
{
|
||||
constructor(snapshotObjectId, {id, className, size, retainedSize, internal, isObjectType, gcRoot, dead, dominatorNodeIdentifier, hasChildren})
|
||||
{
|
||||
this._proxyObjectId = snapshotObjectId;
|
||||
|
||||
this.id = id;
|
||||
this.className = className;
|
||||
this.size = size;
|
||||
this.retainedSize = retainedSize;
|
||||
this.internal = internal;
|
||||
this.isObjectType = isObjectType;
|
||||
this.gcRoot = gcRoot;
|
||||
this.dead = dead;
|
||||
this.dominatorNodeIdentifier = dominatorNodeIdentifier;
|
||||
this.hasChildren = hasChildren;
|
||||
}
|
||||
|
||||
// Static
|
||||
|
||||
static deserialize(objectId, serializedNode)
|
||||
{
|
||||
return new WI.HeapSnapshotNodeProxy(objectId, serializedNode);
|
||||
}
|
||||
|
||||
// Proxied
|
||||
|
||||
shortestGCRootPath(callback)
|
||||
{
|
||||
WI.HeapSnapshotWorkerProxy.singleton().callMethod(this._proxyObjectId, "shortestGCRootPath", this.id, (serializedPath) => {
|
||||
let isNode = false;
|
||||
let path = serializedPath.map((component) => {
|
||||
isNode = !isNode;
|
||||
if (isNode)
|
||||
return WI.HeapSnapshotNodeProxy.deserialize(this._proxyObjectId, component);
|
||||
return WI.HeapSnapshotEdgeProxy.deserialize(this._proxyObjectId, component);
|
||||
});
|
||||
|
||||
for (let i = 1; i < path.length; i += 2) {
|
||||
console.assert(path[i] instanceof WI.HeapSnapshotEdgeProxy);
|
||||
let edge = path[i];
|
||||
edge.from = path[i - 1];
|
||||
edge.to = path[i + 1];
|
||||
}
|
||||
|
||||
callback(path);
|
||||
});
|
||||
}
|
||||
|
||||
dominatedNodes(callback)
|
||||
{
|
||||
WI.HeapSnapshotWorkerProxy.singleton().callMethod(this._proxyObjectId, "dominatedNodes", this.id, (serializedNodes) => {
|
||||
callback(serializedNodes.map(WI.HeapSnapshotNodeProxy.deserialize.bind(null, this._proxyObjectId)));
|
||||
});
|
||||
}
|
||||
|
||||
retainedNodes(callback)
|
||||
{
|
||||
WI.HeapSnapshotWorkerProxy.singleton().callMethod(this._proxyObjectId, "retainedNodes", this.id, ({retainedNodes: serializedNodes, edges: serializedEdges}) => {
|
||||
let deserializedNodes = serializedNodes.map(WI.HeapSnapshotNodeProxy.deserialize.bind(null, this._proxyObjectId));
|
||||
let deserializedEdges = serializedEdges.map(WI.HeapSnapshotEdgeProxy.deserialize.bind(null, this._proxyObjectId));
|
||||
callback(deserializedNodes, deserializedEdges);
|
||||
});
|
||||
}
|
||||
|
||||
retainers(callback)
|
||||
{
|
||||
WI.HeapSnapshotWorkerProxy.singleton().callMethod(this._proxyObjectId, "retainers", this.id, ({retainers: serializedNodes, edges: serializedEdges}) => {
|
||||
let deserializedNodes = serializedNodes.map(WI.HeapSnapshotNodeProxy.deserialize.bind(null, this._proxyObjectId));
|
||||
let deserializedEdges = serializedEdges.map(WI.HeapSnapshotEdgeProxy.deserialize.bind(null, this._proxyObjectId));
|
||||
callback(deserializedNodes, deserializedEdges);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Apple Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
WI.HeapSnapshotProxy = class HeapSnapshotProxy extends WI.Object
|
||||
{
|
||||
constructor(snapshotObjectId, identifier, title, totalSize, totalObjectCount, liveSize, categories, imported)
|
||||
{
|
||||
super();
|
||||
|
||||
this._proxyObjectId = snapshotObjectId;
|
||||
|
||||
this._identifier = identifier;
|
||||
this._title = title;
|
||||
this._totalSize = totalSize;
|
||||
this._totalObjectCount = totalObjectCount;
|
||||
this._liveSize = liveSize;
|
||||
this._categories = Map.fromObject(categories);
|
||||
this._imported = imported;
|
||||
this._snapshotStringData = null;
|
||||
|
||||
console.assert(!this.invalid);
|
||||
|
||||
if (!WI.HeapSnapshotProxy.ValidSnapshotProxies)
|
||||
WI.HeapSnapshotProxy.ValidSnapshotProxies = [];
|
||||
WI.HeapSnapshotProxy.ValidSnapshotProxies.push(this);
|
||||
}
|
||||
|
||||
// Static
|
||||
|
||||
static deserialize(objectId, serializedSnapshot)
|
||||
{
|
||||
let {identifier, title, totalSize, totalObjectCount, liveSize, categories, imported} = serializedSnapshot;
|
||||
return new WI.HeapSnapshotProxy(objectId, identifier, title, totalSize, totalObjectCount, liveSize, categories, imported);
|
||||
}
|
||||
|
||||
static invalidateSnapshotProxies()
|
||||
{
|
||||
if (!WI.HeapSnapshotProxy.ValidSnapshotProxies)
|
||||
return;
|
||||
|
||||
for (let snapshotProxy of WI.HeapSnapshotProxy.ValidSnapshotProxies)
|
||||
snapshotProxy._invalidate();
|
||||
|
||||
WI.HeapSnapshotProxy.ValidSnapshotProxies = null;
|
||||
}
|
||||
|
||||
// Public
|
||||
|
||||
get proxyObjectId() { return this._proxyObjectId; }
|
||||
get identifier() { return this._identifier; }
|
||||
get title() { return this._title; }
|
||||
get totalSize() { return this._totalSize; }
|
||||
get totalObjectCount() { return this._totalObjectCount; }
|
||||
get liveSize() { return this._liveSize; }
|
||||
get categories() { return this._categories; }
|
||||
get imported() { return this._imported; }
|
||||
get invalid() { return this._proxyObjectId === 0; }
|
||||
|
||||
get snapshotStringData()
|
||||
{
|
||||
return this._snapshotStringData;
|
||||
}
|
||||
|
||||
set snapshotStringData(data)
|
||||
{
|
||||
this._snapshotStringData = data;
|
||||
}
|
||||
|
||||
updateForCollectionEvent(event)
|
||||
{
|
||||
console.assert(!this.invalid);
|
||||
if (!event.data.affectedSnapshots.includes(this._identifier))
|
||||
return;
|
||||
|
||||
this.update(() => {
|
||||
this.dispatchEventToListeners(WI.HeapSnapshotProxy.Event.CollectedNodes, event.data);
|
||||
});
|
||||
}
|
||||
|
||||
allocationBucketCounts(bucketSizes, callback)
|
||||
{
|
||||
console.assert(!this.invalid);
|
||||
WI.HeapSnapshotWorkerProxy.singleton().callMethod(this._proxyObjectId, "allocationBucketCounts", bucketSizes, callback);
|
||||
}
|
||||
|
||||
instancesWithClassName(className, callback)
|
||||
{
|
||||
console.assert(!this.invalid);
|
||||
WI.HeapSnapshotWorkerProxy.singleton().callMethod(this._proxyObjectId, "instancesWithClassName", className, (serializedNodes) => {
|
||||
callback(serializedNodes.map(WI.HeapSnapshotNodeProxy.deserialize.bind(null, this._proxyObjectId)));
|
||||
});
|
||||
}
|
||||
|
||||
update(callback)
|
||||
{
|
||||
console.assert(!this.invalid);
|
||||
WI.HeapSnapshotWorkerProxy.singleton().callMethod(this._proxyObjectId, "update", ({liveSize, categories}) => {
|
||||
this._liveSize = liveSize;
|
||||
this._categories = Map.fromObject(categories);
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
nodeWithIdentifier(nodeIdentifier, callback)
|
||||
{
|
||||
console.assert(!this.invalid);
|
||||
WI.HeapSnapshotWorkerProxy.singleton().callMethod(this._proxyObjectId, "nodeWithIdentifier", nodeIdentifier, (serializedNode) => {
|
||||
callback(WI.HeapSnapshotNodeProxy.deserialize(this._proxyObjectId, serializedNode));
|
||||
});
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
_invalidate()
|
||||
{
|
||||
this._proxyObjectId = 0;
|
||||
this._liveSize = 0;
|
||||
|
||||
this.dispatchEventToListeners(WI.HeapSnapshotProxy.Event.Invalidated);
|
||||
}
|
||||
};
|
||||
|
||||
WI.HeapSnapshotProxy.Event = {
|
||||
CollectedNodes: "heap-snapshot-proxy-collected-nodes",
|
||||
Invalidated: "heap-snapshot-proxy-invalidated",
|
||||
};
|
||||
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Apple Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
WI.HeapSnapshotWorkerProxy = class HeapSnapshotWorkerProxy extends WI.Object
|
||||
{
|
||||
constructor()
|
||||
{
|
||||
super();
|
||||
|
||||
this._heapSnapshotWorker = new Worker("Workers/HeapSnapshot/HeapSnapshotWorker.js");
|
||||
this._heapSnapshotWorker.addEventListener("message", this._handleMessage.bind(this));
|
||||
|
||||
this._nextCallId = 1;
|
||||
this._callbacks = new Map;
|
||||
|
||||
WI.Frame.addEventListener(WI.Frame.Event.MainResourceDidChange, this._mainResourceDidChange, this);
|
||||
}
|
||||
|
||||
// Static
|
||||
|
||||
static singleton()
|
||||
{
|
||||
if (!HeapSnapshotWorkerProxy.instance)
|
||||
HeapSnapshotWorkerProxy.instance = new HeapSnapshotWorkerProxy;
|
||||
return HeapSnapshotWorkerProxy.instance;
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
clearSnapshots(callback)
|
||||
{
|
||||
this.performAction("clearSnapshots", callback);
|
||||
}
|
||||
|
||||
createSnapshot(snapshotStringData, callback)
|
||||
{
|
||||
this.performAction("createSnapshot", ...arguments);
|
||||
}
|
||||
|
||||
createSnapshotDiff(objectId1, objectId2, callback)
|
||||
{
|
||||
this.performAction("createSnapshotDiff", ...arguments);
|
||||
}
|
||||
|
||||
createImportedSnapshot(snapshotStringData, title, callback)
|
||||
{
|
||||
const imported = true;
|
||||
this.performAction("createSnapshot", snapshotStringData, title, imported, callback);
|
||||
}
|
||||
|
||||
// Public
|
||||
|
||||
performAction(actionName)
|
||||
{
|
||||
let callId = this._nextCallId++;
|
||||
let callback = arguments[arguments.length - 1];
|
||||
let actionArguments = Array.prototype.slice.call(arguments, 1, arguments.length - 1);
|
||||
|
||||
console.assert(typeof actionName === "string", "performAction should always have an actionName");
|
||||
console.assert(typeof callback === "function", "performAction should always have a callback");
|
||||
|
||||
this._callbacks.set(callId, callback);
|
||||
this._postMessage({callId, actionName, actionArguments});
|
||||
}
|
||||
|
||||
callMethod(objectId, methodName)
|
||||
{
|
||||
let callId = this._nextCallId++;
|
||||
let callback = arguments[arguments.length - 1];
|
||||
let methodArguments = Array.prototype.slice.call(arguments, 2, arguments.length - 1);
|
||||
|
||||
console.assert(typeof objectId === "number", "callMethod should always have an objectId");
|
||||
console.assert(typeof methodName === "string", "callMethod should always have a methodName");
|
||||
console.assert(typeof callback === "function", "callMethod should always have a callback");
|
||||
|
||||
this._callbacks.set(callId, callback);
|
||||
this._postMessage({callId, objectId, methodName, methodArguments});
|
||||
}
|
||||
|
||||
// Private
|
||||
|
||||
_mainResourceDidChange(event)
|
||||
{
|
||||
if (!event.target.isMainFrame())
|
||||
return;
|
||||
|
||||
this.clearSnapshots(() => {
|
||||
WI.HeapSnapshotProxy.invalidateSnapshotProxies();
|
||||
});
|
||||
}
|
||||
|
||||
_postMessage()
|
||||
{
|
||||
this._heapSnapshotWorker.postMessage(...arguments);
|
||||
}
|
||||
|
||||
_handleMessage(event)
|
||||
{
|
||||
let data = event.data;
|
||||
|
||||
// Error.
|
||||
if (data.error) {
|
||||
console.assert(data.callId);
|
||||
this._callbacks.delete(data.callId);
|
||||
return;
|
||||
}
|
||||
|
||||
// Event.
|
||||
if (data.eventName) {
|
||||
this.dispatchEventToListeners(data.eventName, data.eventData);
|
||||
return;
|
||||
}
|
||||
|
||||
// Action or Method Response.
|
||||
if (data.callId) {
|
||||
let callback = this._callbacks.get(data.callId);
|
||||
this._callbacks.delete(data.callId);
|
||||
callback(data.result);
|
||||
return;
|
||||
}
|
||||
|
||||
console.error("Unexpected HeapSnapshotWorker message", data);
|
||||
}
|
||||
};
|
||||
|
||||
WI.HeapSnapshotWorkerProxy.Event = {
|
||||
Collection: "heap-snapshot-collection",
|
||||
};
|
||||
Reference in New Issue
Block a user