cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sylvain Wallez <>
Subject Re: Problem with JPetStore
Date Fri, 21 Mar 2003 17:52:27 GMT
Christopher Oliver wrote:

> Sylvain Wallez wrote: 


>> Does JavaScript, like Java, make a difference between primitive types 
>> (stored by value on the stack) and object types (stored by reference) 
>> ? My understanding after some tests is that a difference is made.
> No, there shouldn't be any difference. If there is, it's a bug. What 
> was your test? 

Here's my test (see below). I modified the viewCategory function in 
PetStore to track the value of "skipResults", and observed that when you 
use the browser back button and then reload the page, "skipResults" is 
correctly restored but not "foo.skip" which is set to the same value.

However, I realize now that my analyzis of the result (special handing 
of primitive types) was wrong. Writing "skipResults = 1" in JavaScript 
is equivalent to writing "Integer skipResults = new Integer(1)" in Java. 
This means "skipResults" refers to a new object of type Integer. And the 
reference to this object is restored when the continuation is restored.

function viewCategory() {
    var categoryId = cocoon.request.get("categoryId");
    var category = getPetStore().getCategory(categoryId);
    var skipResults = 0;
    var maxResults = MAX_RESULTS;
    var foo = new Object();
    foo.skip = skipResults + 0;
    while (true) {
        print("foo before = " + foo.skip);
        print("skipResults = " + skipResults);
        foo.skip = skipResults + 0;
        print("foo after = " + foo.skip);

        var productList =

Am I right in my understanding ?


Sylvain Wallez                                  Anyware Technologies 
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }

View raw message