Skip to main content

DEFAULT_PREPARE

Constant DEFAULT_PREPARE 

Source
pub const DEFAULT_PREPARE: &str = "ErrorPrepareStackTrace";
Expand description

[[Get]](name, receiver) — 10.1.8. receiver is the object the read STARTED from and is what a getter sees as this; it differs from recv only when the read was forwarded down a prototype chain, which is why Reflect.get(t, k, r) and a Proxy get trap’s third argument both need it. Every ordinary read passes recv itself. Re-format an error’s .stack header on its first read, the way V8 does.

The constructor could only stamp the name it was called with, so a subclass that sets this.name after super() — or any e.name = … / e.message = … before the first read — left a stale header. Node re-reads both properties at format time, including one inherited from the prototype (E.prototype.name).

It is formatted ONCE: node caches the string, so renaming AFTER a read does not change what later reads return. @@stackRaw is the not-yet-formatted marker and is dropped here; an explicit e.stack = … drops it too, so an assignment is never clobbered by a later read. The key of node’s DEFAULT Error.prepareStackTrace. Recognised by name so the ordinary stack path can skip the hook round-trip when nothing custom is installed.