Files
scriptc/tests/corpus/class-symbol-cache.mjs
Chris Tate 2069684b40 Expand static Effect support across common APIs (#598)
* Expand static Effect support across common APIs

* Preserve compiler parity across expanded Effect patterns

* Fix compiler regressions exposed by Effect coverage

* Bound shared type conversion traversal

* Clarify conversion contracts and tidy fixtures

* Run every Effect fixture in CI shards

* Preserve inferred array assignments in concurrent Effect programs

* Record inferred array fixture compiler ordering
2026-10-01 02:49:31 -05:00

32 lines
917 B
JavaScript

const hash = Symbol.for("hash");
function cache(self, value) {
Object.defineProperty(self, hash, { value() { return value; }, enumerable: false });
}
class Key {
calls = 0;
[hash]() {
this.calls++;
cache(this, 42);
return 42;
}
}
function read(value) { return value[hash](); }
function own(value) { return Object.hasOwn(value, hash); }
const key = new Key();
console.log(own(key), read(key), read(key), key.calls, own(key));
// A base constructor observes the instance before derived fields initialize.
// Copying properties must not expose an uninitialized native symbol slot.
const tag = Symbol.for("tag");
class AssignedError extends Error {
constructor(properties) {
super();
Object.assign(this, properties);
}
}
class TaggedError extends AssignedError {
[tag] = tag;
}
const failure = new TaggedError({ message: "copied" });
console.log(failure.message, failure[tag] === tag);