我想在运行js脚本时调用每个函数的日志。 所以我想为所有在JavaScript这样的功能的回调:v8:无法在函数调用中获取调用函数名称
global->Set(v8::String::NewFromUtf8(isolate, "print"), v8::FunctionTemplate::New(isolate, LogName));
global->Set(v8::String::NewFromUtf8(isolate, "eval"), v8::FunctionTemplate::New(isolate, LogName));
global->Set(v8::String::NewFromUtf8(isolate, "unescape"), v8::FunctionTemplate::New(isolate, LogName));
我这样定义我的功能:
void LogName(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::String::Utf8Value str_caller(args.Callee());
printf("%s", str_caller);
}
这时候UNESCAPE被称为印刷:功能UNESCAPE() {[本地代码]}
但是,如果这样做:
object = v8::Handle<v8::Object>::Cast(context->Global()->Get(v8::String::NewFromUtf8(isolate, "String")));
object->Set(v8::String::NewFromUtf8(isolate, "fromCharCode"), v8::FunctionTemplate::New(isolate, LogName)->GetFunction());
这是对在调用String.fromCharCode时r:function(){[native code]}
为什么在第二个示例中,我没有函数名称,例如“fromCharCode”?