js-on-sx: fn.constructor === Function for function instances
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s

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.
conformance.sh: 148/148.
This commit is contained in:
2026-05-08 03:24:31 +00:00
parent 9b07f97341
commit d676bcb6b7
2 changed files with 4 additions and 1 deletions

View File

@@ -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

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 — **`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.