ThreadHandle* th = (ThreadHandle)data; v8::Isolate::Scope isolateScope(isolate);…
- User
ThreadHandle* th = (ThreadHandle*)data; v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); v8::Local context = CreateContext(isolate, 0, NULL, th->mRemoteFD); v8::Context::Scope contextScope(context); Environment* env = static_cast<Environment*>(context->GetAlignedPointerFromEmbedderData(kModuleEmbedderDataIndex)); env->mError = &th->mError; env->mError->mHasError = 0; env->mErr.Reset(); th->mEnv = env; // 将libuv loop作为任务运行器 V8Executor executor(isolate, env->mLoop); isolate->SetMicrotasksPolicy(v8::MicrotasksPolicy::kExplicit); v8::MicrotasksScope microtasks(isolate, v8::MicrotasksScope::kRunMicrotasks); v8::MicrotasksScope::PerformCheckpoint(isolate); v8::TryCatch tryCatch(isolate); ModuleLoader& loader = ModuleLoader::Instance(); auto m = loader.LoadModule(isolate, th->mName.c_str(), th->mSource, th->mSize); if (tryCatch.HasCaught()) { ReportException(isolate, &tryCatch); } v8::Localv8::Module module; if (!m.ToLocal(&module)) { std::string prompt = "import module failed ["; prompt += th->mName; prompt += "]"; ReportException(context->GetIsolate(), &tryCatch); return; } if (loader.InstanceModule(isolate, module) == false) { std::string prompt = "instance module failed ["; prompt += th->mName; prompt += "]"; ReportException(context->GetIsolate(), &tryCatch); return; } /*v8::Localv8::Value r = */loader.Evaluate(module, context, false); if (tryCatch.HasCaught()) { ReportException(isolate, &tryCatch); } 我用发v8的引擎, 这是我的线程的启动代码。 其中MicroTask差没有启动起来。 为什么
- Assistant
在你提供的代码中,Microtasks 的运行已经包含在 v8::MicrotasksScope 里面。但从你提供的代码来看,并没有什么明显的问题,关于MicroTasks没有启动起来,需要更详细的信息来分析。
这里有一些建议可能值得检查:
- 请确保 V8 引擎的初始化没有问题,并且可以在其他场景中工作正常。
- 请检查你的
mSource中是否有使用 Promise 或者 async/await,因为这些都是需要在 Microtasks 中运行的。 - 你可以尝试在你的代码之后手动调用 PerformCheckpoint 函数,例如:
executor.Run([&] { isolate->PerformMicrotaskCheckpoint(); });- 另外,尝试在
mSource的源代码中调用 Promise.resolve().then ,看是否会在 Microtasks 中执行。
这些都是一些通常问题排查的方向,如果仍然不能解决问题,请提供更多的详细信息以便我们进一步帮助你。
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.