[v8-users] access violation on Persistent.Reset()

2020-09-09 Thread jres...@gmail.com
Hi,
I have an issue where we sometimes have Persistent handles that outlive the 
Isolate with which they are associated. When Reset() is called, it causes 
an access violation, seemingly because the Isolate no longer exists. Is 
there any way to prevent this (other than avoiding calling Reset() on any 
Persistent handles that outlive the Isolate instance)? I suspect this is a 
dumb question, but just want to make sure I'm not missing something.

Thank you,
Jonathan


-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/248de1f3-9b73-43b2-8c94-449fcf0accd7n%40googlegroups.com.


[v8-users] how to create a Persistent handle cache?

2020-11-09 Thread jres...@gmail.com
I would like to cache Persistent handles in such a way that I can retrieve 
the same Persistent instance given the identical JS object, i.e. imagine a 
function like so:

Persistent GetPersistentForObject(Local obj)
{
   // If we have already created a Persistent for obj, find and return it.
   // Otherwise, create and return a Persistent for obj and cache it for 
   // future calls.
}

The obvious thought is to store the Persistent handles in a map of some 
kind, but what to use as the key? I assume it would not be possible to 
actually use Local handles as keys in a map that outlives the current 
HandleScope.

One thought I had was to assign a unique integer to the object using 
obj.SetPrivate(...), and use that as the key, but SetPrivate is documented 
as experimental, which is discouraging.

Is there an easier way to achieve what I'm trying to do? I feel like I may 
be missing something obvious...

Jonathan


-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/197b2711-31c2-4c88-91d4-6119f0edc37an%40googlegroups.com.


Re: [v8-users] how to create a Persistent handle cache?

2020-11-25 Thread jres...@gmail.com
Thank you for the suggestion Ben!

On Tuesday, November 10, 2020 at 5:14:35 AM UTC-5 Ben Noordhuis wrote:

> On Tue, Nov 10, 2020 at 4:54 AM jres...@gmail.com  
> wrote:
> >
> > I would like to cache Persistent handles in such a way that I can 
> retrieve the same Persistent instance given the identical JS object, i.e. 
> imagine a function like so:
> >
> > Persistent GetPersistentForObject(Local obj)
> > {
> > // If we have already created a Persistent for obj, find and return it.
> > // Otherwise, create and return a Persistent for obj and cache it for
> > // future calls.
> > }
> >
> > The obvious thought is to store the Persistent handles in a map of some 
> kind, but what to use as the key? I assume it would not be possible to 
> actually use Local handles as keys in a map that outlives the current 
> HandleScope.
> >
> > One thought I had was to assign a unique integer to the object using 
> obj.SetPrivate(...), and use that as the key, but SetPrivate is documented 
> as experimental, which is discouraging.
> >
> > Is there an easier way to achieve what I'm trying to do? I feel like I 
> may be missing something obvious...
> >
> > Jonathan
>
> A hashmap should work if you observe the following;
>
> 1. Use `v8::Object::GetIdentityHash()` to compute the hash key.
> 2. Use `Persistent::operator==()` to detect duplicates (also has an
> overload that compares against a Local)
>
> I.e., step 1 is to find the right bucket and step 2 is to find out if
> that bucket already contains the object.
>
> Using just the identity hash isn't sufficient, see [1] and [2] for 
> discussion.
>
> Caveat: use `v8::Value::SameValue()` - not `Persistent::operator==()`
> - if you also store primitives (numbers, strings, etc.)
>
> [1] https://github.com/denoland/deno/pull/7946#discussion_r504192165
> [2] https://github.com/denoland/deno/issues/7969
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/07471ffc-0d52-4fc8-ac9f-07955f9303d2n%40googlegroups.com.