Hello.
I have noticed that the macro APPLY in PS expands to a call to the function's apply method with an invariable “this” as its first argument (thisArg, per http://ecma-international.org/ecma-262/5.1/ #sec-15.3.4.3). When the function is a method of an object, this may result in incorrect code. Consider:
(lambda (some-vector start del-count &rest elts) ... (apply (@ some-vector splice) start del-count elts) ... )
=>
(function (someVector, start, delCount) { var elts = []; for (var i120 = 0; i120 < arguments.length - 3; i120 += 1) { elts[i120] = arguments[i120 + 3]; }; ... someVector.splice.apply(this, [start, delCount].concat(elts)); ... });
Whereas, to be correct, the apply part should go like
someVector.splice.apply(someVector, [start, delCount].concat (elts));
Please find attached a patch which makes APPLY recognize property accessors in the function argument, separate them into object and method, and pass the object to the method's apply. For cases which require more fine-grained control, the patch adds an APPLY-TO macro which provides for a completely custom thisArg.
There's also a separate patch with a couple of unit tests.
Yours, — B. Smilga.
Oops, I'm sorry, I forgot to save some changes prior to doing git commit. The amended patch is attached. The patch with unit tests is ok as is.
— B. Sm.
Hi Boris and everyone else waiting on Parenscript patches.
Sorry I've been busy the past month, I got a new job and relocated countries (Canada -> California, USA). I'm planning to start hacking on Free Software stuff in the next couple of weeks.
Vladimir
On Thu, Oct 18, 2012 at 4:58 PM, Boris Smilga boris.smilga@gmail.com wrote:
Oops, I'm sorry, I forgot to save some changes prior to doing git commit. The amended patch is attached. The patch with unit tests is ok as is.
— B. Sm.
parenscript-devel mailing list parenscript-devel@common-lisp.net http://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
Hi Boris,
Thank you for catching this bug and the patches! I made two additional patches building on top of yours:
One removes the apply-to macro (my general policy now is not to export any non-Common Lisp symbols from Parenscript as possible, and deprecate as many of the existing non-CL exported macros and special forms as possible, and to work on making PS closer to CL - the apply-to macro can be written by people in their own projects and libraries and doesn't need specific support from PS internals, which is why I think it falls under this policy).
The second optimizes output for cases like (apply (@ an-object foo) nil) where the object is a simple symbol.
Happy hacking, Vladimir
On Tue, Nov 13, 2012 at 10:05 AM, Vladimir Sedach vsedach@gmail.com wrote:
Hi Boris and everyone else waiting on Parenscript patches.
Sorry I've been busy the past month, I got a new job and relocated countries (Canada -> California, USA). I'm planning to start hacking on Free Software stuff in the next couple of weeks.
Vladimir
On Thu, Oct 18, 2012 at 4:58 PM, Boris Smilga boris.smilga@gmail.com wrote:
Oops, I'm sorry, I forgot to save some changes prior to doing git commit. The amended patch is attached. The patch with unit tests is ok as is.
— B. Sm.
parenscript-devel mailing list parenscript-devel@common-lisp.net http://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
parenscript-devel@common-lisp.net