Hi again Charles,
I was only considering values and I was thinking that rolling your own Hash
method for a value would be fairly easy since there are not that many basic
types to worry about.
Something along the lines of:
int Hash(Handle<Value> value) {
if (value->IsObject()) {
return Handle<Object>::Cast(value)->GetIdentityHash();
} else if (value->IsString()) {
// compute and return string hash
} else if (value->IsNumber()) {
// compute and return number hash
} else if (value->IsBoolean()) {
if (value->IsTrue()) {
// return hash value for true
} else {
// return hash value for false
}
} else if (value->IsNull()) {
// return hash value for null
} else if (value->IsUndefined()) {
// return hash value for undefined
}
assert(false);
return 0;
}
Cheers, -- Mads
On Tue, May 3, 2011 at 3:41 PM, Charles Lowell <[email protected]>wrote:
> Mads,
>
> Thanks for the helpful tips. I will definitely look into using
> internal fields where possible to achieve the speedup.
>
> Stephan is correct, I'm wanting to associate metadata with non-object,
> non-template created values like dates and regexen. In fact, for my
> use-case (therubyracer), I'd really like to be able to tie metadata to
> anything you can get a Handle to since I also reflect non-value things
> into Ruby like Context and FunctionTemplate. That said, being able to
> get a stable, unique object id for all values would be killer. You
> mentioned that it would be relatively straightforward to roll your
> own? Any chance you could elaborate?
>
> cheers,
> Charles
>
>
> On May 3, 2:01 am, Mads Sig Ager <[email protected]> wrote:
> > On Tue, May 3, 2011 at 8:58 AM, Stephan Beal <[email protected]>
> wrote:
> > > On Tue, May 3, 2011 at 8:56 AM, Mads Sig Ager <[email protected]>
> wrote:
> >
> > >> On Tue, May 3, 2011 at 8:52 AM, Stephan Beal <[email protected]
> >wrote:
> >
> > >>> i think Charles is wanting to tie data to non-template-generated
> values
> > >>> like Numbers. From what i understand, v8 does not have the API to do
> this.
> > >>> Nor ...
> >
> > >> Object::GetIdentityHash should give you what you want to do the
> mapping
> > >> externally. If you want to add external data after the fact in the
> object
> > >> itself hidden values is the way to go. :)
> >
> > > But Object::GetIdentityHash() only works for Objects, right?
> >
> > > In SpiderMonkey each JS value is a numeric handle with a stable value
> (v8's
> > > aren't stable b/c of how the allocator works), and those numbers can be
> used
> > > to map, e.g.
> > > a Window handle to a JS Integer.
> >
> > Yes, GetIdentifyHash only works for Objects. For values you can easily
> roll
> > your own. What you get from GetIdentityHash will stay the same over time.
> >
> > -- Mads
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > > --
> > > ----- stephan beal
> > >http://wanderinghorse.net/home/stephan/
> >
> > > --
> > > v8-users mailing list
> > > [email protected]
> > >http://groups.google.com/group/v8-users
>
> --
> v8-users mailing list
> [email protected]
> http://groups.google.com/group/v8-users
>
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users