Skip to main content

instance_late_methods

Function instance_late_methods 

Source
pub fn instance_late_methods(tag: &str) -> &'static [&'static str]
Expand description

The ACCESSOR properties a native class’s prototype carries, as (name, has_setter), and the Symbol.toStringTag it stamps (empty for none).

Node keeps these OFF the instance: Object.keys(new AbortController()) is empty and JSON.stringify of one is {}, because signal is a getter on AbortController.prototype. Storing them as own data properties — what this did — leaked them into every enumeration, every spread and every serialization of an object that merely held one.

The getter reads the instance’s hidden @@<name> slot, so a construction site stores the value there rather than under the public name. Run whatever a class has to do after one of its accessor SETTERS stored a value — for a URL, rewriting the fields derived from the one just written.

Without this the setter was a plain slot write: u.protocol = 'https:' read back as https: while u.href still showed http://…, so the object disagreed with itself. Whether a class’s prototype MEMBERS are enumerable, as node defines them.

Most are: for (const k in new URL('http://a/')) walks href, origin and the rest, because a WebIDL interface’s members are enumerable and node defines its own classes the same way. The exceptions are the ones written as ES classes — vm.Script and the KeyObject family — whose methods are non-enumerable like any class method’s.

constructor is never enumerable, in either kind. Methods a class defines AFTER its accessors.

Prototype members enumerate in definition order, and node defines URL.prototype as toString, then every accessor, then toJSON — so a for-in over a URL ends with toJSON rather than starting with it.