fix segfault in GlobalPropertyGetter() (closes #89)

GlobalPropertyGetter() is a static function. It can be invoked on
a context which has already been disposed off.

It turned out that there were two possible segfault reasons.

The most obviuos one was NULL pointer dereferencing.

However, there is no way to check whether the context is alive by
examining content of it or its sandbox. Both could look valid, but cause
segfaults in node. As a woraround, we add a self-reference which we clear
on destruction. A valid self-reference is a solid indication of a
valid context now.
Yes, but only if explicitly using Ref and Unref. It can get garbage collected if these are not used. I'll experiment with the test you mentioned.

On November 29, 2014 1:12:57 PM EET, Sergei Ianovich <notifications@github.com> wrote:
>> @@ -174,10 +178,21 @@ class ContextifyContext : public ObjectWrap {
>>      static NAN_PROPERTY_GETTER(GlobalPropertyGetter) {
>>          NanScope();
>>          Local<Object> data = args.Data()->ToObject();
>> -        ContextifyContext* ctx =
>ObjectWrap::Unwrap<ContextifyContext>(data);
>> -        Local<Value> rv =
>NanNew(ctx->sandbox)->GetRealNamedProperty(property);
>> +        Local<ContextifyContext> ctx =
>ObjectWrap::Unwrap<ContextifyContext>(data);
>
>> Thus, the weak callback won't get invoked while there is a reference
>to the wrapped object, because the garbage collector will not touch
>persistent handles.
>
>In other words, you say that it's impossible to have a dangling pointer
>to context. But that's not the case. You can run `zombie` test suite
>with `browser.destroy()` uncommented in `test/event_source_test.js` to
>verify. It will segfault in approx. 3/4 of cases.
>
>---
>Reply to this email directly or view it on GitHub:
>https://github.com/brianmcd/contextify/pull/135/files#r21053219