Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Array interation
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Bryan White  
View profile  
 More options Nov 18 2009, 3:36 pm
From: Bryan White <nickt...@gmail.com>
Date: Wed, 18 Nov 2009 15:36:34 -0500
Local: Wed, Nov 18 2009 3:36 pm
Subject: Array interation
My C++ program supplies to V8 javascript code objects that represent
some internal data structures.  Some of these data structures are in
fact arrays of other objects.  I have implemented the 'length'
accessor and the indexed property interceptor.  This has been working
for a while now like this:

for(var i = 0; i < list.length; ++i)
    ... using list[i]

I would like to get this working as well:

for(elem in list)
    ... do something with elem

If I just do the above, elem will take on the values of the names of
the accessors installed in the ObjectTemplate.  (length and a couple
of other unrelated accessors).  This makes sense as it is enumerating
it as an object, not an array.

To fix this I created an call back and installed it with
objtmpl->SetIndexedPropertyHandler(V8Get,0,0,0,V8Enum)
(V8Enum is the new function, V8Get has been there all along.

In the V8Enum function I create an array, add all the values to the
array and return it.

For reference this is the function (with app specific stuff elided to
keep it simple):

Handle<Array> V8Enum(const AccessorInfo& ai)
{
        int sz = ...;
        Handle<Array> arry = Array::New(sz);
        for(int i = 0; i < sz; ++i)
                arry->Set( V8Int(i), ...);
        return arry;

}

The V8Enum function is being called.  However the javascript
enumeration is still seeing the names of the template accessors and
not the array elements being returned.

Am I misinterpreting how this is supposed to work?

--
Bryan White


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christian Plesner Hansen  
View profile  
 More options Nov 19 2009, 3:13 am
From: Christian Plesner Hansen <christian.plesner.han...@gmail.com>
Date: Thu, 19 Nov 2009 09:13:34 +0100
Local: Thurs, Nov 19 2009 3:13 am
Subject: Re: [v8-users] Array interation
What you're seeing is maybe not the most meaningful behavior but it is
expected and correct.  If you try the same with a standard JS array it
will also iterate through the indexes, not the element values.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »