js-on-sx: Function constructor compiles + evaluates JS source
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 30s

Was unconditionally throwing "Function constructor not supported".
Now js-function-ctor joins param strings with commas, wraps the
body in (function(<params>){<body>}), and runs it through js-eval.
Now Function('a', 'b', 'return a + b')(3,4) === 7.
built-ins/Function: 0/14 → 4/14. conformance.sh: 148/148.
This commit is contained in:
2026-05-08 16:02:14 +00:00
parent f0dffd275d
commit ee422f3d15
4 changed files with 91 additions and 48 deletions

View File

@@ -23,7 +23,58 @@
;; ── Boolean coercion (ToBoolean) ──────────────────────────────────
(define js-function-global {:__callable__ (fn (&rest args) (error "TypeError: Function constructor not supported")) :prototype {:call (fn (&rest args) :js-undefined) :length 0 :bind (fn (&rest args) (fn () :js-undefined)) :toString (fn () "function () { [native code] }") :apply (fn (&rest args) :js-undefined) :name ""}})
(define js-function-global {:__callable__ (fn (&rest args) (js-function-ctor args)) :prototype {:call (fn (&rest args) :js-undefined) :length 0 :bind (fn (&rest args) (fn () :js-undefined)) :toString (fn () "function () { [native code] }") :apply (fn (&rest args) :js-undefined) :name ""}})
(define
js-function-ctor
(fn
(args)
(cond
((empty? args) (js-eval "(function(){})"))
(else
(let
((all-strs (js-fn-args-to-strs args))
(n (len args)))
(let
((param-strs (js-fn-take-init all-strs))
(body-str (js-fn-take-last all-strs)))
(js-eval
(str "(function(" (js-fn-join-commas param-strs) "){" body-str "})"))))))))
(define
js-fn-args-to-strs
(fn
(args)
(cond
((empty? args) (list))
(else (cons (js-to-string (first args)) (js-fn-args-to-strs (rest args)))))))
(define
js-fn-take-init
(fn
(lst)
(cond
((empty? lst) (list))
((empty? (rest lst)) (list))
(else (cons (first lst) (js-fn-take-init (rest lst)))))))
(define
js-fn-take-last
(fn
(lst)
(cond
((empty? lst) "")
((empty? (rest lst)) (first lst))
(else (js-fn-take-last (rest lst))))))
(define
js-fn-join-commas
(fn
(lst)
(cond
((empty? lst) "")
((empty? (rest lst)) (first lst))
(else (str (first lst) "," (js-fn-join-commas (rest lst)))))))
;; ── Numeric coercion (ToNumber) ───────────────────────────────────

View File

@@ -1,61 +1,53 @@
{
"totals": {
"pass": 23,
"fail": 21,
"skip": 5,
"timeout": 1,
"total": 50,
"runnable": 45,
"pass_rate": 51.1
"pass": 4,
"fail": 10,
"skip": 16,
"timeout": 0,
"total": 30,
"runnable": 14,
"pass_rate": 28.6
},
"categories": [
{
"category": "built-ins/Array",
"total": 50,
"pass": 23,
"fail": 21,
"skip": 5,
"timeout": 1,
"pass_rate": 51.1,
"category": "built-ins/Function",
"total": 30,
"pass": 4,
"fail": 10,
"skip": 16,
"timeout": 0,
"pass_rate": 28.6,
"top_failures": [
[
"Test262Error (assertion failed)",
18
"SyntaxError (parse/unsupported syntax)",
4
],
[
"TypeError: not a function",
2
"ReferenceError (undefined symbol)",
3
],
[
"Timeout",
1
],
[
"Unhandled: Not callable: {:2 43 :1 42 :0 41 :length 3}\\",
1
"TypeError (other)",
3
]
]
}
],
"top_failure_modes": [
[
"Test262Error (assertion failed)",
18
"SyntaxError (parse/unsupported syntax)",
4
],
[
"TypeError: not a function",
2
"ReferenceError (undefined symbol)",
3
],
[
"Timeout",
1
],
[
"Unhandled: Not callable: {:2 43 :1 42 :0 41 :length 3}\\",
1
"TypeError (other)",
3
]
],
"pinned_commit": "d5e73fc8d2c663554fb72e2380a8c2bc1a318a33",
"elapsed_seconds": 141.9,
"elapsed_seconds": 11.2,
"workers": 1
}

View File

@@ -1,28 +1,26 @@
# test262 scoreboard
Pinned commit: `d5e73fc8d2c663554fb72e2380a8c2bc1a318a33`
Wall time: 141.9s
Wall time: 11.2s
**Total:** 23/45 runnable passed (51.1%). Raw: pass=23 fail=21 skip=5 timeout=1 total=50.
**Total:** 4/14 runnable passed (28.6%). Raw: pass=4 fail=10 skip=16 timeout=0 total=30.
## Top failure modes
- **18x** Test262Error (assertion failed)
- **2x** TypeError: not a function
- **1x** Timeout
- **1x** Unhandled: Not callable: {:2 43 :1 42 :0 41 :length 3}\
- **4x** SyntaxError (parse/unsupported syntax)
- **3x** ReferenceError (undefined symbol)
- **3x** TypeError (other)
## Categories (worst pass-rate first, min 10 runnable)
| Category | Pass | Fail | Skip | Timeout | Total | Pass % |
|---|---:|---:|---:|---:|---:|---:|
| built-ins/Array | 23 | 21 | 5 | 1 | 50 | 51.1% |
| built-ins/Function | 4 | 10 | 16 | 0 | 30 | 28.6% |
## Per-category top failures (min 10 runnable, worst first)
### built-ins/Array (23/45 — 51.1%)
### built-ins/Function (4/14 — 28.6%)
- **18x** Test262Error (assertion failed)
- **2x** TypeError: not a function
- **1x** Timeout
- **1x** Unhandled: Not callable: {:2 43 :1 42 :0 41 :length 3}\
- **4x** SyntaxError (parse/unsupported syntax)
- **3x** ReferenceError (undefined symbol)
- **3x** TypeError (other)