js-on-sx: String.prototype.* ToString-coerces non-string this; .call/.apply skip global-coerce for built-ins
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 22s

This commit is contained in:
2026-05-10 03:45:25 +00:00
parent 058dcd5600
commit 8a06c2d72b
2 changed files with 14 additions and 3 deletions

View File

@@ -339,6 +339,15 @@
((= (type-of v) "boolean") (js-new-call Boolean (js-args v)))
(else v))))
(define
js-call-this-coerce
(fn
(recv v)
(cond
((or (= (type-of recv) "lambda") (= (type-of recv) "component"))
(js-coerce-this-arg v))
(else v))))
(define
js-invoke-function-method
(fn
@@ -352,7 +361,7 @@
(< (len args) 1)
(list)
(js-list-slice args 1 (len args)))))
(js-call-with-this (js-coerce-this-arg raw-this) recv rest)))
(js-call-with-this (js-call-this-coerce recv raw-this) recv rest)))
((= key "apply")
(let
((raw-this (if (< (len args) 1) :js-undefined (nth args 0)))
@@ -360,7 +369,7 @@
(if (< (len args) 2) (list) (nth args 1))))
(let
((rest (cond ((= arr nil) (list)) ((js-undefined? arr) (list)) ((list? arr) arr) (else (js-iterable-to-list arr)))))
(js-call-with-this (js-coerce-this-arg raw-this) recv rest))))
(js-call-with-this (js-call-this-coerce recv raw-this) recv rest))))
((= key "bind")
(cond
((not (js-function? recv))
@@ -4754,7 +4763,7 @@
(let
((this-val (js-this)))
(let
((s (cond ((= (type-of this-val) "string") this-val) ((and (= (type-of this-val) "dict") (contains? (keys this-val) "__js_string_value__")) (get this-val "__js_string_value__")) (else "[object Object]"))))
((s (cond ((or (= this-val nil) (js-undefined? this-val)) (raise (js-new-call TypeError (js-args (str "String.prototype." name " called on null or undefined"))))) ((= (type-of this-val) "string") this-val) ((and (= (type-of this-val) "dict") (contains? (keys this-val) "__js_string_value__")) (get this-val "__js_string_value__")) (else (js-to-string this-val)))))
(js-invoke-method s name args))))
:length (js-string-proto-fn-length name)
:name name}))