It appears that the WebAssembly compilation is happening on of the v8::Platform's background threads and a task will be posted to the foreground loop to resolve the compilation promise.
So I need to pump the message loop: while (v8::platform::PumpMessageLoop(Runtime::platform, isolate, v8:: platform::MessageLoopBehavior::kDoNotWait)) { isolate->RunMicrotasks(); } Now the question is what would be the best approach to implement such message loop inside an Android application. I initialize the v8::Isolate on the main thread and I cannot block it to wait for such events. I was able to achieve this by using a timer which executes this pumping from time to time but I suppose that this is not the best solution. I was wondering if there's some mechanism I which would notify me that there are some tasks accumulated on the message loop, or maybe somehow consolidate v8 platform's loop with Android's message loop. On Wednesday, January 15, 2020 at 10:15:49 AM UTC+2, Darin Dimitrov wrote: > > I have embedded V8 (7.8.279.19) inside my Android application and tried > executing a script that compiles a WebAssembly module. > > Unfortunately the promise returned by the "WebAssembly.compile" method is > never completed (neither the "then" or the "catch" methods are invoked). > The same happens with the "WebAssembly.instantiate" method: > > std::unique_ptr<v8::Platform> platform = v8::platform::NewDefaultPlatform > (); > v8::V8::InitializePlatform(platform.get()); > v8::V8::Initialize(); > > v8::Isolate::CreateParams create_params; > create_params.array_buffer_allocator = v8::ArrayBuffer::Allocator:: > NewDefaultAllocator(); > v8::Isolate* isolate = v8::Isolate::New(create_params); > v8::Isolate::Scope isolate_scope(isolate); > v8::HandleScope scope(isolate); > auto global_template = v8::ObjectTemplate::New(isolate); > global_template->Set(v8::String::NewFromUtf8(isolate, "log", v8:: > NewStringType::kNormal).ToLocalChecked(), v8::FunctionTemplate::New( > isolate, [](const v8::FunctionCallbackInfo<v8::Value>& info) { > v8::Isolate* isolate = info.GetIsolate(); > v8::String::Utf8Value utf(isolate, info[0].As<v8::String>()); > __android_log_print(ANDROID_LOG_DEBUG, "V8Native", "%s",*utf); > })); > > v8::Local<v8::Context> context = v8::Context::New(isolate, nullptr, > global_template); > v8::Context::Scope context_scope(context); > const char* csource = R"( > let bytes = new Uint8Array([ > 0,97,115,109,1,0,0,0,1,8,2,96,1,127,0,96,0,0,2,8,1,2,106, > 115,1,95,0,0,3,2,1,1,8,1,1,10,9,1,7,0,65,185,10,16,0,11 > ]); > log('before the call'); > WebAssembly > .instantiate(bytes) > .then(obj => log('success')) > .catch(err => log('log')); > )"; > v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, csource, > v8::NewStringType::kNormal).ToLocalChecked(); > v8::Local<v8::Script> script = v8::Script::Compile(context, source). > ToLocalChecked(); > v8::Local<v8::Value> result; > script->Run(context).ToLocal(&result); > > > > Do you have any idea what I might be missing here? The same javascript code > works fine in the desktop browser. > > -- -- v8-users mailing list v8-users@googlegroups.com http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/v8-users/b7e02e2e-3758-4d2a-a287-611f577f1b83%40googlegroups.com.