Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quickjs-libc: handle null prototype objects in console.log #632

Open
bnoordhuis opened this issue Oct 27, 2024 · 4 comments
Open

quickjs-libc: handle null prototype objects in console.log #632

bnoordhuis opened this issue Oct 27, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@bnoordhuis
Copy link
Contributor

bnoordhuis commented Oct 27, 2024

$ qjs -e 'console.log({__proto__:null})'
TypeError: toPrimitive
    at log (native)
    at <eval> (<cmdline>:1:1)

edit: originates in JS_ToCString() but that's no excuse for console.log to not show a human-readable representation

@bnoordhuis bnoordhuis added the bug Something isn't working label Oct 27, 2024
@bnoordhuis
Copy link
Contributor Author

After thinking about it for a few minutes, maybe what is needed is something like V8's Value::ToDetailString: a stringifier that always returns something (preferably a useful human-readable representation) without side effects (doesn't call JS code, etc.)

Related to #630.

@chqrlie
Copy link
Collaborator

chqrlie commented Oct 27, 2024

@bnoordhuis Hello! back from limboland!

repl already handles this via a local implementation of util.inspect. Doesn't v8 implement console.log as a wrapper around this?

Our implementation of console.log is very minimal and should be extended, albeit probably not with the full extend of util.inspect.

@bnoordhuis
Copy link
Contributor Author

Hiya Charlie, welcome back.

Doesn't v8 implement console.log as a wrapper around this?

No, V8 only has stubs for console.log and friends; it leaves it up to the embedder.

A prime use case for ToDetailString is printing potentially poisoned/proxied objects (note that aforementioned awesome alliteration) like { toString() { return String(this) } }.

The motivation is that it should be easy for an embedder to - robustly! - print an object.

@saghul
Copy link
Contributor

saghul commented Oct 27, 2024

That SGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants