Closed Bug 1782491 Opened 2 months ago Closed 2 months ago

Enable "no-undef" ESLint rule for self-hosted code


(Core :: JavaScript Engine, task, P1)




105 Branch
Tracking Status
firefox105 --- fixed


(Reporter: anba, Assigned: anba)




(5 files)

Misspelled variable names in self-hosted code currently lead to assertion errors, but only when the relevant code is actually executed. We can improve this situation for ESLint capable editors [1] by providing an ESLint plugin which determines all self-hosted global variables.

[1] Or when manually executing ./mach lint js/src/builtin/.

Adds a simple ESLint plugin for custom environments.

The plugin has a single exported value named globals, which is an object with
keys for all globally available self-hosted identifiers. All self-hosted values
are read-only, so we set all properties of globals to "readonly".

BytecodeEmitter special identifiers are added to the .eslintrc.js file,
because that keeps them closer to the SpiderMonkey source tree when compared
to "tools/lint/eslint/eslint-plugin-spidermonkey-js".

Also see:

Enable the "no-undef" ESLint rule for self-hosted code.

The plugin from part 1 can't discover two special cases:

  1. Dynamically generated RegExp functions.
  2. The inner #define in endOfUnicodeExtensions.

Add /* global <name> */ comments to declare these names as global identifiers.

HYPHEN isn't really a global variable, part 5 will clean this up.

Depends on D153337

Standard global identifiers aren't available in self-hosted code. Let's
undefine them, so ESLint-capable editors will warn when they're used.

It seems that names must be undeclared in ".eslintrc.js" files, because any
attempts to undeclare them in the ESLint environment plugin from part 1 didn't
work out.

The Mozilla ESLint plugin enables the "mozilla/privileged" environment by
default, see "tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js".
We don't want it to be enabled for self-hosted code.

Depends on D153338

Self-hosted code is always strict-mode, but ESLint doesn't know about that.

Depends on D153339

charCodeAt was faster than indexed string lookups when this function was
originally written (bug 1440315). After bug 813836 there isn't anymore any
performance difference, so we might as well use the simpler code.

Depends on D153340

Severity: -- → N/A
Priority: -- → P1
Pushed by
Part 1: Add self-hosted code environment plugin. r=tcampbell
Part 2: Warn about undeclared variables in self-hosted code. r=tcampbell
Part 3: Undefine standard built-ins in self-hosted code. r=tcampbell
Part 4: Enable strict-mode by default for eslint. r=tcampbell
Part 5: Use simple string comparison in endOfUnicodeExtensions. r=tcampbell
You need to log in before you can comment on or make changes to this bug.