template<typename Value>
class_& set_js_const(char const* name, Value value)
{
v8::HandleScope scope(isolate());
class_singleton_.js_function_template()->Set(v8pp::to_v8(isolate(), name),
to_v8(isolate(), value), v8::PropertyAttribute(v8::ReadOnly | v8::DontDelete));
return *this;
}
recv
it is. there is also handy v8pp::call_v8()
that allows to call a V8::Function
with C++ arguments, converting them to V8::Values:v8::Local<v8::Function> fun;
v8::Local<v8::Object> fun_this;
v8::Local<v8::Value> ret = v8pp::call_v8(isolate, fun, fun_this, 11, "str", you_wrapped_cpp_object);
var enumeratedArray = new Array();
for (var n in object)
enumeratedArray.push(n);
So I want to be able to override "in" so that i can send the values that I want back
so i changed the class function to this
v8::Local<v8::FunctionTemplate> func = v8::FunctionTemplate::New(isolate_,//);
//v8::Local<v8::FunctionTemplate> js_func = v8::FunctionTemplate::New(isolate_,
[](v8::FunctionCallbackInfo<v8::Value> const& args)
{
v8::Isolate* isolate = args.GetIsolate();
try
{
return args.GetReturnValue().Set(instance(isolate).wrap_object(args));
}
catch (std::exception const& ex)
{
args.GetReturnValue().Set(throw_ex(isolate, ex.what()));
}
});
setting the constructor on the class_function_template. then I'm also creating an object template after that
func->InstanceTemplate()->SetInternalFieldCount(2);
v8::Local<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(isolate_, class_function_template());
obj_temp_.Reset(isolate_, obj);
and in the wrap function I changed it to
v8::EscapableHandleScope scope(isolate_);
v8::Local<v8::Object> obj = object_template()->NewInstance();
//class_function_template()->GetFunction()->NewInstance();
obj->SetAlignedPointerInInternalField(0, object);
obj->SetAlignedPointerInInternalField(1, this);
creating the new instance of the object template appears to not call the constr. I tested it out and so far I don't see any problems with this. Is there anything that you can think of that will go wrong?
So, anyways I put the dynamic external data into a static class per isolate and just deleted them when the isolate was done. Which works fine for me now. Though I'm curious as to why it was crashing to begin with.
So, when the weak callback was called to delete the external data it went into that function and deleted the external data fine. then when exiting it went back into global-handlers.cc -PostGarbageCollectionProcessing function. and crashes at CHECK(state() != NEAR_DEATH); Do you know what would cause it to crash here?
v8pp::class_::destroy()
function to delete all wrapped C++objects and the class_
instance
I uploaded my changes to github. my version of v8pp::context is not finished though. A lot of that was testing around to see what works. Though I eventually will add a callback function for context creation that would allow you to create the global object as a v8pp::class_.
I added interceptors to v8pp::class_. which is similar to the property. any_object.h was just stuff I was testing out. hopefully allowing a cpp function to accept either a cpp object or a v8 object. I just added v8pp::Function to that file which allows for accepting a function that is either from v8 or from cpp and if the object is passed to v8 with a cpp function that function would be converted so that It could be used within v8. also with that I enabled using std::function as a function withing v8pp.
reference_tracker.h is just for debugging memory leaks. I should probably change it to a macro.
I also added some destroy functions in class_ though those were kinda just put together quickly. also added set_js_const which allows to add a const value on to the js function.
the interceptors don't include all the static asserts needed. Haven't really tried merging it to your version yet. I need to redo all my changes to v8pp::context first lol.