Skip to content

Commit 83e561b

Browse files
committed
Modernize internal JS code and run it through eslint. NFC
This change does not effect the JS that we output, only the the internal JS tooling. This is a followup to #15836 which did this cleanup just for a single file. The long list of exclusions in `.eslintrc.yml` is because these files are part of the JS library code which we ship and we a lot of that cannot be run though the lint tool because it uses our speciall pre-processing techniques.
1 parent 5fe16c6 commit 83e561b

File tree

11 files changed

+247
-207
lines changed

11 files changed

+247
-207
lines changed

.eslintrc.yml

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,48 @@ extends:
66
- google
77
parserOptions:
88
ecmaVersion: 12
9-
ignorePatterns: "library_*.js"
9+
ignorePatterns:
10+
- "site/"
11+
- "third_party/"
12+
- "tests/"
13+
- "src/library*.js"
14+
- "src/runtime_*.js"
15+
- "src/shell*.js"
16+
- "src/preamble*.js"
17+
- "src/postamble*.js"
18+
- "src/closure-externs/"
19+
- "src/embind/"
20+
- "src/emrun_postjs.js"
21+
- "src/worker.js"
22+
- "src/wrtcp.js"
23+
- "src/wasm2js.js"
24+
- "src/webGLClient.js"
25+
- "src/webGLWorker.js"
26+
- "src/*_shell_read.js"
27+
- "src/wasm_offset_converter.js"
28+
- "src/threadprofiler.js"
29+
- "src/cpuprofiler.js"
30+
- "src/memoryprofiler.js"
31+
- "src/support.js"
32+
- "src/gl-matrix.js"
33+
- "src/promise_polyfill.js"
34+
- "src/headless.js"
35+
- "src/headlessCanvas.js"
36+
- "src/socket.io.js"
37+
- "src/emscripten-source-map.min.js"
38+
- "src/source_map_support.js"
39+
- "src/Fetch.js"
40+
- "src/settings.js"
41+
- "src/settings_internal.js"
42+
- "src/arrayUtils.js"
43+
- "src/deterministic.js"
44+
- "src/base64Utils.js"
45+
- "src/base64Decode.js"
46+
- "src/proxyWorker.js"
47+
- "src/proxyClient.js"
48+
- "src/IDBStore.js"
49+
- "src/URIUtils.js"
50+
- "tools/experimental"
1051
rules:
1152
#max-len: ["error", 100]
1253
max-len: "off"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
"wasm2c": "1.0.0"
1515
},
1616
"scripts": {
17-
"lint": "eslint src/parseTools.js tools/acorn-optimizer.js tools/lz4-compress.js"
17+
"lint": "eslint ."
1818
}
1919
}

src/compiler.js

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,30 @@
77

88
// LLVM => JavaScript compiler, main entry point
99

10-
var nodeFS = require('fs');
11-
nodePath = require('path');
10+
global.nodeFS = require('fs');
11+
global.nodePath = require('path');
1212

13-
print = (x) => {
13+
global.print = (x) => {
1414
process['stdout'].write(x + '\n');
1515
};
1616

17-
printErr = (x) => {
17+
global.printErr = (x) => {
1818
process['stderr'].write(x + '\n');
1919
};
2020

2121
function find(filename) {
22-
var prefixes = [__dirname, process.cwd()];
23-
for (var i = 0; i < prefixes.length; ++i) {
24-
var combined = nodePath.join(prefixes[i], filename);
22+
const prefixes = [__dirname, process.cwd()];
23+
for (let i = 0; i < prefixes.length; ++i) {
24+
const combined = nodePath.join(prefixes[i], filename);
2525
if (nodeFS.existsSync(combined)) {
2626
return combined;
2727
}
2828
}
2929
return filename;
3030
}
3131

32-
read = (filename) => {
33-
var absolute = find(filename);
32+
global.read = (filename) => {
33+
const absolute = find(filename);
3434
return nodeFS.readFileSync(absolute).toString();
3535
};
3636

@@ -45,22 +45,23 @@ load('utility.js');
4545
load('./settings.js');
4646
load('./settings_internal.js');
4747

48-
var arguments_ = process['argv'].slice(2);
49-
var settingsFile = arguments_[0];
48+
const settingsFile = process['argv'][2];
5049

5150
if (settingsFile) {
52-
var settings = JSON.parse(read(settingsFile));
53-
for (var key in settings) {
54-
var value = settings[key];
55-
if (value[0] == '@') {
56-
// response file type thing, workaround for large inputs: value is @path-to-file
57-
try {
58-
value = JSON.parse(read(value.substr(1)));
59-
} catch(e) {
60-
// continue normally; assume it is not a response file
51+
const settings = JSON.parse(read(settingsFile));
52+
for (const key in settings) {
53+
if (Object.prototype.hasOwnProperty.call(settings, key)) {
54+
let value = settings[key];
55+
if (value[0] == '@') {
56+
// response file type thing, workaround for large inputs: value is @path-to-file
57+
try {
58+
value = JSON.parse(read(value.substr(1)));
59+
} catch (e) {
60+
// continue normally; assume it is not a response file
61+
}
6162
}
63+
global[key] = eval(JSON.stringify(value));
6264
}
63-
global[key] = eval(JSON.stringify(value));
6465
}
6566
}
6667

@@ -72,7 +73,7 @@ INCOMING_MODULE_JS_API = new Set(INCOMING_MODULE_JS_API);
7273
RUNTIME_DEBUG = LIBRARY_DEBUG || GL_DEBUG || DYLINK_DEBUG || PTHREADS_DEBUG;
7374

7475
// Side modules are pure wasm and have no JS
75-
assert(!SIDE_MODULE, "JS compiler should not run on side modules");
76+
assert(!SIDE_MODULE, 'JS compiler should not run on side modules');
7677

7778
// Output some info and warnings based on settings
7879

@@ -87,17 +88,17 @@ load('parseTools.js');
8788
load('jsifier.js');
8889
load('runtime.js');
8990

90-
//===============================
91+
// ===============================
9192
// Main
92-
//===============================
93+
// ===============================
9394

9495
B = new Benchmarker();
9596

9697
try {
97-
JSify();
98+
runJSify();
9899

99100
B.print('glue');
100-
} catch(err) {
101+
} catch (err) {
101102
if (err.toString().includes('Aborting compilation due to previous errors')) {
102103
// Compiler failed on user error, don't print the stacktrace in this case.
103104
printErr(err);

src/emrun_prejs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
// Route URL GET parameters to argc+argv
8-
if (typeof window === "object") {
8+
if (typeof window === 'object') {
99
Module['arguments'] = window.location.search.substr(1).trim().split('&');
1010
// If no args were passed arguments = [''], in which case kill the single empty string.
1111
if (!Module['arguments'][0]) {

0 commit comments

Comments
 (0)