Skip to content

Commit

Permalink
Bug 833747 - recognize "debugger eval" as eval source; r=jlast
Browse files Browse the repository at this point in the history
isEvalSource was missing one introduction type, so evaluating
  function(){...}
  //# sourceURL=blah
in the console would fail -- but wrapping the whole thing in
eval("...") would work.

MozReview-Commit-ID: 13oRnbs1eyF

--HG--
extra : rebase_source : d2360bd3698f4ce20064397aab075d29449dfdcd
  • Loading branch information
tromey committed Sep 18, 2017
1 parent 1d0e9fe commit a13df2c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
6 changes: 3 additions & 3 deletions devtools/server/actors/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function isEvalSource(source) {
// These are all the sources that are essentially eval-ed (either
// by calling eval or passing a string to one of these functions).
return (introType === "eval" ||
introType === "debugger eval" ||
introType === "Function" ||
introType === "eventHandler" ||
introType === "setTimeout" ||
Expand All @@ -41,16 +42,15 @@ function getSourceURL(source, window) {
// created with the sourceURL pragma. If the introduction script
// is a non-eval script, generate an full absolute URL relative to it.

if (source.displayURL && source.introductionScript &&
!isEvalSource(source.introductionScript.source)) {
if (source.displayURL && source.introductionScript) {
if (source.introductionScript.source.url === "debugger eval code") {
if (window) {
// If this is a named eval script created from the console, make it
// relative to the current page. window is only available
// when we care about this.
return joinURI(window.location.href, source.displayURL);
}
} else {
} else if (!isEvalSource(source.introductionScript.source)) {
return joinURI(source.introductionScript.source.url, source.displayURL);
}
}
Expand Down
47 changes: 47 additions & 0 deletions devtools/server/tests/unit/test_new_source-02.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
* Check that sourceURL has the correct effect when using gThreadClient.eval.
*/

var gDebuggee;
var gClient;
var gThreadClient;

function run_test() {
initTestDebuggerServer();
gDebuggee = addTestGlobal("test-stack");
gClient = new DebuggerClient(DebuggerServer.connectPipe());
gClient.connect().then(function () {
attachTestTabAndResume(gClient, "test-stack",
function (response, tabClient, threadClient) {
gThreadClient = threadClient;
test_simple_new_source();
});
});
do_test_pending();
}

function test_simple_new_source() {
gThreadClient.addOneTimeListener("paused", function () {
gThreadClient.addOneTimeListener("newSource", function (event, packet) {
do_check_eq(event, "newSource");
do_check_eq(packet.type, "newSource");
do_check_true(!!packet.source);
do_check_true(!!packet.source.url.match(/example\.com/));

finishClient(gClient);
});
gThreadClient.eval(null, "function f() { }\n//# sourceURL=http://example.com/code.js");
});

/* eslint-disable */
gDebuggee.eval("(" + function () {
function stopMe(arg1) { debugger; }
stopMe({obj: true});
} + ")()");
/* eslint-enable */
}
1 change: 1 addition & 0 deletions devtools/server/tests/unit/xpcshell.ini
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ reason = only ran on B2G
[test_listsources-03.js]
[test_listsources-04.js]
[test_new_source-01.js]
[test_new_source-02.js]
[test_sourcemaps-01.js]
[test_sourcemaps-02.js]
[test_sourcemaps-03.js]
Expand Down

0 comments on commit a13df2c

Please sign in to comment.