我想在運行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」?