From 96a7541d70eb8119bbca574461d0ffeac8985ca7 Mon Sep 17 00:00:00 2001 From: giles Date: Thu, 7 May 2026 21:19:43 +0000 Subject: [PATCH] js-on-sx: Object(null) and Object(undefined) return new empty object MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per ES spec, Object(value) returns a new object when value is null or undefined. Was returning the argument itself, breaking Object(null).toString(). Added a cond clause to Object.__callable__ that detects nil/js-undefined and falls through to (dict). built-ins/Object: 15/50 → 16/50. conformance.sh: 148/148. --- lib/js/runtime.sx | 2 +- lib/js/test262-scoreboard.json | 2 +- lib/js/test262-scoreboard.md | 2 +- plans/js-on-sx.md | 2 ++ 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/js/runtime.sx b/lib/js/runtime.sx index 6e170d61..eb5fa1f8 100644 --- a/lib/js/runtime.sx +++ b/lib/js/runtime.sx @@ -3396,7 +3396,7 @@ (and (>= idx 0) (< idx (len o)) (integer? idx)))) (else false)))) -(define Object {:keys js-object-keys :getPrototypeOf js-object-get-prototype-of :isSealed js-object-is-sealed :seal js-object-seal :create js-object-create :isExtensible js-object-is-extensible :is js-object-is :setPrototypeOf js-object-set-prototype-of :getOwnPropertyNames js-object-get-own-property-names :getOwnPropertyDescriptors js-object-get-own-property-descriptors :defineProperty js-object-define-property :fromEntries js-object-from-entries :getOwnPropertyDescriptor js-object-get-own-property-descriptor :assign js-object-assign :isFrozen js-object-is-frozen :freeze js-object-freeze :values js-object-values :hasOwn js-object-has-own :prototype {:hasOwnProperty (fn (k) (let ((o (js-this))) (js-object-has-own o k))) :toLocaleString (fn () "[object Object]") :isPrototypeOf (fn (o) (let ((this-val (js-this))) (cond ((not (dict? o)) false) (else (let ((proto (if (contains? (keys o) "__proto__") (get o "__proto__") nil))) (cond ((= proto this-val) true) ((= proto nil) false) (else ((get (get Object "prototype") "isPrototypeOf") proto)))))))) :toString (fn () "[object Object]") :propertyIsEnumerable (fn (k) (let ((o (js-this))) (js-object-has-own o k))) :valueOf (fn () (js-this))} :__callable__ (fn (&rest args) (cond ((= (len args) 0) (dict)) (else (nth args 0)))) :preventExtensions js-object-prevent-extensions :entries js-object-entries :defineProperties js-object-define-properties}) +(define Object {:keys js-object-keys :getPrototypeOf js-object-get-prototype-of :isSealed js-object-is-sealed :seal js-object-seal :create js-object-create :isExtensible js-object-is-extensible :is js-object-is :setPrototypeOf js-object-set-prototype-of :getOwnPropertyNames js-object-get-own-property-names :getOwnPropertyDescriptors js-object-get-own-property-descriptors :defineProperty js-object-define-property :fromEntries js-object-from-entries :getOwnPropertyDescriptor js-object-get-own-property-descriptor :assign js-object-assign :isFrozen js-object-is-frozen :freeze js-object-freeze :values js-object-values :hasOwn js-object-has-own :prototype {:hasOwnProperty (fn (k) (let ((o (js-this))) (js-object-has-own o k))) :toLocaleString (fn () "[object Object]") :isPrototypeOf (fn (o) (let ((this-val (js-this))) (cond ((not (dict? o)) false) (else (let ((proto (if (contains? (keys o) "__proto__") (get o "__proto__") nil))) (cond ((= proto this-val) true) ((= proto nil) false) (else ((get (get Object "prototype") "isPrototypeOf") proto)))))))) :toString (fn () "[object Object]") :propertyIsEnumerable (fn (k) (let ((o (js-this))) (js-object-has-own o k))) :valueOf (fn () (js-this))} :__callable__ (fn (&rest args) (cond ((= (len args) 0) (dict)) ((or (= (nth args 0) nil) (js-undefined? (nth args 0))) (dict)) (else (nth args 0)))) :preventExtensions js-object-prevent-extensions :entries js-object-entries :defineProperties js-object-define-properties}) (dict-set! Object "length" 1) diff --git a/lib/js/test262-scoreboard.json b/lib/js/test262-scoreboard.json index f4cdbc0c..dbce29c3 100644 --- a/lib/js/test262-scoreboard.json +++ b/lib/js/test262-scoreboard.json @@ -56,6 +56,6 @@ ] ], "pinned_commit": "d5e73fc8d2c663554fb72e2380a8c2bc1a318a33", - "elapsed_seconds": 152.5, + "elapsed_seconds": 158.2, "workers": 1 } \ No newline at end of file diff --git a/lib/js/test262-scoreboard.md b/lib/js/test262-scoreboard.md index 802eeb95..5535dd0a 100644 --- a/lib/js/test262-scoreboard.md +++ b/lib/js/test262-scoreboard.md @@ -1,7 +1,7 @@ # test262 scoreboard Pinned commit: `d5e73fc8d2c663554fb72e2380a8c2bc1a318a33` -Wall time: 152.5s +Wall time: 158.2s **Total:** 78/99 runnable passed (78.8%). Raw: pass=78 fail=15 skip=1 timeout=6 total=100. diff --git a/plans/js-on-sx.md b/plans/js-on-sx.md index 91cc916b..63e99394 100644 --- a/plans/js-on-sx.md +++ b/plans/js-on-sx.md @@ -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-07 — **`Object(null)` and `Object(undefined)` return a new empty object.** Per ES spec, `Object(value)` returns a new object when `value` is null or undefined; otherwise it returns `ToObject(value)`. Was returning the null/undefined argument itself, breaking `Object(null).toString()`. Added a clause to the `Object.__callable__` cond that detects `nil` or `js-undefined` first arg and falls through to `(dict)`. built-ins/Object: 15/50 → 16/50. conformance.sh: 148/148. + - 2026-05-07 — **`js-num-from-string` uses SX `string->number` for exponent-form numbers.** Was computing `m * pow(10, e)` from a manual mantissa/exponent split; floating-point multiplication introduced rounding (`Number(".12345e-3") - 0.00012345 == 2.7e-20`). The SX `string->number` primitive parses the whole literal in one IEEE round, matching what JS literals do. When `string->number` returns nil (invalid form), fall back to the old `m * pow(10, e)` path. built-ins/Number: 42/50 → 43/50. conformance.sh: 148/148. - 2026-05-07 — **Constructors (`Object`/`Array`/`Number`/`String`/`Boolean`) carry `__proto__ = Function.prototype`.** Per spec, the constructors are functions and inherit from `Function.prototype`, so `Function.prototype.foo = 1; Array.foo === 1`. Previously the constructor dicts had no `__proto__`, so they only saw `Object.prototype` via the recent fallback — `Function.prototype` mutations were invisible. Added a `(begin (dict-set! ...))` post-init at the end of `runtime.sx` after the constructors are defined. Combined with the existing Object.prototype fallback, the proto chain now terminates correctly for the constructor → `Function.prototype` → `Object.prototype` walk. built-ins/Number: 41/50 → 42/50, built-ins/String: 75/99 → 78/99, built-ins/Array: 12/45 → 13/45. conformance.sh: 148/148.