You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Toby <to...@linux.it> on 2006/07/25 16:34:01 UTC

Weird Javascript error in continuations

I just came across a very strange error, possibly a bug in Cocoon!

It's easy to reproduce: edit samples/blocks/forms/flow/registration.js
from Cocoon 2.1.8, adding the lines marked with '>'


function registration() {
>   var useless = 'one two';
    var form = new Form("forms/registration.xml");

    // The showForm function will keep redisplaying the form until
    // everything is valid
    form.showForm("registration-display-pipeline");

>   useless = useless.split(' ');
    var model = form.getModel();
    var bizdata = { "username" : model.name }
    cocoon.sendPage("registration-success-pipeline.jx", bizdata);
}


Then do the following:

1. invoke /samples/blocks/forms/registration
    -> the form is created and displayed, OK

2. submit the form with valid fields (thus calling continuation #1)
    -> "Registration successful", OK

3. either hit reload or go back and re-submit it
   (thus calling the SAME continuation again)
    -> "org.mozilla.javascript.EcmaError: split is not a function."


Split is not a function!?  How does it work the first time then?


Toby

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Weird Javascript error in continuations

Posted by Mark Lundquist <ml...@wrinkledog.com>.
On Jul 25, 2006, at 7:34 AM, Toby wrote:

> I just came across a very strange error, possibly a bug in Cocoon!

Nope, as Jason explained, this is the correct behavior.

The cocoon.createPageLocal() method might help you, see here:

	http://cocoon.apache.org/2.1/userdocs/flow/api.html

—ml—


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Weird Javascript error in continuations

Posted by Toby <to...@linux.it>.
Jason Johnston wrote:
> First you assign the 'useless' variable a String value, then you
> create the continuation.  When you resume the continuation the first
> time, you re-assign the 'useless' variable so that it now holds an
> Array value (String.split() returns an Array).  When you resume the
> continuation again, you try to call .split() on the 'useless' var,
> which is now an Array, and the error is appropriately thrown since an
> Array has no such method.

If that's the case, I think this piece of documentation is misleading:

«Think of a continuation as an object that, for a given point in your
program, contains a snapshot of the stack trace, including all the local
variables, and the program counter.»


Toby

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Weird Javascript error in continuations

Posted by Leszek Gawron <lg...@mobilebox.pl>.
Simone Gianni wrote:
> Hi Toby,
> I think you are right. What a continuation does (should do) is dump the
> local variables and restore them before restarting the flow. This means
> that if you write var a = 1; then create a continuation, when you return
> to that continuation a should be 1 again, even if in other continuations
> it has been changed to 2,3 or 4.
> 
> There is surely one known limitation to this : if you say var bean = new
> MyBean(); bean.setX(1); then produce a continuation, then after the
> continuation you call bean.setX(2), even if you go back to the previous
> continuation you will find that bean.getX() == 2, because the LOCAL
> VARIABLE is still your bean, but it's internal state is not manageable
> by the continuation (more formally, your local variable is a pointer to
> a bean, which is correctly restored when you go back to the
> continuation, but the data it points to is not serialized/deserialized
> by the continuation).
> 
> But this is not your case, in this case you are setting a simple
> javascript variable, so it should work as you say, at least AFAIK :)
> 
> Please, file a bug about it.
I think it works OK. What is a local variable different from a bean?

Continuations are for managing flow, not keeping full state because it 
would consume too much resources. In 99% you do not need variables to 
have values bound to a specific continuation. Still you have an option 
to do so:

var pageLocal = cocoon.createPageLocal();
pageLocal.a = 1;

a PageLocal will have different values for different continuations. 
Please mind resource implications for that approach.

-- 
Leszek Gawron                                      lgawron@mobilebox.pl
IT Manager                                         MobileBox sp. z o.o.
+48 (61) 855 06 67                              http://www.mobilebox.pl
mobile: +48 (501) 720 812                       fax: +48 (61) 853 29 65

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Weird Javascript error in continuations

Posted by Simone Gianni <s....@thebug.it>.
Hi Toby,
I think you are right. What a continuation does (should do) is dump the
local variables and restore them before restarting the flow. This means
that if you write var a = 1; then create a continuation, when you return
to that continuation a should be 1 again, even if in other continuations
it has been changed to 2,3 or 4.

There is surely one known limitation to this : if you say var bean = new
MyBean(); bean.setX(1); then produce a continuation, then after the
continuation you call bean.setX(2), even if you go back to the previous
continuation you will find that bean.getX() == 2, because the LOCAL
VARIABLE is still your bean, but it's internal state is not manageable
by the continuation (more formally, your local variable is a pointer to
a bean, which is correctly restored when you go back to the
continuation, but the data it points to is not serialized/deserialized
by the continuation).

But this is not your case, in this case you are setting a simple
javascript variable, so it should work as you say, at least AFAIK :)

Please, file a bug about it.

Simone

Toby wrote:

>Jason Johnston wrote:
>  
>
>>First you assign the 'useless' variable a String value, then you
>>create the continuation.  When you resume the continuation the first
>>time, you re-assign the 'useless' variable so that it now holds an
>>Array value (String.split() returns an Array).  When you resume the
>>continuation again, you try to call .split() on the 'useless' var,
>>which is now an Array, and the error is appropriately thrown since an
>>Array has no such method.
>>    
>>
>
>When I resume the continuation again, I'm resuming it from before
>assigning the array, so one would think that useless (which is a local
>variable) would still contain a string!
>
>What am I missing?
>
>
>Toby
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>For additional commands, e-mail: users-help@cocoon.apache.org
>
>  
>
-- 
Simone Gianni

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Weird Javascript error in continuations

Posted by Toby <to...@linux.it>.
Jason Johnston wrote:
> First you assign the 'useless' variable a String value, then you
> create the continuation.  When you resume the continuation the first
> time, you re-assign the 'useless' variable so that it now holds an
> Array value (String.split() returns an Array).  When you resume the
> continuation again, you try to call .split() on the 'useless' var,
> which is now an Array, and the error is appropriately thrown since an
> Array has no such method.

When I resume the continuation again, I'm resuming it from before
assigning the array, so one would think that useless (which is a local
variable) would still contain a string!

What am I missing?


Toby

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Weird Javascript error in continuations

Posted by Jason Johnston <co...@lojjic.net>.
> I just came across a very strange error, possibly a bug in Cocoon!
>
> It's easy to reproduce: edit samples/blocks/forms/flow/registration.js
> from Cocoon 2.1.8, adding the lines marked with '>'
>
>
> function registration() {
>>   var useless = 'one two';
>     var form = new Form("forms/registration.xml");
>
>     // The showForm function will keep redisplaying the form until
>     // everything is valid
>     form.showForm("registration-display-pipeline");
>
>>   useless = useless.split(' ');
>     var model = form.getModel();
>     var bizdata = { "username" : model.name }
>     cocoon.sendPage("registration-success-pipeline.jx", bizdata);
> }
>
>
> Then do the following:
>
> 1. invoke /samples/blocks/forms/registration
>     -> the form is created and displayed, OK
>
> 2. submit the form with valid fields (thus calling continuation #1)
>     -> "Registration successful", OK
>
> 3. either hit reload or go back and re-submit it
>    (thus calling the SAME continuation again)
>     -> "org.mozilla.javascript.EcmaError: split is not a function."


This is working correctly.

First you assign the 'useless' variable a String value, then you create
the continuation.  When you resume the continuation the first time, you
re-assign the 'useless' variable so that it now holds an Array value
(String.split() returns an Array).  When you resume the continuation
again, you try to call .split() on the 'useless' var, which is now an
Array, and the error is appropriately thrown since an Array has no such
method.





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org