Christopher Oliver wrote:

Sylvain Wallez wrote:


<snip/>

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 =
           getPetStore().getProductListByCategory(categoryId,
                                                  skipResults,
                                                  maxResults);
       .../...


Am I right in my understanding ?


Sylvain

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




Reply via email to