From 8e39cfec4098c8b27929e1e7908b931cdc9ff12c Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20V=C3=A1zquez?= Date: Thu, 6 Jun 2013 12:49:03 +0100 Subject: [PATCH] oget support multiple key chaining --- src/compiler.lisp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/compiler.lisp b/src/compiler.lisp index c5787c8..a98e6b6 100644 --- a/src/compiler.lisp +++ b/src/compiler.lisp @@ -1317,15 +1317,18 @@ (define-builtin oset* (object key value) (code "((" object ")[xstring(" key ")] = " value ")")) -(define-builtin oget (object key) +(define-raw-builtin oget (object key &rest keys) (js!selfcall - "var tmp = " "(" object ")[xstring(" key ")];" *newline* - "return tmp == undefined? " (ls-compile nil) ": js_to_lisp(tmp);" *newline*)) + "var tmp = (" (ls-compile object) ")[xstring(" (ls-compile key) ")];" *newline* + (mapconcat (lambda (key) + (code "if (tmp === undefined) return " (ls-compile nil) ";" *newline*) + (code "tmp = tmp[xstring(" (ls-compile key) ")];" *newline*)) + keys) + "return tmp === undefined? " (ls-compile nil) " : js_to_lisp(tmp);" *newline*)) (define-builtin oset (object key value) (code "((" object ")[xstring(" key ")] = lisp_to_js(" value "))")) - (define-builtin objectp (x) (js!bool (code "(typeof (" x ") === 'object')"))) -- 1.7.10.4