You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Igor Bukanov <ml...@igor.fastmail.fm> on 2004/09/15 23:53:13 UTC

Rhino from mozilla.org and continuations

Hi!

http://bugzilla.mozilla.org/show_bug.cgi?id=258844 contains a working 
patch against Rhino CVS from mozilla.org to enable Continuation support 
there.

Note although the implementation is based on ideas from Christopher 
Oliver patch it is not a patch port.

In particular, there is no support for catch (continue|break|return) but 
  on the same time finally is respected, so the example from 
http://wiki.apache.org/cocoon/RhinoWithContinuations

var pool = ...;

function someFunction() {

     var conn = pool.getConnection();
     ...

     catch (break) {
         conn.close();
         conn = null;
     }

     catch (continue) {
         conn = pool.getConnection();
     }
}

with the patch would like:

var pool = ...;

function someFunction() {

     var conn = null;
     try {
         if (conn == null) {
             conn = pool.getConnection();
         }
         ...
     } finally {
         conn.close();
         conn = null;
     }
}

That is, if the control leaves "..." during continuation jump, then 
finally will be executed in the same way as it would be executed if ... 
contains return, throws exceptions etc.

Another "differences" is that ContinuationException support for 
continuations across eval/Function.apply|call is not implemented yet.

On the other hand Continuation usage is the same as with Christopher's 
patch including support for serialization so the last example from 
http://wiki.apache.org/cocoon/RhinoWithContinuations does work.

Regards, Igor

Re: Rhino from mozilla.org and continuations

Posted by Bertrand Delacretaz <bd...@apache.org>.
Le 16 sept. 04, à 01:02, Igor Bukanov a écrit :

> ...I think I will commit the patch early next week after I add few 
> changes to Rhino documentation about it so it will be included in 
> Rhino 1.6...

Big thanks for making this finally happen!

Just reading "Rhino from mozilla.org and continuations" gives that warm 
fuzzy feeling ;-)

-Bertrand


Re: Rhino from mozilla.org and continuations

Posted by Nicola Ken Barozzi <ni...@apache.org>.
Igor Bukanov wrote:
...
> I think I will commit the patch early next week after I add few changes 
> to Rhino documentation about it so it will be included in Rhino 1.6.

http://www.textfiles.com/art/beer.vt

:-)

-- 
Nicola Ken Barozzi                   nicolaken@apache.org
             - verba volant, scripta manent -
    (discussions get forgotten, just code remains)
---------------------------------------------------------------------


Re: Rhino from mozilla.org and continuations

Posted by Igor Bukanov <ml...@igor.fastmail.fm>.
Stefano Mazzocchi wrote:
...
> Now, question: will this patch ever enter the main Rhino trunk? I'm sure 
> I speak for the whole community here when I say that we would like to 
> avoid having to distributed a forked version of rhino again because the 
> patch might become no longer applicable.

I think I will commit the patch early next week after I add few changes 
to Rhino documentation about it so it will be included in Rhino 1.6.

Regards, Igor



Re: Rhino from mozilla.org and continuations

Posted by Stefano Mazzocchi <st...@apache.org>.
Igor Bukanov wrote:

> Hi!
> 
> http://bugzilla.mozilla.org/show_bug.cgi?id=258844 contains a working 
> patch against Rhino CVS from mozilla.org to enable Continuation support 
> there.
> 
> Note although the implementation is based on ideas from Christopher 
> Oliver patch it is not a patch port.
> 
> In particular, there is no support for catch (continue|break|return) but 
>  on the same time finally is respected, so the example from 
> http://wiki.apache.org/cocoon/RhinoWithContinuations
> 
> var pool = ...;
> 
> function someFunction() {
> 
>     var conn = pool.getConnection();
>     ...
> 
>     catch (break) {
>         conn.close();
>         conn = null;
>     }
> 
>     catch (continue) {
>         conn = pool.getConnection();
>     }
> }
> 
> with the patch would like:
> 
> var pool = ...;
> 
> function someFunction() {
> 
>     var conn = null;
>     try {
>         if (conn == null) {
>             conn = pool.getConnection();
>         }
>         ...
>     } finally {
>         conn.close();
>         conn = null;
>     }
> }
> 
> That is, if the control leaves "..." during continuation jump, then 
> finally will be executed in the same way as it would be executed if ... 
> contains return, throws exceptions etc.
> 
> Another "differences" is that ContinuationException support for 
> continuations across eval/Function.apply|call is not implemented yet.
> 
> On the other hand Continuation usage is the same as with Christopher's 
> patch including support for serialization so the last example from 
> http://wiki.apache.org/cocoon/RhinoWithContinuations does work.

Igor, YOU ROCK!

Now, question: will this patch ever enter the main Rhino trunk? I'm sure 
I speak for the whole community here when I say that we would like to 
avoid having to distributed a forked version of rhino again because the 
patch might become no longer applicable.

Anyway, thanks so much for this!

-- 
Stefano.


Re: Rhino from mozilla.org and continuations

Posted by Igor Bukanov <ml...@igor.fastmail.fm>.
Igor Bukanov wrote:
> 
> And here is a patch to alter cocoon-2.1.5.1 to use Rhino from mozilla.org.
> 
> The patch assumes that rhino1.5r4-continuations-20040228.jar is replaced 
>   by rhino1_6R1pre.jar which should be produced by checking out the very 
> latest CVS sources from mozilla.org, building js.jar and moving that to 
> lib/core as rhino1_6R1pre.jar.

That patch was not enough to make the calculator example to work, use 
the one attached instead. Strictly speaking changes to 
ScriptablePropertyHandler.java are backward compatible with Rhino from 
cocoondev.org and probably should go to the first patch but for now they 
are here.

Regards, Igor

Re: Rhino from mozilla.org and continuations

Posted by Igor Bukanov <ml...@igor.fastmail.fm>.
Igor Bukanov wrote:
> Igor Bukanov wrote:
> 
>> Ugo Cei wrote:
>>
>>> Igor Bukanov wrote:
>>>
>>>> http://bugzilla.mozilla.org/show_bug.cgi?id=258844 contains a 
>>>> working patch against Rhino CVS from mozilla.org to enable 
>>>> Continuation support there.
>>>
>>>
>>>
>>>
>>> What am I supposed to do if I want to play with it?
>>
>>
>> ...
>>
>>> 2) Do a cvs checkout and build since your patch is already applied?
>>
>>
>> Use this option.
>>
> 
> The attached patch against cocoon-2.1.5.1 simplifies "playing": it 
> changes Rhino bindings to use "org.mozilla.javascript.Function" instead 
> of "org.mozilla.javascript.continuations.Continuation" to refer to 
> script Continuation objects.
> 
> In Rhino from mozilla.org Continuation class is package-private and 
> implemented in a very different way compared with Rhino from 
> cocondev.org. On the other hand the class in both versions implements 
> Function interface and since the bindings in Cocoon use only 
> functionality available through this interface the patch minimize the 
> amount of code that has to be modified to use Rhino from mozilla.org.
> 

And here is a patch to alter cocoon-2.1.5.1 to use Rhino from mozilla.org.

The patch assumes that rhino1.5r4-continuations-20040228.jar is replaced 
   by rhino1_6R1pre.jar which should be produced by checking out the 
very latest CVS sources from mozilla.org, building js.jar and moving 
that to lib/core as rhino1_6R1pre.jar.

Regards, Igor

Re: Rhino from mozilla.org and continuations

Posted by Igor Bukanov <ml...@igor.fastmail.fm>.
Igor Bukanov wrote:
> Ugo Cei wrote:
> 
>> Igor Bukanov wrote:
>>
>>> http://bugzilla.mozilla.org/show_bug.cgi?id=258844 contains a working 
>>> patch against Rhino CVS from mozilla.org to enable Continuation 
>>> support there.
>>
>>
>>
>> What am I supposed to do if I want to play with it?
> 
> ...
> 
>> 2) Do a cvs checkout and build since your patch is already applied?
> 
> Use this option.
> 
> Regards, Igor

The attached patch against cocoon-2.1.5.1 simplifies "playing": it 
changes Rhino bindings to use "org.mozilla.javascript.Function" instead 
of "org.mozilla.javascript.continuations.Continuation" to refer to 
script Continuation objects.

In Rhino from mozilla.org Continuation class is package-private and 
implemented in a very different way compared with Rhino from 
cocondev.org. On the other hand the class in both versions implements 
Function interface and since the bindings in Cocoon use only 
functionality available through this interface the patch minimize the 
amount of code that has to be modified to use Rhino from mozilla.org.

Regards, Igor

Re: Rhino from mozilla.org and continuations

Posted by Igor Bukanov <ml...@igor.fastmail.fm>.
Ugo Cei wrote:
> Igor Bukanov wrote:
> 
>> http://bugzilla.mozilla.org/show_bug.cgi?id=258844 contains a working 
>> patch against Rhino CVS from mozilla.org to enable Continuation 
>> support there.
> 
> 
> What am I supposed to do if I want to play with it?
...
> 2) Do a cvs checkout and build since your patch is already applied?
Use this option.

Regards, Igor

Re: Rhino from mozilla.org and continuations

Posted by Ugo Cei <u....@cbim.it>.
Igor Bukanov wrote:
> http://bugzilla.mozilla.org/show_bug.cgi?id=258844 contains a working 
> patch against Rhino CVS from mozilla.org to enable Continuation support 
> there.

What am I supposed to do if I want to play with it?

1) Do a cvs checkout and apply your latest patch before building?
2) Do a cvs checkout and build since your patch is already applied?
3) Download a prebuilt binary from http://www.mir2.org/igor/rhino/ ?

Thanks in Advance,

	Ugo

Changes in Rhino-cont implementation

Posted by Reinhard Poetz <re...@apache.org>.
Sylvain Wallez wrote:

> Igor Bukanov wrote:
>
>> It is hard to implement catch(continue|break|return) correctly. For 
>> example, what should happen if an exception is thrown during the 
>> execution of code there or what if continuation is captured/restored 
>> inside the catch block? Depending on the situation the version in 
>> Cocoon would either throw an exception or go into infinite loop. 
>> AFAICS respecting "finally" has rather simple answers in all those 
>> corner cases and that is why I put efforts to implement it rather the 
>> catch blocks.
>>
>> For compatibility a special mode can be added in principle to Rhino 
>> from mozilla.org with support for arguments.continuation and 
>> catch(...) with the clear marks about deprecation (unless, of cause, 
>> it is possible to implement the constructions simply and efficiently 
>> - then no deprecation!). But my continuation curiosity does not 
>> spread far enough to create such patch.
>
>
> "arguments.continuation", AFAIK was never documented publicly, so we 
> can safely forget about it. For the special catch syntaxes, there will 
> be some compatibility problems as many people are likely to have used 
> it. But since the use of "finally" seems to allow the same kind of 
> behaviour with a simpler syntax and a clearly specified semantics, I 
> think it is our job, we cocooners, to prepare our user base to this 
> change and give them directions to upgrade their scripts.


I think we should deprecate this syntax in the next Cocoon 2.1.x release 
and in Cocoon 2.2 we can use the new Rhino continuations implementation 
- this also gives us more time for testing.

-- 
Reinhard


Re: Rhino from mozilla.org and continuations

Posted by Sylvain Wallez <sy...@apache.org>.
Igor Bukanov wrote:

> Sylvain Wallez wrote:
>
>>
>> A minor remark though, about the syntax for creating the 
>> continuation. AFAICS, this is currently done with "Continuation()". I 
>> personally find it misleading, as the continuation represents the 
>> point where the current function was called, and not the point where 
>> the "Continuation()" statement occured.
>>
>> Long ago, I proposed to Chris to allow a syntax suggested in [1] (2nd 
>> post) which is "arguments.continuation" which clearly relates the 
>> continuation to the point where the function is called, and he 
>> implemented it in [2] (search for "TokenStream.GETPROP").
>
>
> Any use of "arguments" in Rhino is very expensive since it prevents 
> fast access to variables in the function that uses that. In addition 
> ECMAScript allows to alias arguments arbitrary or even to hide by 
> local variable/parameter name so the way it is implemented in Cocoon 
> version of Rhino just does not work. It is possible to do it properly 
> but that would give code bloat.
>
> IMO syntax is only nice if it allows a reasonable implementation 
> without many corner cases. By that definition arguments.continuation 
> is not nice while Continuation() is. Note if arguments would be a 
> keyword in JS, the story would be opposite, but JS legacy takes its toll.


Ok, that makes sense, as I didn't knew about these constraints and 
limitations.

> Plus function syntax allows to implement rather trivially optional 
> arguments like amount of frames to capture. For example, suppose you 
> want to define a function in JS that would behave exactly as 
> Continuation() while adding a log about it. Then one could use 
> something like:
>
> function my_continuation()
> {
>     log();
>     return Continuation(2);
> }
>
> And then Continuation(0) would capture exactly at the point of 
> invocation with Continuation() defaulting to Continuation(1). Note 
> that I do not propose that, but rather argue that function syntax has 
> its advantages as well.


Hey, that is a cool idea! Okay, let's keep Continuation() then.

>>
>> This may seem as nitpicking, but if this is to go into the official 
>> Rhino and if Cocoon has to cope with minor incompatibilities like 
>> catch(continue|break|return), it would be good to have a clean syntax 
>> for continuations.
>>
>> What do you think?
>
>
> It is hard to implement catch(continue|break|return) correctly. For 
> example, what should happen if an exception is thrown during the 
> execution of code there or what if continuation is captured/restored 
> inside the catch block? Depending on the situation the version in 
> Cocoon would either throw an exception or go into infinite loop. 
> AFAICS respecting "finally" has rather simple answers in all those 
> corner cases and that is why I put efforts to implement it rather the 
> catch blocks.
>
> For compatibility a special mode can be added in principle to Rhino 
> from mozilla.org with support for arguments.continuation and 
> catch(...) with the clear marks about deprecation (unless, of cause, 
> it is possible to implement the constructions simply and efficiently - 
> then no deprecation!). But my continuation curiosity does not spread 
> far enough to create such patch.


"arguments.continuation", AFAIK was never documented publicly, so we can 
safely forget about it. For the special catch syntaxes, there will be 
some compatibility problems as many people are likely to have used it. 
But since the use of "finally" seems to allow the same kind of behaviour 
with a simpler syntax and a clearly specified semantics, I think it is 
our job, we cocooners, to prepare our user base to this change and give 
them directions to upgrade their scripts.

We've been wanting for long to get rid of the rhino fork which, although 
it brought us an amazingly powerful way of building webapps, brought 
also a lot of community and legal issues. So we can consider that 
upgrading our scripts is the price to pay for being able to use the 
official Mozilla Rhino, and those that don't want to upgrade will just 
be asked to keep the current rhino fork.

Sylvain

-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }


Re: Rhino from mozilla.org and continuations

Posted by Igor Bukanov <ml...@igor.fastmail.fm>.
Sylvain Wallez wrote:
> 
> A minor remark though, about the syntax for creating the continuation. 
> AFAICS, this is currently done with "Continuation()". I personally find 
> it misleading, as the continuation represents the point where the 
> current function was called, and not the point where the 
> "Continuation()" statement occured.
> 
> Long ago, I proposed to Chris to allow a syntax suggested in [1] (2nd 
> post) which is "arguments.continuation" which clearly relates the 
> continuation to the point where the function is called, and he 
> implemented it in [2] (search for "TokenStream.GETPROP").

Any use of "arguments" in Rhino is very expensive since it prevents fast 
access to variables in the function that uses that. In addition 
ECMAScript allows to alias arguments arbitrary or even to hide by local 
variable/parameter name so the way it is implemented in Cocoon version 
of Rhino just does not work. It is possible to do it properly but that 
would give code bloat.

IMO syntax is only nice if it allows a reasonable implementation without 
many corner cases. By that definition arguments.continuation is not nice 
while Continuation() is. Note if arguments would be a keyword in JS, the 
story would be opposite, but JS legacy takes its toll.

Plus function syntax allows to implement rather trivially optional 
arguments like amount of frames to capture. For example, suppose you 
want to define a function in JS that would behave exactly as 
Continuation() while adding a log about it. Then one could use something 
like:

function my_continuation()
{
     log();
     return Continuation(2);
}

And then Continuation(0) would capture exactly at the point of 
invocation with Continuation() defaulting to Continuation(1). Note that 
I do not propose that, but rather argue that function syntax has its 
advantages as well.

> 
> This may seem as nitpicking, but if this is to go into the official 
> Rhino and if Cocoon has to cope with minor incompatibilities like 
> catch(continue|break|return), it would be good to have a clean syntax 
> for continuations.
> 
> What do you think?

It is hard to implement catch(continue|break|return) correctly. For 
example, what should happen if an exception is thrown during the 
execution of code there or what if continuation is captured/restored 
inside the catch block? Depending on the situation the version in Cocoon 
would either throw an exception or go into infinite loop. AFAICS 
respecting "finally" has rather simple answers in all those corner cases 
and that is why I put efforts to implement it rather the catch blocks.

For compatibility a special mode can be added in principle to Rhino from 
mozilla.org with support for arguments.continuation and catch(...) with 
the clear marks about deprecation (unless, of cause, it is possible to 
implement the constructions simply and efficiently - then no 
deprecation!). But my continuation curiosity does not spread far enough 
to create such patch.

Regards, Igor

Re: Rhino from mozilla.org and continuations

Posted by Sylvain Wallez <sy...@apache.org>.
Igor Bukanov wrote:

> Hi!
>
> http://bugzilla.mozilla.org/show_bug.cgi?id=258844 contains a working 
> patch against Rhino CVS from mozilla.org to enable Continuation 
> support there.


Great work, Igor. Thanks a lot!

A minor remark though, about the syntax for creating the continuation. 
AFAICS, this is currently done with "Continuation()". I personally find 
it misleading, as the continuation represents the point where the 
current function was called, and not the point where the 
"Continuation()" statement occured.

Long ago, I proposed to Chris to allow a syntax suggested in [1] (2nd 
post) which is "arguments.continuation" which clearly relates the 
continuation to the point where the function is called, and he 
implemented it in [2] (search for "TokenStream.GETPROP").

This may seem as nitpicking, but if this is to go into the official 
Rhino and if Cocoon has to cope with minor incompatibilities like 
catch(continue|break|return), it would be good to have a clean syntax 
for continuations.

What do you think?

Sylvain

PS: I don't currently have time myself for testing the new Rhino, but 
hope others do!

[1] http://lambda-the-ultimate.org/classic/message8089.html
[2] 
http://svn.cocoondev.org/repos/rhino+cont/trunk/rhino1_5R4pre/src/org/mozilla/javascript/continuations/ContinuationInterpreter.java

-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }


Re: Rhino from mozilla.org and continuations

Posted by Tony Collen <co...@umn.edu>.
Gianugo Rabellino wrote:

> On Wed, 15 Sep 2004 23:53:13 +0200, Igor Bukanov <ml...@igor.fastmail.fm> wrote:
> 
>>Hi!
>>
>>http://bugzilla.mozilla.org/show_bug.cgi?id=258844 contains a working
>>patch against Rhino CVS from mozilla.org to enable Continuation support
>>there.
> 
> 
> Igor, I think you just earnt a beer from each and every Cocoon user
> around. Quite a lot of booze, may I say, but definitely well deserved.
> Thanks *SO* much for your work, I hope you might be around for the
> next Cocoon GetTogether as the party hero.
> 
> I'd even say, echoing Stefano, that pints will become kegs if this
> patch enters the main Rhino trunk... :-)
> 

I think this deserves a +BEER for Igor!!!

Awesome work indeed!

Tony

Re: Rhino from mozilla.org and continuations

Posted by Gianugo Rabellino <gi...@gmail.com>.
On Wed, 15 Sep 2004 23:53:13 +0200, Igor Bukanov <ml...@igor.fastmail.fm> wrote:
> Hi!
> 
> http://bugzilla.mozilla.org/show_bug.cgi?id=258844 contains a working
> patch against Rhino CVS from mozilla.org to enable Continuation support
> there.

Igor, I think you just earnt a beer from each and every Cocoon user
around. Quite a lot of booze, may I say, but definitely well deserved.
Thanks *SO* much for your work, I hope you might be around for the
next Cocoon GetTogether as the party hero.

I'd even say, echoing Stefano, that pints will become kegs if this
patch enters the main Rhino trunk... :-)

-- 
Gianugo Rabellino
Pro-netics s.r.l. -  http://www.pro-netics.com
Orixo, the XML business alliance: http://www.orixo.com

Re: Rhino from mozilla.org and continuations

Posted by Antonio Gallardo <ag...@agssa.net>.
Hi Igor:

You are a Cocoon heroe!

Please, write down: I owe you a beer! ;-)

Best Regards,

Antonio Gallardo

Igor Bukanov dijo:
> Hi!
>
> http://bugzilla.mozilla.org/show_bug.cgi?id=258844 contains a working
> patch against Rhino CVS from mozilla.org to enable Continuation support
> there.
>
> Note although the implementation is based on ideas from Christopher
> Oliver patch it is not a patch port.
>
> In particular, there is no support for catch (continue|break|return) but
>   on the same time finally is respected, so the example from
> http://wiki.apache.org/cocoon/RhinoWithContinuations
>
> var pool = ...;
>
> function someFunction() {
>
>      var conn = pool.getConnection();
>      ...
>
>      catch (break) {
>          conn.close();
>          conn = null;
>      }
>
>      catch (continue) {
>          conn = pool.getConnection();
>      }
> }
>
> with the patch would like:
>
> var pool = ...;
>
> function someFunction() {
>
>      var conn = null;
>      try {
>          if (conn == null) {
>              conn = pool.getConnection();
>          }
>          ...
>      } finally {
>          conn.close();
>          conn = null;
>      }
> }
>
> That is, if the control leaves "..." during continuation jump, then
> finally will be executed in the same way as it would be executed if ...
> contains return, throws exceptions etc.
>
> Another "differences" is that ContinuationException support for
> continuations across eval/Function.apply|call is not implemented yet.
>
> On the other hand Continuation usage is the same as with Christopher's
> patch including support for serialization so the last example from
> http://wiki.apache.org/cocoon/RhinoWithContinuations does work.
>
> Regards, Igor
>