I want to get script’s origin filename in global functions.
I tried following code, but filename.IsEmpty() returns true.
using namespace v8;
HandleScope handle_scope;
// Define Global Function 'func'
Handle<ObjectTemplate> global = ObjectTemplate::New();
auto func_name = v8::String::New("func");
auto func = v8::FunctionTemplate::New(
[](const v8::Arguments& args) -> v8::Handle<v8::Value>{
// I want to get Filename here.
auto filename = args.Callee()->GetScriptOrigin().ResourceName();
std::cout << filename.IsEmpty() << std::endl;
return v8::Undefined();
});
global->Set(func_name, func);
auto context = Context::New(nullptr, global);
Context::Scope context_scope(context);
auto source = String::New("func()");
// Set Filename
auto filename = String::New("abc.js");
auto script = v8::Script::Compile(source, filename);
script->Run();
context.Dispose();
Is there a correct way to access script’s origin filename?
Solved by myself: