Sorry for the confusion I you should use the Persistent constructor to cast
a Handle to Persistent when the Handle refers to a Persistent.
Handle<Object> x
... // x is know to be a persistent handle.
Persistent<Object>(x).ClearWeak();
In the following sample the callback XXXCallback will never be called.
void XXXCallback(v8::Persistent<v8::Value> handle, void*) {
printf("XXX\n");
handle.Dispose();
}
void ClearWeak(v8::Handle<v8::Object> handle) {
v8::Persistent<v8::Object>(handle).ClearWeak();
}
void main(...) {
v8::HandleScope scope;
... // Create and enter context.
v8::Persistent<v8::Object> handle;
{
v8::HandleScope scope;
handle = v8::Persistent<v8::Object>::New(v8::Object::New());
handle.MakeWeak(NULL, XXXCallback);
}
ClearWeak(handle);
.. // More stuff eventually causing GC.
}
Regards,
Søren
On Tue, Dec 1, 2009 at 12:16, Abdulla Kamar <[email protected]> wrote:
> I assumed that you could construct a persistent directly, as the header has
> the following statement for the persistent constructor that takes a handle:
>
> "Casts" a plain handle which is known to be a persistent handle to a
> persistent handle.
>
> The cast for a persistent takes a persistent, and the persistent construct
> that takes a handle requires is explicit, so I did the following:
>
> v8::Persistent< v8::Object > persistent( v8::Object::Cast( *value ) );
> v8::Persistent< v8::Object >::Cast( persistent ).ClearWeak();
>
>
> But that doesn't seem to work. Instead, I've just set the pointer stored in
> the object to null, which seems to work for now but feels like a hack.
>
> --
> Thank you
> Abdulla
>
> --
> v8-users mailing list
> [email protected]
> http://groups.google.com/group/v8-users
>
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users