Do you know how to set constants on the class_ so that the value can be accessed without first creating a instance of the object
ex. I've created v8pp::class_<c++_node_class> node_class and the class is on the context with context.set("Node", node_class) I want to be able to set a value on that class say .ELEMENT_TYPE = 0, but I want to be able to access that class on the main Object. So that Node.ELEMENT_TYPE would return 0. without first having to have a make a node_class object.
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?