-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
v8pp::cleanup deletes instances exported with reference_external #44
Comments
v8pp::cleanup
calls v8pp::factory<X>::destroy
for instances exported with reference_external
Thanks, this is definitely a bug, I'll fix it. |
I'm trying to merge this fix with a Currently there is a workaround to use #include "v8.h"
#include "libplatform/libplatform.h"
#include "v8pp/context.hpp"
#include "v8pp/class.hpp"
#include "v8pp/object.hpp"
struct X
{
bool b;
X(bool b) : b(b) {}
};
int main()
{
X x(true);
v8::V8::InitializeICU();
//v8::V8::InitializeExternalStartupData(argv[0]);
std::unique_ptr<v8::Platform> platform(v8::platform::CreateDefaultPlatform());
v8::V8::InitializePlatform(platform.get());
v8::V8::Initialize();
{
v8pp::context context; // a wrapper for v8::Context
v8::Isolate* isolate = context.isolate();
v8::HandleScope scope(isolate);
v8pp::class_<X> X_class(isolate);
X_class.set("b", &X::b);
context.set("X", X_class);
v8pp::set_option(isolate, isolate->GetCurrentContext()->Global(),
"x", X_class.reference_external(isolate, &x));
bool const b = v8pp::from_v8<bool>(isolate, context.run_script("x.b"));
assert(b == x.b);
// unreference x object before context cleanup
X_class.unreference_external(isolate, &x);
// v8pp::context::~context() calls v8pp::cleanup()
}
v8::V8::Dispose();
v8::V8::ShutdownPlatform();
} |
Thanks. The workaround is ok for now. Good to hear you plan to merge the shared_ptr branch to master. I'm currently on that branch. I need |
Fixed in #60 |
I have a stack allocated object. I wan't to access to that particular instance from JavaScript. I don't want v8 to manage the lifetime of that object. I'm using
v8pp::class_<X>::reference_external
to achieve that. However, when callingv8pp::cleanup(isolate)
v8pp tries to delete the instance. I think this is a bug (unless I'm misunderstandingreference_external
).Please check the code below that illustrates the problem. There is also the AddressSanitizer output below. Sample is a bit long because there is the whole boilerplate code to init/destroy v8, which is relevant for that issue (based on https://chromium.googlesource.com/v8/v8/+/master/samples/hello-world.cc):
The text was updated successfully, but these errors were encountered: