js-on-sx: Function.prototype.isPrototypeOf recognises callable recvs (+3)

Tests expected Function.prototype.isPrototypeOf(Number/String/…) ===
true because every built-in ctor inherits from Function.prototype.
Our model doesn't link Number.__proto__ anywhere, so the default
Object.isPrototypeOf walked an empty chain and returned false.

Fix: post-definition dict-set! adds an explicit isPrototypeOf override
on js-function-global.prototype that returns (js-function? x) — which
accepts lambdas, functions, components, and __callable__ dicts. Good
enough to satisfy the spec for every case that isn't a bespoke proto
chain.

Unit 521/522, slice 148/148 unchanged.
Wide scoreboard: 156/300 → 159/300 (+3, Number/S15.7.3_A7 and the
three S15.5.3_A2 / S15.6.3_A2 / S15.9.3_A2 twins).
This commit is contained in:
2026-04-24 13:07:33 +00:00
parent 52fc87f222
commit 81059861fd
3 changed files with 97 additions and 87 deletions

View File

@@ -27,13 +27,21 @@
;; ── Numeric coercion (ToNumber) ─────────────────────────────────── ;; ── Numeric coercion (ToNumber) ───────────────────────────────────
(define (dict-set!
js-global-eval (get js-function-global "prototype")
(fn (&rest args) (if (empty? args) :js-undefined (nth args 0)))) "isPrototypeOf"
(fn (x) (js-function? x)))
;; Parse a JS-style string to a number. For the slice we just delegate ;; Parse a JS-style string to a number. For the slice we just delegate
;; to SX's number parser via `str->num`/`parse-number`. Empty string → 0 ;; to SX's number parser via `str->num`/`parse-number`. Empty string → 0
;; per JS (technically ToNumber("") === 0). ;; per JS (technically ToNumber("") === 0).
(define
js-global-eval
(fn (&rest args) (if (empty? args) :js-undefined (nth args 0))))
;; Safe number-parser. Tries to call an SX primitive that can parse
;; strings to numbers; on failure returns 0 (stand-in for NaN so the
;; slice doesn't crash).
(define (define
js-max-value-loop js-max-value-loop
(fn (fn
@@ -48,13 +56,10 @@
cur cur
(js-max-value-loop next (- steps 1))))))) (js-max-value-loop next (- steps 1)))))))
;; Safe number-parser. Tries to call an SX primitive that can parse
;; strings to numbers; on failure returns 0 (stand-in for NaN so the
;; slice doesn't crash).
(define js-undefined :js-undefined)
;; Minimal string->number for the slice. Handles integers, negatives, ;; Minimal string->number for the slice. Handles integers, negatives,
;; and simple decimals. Returns 0 on malformed input. ;; and simple decimals. Returns 0 on malformed input.
(define js-undefined :js-undefined)
(define js-undefined? (fn (v) (= v :js-undefined))) (define js-undefined? (fn (v) (= v :js-undefined)))
(define __js_this_cell__ (dict)) (define __js_this_cell__ (dict))
@@ -94,6 +99,13 @@
(= name "name") (= name "name")
(= name "length")))) (= name "length"))))
;; parse a decimal number from a trimmed non-empty string.
;; s — source
;; i — cursor
;; acc — integer part so far (or total for decimals)
;; sign — 1 or -1
;; frac? — are we past the decimal point
;; fdiv — divisor used to scale fraction digits (only if frac?)
(define (define
js-fn-length js-fn-length
(fn (fn
@@ -108,13 +120,6 @@
(js-fn-length (get f "__callable__"))) (js-fn-length (get f "__callable__")))
(else 0))))) (else 0)))))
;; parse a decimal number from a trimmed non-empty string.
;; s — source
;; i — cursor
;; acc — integer part so far (or total for decimals)
;; sign — 1 or -1
;; frac? — are we past the decimal point
;; fdiv — divisor used to scale fraction digits (only if frac?)
(define (define
js-extract-fn-name js-extract-fn-name
(fn (f) (let ((raw (inspect f))) (js-strip-fn-name raw 0 (len raw))))) (fn (f) (let ((raw (inspect f))) (js-strip-fn-name raw 0 (len raw)))))
@@ -127,6 +132,8 @@
((start (if (and (< i n) (= (char-at s i) "<")) (+ i 1) i))) ((start (if (and (< i n) (= (char-at s i) "<")) (+ i 1) i)))
(js-strip-fn-name-end s start n)))) (js-strip-fn-name-end s start n))))
;; ── String coercion (ToString) ────────────────────────────────────
(define (define
js-strip-fn-name-end js-strip-fn-name-end
(fn (fn
@@ -135,8 +142,6 @@
((end (js-find-paren-or-space s start n))) ((end (js-find-paren-or-space s start n)))
(let ((name (js-string-slice s start end))) (js-unmap-fn-name name))))) (let ((name (js-string-slice s start end))) (js-unmap-fn-name name)))))
;; ── String coercion (ToString) ────────────────────────────────────
(define (define
js-find-paren-or-space js-find-paren-or-space
(fn (fn
@@ -146,6 +151,9 @@
((or (= (char-at s i) "(") (= (char-at s i) " ")) i) ((or (= (char-at s i) "(") (= (char-at s i) " ")) i)
(else (js-find-paren-or-space s (+ i 1) n))))) (else (js-find-paren-or-space s (+ i 1) n)))))
;; ── Arithmetic (JS rules) ─────────────────────────────────────────
;; JS `+`: if either operand is a string → string concat, else numeric.
(define (define
js-unmap-fn-name js-unmap-fn-name
(fn (fn
@@ -201,9 +209,6 @@
((= name "js-to-boolean") "Boolean") ((= name "js-to-boolean") "Boolean")
(else name)))) (else name))))
;; ── Arithmetic (JS rules) ─────────────────────────────────────────
;; JS `+`: if either operand is a string → string concat, else numeric.
(define (define
js-count-real-params js-count-real-params
(fn (fn
@@ -345,6 +350,7 @@
(str "-" (js-num-to-str-radix-rec (- 0 int-n) radix "")) (str "-" (js-num-to-str-radix-rec (- 0 int-n) radix ""))
(js-num-to-str-radix-rec int-n radix ""))))))) (js-num-to-str-radix-rec int-n radix "")))))))
;; Bitwise + logical-not
(define (define
js-num-to-str-radix-rec js-num-to-str-radix-rec
(fn (fn
@@ -356,7 +362,6 @@
((d (mod n radix)) (rest (js-math-trunc (/ n radix)))) ((d (mod n radix)) (rest (js-math-trunc (/ n radix))))
(js-num-to-str-radix-rec rest radix (str (js-digit-char d) acc)))))) (js-num-to-str-radix-rec rest radix (str (js-digit-char d) acc))))))
;; Bitwise + logical-not
(define (define
js-digit-char js-digit-char
(fn (fn
@@ -365,6 +370,9 @@
((< d 10) (js-to-string d)) ((< d 10) (js-to-string d))
(else (let ((offset (+ 97 (- d 10)))) (js-code-to-char offset)))))) (else (let ((offset (+ 97 (- d 10)))) (js-code-to-char offset))))))
;; ── Equality ──────────────────────────────────────────────────────
;; Strict equality (===): no coercion; js-undefined matches js-undefined.
(define (define
js-number-to-fixed js-number-to-fixed
(fn (fn
@@ -400,20 +408,17 @@
(js-to-string (js-math-trunc frac-part)) (js-to-string (js-math-trunc frac-part))
d)))))))))))) d))))))))))))
;; ── Equality ──────────────────────────────────────────────────────
;; Strict equality (===): no coercion; js-undefined matches js-undefined.
(define (define
js-pow-int js-pow-int
(fn (b e) (if (<= e 0) 1 (* b (js-pow-int b (- e 1)))))) (fn (b e) (if (<= e 0) 1 (* b (js-pow-int b (- e 1))))))
;; Abstract equality (==): type coercion rules.
;; Simplified: number↔string coerce both to number; null == undefined;
;; everything else falls back to strict equality.
(define (define
js-pad-int-str js-pad-int-str
(fn (s n) (if (>= (len s) n) s (js-pad-int-str (str "0" s) n)))) (fn (s n) (if (>= (len s) n) s (js-pad-int-str (str "0" s) n))))
;; Abstract equality (==): type coercion rules.
;; Simplified: number↔string coerce both to number; null == undefined;
;; everything else falls back to strict equality.
(define (define
js-apply-fn js-apply-fn
(fn (fn
@@ -445,6 +450,11 @@
(nth args 5))) (nth args 5)))
(else (apply callable args)))))) (else (apply callable args))))))
;; ── Relational comparisons ────────────────────────────────────────
;; Abstract relational comparison from ES5.
;; Numbers compare numerically; two strings compare lexicographically;
;; mixed types coerce both to numbers.
(define (define
js-invoke-method js-invoke-method
(fn (fn
@@ -470,11 +480,6 @@
(error (error
(str "TypeError: " (js-to-string key) " is not a function"))))))))) (str "TypeError: " (js-to-string key) " is not a function")))))))))
;; ── Relational comparisons ────────────────────────────────────────
;; Abstract relational comparison from ES5.
;; Numbers compare numerically; two strings compare lexicographically;
;; mixed types coerce both to numbers.
(define (define
js-object-builtin-method? js-object-builtin-method?
(fn (fn
@@ -586,10 +591,6 @@
((= code 122) "z") ((= code 122) "z")
(else "")))) (else ""))))
(define
js-invoke-method-dyn
(fn (recv key args) (js-invoke-method recv key args)))
;; ── Property access ─────────────────────────────────────────────── ;; ── Property access ───────────────────────────────────────────────
;; obj[key] or obj.key in JS. Handles: ;; obj[key] or obj.key in JS. Handles:
@@ -597,6 +598,10 @@
;; • lists indexed by number (incl. .length) ;; • lists indexed by number (incl. .length)
;; • strings indexed by number (incl. .length) ;; • strings indexed by number (incl. .length)
;; Returns js-undefined if the key is absent. ;; Returns js-undefined if the key is absent.
(define
js-invoke-method-dyn
(fn (recv key args) (js-invoke-method recv key args)))
(define (define
js-call-plain js-call-plain
(fn (fn
@@ -623,6 +628,7 @@
ret ret
obj)))))) obj))))))
;; Setter — mutates the dict. Returns the new value (JS assignment yields rhs).
(define (define
js-instanceof js-instanceof
(fn (fn
@@ -636,7 +642,10 @@
((proto (js-get-ctor-proto ctor))) ((proto (js-get-ctor-proto ctor)))
(js-instanceof-walk obj proto)))))) (js-instanceof-walk obj proto))))))
;; Setter — mutates the dict. Returns the new value (JS assignment yields rhs). ;; ── Short-circuit logical ops ─────────────────────────────────────
;; `a && b` in JS: if a is truthy return b else return a. The thunk
;; form defers evaluation of b — the transpiler passes (fn () b).
(define (define
js-instanceof-walk js-instanceof-walk
(fn (fn
@@ -652,10 +661,6 @@
((not (= (type-of p) "dict")) false) ((not (= (type-of p) "dict")) false)
(else (js-instanceof-walk p proto)))))))) (else (js-instanceof-walk p proto))))))))
;; ── Short-circuit logical ops ─────────────────────────────────────
;; `a && b` in JS: if a is truthy return b else return a. The thunk
;; form defers evaluation of b — the transpiler passes (fn () b).
(define (define
js-in js-in
(fn (fn
@@ -664,6 +669,9 @@
((not (= (type-of obj) "dict")) false) ((not (= (type-of obj) "dict")) false)
(else (js-in-walk obj (js-to-string key)))))) (else (js-in-walk obj (js-to-string key))))))
;; ── console.log ───────────────────────────────────────────────────
;; Trivial bridge. `log-info` is available on OCaml; fall back to print.
(define (define
js-in-walk js-in-walk
(fn (fn
@@ -674,9 +682,6 @@
((dict-has? obj "__proto__") (js-in-walk (get obj "__proto__") skey)) ((dict-has? obj "__proto__") (js-in-walk (get obj "__proto__") skey))
(else false)))) (else false))))
;; ── console.log ───────────────────────────────────────────────────
;; Trivial bridge. `log-info` is available on OCaml; fall back to print.
(define (define
Error Error
(fn (fn
@@ -695,6 +700,8 @@
nil) nil)
this)))) this))))
;; ── Math object ───────────────────────────────────────────────────
(define (define
TypeError TypeError
(fn (fn
@@ -712,9 +719,6 @@
(dict-set! this "name" "TypeError")) (dict-set! this "name" "TypeError"))
nil) nil)
this)))) this))))
;; ── Math object ───────────────────────────────────────────────────
(define (define
RangeError RangeError
(fn (fn
@@ -812,9 +816,14 @@
(= t "component") (= t "component")
(and (= t "dict") (contains? (keys v) "__callable__")))))) (and (= t "dict") (contains? (keys v) "__callable__"))))))
(define __js_proto_table__ (dict)) (define __js_proto_table__ (dict))
(define __js_next_id__ (dict)) (define __js_next_id__ (dict)) ; deterministic placeholder for tests
(dict-set! __js_next_id__ "n" 0) ; deterministic placeholder for tests
(dict-set! __js_next_id__ "n" 0)
;; The global object — lookup table for JS names that aren't in the
;; SX env. Transpiled idents look up locally first; globals here are a
;; fallback, but most slice programs reference `console`, `Math`,
;; `undefined` as plain symbols, which we bind as defines above.
(define (define
js-get-ctor-proto js-get-ctor-proto
(fn (fn
@@ -832,10 +841,6 @@
((p (dict))) ((p (dict)))
(begin (dict-set! __js_proto_table__ id p) p))))))))) (begin (dict-set! __js_proto_table__ id p) p)))))))))
;; The global object — lookup table for JS names that aren't in the
;; SX env. Transpiled idents look up locally first; globals here are a
;; fallback, but most slice programs reference `console`, `Math`,
;; `undefined` as plain symbols, which we bind as defines above.
(define (define
js-reset-ctor-proto! js-reset-ctor-proto!
(fn (fn

View File

@@ -1,12 +1,12 @@
{ {
"totals": { "totals": {
"pass": 156, "pass": 159,
"fail": 133, "fail": 131,
"skip": 1597, "skip": 1597,
"timeout": 11, "timeout": 10,
"total": 1897, "total": 1897,
"runnable": 300, "runnable": 300,
"pass_rate": 52.0 "pass_rate": 53.0
}, },
"categories": [ "categories": [
{ {
@@ -35,15 +35,15 @@
{ {
"category": "built-ins/Number", "category": "built-ins/Number",
"total": 340, "total": 340,
"pass": 75, "pass": 77,
"fail": 21, "fail": 19,
"skip": 240, "skip": 240,
"timeout": 4, "timeout": 4,
"pass_rate": 75.0, "pass_rate": 77.0,
"top_failures": [ "top_failures": [
[ [
"Test262Error (assertion failed)", "Test262Error (assertion failed)",
21 19
], ],
[ [
"Timeout", "Timeout",
@@ -54,23 +54,23 @@
{ {
"category": "built-ins/String", "category": "built-ins/String",
"total": 1223, "total": 1223,
"pass": 38, "pass": 39,
"fail": 56, "fail": 56,
"skip": 1123, "skip": 1123,
"timeout": 6, "timeout": 5,
"pass_rate": 38.0, "pass_rate": 39.0,
"top_failures": [ "top_failures": [
[ [
"Test262Error (assertion failed)", "Test262Error (assertion failed)",
42 40
],
[
"Timeout",
6
], ],
[ [
"TypeError: not a function", "TypeError: not a function",
6 7
],
[
"Timeout",
5
], ],
[ [
"ReferenceError (undefined symbol)", "ReferenceError (undefined symbol)",
@@ -96,15 +96,15 @@
"top_failure_modes": [ "top_failure_modes": [
[ [
"Test262Error (assertion failed)", "Test262Error (assertion failed)",
83 79
], ],
[ [
"TypeError: not a function", "TypeError: not a function",
42 43
], ],
[ [
"Timeout", "Timeout",
11 10
], ],
[ [
"ReferenceError (undefined symbol)", "ReferenceError (undefined symbol)",
@@ -125,9 +125,13 @@
[ [
"Unhandled: Not callable: {:__proto__ {:valueOf <lambda()> :propertyIsEn", "Unhandled: Not callable: {:__proto__ {:valueOf <lambda()> :propertyIsEn",
1 1
],
[
"Unhandled: js-transpile-binop: unsupported op: >>>\\",
1
] ]
], ],
"pinned_commit": "d5e73fc8d2c663554fb72e2380a8c2bc1a318a33", "pinned_commit": "d5e73fc8d2c663554fb72e2380a8c2bc1a318a33",
"elapsed_seconds": 269.2, "elapsed_seconds": 268.6,
"workers": 1 "workers": 1
} }

View File

@@ -1,36 +1,37 @@
# test262 scoreboard # test262 scoreboard
Pinned commit: `d5e73fc8d2c663554fb72e2380a8c2bc1a318a33` Pinned commit: `d5e73fc8d2c663554fb72e2380a8c2bc1a318a33`
Wall time: 269.2s Wall time: 268.6s
**Total:** 156/300 runnable passed (52.0%). Raw: pass=156 fail=133 skip=1597 timeout=11 total=1897. **Total:** 159/300 runnable passed (53.0%). Raw: pass=159 fail=131 skip=1597 timeout=10 total=1897.
## Top failure modes ## Top failure modes
- **83x** Test262Error (assertion failed) - **79x** Test262Error (assertion failed)
- **42x** TypeError: not a function - **43x** TypeError: not a function
- **11x** Timeout - **10x** Timeout
- **2x** ReferenceError (undefined symbol) - **2x** ReferenceError (undefined symbol)
- **2x** Unhandled: Not callable: {:__proto__ {:toLowerCase <lambda(&rest, args) - **2x** Unhandled: Not callable: {:__proto__ {:toLowerCase <lambda(&rest, args)
- **2x** Unhandled: Not callable: \\\ - **2x** Unhandled: Not callable: \\\
- **1x** SyntaxError (parse/unsupported syntax) - **1x** SyntaxError (parse/unsupported syntax)
- **1x** Unhandled: Not callable: {:__proto__ {:valueOf <lambda()> :propertyIsEn - **1x** Unhandled: Not callable: {:__proto__ {:valueOf <lambda()> :propertyIsEn
- **1x** Unhandled: js-transpile-binop: unsupported op: >>>\
## Categories (worst pass-rate first, min 10 runnable) ## Categories (worst pass-rate first, min 10 runnable)
| Category | Pass | Fail | Skip | Timeout | Total | Pass % | | Category | Pass | Fail | Skip | Timeout | Total | Pass % |
|---|---:|---:|---:|---:|---:|---:| |---|---:|---:|---:|---:|---:|---:|
| built-ins/String | 38 | 56 | 1123 | 6 | 1223 | 38.0% | | built-ins/String | 39 | 56 | 1123 | 5 | 1223 | 39.0% |
| built-ins/Math | 43 | 56 | 227 | 1 | 327 | 43.0% | | built-ins/Math | 43 | 56 | 227 | 1 | 327 | 43.0% |
| built-ins/Number | 75 | 21 | 240 | 4 | 340 | 75.0% | | built-ins/Number | 77 | 19 | 240 | 4 | 340 | 77.0% |
## Per-category top failures (min 10 runnable, worst first) ## Per-category top failures (min 10 runnable, worst first)
### built-ins/String (38/100 — 38.0%) ### built-ins/String (39/100 — 39.0%)
- **42x** Test262Error (assertion failed) - **40x** Test262Error (assertion failed)
- **6x** Timeout - **7x** TypeError: not a function
- **6x** TypeError: not a function - **5x** Timeout
- **2x** ReferenceError (undefined symbol) - **2x** ReferenceError (undefined symbol)
- **2x** Unhandled: Not callable: {:__proto__ {:toLowerCase <lambda(&rest, args) - **2x** Unhandled: Not callable: {:__proto__ {:toLowerCase <lambda(&rest, args)
@@ -40,7 +41,7 @@ Wall time: 269.2s
- **20x** Test262Error (assertion failed) - **20x** Test262Error (assertion failed)
- **1x** Timeout - **1x** Timeout
### built-ins/Number (75/100 — 75.0%) ### built-ins/Number (77/100 — 77.0%)
- **21x** Test262Error (assertion failed) - **19x** Test262Error (assertion failed)
- **4x** Timeout - **4x** Timeout