Skip to content

Use destructuring across JS library and runtime code - #28287

Merged
sbc100 merged 1 commit into
emscripten-core:mainfrom
sbc100:destructuring-followup
Nov 23, 2026
Merged

sbc100 merged 1 commit into
emscripten-core:mainfrom
sbc100:destructuring-followup

Conversation

@sbc100

@sbc100 sbc100 commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Followup to #28286
Depends on #28288

Use object and parameter destructuring for multi-property reads and
unused event parameters across src/lib/ and
src/pthread_esm_startup.mjs, using const for declarations so
Closure Compiler lowers them cleanly without extra bindings.

Update affected test/codesize/ expectations.

See: #28272

@sbc100
sbc100 requested a review from brendandahl as a code owner November 17, 2026 16:30

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modernizes various parts of the codebase by replacing multiple individual variable declarations with object destructuring for better readability and conciseness. Additionally, it updates regular expressions in the JSifier to better support async arrow functions, though the reviewer identified that the current regexes still require a space after 'async' and suggested using '\s*' instead to handle cases without a space.

Comment thread src/jsifier.mjs Resolved
Comment thread src/jsifier.mjs Resolved
@sbc100
sbc100 force-pushed the destructuring-followup branch from fdf01db to 0fabb34 Compare November 17, 2026 18:04
@sbc100
sbc100 requested a review from RReverser November 17, 2026 18:04
@sbc100
sbc100 force-pushed the destructuring-followup branch from 0fabb34 to 05702fb Compare November 17, 2026 18:05
Comment thread src/lib/libpthread.js
worker.onmessage = (e) => {
var d = e.data;
worker.onmessage = ({data: d}) => {
var cmd = d.cmd;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not these like

const {cmd, targetThread} = d;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better yet, put it straight in the param like ({ data: { cmd, targetThread } }) => { - the d stringifcation below is useless anyway and would result in "[object Object]".

Comment thread src/lib/libsdl.js Outdated
Comment on lines +1628 to +1629
var canvas = Browser.getCanvas();
var width = canvas.width;
var height = canvas.height;
const {width, height} = canvas;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Destructuring can eliminate quite a few variables as they are now single-use:

const {width, height} = Browser.getCanvas();

Comment thread src/lib/libembind.js
var registeredClass = wrapperType.registeredClass;
var wrapperPrototype = registeredClass.instancePrototype;
var baseClass = registeredClass.baseClass;
const {instancePrototype: wrapperPrototype, baseClass} = registeredClass;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const {instancePrototype: wrapperPrototype, baseClass} = registeredClass;
const {instancePrototype: wrapperPrototype, baseClass: {instancePrototype: baseClassPrototype, constructor: baseConstructor, pureVirtualFunctions}} = registeredClass;

@RReverser RReverser left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but there's definitely more places where 2nd pass could nest even more property accesses into the pattern or variables into the RHS expression.

@sbc100

sbc100 commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

If it OK with you I'll land this change then then we and propose a followup taking it all the next level?

@sbc100
sbc100 force-pushed the destructuring-followup branch from 05702fb to ec88e75 Compare November 18, 2026 05:30

@RReverser RReverser left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I wasn't sure what feedback you are looking for, hence the comments, but fine either way :)

@sbc100
sbc100 force-pushed the destructuring-followup branch from ec88e75 to 238e429 Compare November 18, 2026 18:05
Followup to emscripten-core#28286

Use object and parameter destructuring for multi-property reads and
unused event parameters across `src/lib/` and
`src/pthread_esm_startup.mjs`, using `const` for declarations so
Closure Compiler lowers them cleanly without extra bindings.

Update affected `test/codesize/` expectations.

See: emscripten-core#28272
@sbc100
sbc100 force-pushed the destructuring-followup branch from 238e429 to 1fbe902 Compare November 23, 2026 22:13
@sbc100
sbc100 merged commit fa9168b into emscripten-core:main Nov 23, 2026
22 of 26 checks passed
@sbc100
sbc100 deleted the destructuring-followup branch November 23, 2026 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants