Skip to content

Commit 53eb3a7

Browse files
committed
Use async/await for internal readAsync function. NFC
Followup to #23104.
1 parent d5c419f commit 53eb3a7

File tree

84 files changed

+91
-101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+91
-101
lines changed

src/node_shell_read.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@ readBinary = (filename) => {
1414
return ret;
1515
};
1616

17-
readAsync = (filename, binary = true) => {
17+
readAsync = async (filename, binary = true) => {
1818
// See the comment in the `readBinary` function.
1919
filename = isFileURI(filename) ? new URL(filename) : filename;
20-
return new Promise((resolve, reject) => {
21-
fs.readFile(filename, binary ? undefined : 'utf8', (err, data) => {
22-
if (err) reject(err);
23-
else resolve(binary ? data.buffer : data);
24-
});
25-
});
20+
var data = fs.readFileSync(filename, binary ? undefined : 'utf8');
21+
return binary ? data.buffer : data;
2622
};

src/shell.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,7 @@ if (ENVIRONMENT_IS_SHELL) {
300300
return data;
301301
};
302302

303-
readAsync = (f) => {
304-
return new Promise((resolve, reject) => {
305-
setTimeout(() => resolve(readBinary(f)));
306-
});
307-
};
303+
readAsync = async (f) => readBinary(f);
308304

309305
globalThis.clearTimeout ??= (id) => {};
310306

src/web_or_worker_shell_read.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717
#endif
1818

19-
readAsync = (url) => {
19+
readAsync = async (url) => {
2020
#if ENVIRONMENT_MAY_BE_WEBVIEW
2121
// Fetch has some additional restrictions over XHR, like it can't be used on a file:// url.
2222
// See https://github.com/github/fetch/pull/92#issuecomment-140665932
@@ -41,11 +41,9 @@
4141
#elif ASSERTIONS
4242
assert(!isFileURI(url), "readAsync does not work with file:// URLs");
4343
#endif
44-
return fetch(url, {{{ makeModuleReceiveExpr('fetchSettings', "{ credentials: 'same-origin' }") }}})
45-
.then((response) => {
46-
if (response.ok) {
47-
return response.arrayBuffer();
48-
}
49-
return Promise.reject(new Error(response.status + ' : ' + response.url));
50-
})
44+
var response = await fetch(url, {{{ makeModuleReceiveExpr('fetchSettings', "{ credentials: 'same-origin' }") }}});
45+
if (response.ok) {
46+
return response.arrayBuffer();
47+
}
48+
throw new Error(response.status + ' : ' + response.url);
5149
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8592
1+
8575
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
21002
1+
20991
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8578
1+
8559
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20969
1+
20958
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9626
1+
9609
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
24845
1+
24834
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8562
1+
8543

0 commit comments

Comments
 (0)