Skip to content

Commit 455d23f

Browse files
spahnkeoliverbock
authored andcommitted
Avoid overriding an already existent Persistent handle
If the object has already been wrapped just return a new Local handle from the Persistent. Only if the Persistent handle is empty create a new one.
1 parent c6bed0a commit 455d23f

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Source/Noesis.Javascript/JavascriptInterop.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,19 @@ JavascriptInterop::WrapObject(System::Object^ iObject)
294294
{
295295
v8::Isolate *isolate = JavascriptContext::GetCurrentIsolate();
296296
JavascriptExternal *external = context->WrapObject(iObject);
297+
if (external->mPersistent.IsEmpty())
298+
{
299+
Local<FunctionTemplate> templ = context->GetObjectWrapperConstructorTemplate(iObject->GetType());
300+
Local<ObjectTemplate> instanceTemplate = templ->InstanceTemplate();
301+
Local<Object> object = instanceTemplate->NewInstance(isolate->GetCurrentContext()).ToLocalChecked();
302+
external->Wrap(isolate, object);
297303

298-
Local<FunctionTemplate> templ = context->GetObjectWrapperConstructorTemplate(iObject->GetType());
299-
Local<ObjectTemplate> instanceTemplate = templ->InstanceTemplate();
300-
Local<Object> object = instanceTemplate->NewInstance(isolate->GetCurrentContext()).ToLocalChecked();
301-
external->Wrap(isolate, object);
302-
303-
return object;
304+
return object;
305+
}
306+
else
307+
{
308+
return Local<Object>::New(isolate, external->mPersistent);
309+
}
304310
}
305311

306312
throw gcnew System::Exception("No context currently active.");

0 commit comments

Comments
 (0)