mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-26 19:51:11 +08:00
refactor: 从 run 抽 execute_task 与 drain_microtasks 两原语
This commit is contained in:
@@ -11,15 +11,17 @@ use super::{Microtask, MAX_DRAIN_JOBS};
|
||||
impl Vm {
|
||||
/// drain 微任务队列:FIFO 逐条处理直到清空或达到上限。
|
||||
///
|
||||
/// 调用时机:`run()` 末尾与事件循环每个 turn 边界。
|
||||
///
|
||||
/// # 副作用
|
||||
/// - 任务内调用 JS 回调(`call_function_sync`),可能入队新任务。
|
||||
/// - 单任务抛错不中断 drain(未处理拒绝按规范不可见)。
|
||||
pub(crate) fn drain_job_queue(&mut self) {
|
||||
pub fn drain_microtasks(&mut self) {
|
||||
let mut count = 0usize;
|
||||
while let Some(job) = self.job_queue.pop_front() {
|
||||
count += 1;
|
||||
if count > MAX_DRAIN_JOBS {
|
||||
vm_warn!("drain_job_queue: exceeded {MAX_DRAIN_JOBS} microtasks, aborting");
|
||||
vm_warn!("drain_microtasks: exceeded {MAX_DRAIN_JOBS} microtasks, aborting");
|
||||
break;
|
||||
}
|
||||
self.run_microtask(job);
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
//! Promise 对象把 `PromiseState` 状态盒(Box)挂在 `native_data`;resolve/reject
|
||||
//! 是携带目标 promise 的 native 闭包函数(函数对象 prop 存 promise 引用)。
|
||||
//! 反应(reaction)与 thenable 委托以 `Microtask` 入队 `Vm::job_queue`,
|
||||
//! 由 `run()` 末尾的 drain 循环 FIFO 执行。所有盒内 JsValue 由 session GC
|
||||
//! 由 `drain_microtasks` 在 `run()` 末尾与事件循环每个 turn 边界 FIFO 执行。
|
||||
//! 所有盒内 JsValue 由 session GC
|
||||
//! 经 Promise 对象边追踪(见 `promise_native_edges` / `drop_promise_native`)。
|
||||
|
||||
use oxide_types::object::JsObject;
|
||||
|
||||
Reference in New Issue
Block a user