msaboff@apple.com | 95c4315 | 2015-02-26 06:05:02 +0000 | [diff] [blame] | 1 | <!doctype html> |
| 2 | <html> |
| 3 | <head> |
commit-queue@webkit.org | 0c88cda | 2015-08-06 21:17:03 +0000 | [diff] [blame] | 4 | <script type="text/javascript" src="../../http/tests/inspector/resources/inspector-test.js"></script> |
msaboff@apple.com | 95c4315 | 2015-02-26 06:05:02 +0000 | [diff] [blame] | 5 | <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 | |
| 9 | function test() |
| 10 | { |
| 11 | var testInfoList = [ |
joepeck@webkit.org | ef4a881 | 2015-12-04 18:49:47 +0000 | [diff] [blame] | 12 | { line : 4, column : 8, startFunc : "testNativeScope()" } |
msaboff@apple.com | 95c4315 | 2015-02-26 06:05:02 +0000 | [diff] [blame] | 13 | ]; |
| 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.org | 6bf02b6 | 2016-01-07 01:44:08 +0000 | [diff] [blame] | 60 | scope.objects[0].getAllPropertyDescriptors(function(properties) { |
msaboff@apple.com | 95c4315 | 2015-02-26 06:05:02 +0000 | [diff] [blame] | 61 | 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> |