Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions src/utils/scopes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
113 changes: 1 addition & 112 deletions src/utils/tests/scopes.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
const {
getSpecialVariables,
getVisibleVariablesFromScope,
getScopes
} = require("../scopes");
const { getSpecialVariables, getScopes } = require("../scopes");

const errorGrip = {
type: "object",
Expand Down Expand Up @@ -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 = {
Expand Down