From: David Vázquez Date: Sun, 20 Jan 2013 16:37:22 +0000 (+0000) Subject: Array out-of-range checks X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=3c6beba19730ea86d423a9970fe6a600fe3c3ef3;p=jscl.git Array out-of-range checks --- diff --git a/ecmalisp.lisp b/ecmalisp.lisp index c7097c6..de2fe68 100644 --- a/ecmalisp.lisp +++ b/ecmalisp.lisp @@ -846,6 +846,7 @@ (ecase (%read-char stream) (#\' (list 'function (ls-read stream))) + (#\( (list-to-vector (%read-list stream))) (#\\ (let ((cname (concat (string (%read-char stream)) @@ -1819,10 +1820,17 @@ "return typeof x === 'object' && 'length' in x;"))) (define-builtin aref (array n) - (concat "(" array ")[" n "]")) + (js!selfcall + "var x = " "(" array ")[" n "];" *newline* + "if (x === undefined) throw 'Out of range';" *newline* + "return x;" *newline*)) (define-builtin aset (array n value) - (concat "(" array ")[" n "] = " value)) + (js!selfcall + "var x = " array ";" *newline* + "var i = " n ";" *newline* + "if (i < 0 || i >= x.length) throw 'Out of range';" *newline* + "return x[i] = " value ";" *newline*)) (defun macro (x)