Files
scriptc/tests/corpus/js-class-enumeration.js
Chris Tate a07998f667 Expand static three.js workflows and host integration (#621)
* Expand static three.js workflows and host integration

* Preserve JavaScript class state in static three.js workflows

* Preserve inferred JavaScript behavior across static workflows

* Preserve inferred callables and native compatibility boundaries

* Retain annotated JavaScript factory exports and bootstrap-safe call spreads

* Preserve Buffer and child callback identities in static packages

* Clarify JavaScript symbol spread support
2026-10-02 19:56:34 -05:00

62 lines
1.7 KiB
JavaScript

class Base {
#secret = 9;
constructor(include) {
this.first = 1;
Object.defineProperty(this, "id", { value: 42 });
if (include) this.optional = undefined;
this.last = 3;
}
method() { return this.first; }
self() { return this; }
}
Base.prototype.inherited = 7;
Base.prototype.id = "shadowed";
class Child extends Base {
field = 4;
constructor(include) {
super(include);
this[2] = "two";
this[1] = "one";
}
}
function enumerate(value) {
const keys = [];
for (const key in value) keys.push(key + ":" + String(value[key]));
return keys.join(",");
}
console.log(enumerate(new Child(false)));
console.log(enumerate(new Child(true)));
const value = new Child(false);
console.log(Object.keys(value).join(","));
console.log(Object.getOwnPropertyDescriptor(value, "id").enumerable);
console.log(Object.hasOwn(value, "optional"));
value.optional = undefined;
console.log(Object.hasOwn(value, "optional"), Object.keys(value).join(","));
console.log(enumerate(value));
Object.assign(value, { optional: 8, extra: 9 });
console.log(enumerate(value));
Object.assign(value.self(), { field: 6, extra: 10 });
console.log(value.field, enumerate(value));
const direct = [];
for (const key in value) direct.push(key);
console.log(direct.join(","));
class Reentrant {
constructor() {
this.first = enumerate(this);
this.second = enumerate(this);
}
}
console.log(new Reentrant().second);
// Record capsules retain their declared order and live values through JS calls.
function visit(record) {
const output = [];
for (const key in record) output.push(key + ":" + String(record[key]));
return output.join(",");
}
const record = { z: 3, a: 1 };
console.log(visit(record));
record.a = 2;
console.log(visit(record));