From 5ca828dcc0aa43c0a52b17a3eaad05c44b1cbb12 Mon Sep 17 00:00:00 2001 From: Boris Smilga Date: Wed, 17 Oct 2012 02:09:26 +0400 Subject: [PATCH] Method functions should be applied to their host objects as thisArgs, rather than to the callers' this. Also, we might want a way to apply functions to whatever thisArg we like. --- src/macros.lisp | 14 +++++++++++++- src/package.lisp | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/macros.lisp b/src/macros.lisp index d2f1d83..10a8b64 100644 --- a/src/macros.lisp +++ b/src/macros.lisp @@ -445,7 +445,19 @@ lambda-list::= (let ((arglist (if (> (length args) 1) `(append (list ,@(butlast args)) ,(car (last args))) (first args)))) - `(funcall (getprop ,fn 'apply) this ,arglist))) + (case (and (listp fn) (car fn)) + ((getprop @ chain) + (let ((obj (ps-gensym)) (method (ps-gensym))) + `(let* ((,obj ,(if (= (length fn) 3) (cadr fn) (butlast fn))) + (,method (,(car fn) ,obj ,(car (last fn))))) + (funcall (getprop ,method 'apply) ,obj ,arglist)))) + (t `(funcall (getprop ,fn 'apply) this ,arglist))))) + +(defpsmacro apply-to (this-arg fn &rest args) + (let ((arglist (if (> (length args) 1) + `(append (list ,@(butlast args)) ,(car (last args))) + (first args)))) + `(funcall (getprop ,fn 'apply) ,this-arg ,arglist))) ;;; misc diff --git a/src/package.lisp b/src/package.lisp index 3f23183..e18dc64 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -201,6 +201,7 @@ #:functionp #:append #:apply + #:apply-to #:destructuring-bind ;; js runtime utils -- 2.11.4.GIT