Skip to main content

window_dispatch_event

Function window_dispatch_event 

Source
pub(crate) fn window_dispatch_event(
    it: &mut Interp,
    this: Value,
    a: &[Value],
) -> Result<Value, Value>
Expand description

window.dispatchEvent(event)(丸ごと未対応だった。window オブジェクトに addEventListener/removeEventListener はあったが dispatchEvent 自体が 存在せず、window.dispatchEvent(new HashChangeEvent(...)) のような JS 側 からのイベントシミュレーションが一切できなかった。window_add_event_ listener が対応する6種の固定イベント種別(scroll/popstate/ hashchange/resize/message/error)に限り、対応する隠し配列 (push_window_listenerが書き込む先)からリスナを読み出し、渡された event オブジェクトをそのまま転送して呼び出す(fire_window_listeners のような独自 Event 再構築は行わず、JS 側が構築した実際のオブジェクトを そのまま渡す)。対応外の種別は無害に無視する(addEventListener側の 未対応種別の扱いと同じ)。window.onerrorreport_error側で既に 対応済み)と同様に、window.on<type>window.onhashchange = fn等の IDL属性スタイルのハンドラ)が設定されていればそれも合わせて呼び出す。