Cannot rerun compiled script in V8 C++ embedding

24 views
Skip to first unread message

Jonathan Claassens

unread,
Jul 31, 2021, 7:10:00 AM7/31/21
to v8-users
Hi,

I'm attempting to rerun a V8 script in a given context/scope, but I'm getting a segmentation fault. If I compile other scripts and run in succession it works.

int loadScript(const char * scriptCode) { v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, scriptCode, v8::NewStringType::kNormal) .ToLocalChecked(); // Compile the source code. script = v8::Script::Compile(context, source).ToLocalChecked(); return 0; } std::string executeScript() { // Run the script to get the result. v8::Local<v8::Value> result = script->Run(context).ToLocalChecked(); // Convert the result to an UTF8 string and print it. v8::String::Utf8Value utf8(isolate, result); return std::string(*utf8); }

////

sv8i.loadScript("let a = 1; \ let b = 2; \ JSON.stringify({a, b}); \ "); printf("%s\n", sv8i.executeScript().c_str()); printf("%s\n", sv8i.executeScript().c_str()); // Seg fault

Why?


Reply all
Reply to author
Forward
0 new messages