Web Inspector: Save Console Evaluations into Command Line variables $1-$99 ($n)
[WebKit-https.git] / LayoutTests / inspector / model / remote-object-weak-collection.html
1 <!doctype html>
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5 <script type="text/javascript" src="../../http/tests/inspector/inspector-test.js"></script>
6 <script>
7 strongKey1 = {id:1};
8 strongKey2 = {id:2};
9 weakMap = new WeakMap;
10
11 function test()
12 {
13     var weakMapObjectId = null;
14
15     var currentStepIndex = 0;
16     var steps = [
17         // WeakMap {}
18         {expression: ""},
19         
20         // WeakMap {key1 => 1, key2 => 2}
21         {expression: "weakMap.set(strongKey1, 1); weakMap.set(strongKey2, 2);"},
22         
23         // WeakMap {key2 => 2}
24         {expression: "delete window.strongKey1;"},
25
26         // WeakMap {key2 => 2} (add and immediately garbage collect temporary objects)
27         {expression: "weakMap.set({id:3}, 3); weakMap.set({id:4}, 4);"},
28         
29         // WeakMap {}
30         {expression: "delete window.strongKey2;"},
31     ];
32
33     function remoteObjectJSONFilter(key, value)
34     {
35         if (key === "_objectId")
36             return "<filtered>";
37
38         return value;
39     }
40
41     function runNextStep() {
42         if (currentStepIndex >= steps.length) {
43             InspectorTest.completeTest();
44             return;
45         }
46
47         var step = steps[currentStepIndex++];
48         step.expression += " weakMap";
49
50         InspectorTest.log("");
51         InspectorTest.log("-----------------------------------------------------");
52         InspectorTest.log("EXPRESSION: " + step.expression);
53
54         // Run the expression, and then run a garbage collection on a different
55         // event loop so no objects are kept alive by the stack.
56         WebInspector.runtimeManager.evaluateInInspectedWindow(step.expression, "test", false, true, false, true, false, function(remoteObject, wasThrown) {
57             WebInspector.runtimeManager.evaluateInInspectedWindow("GCController.collect()", "test", false, true, false, false, false, function() {
58                 InspectorTest.assert(remoteObject instanceof WebInspector.RemoteObject);
59                 remoteObject.getCollectionEntries(0, 100, function(entries) {
60                     InspectorTest.log("ENTRIES:");
61                     entries.sort(function(a, b) { return a.value.value - b.value.value; });
62                     for (var entry of entries)
63                         InspectorTest.assert(entry instanceof WebInspector.CollectionEntry);
64                     InspectorTest.log(JSON.stringify(entries, remoteObjectJSONFilter, "  "));
65                     remoteObject.releaseWeakCollectionEntries();
66                     runNextStep();
67                 });
68             });
69         });
70     }
71
72     runNextStep();
73 }
74 </script>
75 </head>
76 <body onload="runTest();">
77 </body>
78 </html>