feat: for-of 异常中断按规范关闭迭代器,next() 抛错可捕获并保留原始值
This commit is contained in:
@@ -176,6 +176,8 @@ impl Vm {
|
||||
self.restore_frame(frame);
|
||||
}
|
||||
}
|
||||
// IteratorClose any for-of loops abandoned inside this handler's scope.
|
||||
self.close_for_of_above(handler.for_of_depth);
|
||||
if let Some(finally_pc) = handler.finally_pc {
|
||||
vm_trace!("unwind: entering finally at pc={}", finally_pc);
|
||||
if self.pending_exception.is_none() {
|
||||
@@ -193,10 +195,14 @@ impl Vm {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
self.close_for_of_above(0);
|
||||
while let Some(frame) = self.frames.pop() {
|
||||
self.restore_frame(frame);
|
||||
}
|
||||
let exc = self.exception_value.take().unwrap_or(JsValue::undefined());
|
||||
// Preserve the escaping JsValue so a for-of next()-throw can re-throw the original
|
||||
// value instead of the flattened string (consumed by dispatch_for_of_done/next).
|
||||
self.last_uncaught_value = Some(exc);
|
||||
let kind_str = self.pending_error_kind.take().unwrap_or("Error");
|
||||
let exc_text = self.error_text(exc);
|
||||
let msg = if exc_text.starts_with(kind_str) {
|
||||
|
||||
Reference in New Issue
Block a user