+(define-builtin new ()
+ '(object))
+
+(define-raw-builtin oget* (object key &rest keys)
+ (js!selfcall*
+ `(progn
+ (var (tmp (property ,(ls-compile object) (call |xstring| ,(ls-compile key)))))
+ ,@(mapcar (lambda (key)
+ `(progn
+ (if (=== tmp undefined) (return ,(ls-compile nil)))
+ (= tmp (property tmp (call |xstring| ,(ls-compile key))))))
+ keys))
+ `(return (if (=== tmp undefined) ,(ls-compile nil) tmp))))
+
+(define-raw-builtin oset* (value object key &rest keys)
+ (let ((keys (cons key keys)))
+ (js!selfcall*
+ `(progn
+ (var (obj ,(ls-compile object)))
+ ,@(mapcar (lambda (key)
+ `(progn
+ (= obj (property obj (call |xstring| ,(ls-compile key))))
+ (if (=== object undefined)
+ (throw "Impossible to set object property."))))
+ (butlast keys))
+ (var (tmp
+ (= (property obj (call |xstring| ,(ls-compile (car (last keys)))))
+ ,(ls-compile value))))
+ (return (if (=== tmp undefined)
+ ,(ls-compile nil)
+ tmp))))))
+
+(define-raw-builtin oget (object key &rest keys)
+ `(call |js_to_lisp| ,(ls-compile `(oget* ,object ,key ,@keys))))
+
+(define-raw-builtin oset (value object key &rest keys)
+ (ls-compile `(oset* (lisp-to-js ,value) ,object ,key ,@keys)))
+
+(define-builtin objectp (x)
+ (js!bool `(=== (typeof ,x) "object")))
+
+(define-builtin lisp-to-js (x) `(call |lisp_to_js| ,x))
+(define-builtin js-to-lisp (x) `(call |js_to_lisp| ,x))
+
+
+(define-builtin in (key object)
+ (js!bool `(in (call |xstring| ,key) ,object)))
+
+(define-builtin map-for-in (function object)
+ (js!selfcall*
+ `(var (f ,function)
+ (g (if (=== (typeof f) "function") f (get f "fvalue")))
+ (o ,object))
+ `(for-in (key o)
+ (call g ,(if *multiple-value-p* '|values| '|pv|) 1 (get o "key")))
+ `(return ,(ls-compile nil))))
+