diff --git a/src/utils/scopes.js b/src/utils/scopes.js index d5c08bb5ce..931c295670 100644 --- a/src/utils/scopes.js +++ b/src/utils/scopes.js @@ -143,29 +143,3 @@ export function getScopes( return scopes; } - -/** - * Returns variables that are visible from this scope. - * TODO: returns global variables as well - */ -export function getVisibleVariablesFromScope( - pauseInfo: Pause, - selectedFrame: Frame -) { - const result = new Map(); - - const scopes = getScopes(pauseInfo, selectedFrame); - if (!scopes) { - return result; - } - - // reverse so that the local variables shadow global variables - let scopeContents = scopes.reverse().map(scope => scope.contents); - scopeContents = [].concat(...scopeContents); - - scopeContents.forEach(content => { - result.set(content.name || null, content); - }); - - return result; -} diff --git a/src/utils/tests/scopes.js b/src/utils/tests/scopes.js index c5ff3bffcd..d91c067ca3 100644 --- a/src/utils/tests/scopes.js +++ b/src/utils/tests/scopes.js @@ -1,8 +1,4 @@ -const { - getSpecialVariables, - getVisibleVariablesFromScope, - getScopes -} = require("../scopes"); +const { getSpecialVariables, getScopes } = require("../scopes"); const errorGrip = { type: "object", @@ -106,113 +102,6 @@ describe("scopes", () => { }); }); - describe("getVisibleVariablesFromScope", function() { - /* These are real-life pauseInfo and frames with some shadowed variables - * coming from the following JS code: - * - * (function() { - * var a = 'a'; - * var b = 'b'; - * var c = 'c'; - * - * function func(b, d) { - * var c = 'cc'; - * debugger; // This is where we are paused. - * } - * - * document.querySelector('button').onclick = - * () => func.call('this', 'bb', 'dd'); - * })(); - * - * - * We use a IIFE because we don't support global variables yet, so this is - * necessary to get variables in the outer scope. This can be removed once - * getVisibleVariablesFromScope supports global variables. - * - * `b` is shadowed by a function parameter, `c` is shadowed by a local - * variable, but `a` is not shadowed. `this` is a string containing te value - * `"this"`. - */ - - const frame = { - id: "server2.conn1.frame37", - displayName: "func", - this: "this", - scope: { - actor: "server2.conn1.environment39", - type: "function", - parent: { - actor: "server2.conn1.environment40", - type: "function", - function: { - type: "object", - class: "Function", - actor: "server2.conn1.pausedobj44" - }, - bindings: { - arguments: [], - variables: { - a: { value: "a" }, - b: { value: "b" }, - c: { value: "c" }, - func: { - value: { - name: "func", - displayName: "func", - actor: "server2.conn1.pausedobj45", - class: "Function", - type: "object" - } - } - } - } - }, - function: { - name: "func", - displayName: "func", - actor: "server2.conn1.pausedobj45", - class: "Function", - type: "object" - }, - bindings: { - arguments: [{ b: { value: "bb" } }, { d: { value: "dd" } }], - variables: { - c: { value: "cc" } - } - } - } - }; - - let pauseInfo; - - beforeEach(function() { - // Default pauseInfo is using the innermost frame in the stack. - pauseInfo = { - why: { - type: "debuggerStatement" - }, - frame, - isInterrupted: false - }; - }); - - it("Returns variables from the outer scope", function() { - const variables = getVisibleVariablesFromScope(pauseInfo, frame); - - const expectations = { - a: "a", - b: "bb", - c: "cc", - d: "dd" - }; - - for (const variableName in expectations) { - const variable = variables.get(variableName); - expect(variable.contents.value).toEqual(expectations[variableName]); - } - }); - }); - describe("getScopes", () => { it("single scope", () => { const pauseData = {