|
| 1 | +// Copyright 2017 the V8 project authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +let {session, contextGroup, Protocol} = |
| 6 | + InspectorTest.start('Test for Runtime.globalLexicalScopeVariablesNames'); |
| 7 | + |
| 8 | +(async function test() { |
| 9 | + InspectorTest.log('Running \'let a = 1\''); |
| 10 | + Protocol.Runtime.evaluate({expression: 'let a = 1'}); |
| 11 | + await dumpGlobalScopeVariables(); |
| 12 | + |
| 13 | + InspectorTest.log('Running \'let b = 2\''); |
| 14 | + Protocol.Runtime.evaluate({expression: 'let b = 2'}); |
| 15 | + await dumpGlobalScopeVariables(); |
| 16 | + |
| 17 | + InspectorTest.log('Running \'let b = 3\''); |
| 18 | + Protocol.Runtime.evaluate({expression: 'let b = 3'}); |
| 19 | + await dumpGlobalScopeVariables(); |
| 20 | + |
| 21 | + InspectorTest.log('Running \'const c = 4\''); |
| 22 | + Protocol.Runtime.evaluate({expression: 'const c = 4'}); |
| 23 | + await dumpGlobalScopeVariables(); |
| 24 | + |
| 25 | + InspectorTest.log('Running \'var d = 5\''); |
| 26 | + InspectorTest.log('(should not be in list of scoped variables)'); |
| 27 | + Protocol.Runtime.evaluate({expression: 'var d = 5'}); |
| 28 | + await dumpGlobalScopeVariables(); |
| 29 | + |
| 30 | + InspectorTest.log('Running \'class Foo{}\''); |
| 31 | + Protocol.Runtime.evaluate({expression: 'class Foo{}'}); |
| 32 | + await dumpGlobalScopeVariables(); |
| 33 | + |
| 34 | + InspectorTest.log('Adding script with scope variables'); |
| 35 | + contextGroup.addScript(` |
| 36 | + let e = 1; |
| 37 | + const f = 2; |
| 38 | + const g = 3; |
| 39 | + class Boo {}; |
| 40 | + `); |
| 41 | + await dumpGlobalScopeVariables(); |
| 42 | + InspectorTest.completeTest(); |
| 43 | +})(); |
| 44 | + |
| 45 | +async function dumpGlobalScopeVariables() { |
| 46 | + let {result:{names}} = |
| 47 | + await Protocol.Runtime.globalLexicalScopeNames(); |
| 48 | + InspectorTest.log('Values:'); |
| 49 | + for (let name of names) { |
| 50 | + let {result:{result}} = await Protocol.Runtime.evaluate({expression: name}); |
| 51 | + if (result.value) { |
| 52 | + InspectorTest.log(`${name} = ${result.value}`); |
| 53 | + } else { |
| 54 | + InspectorTest.log(`${name} =`); |
| 55 | + InspectorTest.logMessage(result); |
| 56 | + } |
| 57 | + } |
| 58 | + InspectorTest.log(''); |
| 59 | +} |
0 commit comments