A guess would be that it only works on types with internal fields, which
are only objecttemplate-sourced objects.   That's the only thing that would
need any type of user-specified code to run on GC.  But that's just a
guess.   A quick glance at the source doesn't back it up.

On Thu, Oct 6, 2016 at 9:48 AM, Theodore Dubois <[email protected]> wrote:

> I don’t think the problem is allocating the handle on the heap, I’m doing
> that in my code too. The significant difference between your code and my
> code is that I’m using a FunctionTemplate and trying to get a weak callback
> on the Functions it creates, and you’re using an ObjectTemplate. When I
> changed Function to Object in my code and fixed a few compiler errors, it
> worked.
>
> It seems like it’s pretty easy to get this to work with objects, but much
> harder with functions. Does anyone know how to make this work?
>
> Thanks,
> ~Theodore
>
> > On Oct 5, 2016, at 8:41 PM, Zac Hansen <[email protected]> wrote:
> >
> > Also, here's the somewhat generalized code I use for doing this in my
> integration library:
> >
> > https://github.com/xaxxon/v8toolkit/blob/master/include/v8toolkit.h#L972
> >
> > On Wed, Oct 5, 2016 at 8:36 PM, Zac Hansen <[email protected]> wrote:
> > Good news is, this program calls the callback.  Bad news it crashes, but
> I think it demonstrates the general idea.
> >
> > I believe the problem with your program is that your global with the
> weak callback goes away too early.  In my program below you can see I'm
> allocating the global on the heap (and leaking the crap out of it - but you
> can clean it up in the callback) and that makes the callback get called
> because the global is still around.
> >
> >
> >
> > caveat emptor
> >
> >
> >
> > P.S. Posting a compilable program next time makes it easier for me to
> help you
> >
> >
> >
> > #include <v8.h>
> >
> > #include <v8-platform.h>
> >
> > #include <libplatform/libplatform.h>
> >
> > #include <stdio.h>
> >
> >
> >
> > using namespace v8;
> >
> >
> >
> > void func_callback(const FunctionCallbackInfo<v8::Value> &data) {
> >
> >   fprintf(stderr, "Here\n");
> >
> > }
> >
> >
> >
> > void weak_callback(const WeakCallbackInfo<int> &data) {
> >
> >   fprintf(stderr, "weak callback\n");
> >
> > }
> >
> >
> >
> >
> >
> > class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
> >
> > public:
> >
> >   inline virtual void* Allocate(size_t length) override {
> >
> >     void* data = AllocateUninitialized(length);
> >
> >     return data == NULL ? data : memset(data, 0, length);
> >
> >   }
> >
> >   inline virtual void* AllocateUninitialized(size_t length) override {
> return malloc(length); }
> >
> >   inline virtual void Free(void* data, size_t) override { free(data); }
> >
> > };
> >
> >
> >
> >
> >
> > int main() {
> >
> >   V8::InitializeICU();
> >
> >   Platform *current_platform = v8::platform::CreateDefaultPlatform();
> >
> >   V8::InitializePlatform(current_platform);
> >
> >   V8::Initialize();
> >
> >   V8::SetFlagsFromString("--expose_gc", strlen("--expose_gc"));
> >
> >   Isolate::CreateParams params;
> >
> >   params.array_buffer_allocator = new ArrayBufferAllocator();
> >
> >   Isolate *isolate = Isolate::New(params);
> >
> >   HandleScope hs(isolate);
> >
> >
> >
> >   Local<Context> context = Context::New(isolate);
> >
> >
> >
> >
> >
> >   int iii; // bogus int
> >
> >   Local<ObjectTemplate> ot = ObjectTemplate::New(isolate);
> >
> >   ot->SetInternalFieldCount(1);
> >
> >
> >
> >   for (int i = 0; ; i++) {
> >
> >     HandleScope hs2(isolate);
> >
> >     Local<Object> obj = ot->NewInstance(context).ToLocalChecked();
> >
> >     Global<Object> * gobject = new Global<Object>(isolate, obj);
> >
> >     gobject->SetWeak<int>(&iii, weak_callback,
> WeakCallbackType::kParameter);
> >
> >     isolate->AdjustAmountOfExternalAllocatedMemory(100000000);
> >
> >
> >
> >     if (i%1000==0)printf("%d\r", i);
> >
> >     /* context->Global()->Set(context, key, func).FromJust(); */
> >
> >     /* context->Global()->Delete(context, key).FromJust(); */
> >
> >   }
> >
> >
> >
> >
> >
> >   return 0;
> >
> >
> > On Wed, Oct 5, 2016 at 7:56 PM, <[email protected]> wrote:
> > Actually, that didn't work. Any other ideas? Any techniques for
> debugging GC (like getting information on where an object is referenced?)
> >
> > --
> > --
> > v8-users mailing list
> > [email protected]
> > http://groups.google.com/group/v8-users
> > ---
> > You received this message because you are subscribed to a topic in the
> Google Groups "v8-users" group.
> > To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/v8-users/Rshbi2HKYCM/unsubscribe.
> > To unsubscribe from this group and all its topics, send an email to
> [email protected].
> > For more options, visit https://groups.google.com/d/optout.
> >
> >
> >
> > --
> > --
> > v8-users mailing list
> > [email protected]
> > http://groups.google.com/group/v8-users
> > ---
> > You received this message because you are subscribed to a topic in the
> Google Groups "v8-users" group.
> > To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/v8-users/Rshbi2HKYCM/unsubscribe.
> > To unsubscribe from this group and all its topics, send an email to
> [email protected].
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> --
> v8-users mailing list
> [email protected]
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "v8-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/v8-users/Rshbi2HKYCM/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- 
v8-users mailing list
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to