mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-12 04:45:45 +00:00
Bug 1366853 - SourceMapURLService must wait for sources to be available; r=bgrins
MozReview-Commit-ID: CVbYQCzJQTu --HG-- extra : rebase_source : 8a77d672917ac4016ad433fbd298b3d620123a9a
This commit is contained in:
parent
14874cee6d
commit
cb34410a81
@ -11,10 +11,12 @@
|
||||
*
|
||||
* @param {object} target
|
||||
* The object the toolbox is debugging.
|
||||
* @param {object} threadClient
|
||||
* The toolbox's thread client
|
||||
* @param {SourceMapService} sourceMapService
|
||||
* The devtools-source-map functions
|
||||
*/
|
||||
function SourceMapURLService(target, sourceMapService) {
|
||||
function SourceMapURLService(target, threadClient, sourceMapService) {
|
||||
this._target = target;
|
||||
this._sourceMapService = sourceMapService;
|
||||
this._urls = new Map();
|
||||
@ -24,6 +26,14 @@ function SourceMapURLService(target, sourceMapService) {
|
||||
|
||||
target.on("source-updated", this._onSourceUpdated);
|
||||
target.on("will-navigate", this.reset);
|
||||
|
||||
// Start fetching the sources now.
|
||||
this._loadingPromise = new Promise(resolve => {
|
||||
threadClient.getSources(({sources}) => {
|
||||
// Just ignore errors.
|
||||
resolve(sources);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -75,6 +85,14 @@ SourceMapURLService.prototype._onSourceUpdated = function (_, sourceEvent) {
|
||||
* A promise resolving either to the original location, or null.
|
||||
*/
|
||||
SourceMapURLService.prototype.originalPositionFor = async function (url, line, column) {
|
||||
// Ensure the sources are loaded before replying.
|
||||
await this._loadingPromise;
|
||||
|
||||
// Maybe we were shut down while waiting.
|
||||
if (!this._urls) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const urlInfo = this._urls.get(url);
|
||||
if (!urlInfo) {
|
||||
return null;
|
||||
|
@ -13,6 +13,8 @@ support-files =
|
||||
code_binary_search.map
|
||||
code_binary_search_absolute.js
|
||||
code_binary_search_absolute.map
|
||||
code_bundle_no_race.js
|
||||
code_bundle_no_race.js.map
|
||||
code_bundle_reload_1.js
|
||||
code_bundle_reload_1.js.map
|
||||
code_bundle_reload_2.js
|
||||
@ -20,6 +22,7 @@ support-files =
|
||||
code_inline_bundle.js
|
||||
code_inline_original.js
|
||||
code_math.js
|
||||
code_no_race.js
|
||||
code_reload_1.js
|
||||
code_reload_2.js
|
||||
doc_empty-tab-01.html
|
||||
@ -52,6 +55,7 @@ support-files =
|
||||
[browser_source_map-01.js]
|
||||
[browser_source_map-absolute.js]
|
||||
[browser_source_map-inline.js]
|
||||
[browser_source_map-no-race.js]
|
||||
[browser_source_map-reload.js]
|
||||
[browser_target_from_url.js]
|
||||
[browser_target_events.js]
|
||||
|
41
devtools/client/framework/test/browser_source_map-no-race.js
Normal file
41
devtools/client/framework/test/browser_source_map-no-race.js
Normal file
@ -0,0 +1,41 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
// Test that the source map service doesn't race against source
|
||||
// reporting.
|
||||
|
||||
"use strict";
|
||||
|
||||
const JS_URL = URL_ROOT + "code_bundle_no_race.js";
|
||||
|
||||
const PAGE_URL = `data:text/html,
|
||||
<!doctype html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title>Empty test page to test race case</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<script src="${JS_URL}"></script>
|
||||
</body>
|
||||
|
||||
</html>`;
|
||||
|
||||
const ORIGINAL_URL = "webpack:///code_no_race.js";
|
||||
|
||||
const GENERATED_LINE = 84;
|
||||
const ORIGINAL_LINE = 11;
|
||||
|
||||
add_task(function* () {
|
||||
// Start with the empty page, then navigate, so that we can properly
|
||||
// listen for new sources arriving.
|
||||
const toolbox = yield openNewTabAndToolbox(PAGE_URL, "webconsole");
|
||||
const service = toolbox.sourceMapURLService;
|
||||
|
||||
info(`checking original location for ${JS_URL}:${GENERATED_LINE}`);
|
||||
let newLoc = yield service.originalPositionFor(JS_URL, GENERATED_LINE);
|
||||
is(newLoc.sourceUrl, ORIGINAL_URL, "check mapped URL");
|
||||
is(newLoc.line, ORIGINAL_LINE, "check mapped line number");
|
||||
});
|
92
devtools/client/framework/test/code_bundle_no_race.js
Normal file
92
devtools/client/framework/test/code_bundle_no_race.js
Normal file
@ -0,0 +1,92 @@
|
||||
/******/ (function(modules) { // webpackBootstrap
|
||||
/******/ // The module cache
|
||||
/******/ var installedModules = {};
|
||||
/******/
|
||||
/******/ // The require function
|
||||
/******/ function __webpack_require__(moduleId) {
|
||||
/******/
|
||||
/******/ // Check if module is in cache
|
||||
/******/ if(installedModules[moduleId]) {
|
||||
/******/ return installedModules[moduleId].exports;
|
||||
/******/ }
|
||||
/******/ // Create a new module (and put it into the cache)
|
||||
/******/ var module = installedModules[moduleId] = {
|
||||
/******/ i: moduleId,
|
||||
/******/ l: false,
|
||||
/******/ exports: {}
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // Execute the module function
|
||||
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
||||
/******/
|
||||
/******/ // Flag the module as loaded
|
||||
/******/ module.l = true;
|
||||
/******/
|
||||
/******/ // Return the exports of the module
|
||||
/******/ return module.exports;
|
||||
/******/ }
|
||||
/******/
|
||||
/******/
|
||||
/******/ // expose the modules object (__webpack_modules__)
|
||||
/******/ __webpack_require__.m = modules;
|
||||
/******/
|
||||
/******/ // expose the module cache
|
||||
/******/ __webpack_require__.c = installedModules;
|
||||
/******/
|
||||
/******/ // identity function for calling harmony imports with the correct context
|
||||
/******/ __webpack_require__.i = function(value) { return value; };
|
||||
/******/
|
||||
/******/ // define getter function for harmony exports
|
||||
/******/ __webpack_require__.d = function(exports, name, getter) {
|
||||
/******/ if(!__webpack_require__.o(exports, name)) {
|
||||
/******/ Object.defineProperty(exports, name, {
|
||||
/******/ configurable: false,
|
||||
/******/ enumerable: true,
|
||||
/******/ get: getter
|
||||
/******/ });
|
||||
/******/ }
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
||||
/******/ __webpack_require__.n = function(module) {
|
||||
/******/ var getter = module && module.__esModule ?
|
||||
/******/ function getDefault() { return module['default']; } :
|
||||
/******/ function getModuleExports() { return module; };
|
||||
/******/ __webpack_require__.d(getter, 'a', getter);
|
||||
/******/ return getter;
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // Object.prototype.hasOwnProperty.call
|
||||
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
||||
/******/
|
||||
/******/ // __webpack_public_path__
|
||||
/******/ __webpack_require__.p = "";
|
||||
/******/
|
||||
/******/ // Load entry module and return exports
|
||||
/******/ return __webpack_require__(__webpack_require__.s = 0);
|
||||
/******/ })
|
||||
/************************************************************************/
|
||||
/******/ ([
|
||||
/* 0 */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
// Original source code for the inline source map test.
|
||||
// The generated file was made with
|
||||
// webpack --devtool source-map code_no_race.js code_bundle_no_race.js
|
||||
|
||||
|
||||
|
||||
function f() {
|
||||
console.log("anything will do");
|
||||
}
|
||||
|
||||
f();
|
||||
|
||||
|
||||
/***/ })
|
||||
/******/ ]);
|
||||
//# sourceMappingURL=code_bundle_no_race.js.map
|
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["webpack:///webpack/bootstrap 40c4319d19d88c63024f","webpack:///./code_no_race.js"],"names":[],"mappings":";AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA,mDAA2C,cAAc;;AAEzD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,aAAK;AACL;AACA;;AAEA;AACA;AACA;AACA,mCAA2B,0BAA0B,EAAE;AACvD,yCAAiC,eAAe;AAChD;AACA;AACA;;AAEA;AACA,8DAAsD,+DAA+D;;AAErH;AACA;;AAEA;AACA;;;;;;;;AChEA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA","file":"code_bundle_no_race.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// identity function for calling harmony imports with the correct context\n \t__webpack_require__.i = function(value) { return value; };\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 40c4319d19d88c63024f","/* Any copyright is dedicated to the Public Domain.\n http://creativecommons.org/publicdomain/zero/1.0/ */\n\n// Original source code for the inline source map test.\n// The generated file was made with\n// webpack --devtool source-map code_no_race.js code_bundle_no_race.js\n\n\"use strict\";\n\nfunction f() {\n console.log(\"anything will do\");\n}\n\nf();\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./code_no_race.js\n// module id = 0\n// module chunks = 0"],"sourceRoot":""}
|
14
devtools/client/framework/test/code_no_race.js
Normal file
14
devtools/client/framework/test/code_no_race.js
Normal file
@ -0,0 +1,14 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
// Original source code for the inline source map test.
|
||||
// The generated file was made with
|
||||
// webpack --devtool source-map code_no_race.js code_bundle_no_race.js
|
||||
|
||||
"use strict";
|
||||
|
||||
function f() {
|
||||
console.log("anything will do");
|
||||
}
|
||||
|
||||
f();
|
@ -567,7 +567,8 @@ Toolbox.prototype = {
|
||||
if (!sourceMaps) {
|
||||
return null;
|
||||
}
|
||||
this._sourceMapURLService = new SourceMapURLService(this._target, sourceMaps);
|
||||
this._sourceMapURLService = new SourceMapURLService(this._target, this.threadClient,
|
||||
sourceMaps);
|
||||
return this._sourceMapURLService;
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user