js-on-sx: call/apply box primitive thisArg per non-strict ToObject
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 48s

This commit is contained in:
2026-05-09 14:13:57 +00:00
parent 699b30ed1b
commit 802544fdc6
2 changed files with 18 additions and 8 deletions

View File

@@ -326,6 +326,19 @@
0
(+ 1 (js-count-real-params (rest params)))))))))
(define
js-coerce-this-arg
(fn
(v)
(cond
((js-undefined? v) js-global-this)
((= v nil) js-global-this)
((or (= (type-of v) "number") (= (type-of v) "rational"))
(js-new-call Number (js-args v)))
((= (type-of v) "string") (js-new-call String (js-args v)))
((= (type-of v) "boolean") (js-new-call Boolean (js-args v)))
(else v))))
(define
js-invoke-function-method
(fn
@@ -339,20 +352,15 @@
(< (len args) 1)
(list)
(js-list-slice args 1 (len args)))))
(let
((this-arg
(if (or (js-undefined? raw-this) (= raw-this nil)) js-global-this raw-this)))
(js-call-with-this this-arg recv rest))))
(js-call-with-this (js-coerce-this-arg raw-this) recv rest)))
((= key "apply")
(let
((raw-this (if (< (len args) 1) :js-undefined (nth args 0)))
(arr
(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))))
(this-arg
(if (or (js-undefined? raw-this) (= raw-this nil)) js-global-this raw-this)))
(js-call-with-this this-arg recv rest))))
((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))))
((= key "bind")
(cond
((not (js-function? recv))