js-on-sx: Array.prototype and String.prototype stubs
Each prototype contains method-name → closure pairs. Each closure reads this via js-this and dispatches through js-invoke-method. Lets Array.prototype.push, String.prototype.slice etc. be accessed and invoked as (expected) functions. 440/442 unit unchanged, 148/148 slice unchanged.
This commit is contained in:
@@ -1844,6 +1844,14 @@
|
||||
|
||||
(define js-array-of (fn (&rest args) args))
|
||||
|
||||
(define
|
||||
js-array-proto-fn
|
||||
(fn
|
||||
(name)
|
||||
(fn
|
||||
(&rest args)
|
||||
(let ((this-val (js-this))) (js-invoke-method this-val name args)))))
|
||||
|
||||
(define
|
||||
js-array-from
|
||||
(fn
|
||||
@@ -1867,7 +1875,7 @@
|
||||
src)
|
||||
result)))))))
|
||||
|
||||
(define Array {:__callable__ (fn (&rest args) (cond ((= (len args) 0) (list)) ((and (= (len args) 1) (number? (nth args 0))) (js-make-list-of-length (js-num-to-int (nth args 0)) js-undefined)) (else args))) :isArray js-array-is-array :of js-array-of :from js-array-from})
|
||||
(define Array {:__callable__ (fn (&rest args) (cond ((= (len args) 0) (list)) ((and (= (len args) 1) (number? (nth args 0))) (js-make-list-of-length (js-num-to-int (nth args 0)) js-undefined)) (else args))) :prototype {:sort (js-array-proto-fn "sort") :concat (js-array-proto-fn "concat") :every (js-array-proto-fn "every") :indexOf (js-array-proto-fn "indexOf") :push (js-array-proto-fn "push") :map (js-array-proto-fn "map") :filter (js-array-proto-fn "filter") :some (js-array-proto-fn "some") :flat (js-array-proto-fn "flat") :shift (js-array-proto-fn "shift") :join (js-array-proto-fn "join") :pop (js-array-proto-fn "pop") :reduce (js-array-proto-fn "reduce") :slice (js-array-proto-fn "slice") :includes (js-array-proto-fn "includes") :forEach (js-array-proto-fn "forEach") :find (js-array-proto-fn "find") :fill (js-array-proto-fn "fill") :findIndex (js-array-proto-fn "findIndex") :reverse (js-array-proto-fn "reverse")} :isArray js-array-is-array :of js-array-of :from js-array-from})
|
||||
|
||||
(define
|
||||
js-string-from-char-code
|
||||
@@ -1885,7 +1893,17 @@
|
||||
(+ i 1)
|
||||
(str acc (js-code-to-char (js-num-to-int (nth args i))))))))
|
||||
|
||||
(define String {:fromCharCode js-string-from-char-code :__callable__ (fn (&rest args) (if (= (len args) 0) "" (js-to-string (nth args 0))))})
|
||||
(define
|
||||
js-string-proto-fn
|
||||
(fn
|
||||
(name)
|
||||
(fn
|
||||
(&rest args)
|
||||
(let
|
||||
((this-val (js-this)))
|
||||
(js-invoke-method (js-to-string this-val) name args)))))
|
||||
|
||||
(define String {:fromCharCode js-string-from-char-code :__callable__ (fn (&rest args) (if (= (len args) 0) "" (js-to-string (nth args 0)))) :prototype {:toLowerCase (js-string-proto-fn "toLowerCase") :concat (js-string-proto-fn "concat") :startsWith (js-string-proto-fn "startsWith") :padEnd (js-string-proto-fn "padEnd") :indexOf (js-string-proto-fn "indexOf") :split (js-string-proto-fn "split") :endsWith (js-string-proto-fn "endsWith") :trim (js-string-proto-fn "trim") :valueOf (js-string-proto-fn "valueOf") :substring (js-string-proto-fn "substring") :repeat (js-string-proto-fn "repeat") :padStart (js-string-proto-fn "padStart") :search (js-string-proto-fn "search") :toUpperCase (js-string-proto-fn "toUpperCase") :trimEnd (js-string-proto-fn "trimEnd") :toString (js-string-proto-fn "toString") :charCodeAt (js-string-proto-fn "charCodeAt") :slice (js-string-proto-fn "slice") :charAt (js-string-proto-fn "charAt") :match (js-string-proto-fn "match") :includes (js-string-proto-fn "includes") :trimStart (js-string-proto-fn "trimStart") :replace (js-string-proto-fn "replace")}})
|
||||
|
||||
(define Boolean {:__callable__ (fn (&rest args) (if (= (len args) 0) false (js-to-boolean (nth args 0))))})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user