(define-builtin characterp (x)
(js!bool
- (js!selfcall
- "var x = " x ";"
- "return (typeof(" x ") == \"string\") && (x.length == 1 || x.length == 2);")))
+ (js!selfcall*
+ `(var (x ,x))
+ `(return (and (== (typeof x) "string")
+ (or (== (get x "length") 1)
+ (== (get x "length") 2)))))))
(define-builtin char-upcase (x)
`(call |safe_char_upcase| ,x))
(== (get x "stringp") 1))))))
(define-raw-builtin funcall (func &rest args)
- (js!selfcall
- "var f = " (ls-compile func) ";"
- "return (typeof f === 'function'? f: f.fvalue)("
- `(code
- ,@(interleave (list* (if *multiple-value-p* "values" "pv")
- (integer-to-string (length args))
- (mapcar #'ls-compile args))
- ", "))
- ")"))
+ (js!selfcall*
+ `(var (f ,(ls-compile func)))
+ `(return (call (if (=== (typeof f) "function")
+ f
+ (get f "fvalue"))
+ ,@(list* (if *multiple-value-p* '|values| '|pv|)
+ (length args)
+ (mapcar #'ls-compile args))))))
(define-raw-builtin apply (func &rest args)
(if (null args)
`(return r)))
(define-builtin get-internal-real-time ()
- `(call (get (new (call Date)) "getTime")))
+ `(call (get (new (call |Date|)) "getTime")))
(define-builtin values-array (array)
(if *multiple-value-p*
`(return ,(ls-compile nil))))
(define-compilation %js-vref (var)
- `(code "js_to_lisp(" ,var ")"))
+ `(call |js_to_lisp| ,(make-symbol var)))
(define-compilation %js-vset (var val)
- `(code "(" ,var " = lisp_to_js(" ,(ls-compile val) "))"))
+ `(= ,(make-symbol var) (call |lisp_to_js| ,(ls-compile val))))
(define-setf-expander %js-vref (var)
(let ((new-value (gensym)))