I find an old anwser and later updates here, but it is hard for me to adapt this code to the latest(2020) V8 version.
There are many difficulties that I encounter:
String::New
is removed and now aString::NewFromUtf8Literal
needs anIsolate* isolate
which I don't know how to pass to functionInclude
, should I just add this beforeconst Arguments& args
?Script::Compile
takes aContext
object as paramater now- And I don't know where to put the last two line codes
Handle<ObjectTemplate> global = ObjectTemplate::New(); global->Set(String::New("include"), FunctionTemplate::New(Include));
-- UPDATE --
After some work, I have my code like the this.
However, it still won't compile because of there errors:
Seems that I can't get a
Local
from aPersistent
, even I have used danijar's strategy. Maybe it is because I have not used the constructor, but I don't think I can construct a Persist here inside this function scope.samples/import.cc:74:103: Error:cannot convert ‘v8::Local<v8::Context>’ to ‘v8::Context*’ 74 | global_context = v8::Persistent<v8::Context, CopyablePersistentTraits<v8::Context>>::New(isolate, local_context); | ^~~~~~~~~~~~~ | | | v8::Local<v8::Context>
There are some errors with
String::NewFromUtf8Literal
heresamples/import.cc:34:110: Error:‘static v8::Local<v8::String> v8::String::NewFromUtf8Literal(v8::Isolate*, const char*, v8::NewStringType, int)’ is private within this context 34 | Handle<String> source = String::NewFromUtf8Literal(args.GetIsolate(), buff, v8::NewStringType::kNormal, len); |