mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-23 18:21:13 +08:00
feat: 生成器基础支持(YIELD 帧快照挂起/恢复 + GeneratorPrototype next/return/throw)
- 新增 YIELD/SUSPEND_BODY opcode;function* 识别与 yield emit - GeneratorState 全量快照 VM 执行上下文(regs/pc/bytecode/spill/save/try/cell 栈段/迭代器) - 调用时参数初始化(默认值/解构副作用与异常在 g() 时刻生效) - %GeneratorPrototype%/%GeneratorFunction.prototype% 内建对象与 next/return/throw - session GC trace 生成器状态 JsValues;闭包捕获分析补 yield/赋值目标扫描
This commit is contained in:
@@ -741,6 +741,13 @@ impl Vm {
|
||||
}
|
||||
}
|
||||
} else if obj.sub_module_index() > 0 {
|
||||
let sub_idx = obj.sub_module_index() as usize;
|
||||
// 生成器函数调用返回迭代器对象,不执行函数体。
|
||||
if sub_idx < self.sub_modules.len() && self.sub_modules[sub_idx].is_generator {
|
||||
let gen = self.create_generator_object(callee, this_value, &args)?;
|
||||
self.regs[0] = gen;
|
||||
return Ok(false);
|
||||
}
|
||||
self.push_bytecode_frame(
|
||||
callee,
|
||||
this_value,
|
||||
@@ -827,6 +834,12 @@ impl Vm {
|
||||
}
|
||||
}
|
||||
} else if ctor_obj.sub_module_index() > 0 {
|
||||
// 生成器函数不是构造器:`new g()` 抛 TypeError。
|
||||
if (ctor_obj.sub_module_index() as usize) < self.sub_modules.len()
|
||||
&& self.sub_modules[ctor_obj.sub_module_index() as usize].is_generator
|
||||
{
|
||||
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"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user