Created
September 26, 2013 13:27
-
-
Save Jarvix/6714139 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It is about resultObject | |
object = [cls alloc]; | |
invocation.target = object; // its selector is -init | |
[invocation invoke]; | |
[invocation getReturnValue:&resultObject]; | |
info.This()->SetInternalField(0, makeWrapper([[L8Runtime currentRuntime] V8Context], resultObject)); | |
v8::Handle<v8::External> makeWrapper(v8::Handle<v8::Context> context, id wrappedObject) | |
{ | |
// the bridging retain here > | |
void *voidObject = (void *)CFBridgingRetain(wrappedObject); | |
v8::Handle<v8::External> ext = v8::External::New(voidObject); | |
v8::Persistent<v8::External> persist(context->GetIsolate(),ext); | |
persist.MakeWeak((__bridge void *)wrappedObject, ObjCWeakReferenceCallback); | |
return ext; | |
} | |
// the weak callback is not called (it should be when the object is removed by the V8 GC) | |
void ObjCWeakReferenceCallback(v8::Isolate *isolate, v8::Persistent<v8::External> *persistent, void *parameter) | |
{ | |
v8::Local<v8::External> ext = v8::Local<v8::External>::New(isolate, *persistent); | |
#if 1 // Debug | |
id wrappedObject = CFBridgingRelease(ext->Value()); | |
NSLog(@"Weakreferencecallback for object %@",wrappedObject); | |
#else | |
CFRelease(ext->Value()); | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment