Files
scriptc/tests/corpus/object-inherited-to-string.js
Chris Tate 0894b98a48 Honor inherited object formatters in static Effect programs (#602)
* Honor inherited object formatters for Effect shard hashes

* Record inherited formatter corpus preflight baseline
2026-10-01 19:54:28 -05:00

29 lines
991 B
JavaScript

const proto = {
toString() { return `value:${this.label}`; }
};
const value = Object.create(proto);
value.label = "first";
const child = Object.create(value);
child.label = "second";
console.log(value.toString(), child.toString(), String(child));
Object.defineProperty(proto, "toString", {
configurable: true,
get() {
const label = this.label;
return function() { return `${label}/${this.label}`; };
}
});
console.log(value.toString(), child.toString());
const shadow = Object.create(value);
Object.defineProperty(shadow, "toString", { value: undefined });
try { shadow.toString(); } catch (error) { console.log(error.name, error.message); }
Object.defineProperty(proto, "toString", {
configurable: true,
get() { throw new Error("formatter getter"); }
});
try { child.toString(); } catch (error) { console.log(error.name, error.message); }
const own = Object.create(null);
own.label = "own";
own.toString = function() { return this.label; };
console.log(own.toString());