What's the difference between v8::Global and v8::Persistent?

1,218 views
Skip to first unread message

tbl...@icloud.com

unread,
Oct 1, 2016, 9:33:33 PM10/1/16
to v8-users
The documentation comments say Persistent "allows copy and assignment", and Global has "move semantics". What exactly does that mean?

Thanks
~Theodore

Zac Hansen

unread,
Oct 1, 2016, 9:53:57 PM10/1/16
to v8-users
They are synonyms.   Just like Local and Handle.

Theodore Dubois

unread,
Oct 1, 2016, 9:56:07 PM10/1/16
to v8-u...@googlegroups.com
Well, Handle is a typedef to Local, but Global is not a typedef to Persistent. Global and Persistent are different subclasses of PersistentBase. So there must be some difference between them.

~Theodore
> --
> --
> v8-users mailing list
> v8-u...@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/uSx4F8Uvwis/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Zac Hansen

unread,
Oct 1, 2016, 10:29:46 PM10/1/16
to v8-u...@googlegroups.com
Ah, UniquePersistent is what is the same as a Global.


  • Rename UniquePersistent to Global and give it full move semantics: CL CL


Looks like Persistent is copyable?

> To unsubscribe from this group and all its topics, send an email to v8-users+unsubscribe@googlegroups.com.

> For more options, visit https://groups.google.com/d/optout.

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/uSx4F8Uvwis/unsubscribe.
To unsubscribe from this group and all its topics, send an email to v8-users+unsubscribe@googlegroups.com.

Theodore Dubois

unread,
Oct 1, 2016, 10:32:52 PM10/1/16
to v8-u...@googlegroups.com
What exactly does that mean? Does that mean this:

Persistent<String> string(String::NewFromUtf8(isolate, “string”, NewStringType::kNormal).ToLocalChecked());
Persistent<String string2 = string;

would result in two different string objects, and using Global instead would result in two handles to the same object?

~Theodore

> On Oct 1, 2016, at 7:29 PM, Zac Hansen <xax...@gmail.com> wrote:
>
> Ah, UniquePersistent is what is the same as a Global.
>
> https://docs.google.com/document/d/1g8JFi8T_oAE_7uAri7Njtig7fKaPDfotU6huOa1alds/edit
>
> • Rename UniquePersistent to Global and give it full move semantics: CL CL
>
> Looks like Persistent is copyable?
>
> On Sat, Oct 1, 2016 at 6:55 PM, Theodore Dubois <tbl...@icloud.com> wrote:
> Well, Handle is a typedef to Local, but Global is not a typedef to Persistent. Global and Persistent are different subclasses of PersistentBase. So there must be some difference between them.
>
> ~Theodore
>
> > On Oct 1, 2016, at 6:53 PM, Zac Hansen <xax...@gmail.com> wrote:
> >
> > They are synonyms. Just like Local and Handle.
> >
> > On Saturday, October 1, 2016 at 6:33:33 PM UTC-7, tbl...@icloud.com wrote:
> > The documentation comments say Persistent "allows copy and assignment", and Global has "move semantics". What exactly does that mean?
> >
> > Thanks
> > ~Theodore
> >
> > --
> > --
> > v8-users mailing list
> > v8-u...@googlegroups.com
> > http://groups.google.com/group/v8-users
> > ---
> > You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
> > To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/uSx4F8Uvwis/unsubscribe.
> > To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> --
> v8-users mailing list
> v8-u...@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/uSx4F8Uvwis/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> --
> v8-users mailing list
> v8-u...@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/uSx4F8Uvwis/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.

Zac Hansen

unread,
Oct 1, 2016, 10:34:00 PM10/1/16
to v8-u...@googlegroups.com
You get a new object each time you call new.  Everything else is just bumping the reference count on that object.

> > To unsubscribe from this group and all its topics, send an email to v8-users+unsubscribe@googlegroups.com.

> > For more options, visit https://groups.google.com/d/optout.
>
> --
> --
> v8-users mailing list
> v8-u...@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/uSx4F8Uvwis/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to v8-users+unsubscribe@googlegroups.com.

> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> --
> v8-users mailing list
> v8-u...@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/uSx4F8Uvwis/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to v8-users+unsubscribe@googlegroups.com.

> For more options, visit https://groups.google.com/d/optout.

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/uSx4F8Uvwis/unsubscribe.
To unsubscribe from this group and all its topics, send an email to v8-users+unsubscribe@googlegroups.com.

Theodore Dubois

unread,
Oct 1, 2016, 10:38:50 PM10/1/16
to v8-u...@googlegroups.com
I just noticed that the Global copy constructor sets the other Global’s cell to NULL. I guess that means moving the global around won’t accidentally increment the reference count. That makes sense.

~Theodore
> > > To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.
> > > For more options, visit https://groups.google.com/d/optout.
> >
> > --
> > --
> > v8-users mailing list
> > v8-u...@googlegroups.com
> > http://groups.google.com/group/v8-users
> > ---
> > You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
> > To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/uSx4F8Uvwis/unsubscribe.
> > To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
> >
> >
> > --
> > --
> > v8-users mailing list
> > v8-u...@googlegroups.com
> > http://groups.google.com/group/v8-users
> > ---
> > You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
> > To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/uSx4F8Uvwis/unsubscribe.
> > To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> --
> v8-users mailing list
> v8-u...@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/uSx4F8Uvwis/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> --
> v8-users mailing list
> v8-u...@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/uSx4F8Uvwis/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.

Zac Hansen

unread,
Oct 1, 2016, 10:40:31 PM10/1/16
to v8-u...@googlegroups.com
Globals are moveable and not copyable, similar to a unique_ptr.

> > > To unsubscribe from this group and all its topics, send an email to v8-users+unsubscribe@googlegroups.com.

> > > For more options, visit https://groups.google.com/d/optout.
> >
> > --
> > --
> > v8-users mailing list
> > v8-u...@googlegroups.com
> > http://groups.google.com/group/v8-users
> > ---
> > You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
> > To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/uSx4F8Uvwis/unsubscribe.
> > To unsubscribe from this group and all its topics, send an email to v8-users+unsubscribe@googlegroups.com.

> > For more options, visit https://groups.google.com/d/optout.
> >
> >
> > --
> > --
> > v8-users mailing list
> > v8-u...@googlegroups.com
> > http://groups.google.com/group/v8-users
> > ---
> > You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
> > To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/uSx4F8Uvwis/unsubscribe.
> > To unsubscribe from this group and all its topics, send an email to v8-users+unsubscribe@googlegroups.com.

> > For more options, visit https://groups.google.com/d/optout.
>
> --
> --
> v8-users mailing list
> v8-u...@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/uSx4F8Uvwis/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to v8-users+unsubscribe@googlegroups.com.

> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> --
> v8-users mailing list
> v8-u...@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/uSx4F8Uvwis/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to v8-users+unsubscribe@googlegroups.com.

> For more options, visit https://groups.google.com/d/optout.

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/uSx4F8Uvwis/unsubscribe.
To unsubscribe from this group and all its topics, send an email to v8-users+unsubscribe@googlegroups.com.

Theodore Dubois

unread,
Oct 1, 2016, 10:41:20 PM10/1/16
to v8-u...@googlegroups.com
Got it.

~Theodore
> > > > To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.
> > > > For more options, visit https://groups.google.com/d/optout.
> > >
> > > --
> > > --
> > > v8-users mailing list
> > > v8-u...@googlegroups.com
> > > http://groups.google.com/group/v8-users
> > > ---
> > > You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
> > > To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/uSx4F8Uvwis/unsubscribe.
> > > To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.
> > > For more options, visit https://groups.google.com/d/optout.
> > >
> > >
> > > --
> > > --
> > > v8-users mailing list
> > > v8-u...@googlegroups.com
> > > http://groups.google.com/group/v8-users
> > > ---
> > > You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
> > > To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/uSx4F8Uvwis/unsubscribe.
> > > To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.
> > > For more options, visit https://groups.google.com/d/optout.
> >
> > --
> > --
> > v8-users mailing list
> > v8-u...@googlegroups.com
> > http://groups.google.com/group/v8-users
> > ---
> > You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
> > To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/uSx4F8Uvwis/unsubscribe.
> > To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
> >
> >
> > --
> > --
> > v8-users mailing list
> > v8-u...@googlegroups.com
> > http://groups.google.com/group/v8-users
> > ---
> > You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
> > To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/uSx4F8Uvwis/unsubscribe.
> > To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> --
> v8-users mailing list
> v8-u...@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/uSx4F8Uvwis/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> --
> v8-users mailing list
> v8-u...@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/uSx4F8Uvwis/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages