feat: async/await 语法支持(AWAIT 帧快照挂起/恢复 + 微任务驱动 + AsyncFunction intrinsics)

This commit is contained in:
爱特每羊队
2026-08-09 22:02:15 +08:00
parent dcbe3d9320
commit 0d9e6eabc9
28 changed files with 1055 additions and 28 deletions
+12
View File
@@ -748,6 +748,12 @@ impl Vm {
self.regs[0] = gen;
return Ok(false);
}
// 异步函数调用返回 capability promise,立即同步执行 body 到首个 await。
if sub_idx < self.sub_modules.len() && self.sub_modules[sub_idx].is_async {
let promise = self.create_async_object(callee, this_value, &args)?;
self.regs[0] = promise;
return Ok(false);
}
self.push_bytecode_frame(
callee,
this_value,
@@ -840,6 +846,12 @@ impl Vm {
{
return self.raise_type_error("g is not a constructor").map(|_| true);
}
// 异步函数不是构造器:`new f()` 抛 TypeError。
if (ctor_obj.sub_module_index() as usize) < self.sub_modules.len()
&& self.sub_modules[ctor_obj.sub_module_index() as usize].is_async
{
return self.raise_type_error("g is not a constructor").map(|_| true);
}
if self.frames.len() >= self.kernel_core.config.max_call_depth {
return Err(self.error_message_text("RangeError", "Maximum call stack size exceeded"));
}