Skip to content

Remove unnecessary eval() in wrapSyscallFunction#26609

Merged
sbc100 merged 1 commit intoemscripten-core:mainfrom
sbc100:avoid_eval
Apr 3, 2026
Merged

Remove unnecessary eval() in wrapSyscallFunction#26609
sbc100 merged 1 commit intoemscripten-core:mainfrom
sbc100:avoid_eval

Conversation

@sbc100
Copy link
Copy Markdown
Collaborator

@sbc100 sbc100 commented Apr 2, 2026

There is no need to turn the string back into a JS function here.

@sbc100 sbc100 requested a review from kleisauke April 2, 2026 17:36
kleisauke added a commit to kleisauke/emscripten that referenced this pull request Apr 2, 2026
@sbc100 sbc100 requested a review from kripken April 2, 2026 18:37
There is no need to turn the string back into a JS function here.

for (var x in SyscallsLibrary) {
wrapSyscallFunction(x, SyscallsLibrary, false);
for (const name of Object.keys(SyscallsLibrary)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this better?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

for .. of is pretty much always preferred over for .. in in modern JS.

The in interator has the problem that it iterates over everything, no just "own properties", so technically usage of in should using be paired with hasOwnProperty

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fair enough, but here you also add Object.keys(). I guess maybe the overhead is not a big deal in this case, but the code ends up longer and less clear in my opinion?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I just think we should follow best modern JS practices everwhere in the compiler.

We can do crazy stuff in the generated code I guess, but no reason to micro-optimize the compiler code.

Copy link
Copy Markdown
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

Fair enough.

@sbc100 sbc100 merged commit 7fba652 into emscripten-core:main Apr 3, 2026
38 checks passed
@sbc100 sbc100 deleted the avoid_eval branch April 3, 2026 15:43
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