Skip to content

Use JSON.stringify for test tracing output - #28119

Open
jeremy-code wants to merge 3 commits into
emscripten-core:mainfrom
jeremy-code:tracing-post-testing
Open

jeremy-code wants to merge 3 commits into
emscripten-core:mainfrom
jeremy-code:tracing-post-testing

Conversation

@jeremy-code

Copy link
Copy Markdown
Contributor

Currently, it outputs something like this for objects:

Tracing memory-layout,0,[object Object]

@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 updates the tracing logic in src/lib/libtrace.js to serialize the entry object using JSON.stringify when logging. The review feedback correctly points out that JSON.stringify can throw a TypeError if entry contains BigInt values, which are common in Emscripten environments. It is recommended to handle this potential error by wrapping the serialization in a try...catch block or using a custom replacer to safely serialize BigInt values.

Comment thread src/lib/libtrace.js Resolved

@sbc100 sbc100 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.

Its been a while since I heard of anyone actually using this API. Can I ask what you are using it for?

lgtm % comment

Comment thread src/lib/libtrace.js Outdated
);
} catch (e) {
out('Tracing [Serialization Error]: ' + e.message);
}

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.

Might be easier to read this error if you just let the exception flow to the top level? i.e. just remove this try/catch?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That makes sense -- implemented

@jeremy-code

Copy link
Copy Markdown
Contributor Author

Its been a while since I heard of anyone actually using this API. Can I ask what you are using it for?

lgtm % comment

I'm using embind and I want to verify that the memory allocated by the generated code is correctly being freed. I figured the worker setup would be too complicated since it's just quick sanity checking.

This branch has not been deployed

No deployments
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