edge-runtime
edge-runtime copied to clipboard
Wrapping constructors in a `Proxy` breaks `toString`
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 https://github.com/open-telemetry/opentelemetry-js/issues/4473 (https://github.com/vercel/otel/pull/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.