Search code examples
c++v8embedded-v8

ES6 Modules with top-level await on embedded v8


How would one make top-level await in ES6 Modules? I have gotten regultar ES6 modules to work, but I can't find anything about top-level await in ES6 modules with v8. here is my code:

v8::Local<v8::Module> FactoryModule(v8::Isolate* isolate, v8::Local<v8::Context> context, const char* moduleName, const char* code) {
v8::TryCatch tc(context->GetIsolate());
v8::Local<v8::String> source_text = v8::String::NewFromUtf8(
                                        isolate, code)
                                        .ToLocalChecked();

v8::ScriptOrigin origin(v8::String::NewFromUtf8(isolate, moduleName).ToLocalChecked(),
                        v8::Integer::New(isolate, 0),
                        v8::Integer::New(isolate, 0),
                        v8::False(isolate),
                        v8::Local<v8::Integer>(),
                        v8::Local<v8::Value>(),
                        v8::False(isolate),
                        v8::False(isolate),
                        v8::True(isolate));
v8::Context::Scope context_scope(context);
v8::ScriptCompiler::Source source(source_text, origin);
v8::Local<v8::Module> module = v8::ScriptCompiler::CompileModule(isolate, &source).ToLocalChecked();
// I need to do something before this point as the line above already fails.

Solution

  • Top-level await in V8 is under active development, see the tracking bug: https://bugs.chromium.org/p/v8/issues/detail?id=9344