Commit 44934751 authored by Vladimir Sedach's avatar Vladimir Sedach
Browse files

Added in-line code to support &rest arguments.

parent 116f7450
......@@ -243,8 +243,10 @@ the given lambda-list and body."
initform-pairs))
(rest-form
(if rest?
`(defvar ,rest (:.slice (to-array arguments)
,(length effective-args)))
(with-ps-gensyms (i)
`(progn (defvar ,rest array)
(dotimes (,i (- arguments.length ,(length effective-args)))
(setf (aref ,rest ,i) (aref arguments (+ ,i ,(length effective-args)))))))
`(progn)))
(effective-body (append initform-forms (list rest-form) body-paren-forms))
(effective-body
......
......@@ -305,3 +305,23 @@ x = 2 + sideEffect() + x + 5;")
(test-ps-js blank-object-literal
{}
"{ }")
(test-ps-js defun-rest1
(defun foo (&rest bar) (alert bar[1]))
"function foo() {
var bar = [];
for (var _js1 = 0; _js1 < arguments.length - 0; _js1 = _js1 + 1) {
bar[_js1] = arguments[_js1 + 0];
};
alert(bar[1]);
}")
(test-ps-js defun-rest2
(defun foo (baz &rest bar) (return (+ baz (aref bar 1))))
"function foo(baz) {
var bar = [];
for (var _js1 = 0; _js1 < arguments.length - 1; _js1 = _js1 + 1) {
bar[_js1] = arguments[_js1 + 1];
};
return baz + bar[1];
}")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment