Rodrigo, you should be able to trivially cast a v8::Function or v8::Object 
to v8::Value is that what you're trying to do? In that case you don't need 
to put them in a v8::External. You can pass those objects to 
data->SetInternalField safely I would think.
Ben

On Tuesday, 20 October 2020 at 15:10:00 UTC+10:30 Rodrigo Hernandez wrote:

> So, coming back to this, is there a way to cast/convert/wrap a local 
> template (function or object) into a v8::Value?
> I am thinking about hiding them inside an internal field so I could do:
>
> context->global()->GetFunction("constructor")->GetInternalField(X).
>
> how safe would it be to cast them to a void* and wrapping them inside a 
> v8::External?
>
> On Sunday, October 11, 2020 at 11:40:27 AM UTC-6 Rodrigo Hernandez wrote:
>
>> Thanks Ben, I see how those are less optimal, I was hoping for something 
>> along the lines of context->global()->GetFunctionTemplate("constructor"), 
>> or something along those lines.
>> The only problem I have with my approach is that I need a Finalize 
>> function on each wrapped class that pretty much just resets the permanent 
>> handles.
>>
>> Thanks Again!
>> On Sunday, October 11, 2020 at 1:49:10 AM UTC-6 Ben Noordhuis wrote:
>>
>>> On Sat, Oct 10, 2020 at 10:44 PM Rodrigo Hernandez 
>>> <kwizatz.ae...@gmail.com> wrote: 
>>> > 
>>> > Hello, 
>>> > 
>>> > So, suppose I am wrapping a C++ class around a JS constructor, I've 
>>> already created and initialized the isolate, created and initialized a 
>>> context, I have the FunctionTemplate for the constructor and I have 
>>> instantiated the function and I can call it from Js as x() or new X(), 
>>> > all this is fine, the function template context is finished and the 
>>> handle lost. 
>>> > 
>>> > But then I want to create another wrapped object for a class that 
>>> inherits from the first one. 
>>> > Is there a way to retrieve the base class FunctionTemplate so in the 
>>> child class I can call child->Inherit(base)? 
>>> > 
>>> > Is there another way of doing this? 
>>> > 
>>> > Right now I am keeping a C++ unordered_map of isolate to persistent 
>>> handle to function templates, and that works, but is that the only option? 
>>> > 
>>> > Thanks! 
>>>
>>> It's not the only option but it's a pretty good solution. Less optimal 
>>> solutions: 
>>>
>>> - store them in the snapshot with SnapshotCreator::AddData() (but you 
>>> can only retrieve it once) 
>>> - scan the heap for them with Isolate::VisitHandlesWithClassIds(). 
>>>
>>> No doubt there are more ways to stow them away somewhere. 
>>>
>>

-- 
-- 
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/3496e4c4-cf66-42ae-b517-86ac95431901n%40googlegroups.com.

Reply via email to