FUNCALL accepts symbols as function descriptor
[jscl.git] / ecmalisp.lisp
index 9e17b2b..514e259 100644 (file)
     "string1.concat(string2)"))
 
 (define-raw-builtin funcall (func &rest args)
-  (code "(" (ls-compile func) ")("
-        (join (cons (if *multiple-value-p* "values" "pv")
-                    (mapcar #'ls-compile args))
-              ", ")
-        ")"))
+  (js!selfcall
+    "var f = " (ls-compile func) ";" *newline*
+    "return (typeof f === 'function'? f: f.fvalue)("
+    (join (cons (if *multiple-value-p* "values" "pv")
+                (mapcar #'ls-compile args))
+          ", ")
+    ")"))
 
 (define-raw-builtin apply (func &rest args)
   (if (null args)
            fset funcall function functionp gensym get-universal-time
            go identity if in-package incf integerp integerp intern
            keywordp labels lambda last length let let*
-           list-all-packages list listp make-array make-package
+           list-all-packages list listp loop make-array make-package
            make-symbol mapcar member minusp mod multiple-value-bind
            multiple-value-call multiple-value-list
            multiple-value-prog1 nil not nth nthcdr null numberp or