On Wed, Jul 15, 2015 at 2:17 AM, Jeff Waller <[email protected]> wrote:
> When dispatching from an asynchronous operation using C++, the function
> node::MakeCallback is
> supposed to automatically set the domain of the callback. So if method
> throws, then an event will
> be sent to the domain.  At least that's the expectation.  From the node
> source, it appears that recv
> is used to obtain the domain to which these events will posted
>
> NODE_EXTERN v8::Handle<v8::Value> MakeCallback(
>
>     v8::Isolate* isolate,
>
>     v8::Handle<v8::Object> recv,
>
>     const char* method,
>
>     int argc,
>
>     v8::Handle<v8::Value>* argv);
>
>
>
>
> Local<Context> context = recv->CreationContext();
> Environment* env = Environment::GetCurrent(context);
>
> and then later
>
> if (env->using_domains())
>
> etc.
>
> What recv is and how's it's derived  is a mystery.  I can't find it
> documented.  I've tried
> various values for recv:  args.This(), Context()->Global(), the callback
> itself, etc. saved directly
> as a Persistent or saved as a object contained in a Persistent Array... all
> approaches fail. So
> here I am.  If anyone knows what this object is or can suggest a next step,
> thanks in advance.

|recv| is the receiver object, the value of the |this| object inside
the function call.

If your code looks like this:

    var addon = require('/path/to/addon.node');
    var callback = function() { /* ... */ };
    addon.makeCallback(callback);

Then args.This() equals |addon|, the native module object, and won't
normally have the .domain property that MakeCallback() looks for.

You can pass in the receiver explicitly and pass it on to MakeCallback:

    var recv = { domain: process.domain, /* ... */ };
    addon.makeCallback(recv, callback);

Or if you want |recv| to show up as args.This():

    addon.makeCallback.call(recv, callback);

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/CAHQurc8ui32bc5o%2B9b3k%3DSbHHU-X%3DtRe8kdJw-sEKQDJTOmNTA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to