What is recv in Function Call ?

1,276 views
Skip to first unread message

ashish negi

unread,
Oct 15, 2013, 2:56:57 AM10/15/13
to v8-u...@googlegroups.com
In the c++ function class i see the function call definition as :

class Function : public Object {
 public:
  // ........
  V8EXPORT Local<Value> Call(Handle<Object> recv,
                             int argc,
                             Handle<Value> argv[]);
// ......
};

What is the recv for in this ?

From the c++, i am calling a function. i have a persistent handle of the function as 

Persistent<Value> func;
v8::Local<v8::Value> funcRetVal = func.As<v8::Function>()->Call(v8::Context::GetCurrent()->Global(), argv.size(), argv.data());

But this is not working.

Any Tips ?


Ben Noordhuis

unread,
Oct 15, 2013, 3:02:32 AM10/15/13
to v8-u...@googlegroups.com
On Tue, Oct 15, 2013 at 8:56 AM, ashish negi <thisismy...@gmail.com> wrote:
> In the c++ function class i see the function call definition as :
>
> class Function : public Object {
> public:
> // ........
> V8EXPORT Local<Value> Call(Handle<Object> recv,
> int argc,
> Handle<Value> argv[]);
> // ......
> };
>
> What is the recv for in this ?

The receiver is the `this` object to execute the function with.
`fn->Call(obj, argc, argv)` is the C++ equivalent of `fn.apply(obj,
argv)`.

> From the c++, i am calling a function. i have a persistent handle of the
> function as
>
> Persistent<Value> func;
> v8::Local<v8::Value> funcRetVal =
> func.As<v8::Function>()->Call(v8::Context::GetCurrent()->Global(),
> argv.size(), argv.data());
>
> But this is not working.

What is not working? What error do you get?

ashish negi

unread,
Oct 15, 2013, 4:05:45 AM10/15/13
to v8-u...@googlegroups.com
I am actually making an addon for nodejs, that simulates the JS - Proxy - Bridge.
 This addon gets a callback. Can i get the 'this' pointer i.e. v8::Object from that callback. 
The signature of callback is standard:
                    v8::Handle<v8::Value> SPANodeCommunicator::SendCallBackArguments(const v8::Arguments& args)

Actually, the code of the callback has to be deferred to the future for execution. 

I am getting exception, function is toString() on Buffer object that we get after readFile

        Error: Uncaught TypeError: Cannot call method 'utf8Slice' of undefined 

The code of toString is 

       --> this.parent.utf8Slice(...

Ben Noordhuis

unread,
Oct 15, 2013, 4:29:45 AM10/15/13
to v8-u...@googlegroups.com
On Tue, Oct 15, 2013 at 10:05 AM, ashish negi
<thisismy...@gmail.com> wrote:
> I am actually making an addon for nodejs, that simulates the JS - Proxy -
> Bridge.
>
> This addon gets a callback. Can i get the 'this' pointer i.e. v8::Object
> from that callback.
> The signature of callback is standard:
> v8::Handle<v8::Value>
> SPANodeCommunicator::SendCallBackArguments(const v8::Arguments& args)

How are you calling that function from JS land?

Keep in mind that JS functions don't have a fixed `this` object; the
value of `this` depends on the calling context. If you want to invoke
a function f sometime in the future in the context of object o, you
have to retain a reference to o.

ashish negi

unread,
Oct 15, 2013, 4:59:29 AM10/15/13
to v8-u...@googlegroups.com
when i see that there is a funciton proxy, i give a c++ callback function at its place. so my c++ funciton gets called automaically by nodejs.

ashish negi

unread,
Oct 16, 2013, 2:56:52 AM10/16/13
to v8-u...@googlegroups.com
I am storing the persistent handles of both data and toString on the nodejs side.
Would that not help ?
Reply all
Reply to author
Forward
0 new messages