Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by

In the implementation of pr-writer-impl in core.cljs, the first possibility the code checks is whether an object was created with deftype or defrecord. It does so by inspecting the cljs$lang$type property.

ECMAScript 6 introduced Proxy objects, allowing the construction of objects that can intercept arbitrary property lookups. Some modern JavaScript libraries (for example, Pulumi) leverage this functionality as part of their API, and return a "truthy" value for any property lookup.

This leads to code errors when printing these objects in ClojureScript, including at the REPL, and renders the REPL largely unusable when working on objects produced by such libraries.

It is not possible to work around this limitation in client code in the general case, because the check occurs prior to the check for alternative protocols such as IPrintWithWriter.

Suggested fix: rather than testing only for the "truthiness" of the cljs$lang$type property, test for a particular value or type of value such that the condition will not evaluate to true for Proxy objects which respond to arbitrary property lookups with an arbitrary value.

1 Answer

+1 vote
by

Protocols already use the cljs.core/PROTOCOL_SENTINEL object. I guess this cljs$lang$type property could also use that instead of true.

...