Skip to content
This repository was archived by the owner on Sep 21, 2021. It is now read-only.

Commit 32504de

Browse files
committed
Do not add jump to definition icon for evaled in debugger functions.
Fixes #862.
1 parent 009d19c commit 32504de

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

packages/devtools-reps/src/reps/function.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const Svg = require("../shared/images/Svg");
1818
const dom = require("react-dom-factories");
1919
const { span } = dom;
2020

21+
const IGNORED_SOURCE_URLS = ["debugger eval code"];
22+
2123
/**
2224
* This component represents a template for Function objects.
2325
*/
@@ -34,7 +36,11 @@ function FunctionRep(props) {
3436
} = props;
3537

3638
let jumpToDefinitionButton;
37-
if (onViewSourceInDebugger && grip.location && grip.location.url) {
39+
if (onViewSourceInDebugger &&
40+
grip.location &&
41+
grip.location.url &&
42+
!IGNORED_SOURCE_URLS.includes(grip.location.url)
43+
) {
3844
jumpToDefinitionButton = Svg("jump-definition", {
3945
element: "a",
4046
draggable: false,

packages/devtools-reps/src/reps/stubs/function.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,36 @@ stubs.set("AnonGeneratorFunction", {
152152
}
153153
});
154154

155+
stubs.set("getRandom", {
156+
"type": "object",
157+
"actor": "server1.conn7.child1/obj984",
158+
"class": "Function",
159+
"extensible": true,
160+
"frozen": false,
161+
"sealed": false,
162+
"ownPropertyLength": 3,
163+
"name": "getRandom",
164+
"displayName": "getRandom",
165+
"location": {
166+
"url": "https://nchevobbe.github.io/demo/console-test-app.html",
167+
"line": 314
168+
}
169+
});
170+
171+
stubs.set("EvaledInDebuggerFunction", {
172+
"type": "object",
173+
"actor": "server1.conn2.child1/obj29",
174+
"class": "Function",
175+
"extensible": true,
176+
"frozen": false,
177+
"sealed": false,
178+
"ownPropertyLength": 3,
179+
"name": "evaledInDebugger",
180+
"displayName": "evaledInDebugger",
181+
"location": {
182+
"url": "debugger eval code",
183+
"line": 1
184+
}
185+
});
186+
155187
module.exports = stubs;

packages/devtools-reps/src/reps/tests/function.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ describe("Function - Anonymous generator function", () => {
239239
describe("Function - Jump to definition", () => {
240240
it("renders an icon when onViewSourceInDebugger props is provided", () => {
241241
const onViewSourceInDebugger = jest.fn();
242-
const object = stubs.get("Named");
242+
const object = stubs.get("getRandom");
243243
const renderedComponent = renderRep(object, {
244244
onViewSourceInDebugger
245245
});
@@ -256,15 +256,15 @@ describe("Function - Jump to definition", () => {
256256
});
257257

258258
it("does not render an icon when onViewSourceInDebugger props is not provided", () => {
259-
const object = stubs.get("Named");
259+
const object = stubs.get("getRandom");
260260
const renderedComponent = renderRep(object);
261261

262262
const node = renderedComponent.find(".jump-definition");
263263
expect(node.exists()).toBeFalsy();
264264
});
265265

266266
it("does not render an icon when the object has no location", () => {
267-
const object = Object.assign({}, stubs.get("Named"));
267+
const object = Object.assign({}, stubs.get("getRandom"));
268268
delete object.location;
269269
const renderedComponent = renderRep(object, {
270270
onViewSourceInDebugger: () => {}
@@ -275,7 +275,7 @@ describe("Function - Jump to definition", () => {
275275
});
276276

277277
it("does not render an icon when the object has no url location", () => {
278-
const object = Object.assign({}, stubs.get("Named"));
278+
const object = Object.assign({}, stubs.get("getRandom"));
279279
object.location.url = null;
280280
const renderedComponent = renderRep(object, {
281281
onViewSourceInDebugger: () => {}
@@ -284,6 +284,16 @@ describe("Function - Jump to definition", () => {
284284
const node = renderedComponent.find(".jump-definition");
285285
expect(node.exists()).toBeFalsy();
286286
});
287+
288+
it("does not render an icon when function was declared in console input", () => {
289+
const object = Object.assign({}, stubs.get("EvaledInDebuggerFunction"));
290+
const renderedComponent = renderRep(object, {
291+
onViewSourceInDebugger: () => {}
292+
});
293+
294+
const node = renderedComponent.find(".jump-definition");
295+
expect(node.exists()).toBeFalsy();
296+
});
287297
});
288298

289299
describe("Function - Simplify name", () => {

0 commit comments

Comments
 (0)