0

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.
pitust
  • 99
  • 8

1 Answers1

1

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

jmrk
  • 34,271
  • 7
  • 59
  • 74
  • Isn't it available with the --harmony-top-level-await flag? Tbh, i couldn't find anything about it anyway so accepted. It worked with the flag. – pitust Jun 21 '20 at 08:39
  • 2
    Any feature being behind a flag means the teams doesn't believe it's ready for production use. Once the work is completed, the feature will be available by default, without any flags. – jmrk Jun 22 '20 at 11:42
  • I still used it and had no problem with it.Thank you for your help! – pitust Jul 06 '20 at 05:34