js-on-sx: NativeError prototype chain + [object Error/Date/Map/Set] brands
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 49s

This commit is contained in:
2026-05-08 23:08:01 +00:00
parent a1030dce5d
commit 20997d3360
2 changed files with 46 additions and 1 deletions

View File

@@ -158,6 +158,8 @@ Each item: implement → tests → update progress. Mark `[x]` when tests green.
Append-only record of completed iterations. Loop writes one line per iteration: date, what was done, test count delta.
- 2026-05-08 — **NativeError prototype chain wired: `Object.getPrototypeOf(EvalError) === Error`, `Error.prototype.constructor === Error`, `[object Error]` brand.** Three pieces: (1) `js-object-tostring-class` now recognises `__js_error_data__` (returns `"[object Error]"`), `__js_is_date__` (`"[object Date]"`), `__map_keys__` / `__set_items__` (`"[object Map]"` / `"[object Set]"`) — these were all falling through to `"[object Object]"`. (2) New `__js_ctor_proto__` side-table maps lambda-ctor identity → its [[Prototype]] constructor; `js-object-get-prototype-of` consults it for non-dict callables. Populated for all six native error subclasses (TypeError/RangeError/SyntaxError/ReferenceError/URIError/EvalError) → Error. (3) Each subclass's `prototype.__proto__` set to `Error.prototype`, and `Error.prototype` gets `name`, `message`, `constructor` populated; each subclass prototype also gets its own `name` and `constructor`. Result: built-ins/NativeErrors 14/30 → 27/30 (+13), built-ins/Error 11/30 → 17/30 (+6). Object/Map/Array unchanged. conformance.sh: 148/148.
- 2026-05-08 — **Object literals get `__proto__: Object.prototype`; try/catch wraps SX error strings into JS Error instances.** Two fixes that work together: (1) `js-make-obj` now sets `__proto__` to `(get Object "prototype")` on every plain object literal `{}` — was missing, so `({}) instanceof Object` was `false`. (2) `js-transpile-try` now wraps the catch param via `js-wrap-exn` — when SX throws an `Eval_error("TypeError: ...")` / `("RangeError: ...")` / `("SyntaxError: ...")` etc. into the catch body, the user previously got a plain string. Now each prefix dispatches to the matching `js-new-call` so `e instanceof TypeError` etc. is truthy. Note: `Eval_error("Undefined symbol: y")` is NOT caught by SX `guard` at all, so the `1 + y → ReferenceError` shape remains unfixable from JS land — out of scope (would need OCaml-side change to make symbol lookup raisable). Result: language/expressions/instanceof 13/30 → 18/30 (+5). Object/Map/Array unchanged. conformance.sh: 148/148.
- 2026-05-08 — **`Date` constructor + prototype stubs.** `Date` was undefined globally — every test in `built-ins/Date` died at `new Date(...)` with ReferenceError. Implemented as a dict-with-`__callable__` (same pattern as `Map`/`Set`/`Object`). Constructor accepts 0 args (epoch 0), 1 number arg (ms), 1 string arg (parses leading `YYYY` to compute approx ms via `(year-1970)*31557600000`), or 2+ args (year, month, day → simple ms calc). `__date_value__` is the internal slot. Statics: `Date.now()`, `Date.parse(s)`, `Date.UTC(...)`. Prototype: `getTime` / `valueOf` / `setTime`, all `getX` / `getUTCX` (most return 0/1 — only `getFullYear` actually computes), `toISOString` / `toJSON` / `toString` / `toUTCString` produce `YYYY-01-01T00:00:00.000Z` from the stored year, plus the locale variants. Wired `Date` into `js-global` and the post-init `__proto__` chain. The maths is approximate (ignores leap years, varying month lengths, timezone offsets) — but the structural tests `typeof new Date(...) === "object"` and the basic flow now work. Result: built-ins/Date 0/30 → 3/30 (rest timeouts/assertions on month-rollover/leap-year math we don't model). conformance.sh: 148/148.