blob: 76a26bdbd2c9c2dafec57c363413de7e7095bd74 [file] [log] [blame]
msaboff@apple.com95c43152015-02-26 06:05:02 +00001<!doctype html>
2<html>
3<head>
commit-queue@webkit.org0c88cda2015-08-06 21:17:03 +00004<script type="text/javascript" src="../../http/tests/inspector/resources/inspector-test.js"></script>
msaboff@apple.com95c43152015-02-26 06:05:02 +00005<script type="text/javascript" src="../../http/tests/inspector/debugger/debugger-test.js"></script>
6<script type="text/javascript" src="./resources/scope.js"></script>
7<script>
8
9function test()
10{
11 var testInfoList = [
joepeck@webkit.orgef4a8812015-12-04 18:49:47 +000012 { line : 4, column : 8, startFunc : "testNativeScope()" }
msaboff@apple.com95c43152015-02-26 06:05:02 +000013 ];
14
15 var currentTestIndex = 0;
16 var scriptObject;
17
18 function startTest() {
19 InspectorTest.log("Starting Test");
20 runNextTest();
21 }
22
23 function runNextTest() {
24 if (currentTestIndex >= testInfoList.length) {
25 InspectorTest.log("Tests done");
26 InspectorTest.completeTest();
27 return;
28 }
29
30 var testInfo = testInfoList[currentTestIndex];
31 var location = scriptObject.createSourceCodeLocation(testInfo.line, testInfo.column);
32 var breakpoint = new WebInspector.Breakpoint(location);
33
34 WebInspector.debuggerManager.addBreakpoint(breakpoint);
35 InspectorTest.evaluateInPage(testInfo.startFunc);
36
37 currentTestIndex++;
38 }
39
40 WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.CallFramesDidChange, function(event) {
41 var activeCallFrame = WebInspector.debuggerManager.activeCallFrame;
42
43 if (!activeCallFrame)
44 return;
45
46 var stopLocation = "line: " + activeCallFrame.sourceCodeLocation.lineNumber + ", column: " + activeCallFrame.sourceCodeLocation.columnNumber;
47
48 InspectorTest.log("Hit breakpoint at " + stopLocation);
49 InspectorTest.evaluateInPage("console.log('Paused at " + stopLocation + "')");
50
51 var activeCallFrame = WebInspector.debuggerManager.activeCallFrame;
52 var scopeChain = activeCallFrame.scopeChain;
53 var scopeTypes = [];
54 var scopeTypeIndex = 0;
55 var globalScopeCount = 0;
56
57 for (var scope of scopeChain) {
58 scopeTypes.push(scope.type);
59 if (scope.type !== WebInspector.ScopeChainNode.Type.Global) {
joepeck@webkit.org6bf02b62016-01-07 01:44:08 +000060 scope.objects[0].getAllPropertyDescriptors(function(properties) {
msaboff@apple.com95c43152015-02-26 06:05:02 +000061 InspectorTest.log(scopeTypes[scopeTypeIndex++] + " properties:");
62 for (var propertyDescriptor of properties)
63 InspectorTest.log(" " + propertyDescriptor.name);
64
65 if (scopeTypeIndex == scopeTypes.length - 1)
66 InspectorTest.log(scopeTypes[scopeTypeIndex] + " (properties not listed)");
67 });
68 } else
69 globalScopeCount++;
70 }
71
72 if (globalScopeCount != 1)
73 InspectorTest.log("Error: too many " + WebInspector.ScopeChainNode.Type.Global + " scopes");
74
75 WebInspector.debuggerManager.resume();
76 });
77
78 WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.Resumed, function(event) {
79 runNextTest();
80 });
81
82 WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.ScriptAdded, function(event) {
83 eventScriptObject = event.data.script;
84
85 if (/scope\.js$/.test(eventScriptObject.url)) {
86 scriptObject = eventScriptObject;
87 startTest();
88 return;
89 }
90
91 });
92
93 InspectorTest.reloadPage();
94}
95</script>
96</head>
97<body onload="runTest()">
98 <p>Testing that we can access scope in various functions.</p>
99</body>
100</html>