Repository navigation
[JS] Prefer Object.hasOwn over hasOwnProperty. NFC - #28129
Merged
Merged
Conversation
There was a problem hiding this comment.
Code Review
This pull request replaces hasOwnProperty calls with Object.hasOwn or a new $hasOwn helper across the codebase, enforcing this pattern via ESLint's prefer-object-has-own rule. The review feedback points out a compatibility issue in src/lib/libcore.js where MIN_NODE_VERSION < 160900 should be added to the fallback condition to ensure older Node.js environments are properly supported.
kripken
approved these changes
Nov 2, 2026
In compile-time JS code (`src/`, `tools/`, and compile-time helpers in `libwebgl.js`), use `Object.hasOwn` directly instead of `hasOwnProperty`. In runtime JS library code, introduce an internal `$hasOwn` helper in `libcore.js` that aliases `Object.hasOwn` when targeting modern browser versions (`MIN_FIREFOX_VERSION >= 92`, `MIN_CHROME_VERSION >= 93`, and `MIN_SAFARI_VERSION >= 150400`) and falls back to `Object.prototype.hasOwnProperty.call` otherwise. Note that this change comes with minor codesize change, in some cases an improvement and in some a regression. Note that if we were to bump our default min browser versions we would always see an improvement (perhaps we should always target modern browser in our codesize tests?) See emscripten-core#28125
sbc100
added a commit
to sbc100/emscripten
that referenced
this pull request
Nov 2, 2026
Follow-up to emscripten-core#28129: - Enable `prefer-exponentiation-operator`, `prefer-object-spread`, `prefer-rest-params`, `prefer-spread`, and `logical-assignment-operators` in `eslint.config.mjs`. - Use `Object.values`, direct integer indexing, or `??=` in places where `$hasOwn` is not needed. - Use `Map` instead of plain `{}` objects for lookup tables in `acorn-optimizer.mjs` and `libglfw.js`. - Replace legacy `Array.prototype.slice.call`, `.apply`, `.indexOf`, `Math.pow`, and `arr[arr.length - 1]` idioms with `.slice`, `Array.from`, spread syntax, `.includes`, `**` / `Math.hypot`, and `.at(-1)`.
sbc100
added a commit
to sbc100/emscripten
that referenced
this pull request
Nov 2, 2026
Follow-up to emscripten-core#28129: - Enable `prefer-exponentiation-operator`, `prefer-object-spread`, `prefer-rest-params`, `prefer-spread`, and `logical-assignment-operators` in `eslint.config.mjs`. - Use `Object.values`, direct integer indexing, or `??=` in places where `$hasOwn` is not needed. - Use `Map` instead of plain `{}` objects for lookup tables in `acorn-optimizer.mjs` and `libglfw.js`. - Replace legacy `Array.prototype.slice.call`, `.apply`, `.indexOf`, `Math.pow`, and `arr[arr.length - 1]` idioms with `.slice`, `Array.from`, spread syntax, `.includes`, `**` / `Math.hypot`, and `.at(-1)`.
basvandijk
added a commit
to basvandijk/emscripten
that referenced
this pull request
Nov 2, 2026
emscripten-core#28129 added `$hasOwn` to libcore.js. It aliases `Object.hasOwn` when the minimum browser versions support it and falls back to `Object.prototype.hasOwnProperty.call` otherwise. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sbc100
added a commit
to sbc100/emscripten
that referenced
this pull request
Nov 2, 2026
Bump the default target browser versions in `src/settings.js`: - `MIN_CHROME_VERSION`: 85 -> 93 - `MIN_FIREFOX_VERSION`: 79 -> 92 - `MIN_SAFARI_VERSION`: 150000 -> 150400 This allows `$hasOwn` in `libcore.js` (introduced in emscripten-core#28129) to use the `Object.hasOwn` fast path by default. See: emscripten-core#28125
sbc100
added a commit
to sbc100/emscripten
that referenced
this pull request
Nov 2, 2026
Bump the default target browser versions in `src/settings.js`: - `MIN_CHROME_VERSION`: 85 -> 93 - `MIN_FIREFOX_VERSION`: 79 -> 92 - `MIN_SAFARI_VERSION`: 150000 -> 150400 This allows `$hasOwn` in `libcore.js` (introduced in emscripten-core#28129) to use the `Object.hasOwn` fast path by default. See: emscripten-core#28125
sbc100
added a commit
to sbc100/emscripten
that referenced
this pull request
Nov 3, 2026
Follow-up to emscripten-core#28129: - Enable `prefer-exponentiation-operator`, `prefer-object-spread`, `prefer-rest-params`, `prefer-spread`, and `logical-assignment-operators` in `eslint.config.mjs`. - Use `Object.values`, direct integer indexing, or `??=` in places where `$hasOwn` is not needed. - Use `Map` instead of plain `{}` objects for lookup tables in `acorn-optimizer.mjs` and `libglfw.js`. - Replace legacy `.apply`, `.indexOf`, `Math.pow`, and `arr[arr.length - 1]` idioms with `.call` / spread syntax, `.includes`, `**` / `Math.hypot`, and `.at(-1)`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In compile-time JS code (
src/,tools/, and compile-time helpers inlibwebgl.js), useObject.hasOwndirectly instead ofhasOwnProperty.In runtime JS library code, introduce an internal
$hasOwnhelper inlibcore.jsthat aliasesObject.hasOwnwhen targeting modern browserversions (
MIN_FIREFOX_VERSION >= 92,MIN_CHROME_VERSION >= 93, andMIN_SAFARI_VERSION >= 150400) and falls back toObject.prototype.hasOwnProperty.callotherwise.Note that this change comes with minor codesize change, in some cases an
improvement and in some a regression. Note that if we were to bump
our default min browser versions we would always see an improvement
(perhaps we should always target modern browser in our codesize tests?)
See #28125