Temporary ObjectTemplate

24 views
Skip to first unread message

Riccardo Corsi

unread,
Oct 6, 2016, 2:18:46 PM10/6/16
to v8-users
Hi all,

I'm using ObjectTemplate to create JS empty objects that are simple wrappers of a c++ object
(in the JS code they are just used as "handles" to pass the objects around in the script).

I was just wondering if there is any issue or penalty to use a new ObjectTemplate every time (see code below)
or if I should store the ObjectTemplate in a persistent handle and reuse it.

Thank you,
Ricky

v8::Handle<v8::Object> WrapNativeElem(NativeElem* elem)
   
{
     
Isolate* isolate = Isolate::GetCurrent();
     
EscapableHandleScope handle_scope(isolate);

     
// create an empty object
      v8
::Handle<v8::ObjectTemplate> elem_templ = v8::ObjectTemplate::New();
      elem_templ
->SetInternalFieldCount(1);
      v8
::Local<v8::Object> wrapper = elem_templ->NewInstance();
     
     
// set the game state as internal field and return the wrapper
      wrapper
->SetInternalField(0, External::New(Isolate::GetCurrent(), elem));
     
return handle_scope.Escape(wrapper);
   
}


Jochen Eisinger

unread,
Oct 7, 2016, 1:19:58 AM10/7/16
to v8-users
If possible, reusing the object template will save space, and is preferable

--
--
v8-users mailing list
v8-u...@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+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Riccardo Corsi

unread,
Oct 10, 2016, 8:08:54 AM10/10/16
to v8-u...@googlegroups.com
will do, thanks!

To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscribe@googlegroups.com.

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

--
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/GQmzqNKKDrQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to v8-users+unsubscribe@googlegroups.com.

Zac Hansen

unread,
Oct 11, 2016, 6:28:56 PM10/11/16
to v8-users
why wouldn't you just use a v8::External?  Isn't that exactly what they're meant for?
will do, thanks!

To unsubscribe from this group and stop receiving emails from it, 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/GQmzqNKKDrQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.

Jochen Eisinger

unread,
Oct 12, 2016, 3:18:27 AM10/12/16
to v8-users
depends on what you mean by wrapper. Typically, we'd call a JS object that corresponds to an embedder object a "wrapper"

Riccardo Corsi

unread,
Oct 12, 2016, 4:53:41 AM10/12/16
to v8-u...@googlegroups.com
v8::External is exactly what I'm using - see the code snippet in the original post. 

The question was just referring to the ObjectTemplate used to generate the object instances, on which I set the externals.


To unsubscribe from this group and stop receiving emails from it, 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/GQmzqNKKDrQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to v8-users+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages