On Mon, Jan 18, 2021 at 5:28 AM Vinayaka Kamath < vinayaka.kam...@couchbase.com> wrote:
> Hello All, > > I am trying to return a weak persistent handle to JS through a function > template. However the v8 is crashing on triggering the codepath. What is > the correct way to do it? > My intention is to trigger GC on the persistent handle when it goes out of > scope. > > _____________________________________ > *My Function Template:* > > void QueryFunction(const v8::FunctionCallbackInfo<v8::Value> &args) { > // This function is made available as Query() in the JS code > . > . > auto wrapper = new Query::WrapStop(isolate, iterator, > it_info.iterable); > args.GetReturnValue().Set(wrapper->value); *// How to return this?? > Set requires a pointer to Persistent* > args.GetReturnValue().Set(wrapper->value.Get(Isolate)); *// return a reference to the persistent object.* > // The intention is to force GC on wrapper->value when it goes out of > scope in JS > } > ________________________________________ > *Definition of WrapStop* > > struct WrapStop { > explicit WrapStop(v8::Isolate *, Query::Iterator *, > v8::Local<v8::Value>); > virtual ~WrapStop(); > v8::Persistent<v8::Value> value; // Force GC on this handle when > it goes out of scope > Query::Iterator *iterator; > static void Callback(const v8::WeakCallbackInfo<WrapStop> &); // > Callback triggered on GC > }; > ________________________________________ > *Constructor for WrapStop* > > Query::WrapStop::WrapStop(v8::Isolate *isolate, Query::Iterator *iter, > v8::Local<v8::Value> val) : value(isolate, val), iterator(iter) { > value.SetWeak(this, Query::WrapStop::Callback, > v8::WeakCallbackType::kParameter); > // Set value as weak to force GC > } > > > > -- > -- > v8-users mailing list > v8-users@googlegroups.com > http://groups.google.com/group/v8-users > --- > You received this message because you are subscribed to the Google Groups > "v8-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to v8-users+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/v8-users/490983ae-fd94-4b3e-aa4b-0b4ff8e0c23dn%40googlegroups.com > <https://groups.google.com/d/msgid/v8-users/490983ae-fd94-4b3e-aa4b-0b4ff8e0c23dn%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- -- v8-users mailing list v8-users@googlegroups.com http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/v8-users/CAA2GJqUBTkrXjRettWUSk7mtfKzqxhufdk9wjHdf%3DQi3%3D%3DkgDw%40mail.gmail.com.