js-on-sx: arguments object + Array.from mapFn calling convention
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 45s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 45s
Three related fixes: 1. Every JS function body binds arguments to (cons p1 ... __extra_args__), so arguments[k] and arguments.length work as expected. 2. Array.from(iter, mapFn) invokes mapFn through js-call-with-this with the index as second arg (was (map-fn x), missing index and inheriting outer this). 3. thisArg defaults to js-global-this when omitted (per non-strict ES). conformance.sh: 148/148.
This commit is contained in:
@@ -3611,7 +3611,11 @@
|
||||
(let
|
||||
((src (js-iterable-to-list (nth args 0)))
|
||||
(map-fn
|
||||
(if (< (len args) 2) nil (nth args 1))))
|
||||
(if (< (len args) 2) nil (nth args 1)))
|
||||
(this-arg
|
||||
(if (or (< (len args) 3) (js-undefined? (nth args 2)) (= (nth args 2) nil))
|
||||
js-global-this
|
||||
(nth args 2))))
|
||||
(if
|
||||
(= map-fn nil)
|
||||
(let
|
||||
@@ -3623,8 +3627,9 @@
|
||||
(for-each
|
||||
(fn
|
||||
(x)
|
||||
(append! result (map-fn x))
|
||||
(set! i (+ i 1)))
|
||||
(begin
|
||||
(append! result (js-call-with-this this-arg map-fn (list x i)))
|
||||
(set! i (+ i 1))))
|
||||
src)
|
||||
result)))))))
|
||||
|
||||
|
||||
@@ -940,6 +940,21 @@
|
||||
(js-param-sym (first params))
|
||||
(js-build-param-list (rest params)))))))
|
||||
|
||||
(define
|
||||
js-arguments-build-form
|
||||
(fn
|
||||
(params)
|
||||
(cond
|
||||
((empty? params)
|
||||
(js-sym "__extra_args__"))
|
||||
((and (list? (first params)) (js-tag? (first params) "js-rest"))
|
||||
(js-sym (nth (first params) 1)))
|
||||
(else
|
||||
(list
|
||||
(js-sym "cons")
|
||||
(js-param-sym (first params))
|
||||
(js-arguments-build-form (rest params)))))))
|
||||
|
||||
(define
|
||||
js-param-init-forms
|
||||
(fn
|
||||
@@ -1402,7 +1417,9 @@
|
||||
param-syms
|
||||
(list
|
||||
(js-sym "let")
|
||||
(list (list (js-sym "this") (list (js-sym "js-this"))))
|
||||
(list
|
||||
(list (js-sym "this") (list (js-sym "js-this")))
|
||||
(list (js-sym "arguments") (js-arguments-build-form params)))
|
||||
(list
|
||||
(js-sym "let")
|
||||
(list
|
||||
|
||||
Reference in New Issue
Block a user