void a(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
auto context = isolate->GetCurrentContext();
for (int i = 0; i < args.Length(); i++)
{
if (args[i]->IsNumber())
{
if (args[i]->IsInt32())
{
printf("[%d] int\n", i);
}
else {
printf("[%d] float\n", i);
}
}
if (args[i]->IsString())
{
printf("[%d] string\n", i);
}
if (args[i]->IsObject())
{
if (args[i]->IsArray())
{
printf("[%d] array\n", i);
}
else if (args[i]->IsAsyncFunction())
{
printf("[%d] async function\n", i);
}
else if (args[i]->IsGeneratorFunction())
{
printf("[%d] gener function\n", i);
}
else if (args[i]->IsFunction())
{
printf("[%d] function\n", i);
}
else
{
printf("[%d] object({})\n", i);
}
}
if (args[i]->IsBoolean())
{
printf("[%d] bool\n", i);
}
if (args[i]->IsNullOrUndefined())
{
printf("[%d] null or undefided\n", i);
}
args.GetReturnValue().Set(Number::New(isolate, 1));
}
}
let r = addon.a(
1,
2.2,
"2",
true,
() => {},
null,
undefined,
async function fname() {},
[],
{}
);
console.log(r);
打印结果
[0] int
[1] float
[2] string
[3] bool
[4] function
[5] null or undefided
[6] null or undefided
[7] async function
[8] array
[9] object({})
1