Many types in the API have v8::Local<T> data members - how does that even work?

15 views
Skip to first unread message

Zac Hansen

unread,
Oct 1, 2016, 8:35:45 PM10/1/16
to v8-users
My understanding is a v8::Local<T> is only valid within a handlescope, so if you store one in an object, that object is then only valid within a handlescope, right?

For example, ScriptOrigin stores all its parameters as Local's:


and then when I call for the ScriptID later, it's no longer valid and I get a memory error.  Am I missing something about v8::Local?  or something about how to use ScriptOrigin?  Other types, like Script has a v8::Local<v8::UnboundScript>.. same question.   

Thank you.

--Zac

Zac Hansen

unread,
Oct 1, 2016, 10:59:22 PM10/1/16
to v8-users
Maybe I'm just really not understanding the script compilation process..

Zac Hansen

unread,
Oct 1, 2016, 11:13:23 PM10/1/16
to v8-u...@googlegroups.com
I may be starting to understand that an UnboundScript is sort of like a "base type" to a script.  and that a lot of stuff is stored there instead.

--
--
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/WyAoMwyKJ7w/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.

Ben Noordhuis

unread,
Oct 2, 2016, 3:57:25 AM10/2/16
to v8-users
On Sun, Oct 2, 2016 at 2:35 AM, Zac Hansen <xax...@gmail.com> wrote:
> My understanding is a v8::Local<T> is only valid within a handlescope, so if
> you store one in an object, that object is then only valid within a
> handlescope, right?

Correct.

> For example, ScriptOrigin stores all its parameters as Local's:
>
> http://v8.paulfryzel.com/docs/master/include_2v8_8h_source.html#l01028
>
> and then when I call for the ScriptID later, it's no longer valid and I get
> a memory error. Am I missing something about v8::Local? or something about
> how to use ScriptOrigin? Other types, like Script has a
> v8::Local<v8::UnboundScript>.. same question.

You aren't missing anything, that is how Locals works.

Zac Hansen

unread,
Oct 2, 2016, 3:59:03 AM10/2/16
to v8-u...@googlegroups.com
What I was confused about is that I'm not supposed to hold on to a ScriptOrigin.   I'm supposed to get it from the UnboundScript associated with my Script.   

I finally figured out what was going on.

Reply all
Reply to author
Forward
0 new messages