diff --git a/lib/js/runtime.sx b/lib/js/runtime.sx index 65f8ab6e..12cfa681 100644 --- a/lib/js/runtime.sx +++ b/lib/js/runtime.sx @@ -2737,11 +2737,12 @@ (js-dict-get-walk obj (js-to-string key))) ((and (= obj Promise) (dict-has? __js_promise_statics__ (js-to-string key))) (get __js_promise_statics__ (js-to-string key))) - ((and (js-function? obj) (or (= key "prototype") (= key "name") (= key "length") (= key "call") (= key "apply") (= key "bind"))) + ((and (js-function? obj) (or (= key "prototype") (= key "name") (= key "length") (= key "call") (= key "apply") (= key "bind") (= key "constructor"))) (cond ((= key "prototype") (js-get-ctor-proto obj)) ((= key "name") (js-extract-fn-name obj)) ((= key "length") (js-fn-length obj)) + ((= key "constructor") js-function-global) (else (js-invoke-function-bound obj key)))) (else js-undefined)))) (define diff --git a/plans/js-on-sx.md b/plans/js-on-sx.md index 7e0258ff..f994140c 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-08 — **`fn.constructor === Function` for function instances.** Per ES, every function instance's `constructor` slot points to the `Function` global. Was returning undefined for `(function () {}).constructor`. Added `constructor` to the function-property cond in `js-get-prop`; returns `js-function-global`. Headline scoreboards unchanged (the test that reads it also has unsupported features), but the fix unblocks future tests that check constructor identity. conformance.sh: 148/148. + - 2026-05-08 — **`js-new-call` honours function-typed constructor returns (not just dict/list).** `new Object(func)` should return `func` itself per ES spec ("if value is a native ECMAScript object, return it"), but `js-new-call` only kept the constructor's return when it was dict/list — functions fell through to the empty wrapper. Added `(js-function? ret)` to the accept set. Now `new Object(fn) === fn` and `new Object(fn)()` invokes `fn`. built-ins/Object: 42/50 → 44/50. conformance.sh: 148/148. - 2026-05-08 — **`var` declarations hoist out of nested blocks; nested `var` becomes `set!`.** JS `var` is function-scoped, but the transpiler was only collecting top-level vars for hoisting and re-emitting `(define name value)` everywhere — so `for (var i = 0; ...) { var r = i; } r` saw `r` as undefined because the inner `(define r ...)` shadowed the (un-hoisted) outer scope. Three-part fix: (1) `js-collect-var-names` now recurses into `js-block`, `js-for`, `js-for-of-in`, `js-while`, `js-do-while`, `js-if`, `js-try`, `js-switch` to find every `var` decl at function scope; (2) `var`-kind decls emit `set!` (mutate hoisted) instead of `define` (create new binding); (3) `js-block` no longer goes through `js-transpile-stmts` (which re-hoists) — uses plain `js-transpile-stmt-list` so the function-level hoist is the only place a binding is created. built-ins/Array: 17/45 → 18/45, String: 77/99 → 78/99. conformance.sh: 148/148.