Skip to content

Commit 7aa70ae

Browse files
authored
Enable eslint no-undef rule in JS compiler. NFC (#23384)
This required making eslint aware of the settings globals which are used throughout the compiler. Running this change revealed several legacy parseTools function that simply do not run due to references to undefined symbols (because of this we know that there are no active/current user of these functions).
1 parent c7d4255 commit 7aa70ae

File tree

5 files changed

+30
-59
lines changed

5 files changed

+30
-59
lines changed

eslint.config.mjs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
import globals from 'globals';
22
import js from '@eslint/js';
33
import { FlatCompat } from '@eslint/eslintrc';
4+
import { loadDefaultSettings } from './src/utility.mjs';
45

56
const compat = new FlatCompat({
67
baseDirectory: import.meta.dirname,
78
recommendedConfig: js.configs.recommended,
89
allConfig: js.configs.all
910
});
1011

12+
13+
// Emscripten settings are made available to the compiler as global
14+
// variables. Make sure eslint knows about them.
15+
const settings = loadDefaultSettings();
16+
const settingsGlobals = {};
17+
for (const name of Object.keys(settings)) {
18+
settingsGlobals[name] = 'writable';
19+
}
20+
1121
export default [{
1222
ignores: [
1323
'**/out/',
@@ -56,9 +66,10 @@ export default [{
5666
globals: {
5767
...globals.browser,
5868
...globals.node,
69+
...settingsGlobals,
5970
},
6071

61-
ecmaVersion: 13,
72+
ecmaVersion: 'latest',
6273
sourceType: 'module',
6374
},
6475

@@ -77,6 +88,7 @@ export default [{
7788
files: ['**/*.mjs'],
7889

7990
rules: {
91+
'no-undef': 'error',
8092
'no-unused-vars': ['error', {
8193
vars: 'all',
8294
args: 'none',

src/compiler.mjs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77

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

10-
import {Benchmarker, applySettings, assert, loadSettingsFile, printErr, read} from './utility.mjs';
11-
12-
// Load default settings
13-
loadSettingsFile('settings.js');
14-
loadSettingsFile('settings_internal.js');
10+
import {
11+
Benchmarker,
12+
applySettings,
13+
assert,
14+
loadDefaultSettings,
15+
printErr,
16+
read,
17+
} from './utility.mjs';
18+
19+
loadDefaultSettings();
1520

1621
const argv = process.argv.slice(2);
1722
const symbolsOnlyArg = argv.indexOf('--symbols-only');

src/parseTools.mjs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -893,23 +893,6 @@ function buildStringArray(array) {
893893
}
894894
}
895895

896-
function _asmjsDemangle(symbol) {
897-
if (symbol.startsWith('dynCall_')) {
898-
return symbol;
899-
}
900-
// Strip leading "_"
901-
assert(symbol.startsWith('_'), `expected mangled symbol: ${symbol}`);
902-
return symbol.substr(1);
903-
}
904-
905-
// TODO(sbc): Remove this function along with _asmjsDemangle.
906-
function hasExportedFunction(func) {
907-
warnOnce(
908-
'hasExportedFunction has been replaced with hasExportedSymbol, which takes and unmangled (no leading underscore) symbol name',
909-
);
910-
return WASM_EXPORTS.has(_asmjsDemangle(func));
911-
}
912-
913896
function hasExportedSymbol(sym) {
914897
return WASM_EXPORTS.has(sym);
915898
}
@@ -1109,7 +1092,6 @@ addToCompileTimeContext({
11091092
getNativeTypeSize,
11101093
getPerformanceNow,
11111094
getUnsharedTextDecoderView,
1112-
hasExportedFunction,
11131095
hasExportedSymbol,
11141096
implicitSelf,
11151097
isSymbolNeeded,

src/parseTools_legacy.mjs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@
77
import {warn, addToCompileTimeContext} from './utility.mjs';
88
import {ATMAINS, POINTER_SIZE, runIfMainThread} from './parseTools.mjs';
99

10-
// Takes a pair of return values, stashes one in tempRet0 and returns the other.
11-
// Should probably be renamed to `makeReturn64` but keeping this old name in
12-
// case external JS library code uses this name.
13-
function makeStructuralReturn(values) {
14-
warn('use of legacy parseTools function: makeStructuralReturn');
15-
assert(values.length == 2);
16-
return 'setTempRet0(' + values[1] + '); return ' + asmCoercion(values[0], 'i32');
17-
}
18-
1910
// Replaced (at least internally) with receiveI64ParamAsI53 that does
2011
// bounds checking.
2112
function receiveI64ParamAsDouble(name) {
@@ -42,44 +33,18 @@ function makeMalloc(source, param) {
4233
return `_malloc(${param})`;
4334
}
4435

45-
function getNativeFieldSize(type) {
46-
warn('use of legacy parseTools function: getNativeFieldSize');
47-
return Math.max(getNativeTypeSize(type), POINTER_SIZE);
48-
}
49-
5036
const Runtime = {
51-
getNativeFieldSize,
5237
POINTER_SIZE,
5338
QUANTUM_SIZE: POINTER_SIZE,
5439
};
5540

56-
function addAtMain(code) {
57-
warn('use of legacy parseTools function: addAtMain');
58-
assert(HAS_MAIN, 'addAtMain called but program has no main function');
59-
ATMAINS.push(code);
60-
}
61-
62-
function ensureValidFFIType(type) {
63-
return type === 'float' ? 'double' : type; // ffi does not tolerate float XXX
64-
}
65-
66-
// FFI return values must arrive as doubles, and we can force them to floats afterwards
67-
function asmFFICoercion(value, type) {
68-
value = asmCoercion(value, ensureValidFFIType(type));
69-
if (type === 'float') value = asmCoercion(value, 'float');
70-
return value;
71-
}
72-
7341
// Legacy name for runIfMainThread.
7442
const runOnMainThread = runIfMainThread;
7543

7644
addToCompileTimeContext({
7745
ATMAINS,
7846
Runtime,
79-
addAtMain,
80-
asmFFICoercion,
8147
makeMalloc,
82-
makeStructuralReturn,
8348
receiveI64ParamAsDouble,
8449
receiveI64ParamAsI32s,
8550
runOnMainThread,

src/utility.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,13 @@ export function loadSettingsFile(f) {
313313
var settings = {};
314314
vm.runInNewContext(read(f), settings, {filename: find(f)});
315315
applySettings(settings);
316+
return settings;
317+
}
318+
319+
export function loadDefaultSettings() {
320+
const rtn = loadSettingsFile('settings.js');
321+
Object.assign(rtn, loadSettingsFile('settings_internal.js'));
322+
return rtn;
316323
}
317324

318325
export function runInMacroContext(code, options) {

0 commit comments

Comments
 (0)