void Test_RunScript(Isolate *isolate, BaseFramework::String src) {
v8::Locker locker(isolate);
isolate->Enter();
Isolate::Scope isolate_scope(isolate);
{
// Create a stack-allocated handle scope.
HandleScope handle_scope(isolate);
// Create a new context.
Local<Context> context = Context::New(isolate, null, CreateGlobalTemplate(isolate));
// Enter the context for compiling and running the hello world script.
Context::Scope context_scope(context);
// Create a string containing the JavaScript source code.
Local<v8::String> source =
v8::String::NewFromUtf8(isolate, src.data(),
NewStringType::kNormal).ToLocalChecked();
// Compile the source code.
Local<v8::Script> script = Script::Compile(context, source).ToLocalChecked();
// Run the script to get the result.
Local<Value> result = script->Run(context).ToLocalChecked();
// Convert the result to an UTF8 string and print it.
v8::String::Utf8Value strres(result);
fwstdout << *strres << std::endl;
}
isolate->Exit();
v8::Unlocker unlocker(isolate);
}
void CreateIsolateAndRunScript(BaseFramework::String src) {
ArrayBufferAllocator allocator;
Isolate::CreateParams create_params;
create_params.array_buffer_allocator = &allocator;
Isolate* isolate = JScript::JScriptInterface::GetInstance().NewIsolateForCurrentThread(create_params);
Test_RunScript(isolate, src);
JScript::JScriptInterface::GetInstance().FreeCurrentIsolate();
}