cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Toby <>
Subject Re: Weird Javascript error in continuations
Date Wed, 02 Aug 2006 14:31:18 GMT
Leszek wrote:
> Simply speaking: page local is a special variable that has different
> values in different continuations.

So it seems that a continuation by default only saves the "program
counter" (or equivalent notion in JS) but not the local variables.  
This is a bit counter-intuitive, and blatantly against the
documentation[1], but you clearly explained the reasons behind it.

What about global variables? 
And the parameters of a (recursive) function call?

I have run a little test and frankly I don't understand what's
happening any more.

	var called = 0

	function f(x) {
	  cocoon.sendPageAndWait('test', { x: x, called: called })
	  f(x + 1)

	function called_from_sitemap() {

called is a global variable.  There is a sitemap matcher that calls
called_from_sitemap(), which in turn calls f(1), which calls f(2), etc.

Every new call to f() increments called (which should grow on par with
the stack of x parameters) and sends both variables to 'test', which is:

	    <p> x = ${x} </p>
	    <p> called ${called} times </p>
	    <p> <a href="cont=${}">next</a> </p>

The cont=* pipeline calls the continuation.

Following the 'next' links, I expected to see:
	x = 1, called 1 times
	x = 2, called 2 times
	x = 3, called 3 times

At which point I would start playing with the continuations, going back
and forth.  Instead I get:
	x = 1, called 1 times
	x = 1, called 1 times
	x = 1, called 1 times

What's happening?


[1] As I pointed out in a previous email, this page says:
«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.»

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message