Repository navigation
Adopt additional modern JS patterns and ESLint rules. NFC - #28138
Conversation
There was a problem hiding this comment.
Code Review
This pull request modernizes the codebase by adopting several ES6+ features and enforcing them via new ESLint rules. Key changes include replacing Math.pow with the exponentiation operator (**), utilizing Array.from and .slice() instead of Array.prototype.slice.call, adopting .at(-1) for accessing the last element of arrays, replacing indexOf checks with .includes(), and using logical assignment operators (??=, ||=). Additionally, some plain objects were refactored to use Map. Feedback on these changes highlights potential issues with the new logical assignment operators. Specifically, using ??= on objects or constructors (such as derivedClass.constructor and SDL.joystickNamePool) can bypass assignments if the property name collides with inherited prototype properties (e.g., toString or constructor). Reverting to Object.hasOwn checks is recommended in these cases. Furthermore, converting a typed array to a standard array via Array.from(arg).slice(0, 400) in src/runtime_debug.js is highly inefficient for large arrays; slicing the typed array first with .subarray(0, 400) before calling Array.from is suggested to avoid unnecessary memory copying.
439eacc to
57d00f3
Compare
Rename `rawType` and related `raw*Type` variables/parameters in embind JS code to `typeID` and `*TypeID`. This matches the existing `// typeID -> ...` comments and C++ `TYPEID` typedef and makes it clear that these hold numeric `TYPEID` pointers rather than type names or registered type objects. Inspired by the question/confusion in: emscripten-core#28138 (comment)
Rename `rawType` and related `raw*Type` variables/parameters in embind JS code to `typeID` and `*TypeID`. This matches the existing `// typeID -> ...` comments and C++ `TYPEID` typedef and makes it clear that these hold numeric `TYPEID` pointers rather than type names or registered type objects. Inspired by the question/confusion in: emscripten-core#28138 (comment)
Rename `rawType` and related `raw*Type` variables/parameters in embind JS code to `typeID` and `*TypeID`. This matches the existing `// typeID -> ...` comments and C++ `TYPEID` typedef and makes it clear that these hold numeric `TYPEID` pointers rather than type names or registered type objects. Inspired by the question/confusion in: #28138 (comment)
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)`.
Follow-up to #28129 and #28139
prefer-exponentiation-operator,prefer-object-spread,prefer-rest-params,prefer-spread, andlogical-assignment-operatorsineslint.config.mjs.Object.values, direct integer indexing, or??=in places where$hasOwnis not needed.Mapinstead of plain{}objects for lookup tables inacorn-optimizer.mjsandlibglfw.js.Array.prototype.slice.call,.apply,.indexOf,Math.pow, andarr[arr.length - 1]idioms with.slice,Array.from, spread syntax,.includes,**/Math.hypot, and.at(-1).Note: We are not yet using
.at(-1)in runtime code since we still support engines that do not yet support its (and even we we re-introduced babel, its not able to lower this one away).