84 lines
2.7 KiB
HTML
84 lines
2.7 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
|
|
<script>
|
|
strongKey1 = {id:1};
|
|
strongKey2 = {id:2};
|
|
weakMap = new WeakMap;
|
|
|
|
function test()
|
|
{
|
|
var weakMapObjectId = null;
|
|
|
|
var currentStepIndex = 0;
|
|
var steps = [
|
|
// WeakMap {}
|
|
{expression: ""},
|
|
|
|
// WeakMap {key1 => 1, key2 => 2}
|
|
{expression: "weakMap.set(strongKey1, 1); weakMap.set(strongKey2, 2);"},
|
|
|
|
// WeakMap {key2 => 2}
|
|
{expression: "delete window.strongKey1;"},
|
|
|
|
// WeakMap {key2 => 2} (add and immediately garbage collect temporary objects)
|
|
{expression: "weakMap.set({id:3}, 3); weakMap.set({id:4}, 4);"},
|
|
|
|
// WeakMap {}
|
|
{expression: "delete window.strongKey2;"},
|
|
];
|
|
|
|
function remoteObjectJSONFilter(key, value)
|
|
{
|
|
if (key === "_target" || key === "_hasChildren" || key === "_listeners")
|
|
return undefined;
|
|
if (key === "_objectId" || key === "_stackTrace")
|
|
return "<filtered>";
|
|
return value;
|
|
}
|
|
|
|
function runNextStep() {
|
|
if (currentStepIndex >= steps.length) {
|
|
InspectorTest.completeTest();
|
|
return;
|
|
}
|
|
|
|
var step = steps[currentStepIndex++];
|
|
step.expression += " weakMap";
|
|
|
|
InspectorTest.log("");
|
|
InspectorTest.log("-----------------------------------------------------");
|
|
InspectorTest.log("EXPRESSION: " + step.expression);
|
|
|
|
// Run the expression, and then run a garbage collection on a different
|
|
// event loop so no objects are kept alive by the stack.
|
|
WI.runtimeManager.evaluateInInspectedWindow(step.expression, {objectGroup: "test", doNotPauseOnExceptionsAndMuteConsole: true}, function(remoteObject, wasThrown) {
|
|
InspectorTest.assert(remoteObject instanceof WI.RemoteObject);
|
|
InspectorTest.assert(!wasThrown);
|
|
|
|
HeapAgent.gc(function(error) {
|
|
InspectorTest.assert(!error, error);
|
|
|
|
remoteObject.getCollectionEntries(function(entries) {
|
|
InspectorTest.log("ENTRIES:");
|
|
entries.sort((a, b) => a.value.value - b.value.value);
|
|
for (let entry of entries)
|
|
InspectorTest.assert(entry instanceof WI.CollectionEntry);
|
|
InspectorTest.log(JSON.stringify(entries, remoteObjectJSONFilter, " "));
|
|
remoteObject.releaseWeakCollectionEntries();
|
|
runNextStep();
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
runNextStep();
|
|
}
|
|
</script>
|
|
</head>
|
|
<body onload="runTest();">
|
|
</body>
|
|
</html>
|