Yes, you'd usually either store a Persistent in the C++ class itself or
maintain a map.
The Persistent would usually be weak, so you get notified if the object is
no longer needed by V8, and you can create new Local handles to the js
object when needed.
A common pattern to get from the js object
actualy, I am doing this when declaring the type:
v8::Persistentv8::ObjectTemplate v8_combo_persistent;
int v8_combo_id = 0;
void v8_create_combo_template(v8::Isolate* isolate,
v8::Handlev8::ObjectTemplate global)
{
if(v8_combo_id 0) return;
v8_combo_id = 1;
Thanks a lot, I figure it also... But, I have still 3 (related) questions:
Why Persistent are not a subclass of handle? so that it is possible to use
Handle (Local) and persistent in the same way, without the need to do a
cast? And what is the difference between a weak and non weak persistent?
On Tue, Jan 28, 2014 at 9:20 AM, Pierre Saunier
pierre.saun...@ppmodeler.com wrote:
Thanks a lot, I figure it also... But, I have still 3 (related) questions:
Why Persistent are not a subclass of handle? so that it is possible to use
Handle (Local) and persistent in the same way, without the
thanks, that is clear.
but that means i have to store a persistent object for every c++ object I
create so that i can go from javascript objet to c++ object and vice
versa.. . so, either i add the field persistent::object to my class, which
links strongly my code to v8 or i need to have an
What exactly do you want to store; just one class instance - or do you have an
existing C++ class that you are extending to be v8 compatible? There is a giant
difference between these cases.
The first case is what I am doing for nodejs currently; I am taking an existing
c++ class (Fl_Window)
It is very simple:
I want to set javascript callback functions where the first parameter is a
javascript object.
so I have a C++ object, let say a button. When the button is pressed, a
callback function is called with the button in parameter.
In my v8 code, I create an persistent object template
Right, Handle (and Local) can only be stack allocated and have to live
within a HandleScope. If you want to store a reference to a V8 object, you
need a Persistent, see esp. https://developers.google.com/v8/embed#handles
best
-jochen
On Sat, Jan 25, 2014 at 8:52 PM, Kevin Ingwersen
I am myself fairly new to V8, but your handles are dependent on your
HandleScope, so when scriptCompile finishes
your handles get out of scope and will be cleaned up by the garbage
collector.
To ensure the lifetime of your handles you could use Persistent handles
instead.
On Friday, 24
From what I know, you have to first create a Context…then create a new
v8::Script, which you can later -Run();. See shell.cc, it has a function to
run a script.
Am Sa. Jan. 25 2014 11:31:21 schrieb Niklas Voss:
I am myself fairly new to V8, but your handles are dependent on your
HandleScope,
Hi.
A cursory look at the code tells me you aren't quite aware of the existence
of the monster called GC in v8. You can't just
store the return value of a call for later use, there ain't any guarantee
the monster won't devour it before you get to it :-).
Search for the term Persistent in this
To really store something:
PersistentValue MyVal = PersistentValue::New( Value::New() );
Replace Value with something like Array, for example. That will give you an
ever-existing value, not devoured by the GC. That, at least, works in my case
o.o;
Am Sa. Jan. 25 2014 19:07:14 schrieb
12 matches
Mail list logo