Reading the source code and finding different functions that can be called from the js code, for example new TCP
, it is not entirely clear how the C++ level accepts arguments to its level for a specific bound function.
For example, this js call is bound
new TCP(TCPConstants.SERVER)
with the following code on С++
void TCPWrap::New(const FunctionCallbackInfo<Value>& args) {
// This constructor should not be exposed to public javascript.
// Therefore we assert that we are not trying to call this as a
// normal function.
CHECK(args.IsConstructCall());
CHECK(args[0]->IsInt32());
Environment* env = Environment::GetCurrent(args);
int type_value = args[0].As<Int32>()->Value();
TCPWrap::SocketType type = static_cast<TCPWrap::SocketType>(type_value);
ProviderType provider;
switch (type) {
case SOCKET:
provider = PROVIDER_TCPWRAP;
break;
case SERVER:
provider = PROVIDER_TCPSERVERWRAP;
break;
default:
UNREACHABLE();
}
new TCPWrap(env, args.This(), provider);
}
That is, I want to understand how the C++ level const FunctionCallbackInfo<Value>& args
is initialized for the bound function, thanks.
2