js-on-sx: RegExp constructor wraps existing regex stub
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 21s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 21s
This commit is contained in:
@@ -991,6 +991,72 @@
|
||||
|
||||
(define SuppressedError :js-undefined)
|
||||
|
||||
(define
|
||||
RegExp
|
||||
{:length 2
|
||||
:name "RegExp"
|
||||
:__callable__
|
||||
(fn
|
||||
(&rest args)
|
||||
(let
|
||||
((this (js-this)))
|
||||
(let
|
||||
((pattern-arg (if (= (len args) 0) "" (nth args 0)))
|
||||
(flags-arg
|
||||
(if (>= (len args) 2) (nth args 1) :js-undefined)))
|
||||
(let
|
||||
((src
|
||||
(cond
|
||||
((js-regex? pattern-arg) (get pattern-arg "source"))
|
||||
((js-undefined? pattern-arg) "")
|
||||
((= pattern-arg nil) "")
|
||||
(else (js-to-string pattern-arg))))
|
||||
(fl
|
||||
(cond
|
||||
((js-undefined? flags-arg)
|
||||
(if (js-regex? pattern-arg) (get pattern-arg "flags") ""))
|
||||
((= flags-arg nil) "")
|
||||
(else (js-to-string flags-arg)))))
|
||||
(let
|
||||
((rx (js-regex-new src fl)))
|
||||
(cond
|
||||
((not (= (type-of this) "dict")) rx)
|
||||
(else
|
||||
(begin
|
||||
(for-each
|
||||
(fn (k) (dict-set! this k (get rx k)))
|
||||
(keys rx))
|
||||
this))))))))
|
||||
:prototype
|
||||
{:test
|
||||
(fn (s)
|
||||
(let ((rx (js-this)) (str (js-to-string s)))
|
||||
(js-regex-stub-test rx str)))
|
||||
:exec
|
||||
(fn (s)
|
||||
(let ((rx (js-this)) (str (js-to-string s)))
|
||||
(js-regex-stub-exec rx str)))
|
||||
:toString
|
||||
(fn ()
|
||||
(let ((rx (js-this)))
|
||||
(str "/" (get rx "source") "/" (get rx "flags"))))
|
||||
:compile
|
||||
(fn (&rest args)
|
||||
(let ((rx (js-this)))
|
||||
(cond
|
||||
((>= (len args) 1)
|
||||
(let
|
||||
((src (js-to-string (nth args 0)))
|
||||
(fl (if (>= (len args) 2) (js-to-string (nth args 1)) "")))
|
||||
(let
|
||||
((rx2 (js-regex-new src fl)))
|
||||
(begin
|
||||
(for-each
|
||||
(fn (k) (dict-set! rx k (get rx2 k)))
|
||||
(keys rx2))
|
||||
rx))))
|
||||
(else rx))))}})
|
||||
|
||||
(define
|
||||
js-str-startswith?
|
||||
(fn
|
||||
@@ -5693,6 +5759,7 @@
|
||||
(dict-set! Map "__proto__" (get js-function-global "prototype"))
|
||||
(dict-set! Set "__proto__" (get js-function-global "prototype"))
|
||||
(dict-set! Date "__proto__" (get js-function-global "prototype"))
|
||||
(dict-set! RegExp "__proto__" (get js-function-global "prototype"))
|
||||
(dict-set! __js_ctor_proto__ (js-ctor-id TypeError) Error)
|
||||
(dict-set! __js_ctor_proto__ (js-ctor-id RangeError) Error)
|
||||
(dict-set! __js_ctor_proto__ (js-ctor-id SyntaxError) Error)
|
||||
@@ -5728,11 +5795,13 @@
|
||||
(dict-set! (get Map "prototype") "__proto__" (get Object "prototype"))
|
||||
(dict-set! (get Set "prototype") "__proto__" (get Object "prototype"))
|
||||
(dict-set! (get Date "prototype") "__proto__" (get Object "prototype"))
|
||||
(dict-set! (get RegExp "prototype") "__proto__" (get Object "prototype"))
|
||||
(dict-set! (get RegExp "prototype") "constructor" RegExp)
|
||||
(dict-set! (get js-function-global "prototype") "__proto__" (get Object "prototype"))
|
||||
(dict-set! (get Number "prototype") "__js_number_value__" 0)
|
||||
(dict-set! (get String "prototype") "__js_string_value__" "")
|
||||
(dict-set! (get Boolean "prototype") "__js_boolean_value__" false))
|
||||
|
||||
(define js-global {:undefined js-undefined :JSON JSON :parseInt parseInt :Object Object :isNaN js-global-is-nan :Infinity inf :NaN 0 :String String :Boolean Boolean :Array Array :Math Math :parseFloat parseFloat :Number Number :console console :isFinite js-global-is-finite :Map Map :Set Set :Date Date})
|
||||
(define js-global {:undefined js-undefined :JSON JSON :parseInt parseInt :Object Object :isNaN js-global-is-nan :Infinity inf :NaN 0 :String String :Boolean Boolean :Array Array :Math Math :parseFloat parseFloat :Number Number :console console :isFinite js-global-is-finite :Map Map :Set Set :Date Date :RegExp RegExp})
|
||||
|
||||
(set! js-global-this js-global)
|
||||
|
||||
Reference in New Issue
Block a user