js-on-sx: ToPrimitive treats functions as non-primitive
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 21s

Per ES, ToPrimitive only accepts strings/numbers/booleans/null
/undefined as primitives — objects AND functions trigger the next
step. Was treating function returns from toString/valueOf as
primitives (recursing to extract a string), so toString returning
a function didn't fall through to valueOf. Widened the dict-only
check to (or (= type "dict") (js-function? result)) in both
js-to-string and js-to-number ToPrimitive paths.
built-ins/String: 85/99 → 86/99. conformance.sh: 148/148.
This commit is contained in:
2026-05-08 12:50:40 +00:00
parent d51ae65bbb
commit b7627b4102
4 changed files with 35 additions and 53 deletions

View File

@@ -1044,7 +1044,7 @@
(let
((result (js-call-with-this v valueof-fn ())))
(if
(not (= (type-of result) "dict"))
(and (not (= (type-of result) "dict")) (not (js-function? result)))
(js-to-number result)
(let
((tostr-fn (js-get-prop v "toString")))
@@ -1053,7 +1053,7 @@
(let
((result2 (js-call-with-this v tostr-fn ())))
(if
(not (= (type-of result2) "dict"))
(and (not (= (type-of result2) "dict")) (not (js-function? result2)))
(js-to-number result2)
(raise (js-new-call TypeError (list "Cannot convert object to primitive value")))))
(js-nan-value)))))
@@ -1381,7 +1381,7 @@
(let
((result (js-call-with-this v tostr-fn ())))
(if
(= (type-of result) "dict")
(or (= (type-of result) "dict") (js-function? result))
(let
((valueof-fn (js-get-prop v "valueOf")))
(if
@@ -1389,7 +1389,7 @@
(let
((result2 (js-call-with-this v valueof-fn ())))
(if
(= (type-of result2) "dict")
(or (= (type-of result2) "dict") (js-function? result2))
(raise
(js-new-call
TypeError