开发者

Access 'Arguments' in JavaScript V8 Callback

开发者 https://www.devze.com 2023-03-21 09:37 出处:网络
I\'d like to be able to access the Arguments& args of a callback. Right now when I set the C++ function to be called from the JavaScript side it looks like this:

I'd like to be able to access the Arguments& args of a callback. Right now when I set the C++ function to be called from the JavaScript side it looks like this:

global->Set(String::New("login"), FunctionTemplate::New(Login));

And the prototype of the C++ functio开发者_开发百科n is:

Handle<Value> MyClass::Login(const Arguments& args)

How do I access this Arguments& args so that I can pass in a variable when the callback occurs? Thanks for the help.


v8::Arguments::Length() will return the number of arguments passed from JavaScript. The v8::Arguments& variable is accessed using an array subscript.

for (int32_t index = 0; index < arguments->Length(); ++index) {
  if (arguments[index]->IsString()) {
    ::printf("%s\n", *v8::String::Utf8Value(arguments[index]->ToString()));
  }
}

You will find an online version of the v8::Arguments documentation at http://izs.me/v8-docs/classv8_1_1Arguments.html, however I make no guarantees that it is current or will remain online.

Running the following command from the top of the V8 source tree will generate the documentation locally using doxygen.

$ cd include && doxygen -g && doxygen

If doxygen executes successfully you can access the documentation in include/html/index.html.

0

精彩评论

暂无评论...
验证码 换一张
取 消