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

Wrapping constructors in a Proxy breaks toString #1068

Open
chancancode opened this issue Dec 13, 2024 · 0 comments
Open

Wrapping constructors in a Proxy breaks toString #1068

chancancode opened this issue Dec 13, 2024 · 0 comments

Comments

@chancancode
Copy link

Bug Report

A while back, I filed https://issues.chromium.org/issues/380105420 for a completely unrelated issue in a different context.

Today, I came across open-telemetry/opentelemetry-js#4473 (vercel/otel#136) which sounds suspiciously similar. Did some digging, and indeed, edge does wrap the constructor in a proxy.

The TL;DR of the issue is that, currently in V8, wrapping a native function in a Proxy alters the result of toString():

Object.toString();                       // => "function Object() { [native code] }"
p = new Proxy(Object, {}); p.toString(); // => "function () { [native code] }"

IMO, this is a bug in V8, and would appreciate someone representing a different use case chiming in on that issue.

Anyway, this ends up mattering because some code, in this case, lodash's isPlainObject() uses the exact match of the string as a signal and that ends up breaking.

From what I gathered, the whole reason the Proxying code exists is an imperfect workaround to make more existing code work as-is, to that end, you may want to also handle toString() to improve compatibility on the proxies until V8 fixes the underlying bug.

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

No branches or pull requests

1 participant