Skip to content

Commit d4d0b9d

Browse files
committedDec 15, 2022
Bug 1783100 - Remove osfile.jsm usage from DevToolsUtils.js r=ochameau
Differential Revision: https://phabricator.services.mozilla.com/D163500
1 parent 48046eb commit d4d0b9d

File tree

2 files changed

+27
-38
lines changed

2 files changed

+27
-38
lines changed
 

‎devtools/client/debugger/test/mochitest/browser_dbg-features-source-text-content.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -420,15 +420,17 @@ add_task(async function testGarbageCollectedSourceTextContent() {
420420
* - it first loads fine so that it shows up
421421
* - initDebuggerWithAbsoluteURL will first load the document before the debugger
422422
* - so the debugger will have to fetch the html page content via a network request
423-
* - the test page will return a 404 error code on the second load attempt
423+
* - the test page will return a connection reset error on the second load attempt
424424
*/
425425
let loadCount = 0;
426426
httpServer.registerPathHandler(
427-
"/200-then-404-page.html",
427+
"/200-then-connection-reset.html",
428428
(request, response) => {
429429
loadCount++;
430430
if (loadCount > 1) {
431-
response.setStatusLine(request.httpVersion, 404, "Not found");
431+
response.seizePower();
432+
response.bodyOutPutStream.close();
433+
response.finish();
432434
return;
433435
}
434436
response.setStatusLine(request.httpVersion, 200, "OK");
@@ -440,17 +442,17 @@ add_task(async function testFailingHtmlSource() {
440442

441443
// initDebuggerWithAbsoluteURL will first load the document once before the debugger,
442444
// then the debugger will have to fetch the html page content via a network request
443-
// therefore the test page will return a 404 error code on the second load attempt
445+
// therefore the test page will encounter a connection reset error on the second load attempt
444446
const dbg = await initDebuggerWithAbsoluteURL(
445-
BASE_URL + "200-then-404-page.html",
446-
"200-then-404-page.html"
447+
BASE_URL + "200-then-connection-reset.html",
448+
"200-then-connection-reset.html"
447449
);
448450

449451
// We can't select the HTML page as its source content isn't fetched
450452
// (waitForSelectedSource doesn't resolve)
451453
// Note that it is important to load the page *before* opening the page
452454
// so that the thread actor has to request the page content and will fail
453-
const source = findSource(dbg, "200-then-404-page.html");
455+
const source = findSource(dbg, "200-then-connection-reset.html");
454456
await dbg.actions.selectLocation(
455457
getContext(dbg),
456458
{ sourceId: source.id },

‎devtools/shared/DevToolsUtils.js

+18-31
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ var {
1515
} = require("resource://devtools/shared/platform/stack.js");
1616

1717
const lazy = {};
18-
ChromeUtils.defineModuleGetter(lazy, "OS", "resource://gre/modules/osfile.jsm");
1918

2019
ChromeUtils.defineESModuleGetters(lazy, {
2120
FileUtils: "resource://gre/modules/FileUtils.sys.mjs",
@@ -565,7 +564,23 @@ function mainThreadFetch(
565564
// to using the locale default encoding (bug 1181345).
566565

567566
// Read and decode the data according to the locale default encoding.
568-
const available = stream.available();
567+
568+
let available;
569+
try {
570+
available = stream.available();
571+
} catch (ex) {
572+
if (ex.name === "NS_BASE_STREAM_CLOSED") {
573+
// Empty files cause NS_BASE_STREAM_CLOSED exception.
574+
// If there was a real stream error, we would have already rejected above.
575+
resolve({
576+
content: "",
577+
contentType: "text/plan",
578+
});
579+
return;
580+
}
581+
582+
reject(ex);
583+
}
569584
let source = NetUtil.readInputStreamToString(stream, available);
570585
stream.close();
571586

@@ -639,35 +654,7 @@ function mainThreadFetch(
639654
sourceMapURL,
640655
});
641656
} catch (ex) {
642-
const uri = request.originalURI;
643-
if (
644-
ex.name === "NS_BASE_STREAM_CLOSED" &&
645-
uri instanceof Ci.nsIFileURL
646-
) {
647-
// Empty files cause NS_BASE_STREAM_CLOSED exception. Use OS.File to
648-
// differentiate between empty files and other errors (bug 1170864).
649-
// This can be removed when bug 982654 is fixed.
650-
651-
uri.QueryInterface(Ci.nsIFileURL);
652-
// Bug 1779574: IOUtils is not available in non-parent processes.
653-
// eslint-disable-next-line mozilla/reject-osfile
654-
const result = lazy.OS.File.read(uri.file.path).then(bytes => {
655-
// Convert the bytearray to a String.
656-
const decoder = new TextDecoder();
657-
const content = decoder.decode(bytes);
658-
659-
// We can't detect the contentType without opening a channel
660-
// and that failed already. This is the best we can do here.
661-
return {
662-
content,
663-
contentType: "text/plain",
664-
};
665-
});
666-
667-
resolve(result);
668-
} else {
669-
reject(ex);
670-
}
657+
reject(ex);
671658
}
672659
};
673660

0 commit comments

Comments
 (0)
Failed to load comments.