Closed Bug 1782491 Opened 2 years ago Closed 2 years ago

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

Categories

(Core :: JavaScript Engine, task, P1)

task

Tracking

()

RESOLVED FIXED
105 Branch
Tracking Status
firefox105 --- fixed

People

(Reporter: anba, Assigned: anba)

References

Details

Attachments

(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 andre.bargull@gmail.com: https://hg.mozilla.org/integration/autoland/rev/24470be9cddc Part 1: Add self-hosted code environment plugin. r=tcampbell https://hg.mozilla.org/integration/autoland/rev/405f2f052ffb Part 2: Warn about undeclared variables in self-hosted code. r=tcampbell https://hg.mozilla.org/integration/autoland/rev/aec7a500c04e Part 3: Undefine standard built-ins in self-hosted code. r=tcampbell https://hg.mozilla.org/integration/autoland/rev/9fe496797601 Part 4: Enable strict-mode by default for eslint. r=tcampbell https://hg.mozilla.org/integration/autoland/rev/64beab0dc780 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.

Attachment

General

Created:
Updated:
Size: