Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

4.3 KB
Raw Blame
use super::*;

pub(in crate::context_bootstrap) fn set_event_default_prevented(
    scope: &mut v8::PinScope<'_, '_>,
    event: v8::Local<'_, v8::Object>,
) {
    let event = super::base::event_backing(scope, event);
    let key = v8str(scope, "defaultPrevented");
    let value = v8::Boolean::new(scope, true).into();
    let _ = event.define_own_property(scope, key.into(), value, Default::default());
}

pub(in crate::context_bootstrap) fn event_prevent_default_callback<'s>(
    scope: &mut v8::PinScope<'s, '_>,
    args: v8::FunctionCallbackArguments<'s>,
    _rv: v8::ReturnValue<'_, v8::Value>,
) {
    let event = args.this();
    if !crate::context_bootstrap::event_bool_attribute(scope, event, "cancelable") {
        return;
    }
    if event_internal_bool_flag(scope, event, EVENT_PASSIVE_SLOT) {
        return;
    }
    set_event_default_prevented(scope, event);
}

pub(in crate::context_bootstrap) fn event_return_value_getter_function<'s>(
    scope: &mut v8::PinScope<'s, '_>,
    args: v8::FunctionCallbackArguments<'s>,
    mut rv: v8::ReturnValue<'_, v8::Value>,
) {
    if event_initialized(scope, args.this()).is_none() {
        throw_type_error(scope, "Illegal invocation");
        return;
    }
    let default_prevented =
        crate::context_bootstrap::event_bool_attribute(scope, args.this(), "defaultPrevented");
    rv.set(v8::Boolean::new(scope, !default_prevented).into());
}

pub(in crate::context_bootstrap) fn event_return_value_setter_function<'s>(
    scope: &mut v8::PinScope<'s, '_>,
    args: v8::FunctionCallbackArguments<'s>,
    _rv: v8::ReturnValue<'_, v8::Value>,
) {
    let event = args.this();
    if event_initialized(scope, event).is_none() {
        throw_type_error(scope, "Illegal invocation");
        return;
    }
    if args.get(0).boolean_value(scope)
        || !crate::context_bootstrap::event_bool_attribute(scope, event, "cancelable")
        || event_internal_bool_flag(scope, event, EVENT_PASSIVE_SLOT)
    {
        return;
    }
    set_event_default_prevented(scope, event);
}

pub(in crate::context_bootstrap) fn event_cancel_bubble_getter_function<'s>(
    scope: &mut v8::PinScope<'s, '_>,
    args: v8::FunctionCallbackArguments<'s>,
    mut rv: v8::ReturnValue<'_, v8::Value>,
) {
    if event_initialized(scope, args.this()).is_none() {
        throw_type_error(scope, "Illegal invocation");
        return;
    }
    let stopped = event_internal_bool_flag(scope, args.this(), EVENT_STOP_PROPAGATION_SLOT);
    rv.set(v8::Boolean::new(scope, stopped).into());
}

pub(in crate::context_bootstrap) fn event_cancel_bubble_setter_function<'s>(
    scope: &mut v8::PinScope<'s, '_>,
    args: v8::FunctionCallbackArguments<'s>,
    _rv: v8::ReturnValue<'_, v8::Value>,
) {
    if event_initialized(scope, args.this()).is_none() {
        throw_type_error(scope, "Illegal invocation");
        return;
    }
    if !args.get(0).boolean_value(scope) {
        return;
    }
    set_event_internal_flag(scope, args.this(), EVENT_STOP_PROPAGATION_SLOT, true);
}

pub(in crate::context_bootstrap) fn event_stop_propagation_callback<'s>(
    scope: &mut v8::PinScope<'s, '_>,
    args: v8::FunctionCallbackArguments<'s>,
    _rv: v8::ReturnValue<'_, v8::Value>,
) {
    let event = args.this();
    set_event_internal_flag(scope, event, EVENT_STOP_PROPAGATION_SLOT, true);
}

pub(in crate::context_bootstrap) fn event_stop_immediate_propagation_callback<'s>(
    scope: &mut v8::PinScope<'s, '_>,
    args: v8::FunctionCallbackArguments<'s>,
    _rv: v8::ReturnValue<'_, v8::Value>,
) {
    let event = args.this();
    set_event_internal_flag(scope, event, EVENT_STOP_PROPAGATION_SLOT, true);
    set_event_internal_flag(scope, event, EVENT_STOP_IMMEDIATE_PROPAGATION_SLOT, true);
}

pub(in crate::context_bootstrap) fn event_composed_path_callback<'s>(
    scope: &mut v8::PinScope<'s, '_>,
    args: v8::FunctionCallbackArguments<'s>,
    mut rv: v8::ReturnValue<'_, v8::Value>,
) {
    let value = super::base::event_composed_path_value(scope, args.this());
    rv.set(value);
}

pub(in crate::context_bootstrap) fn event_time_stamp_getter_function<'s>(
    scope: &mut v8::PinScope<'s, '_>,
    args: v8::FunctionCallbackArguments<'s>,
    mut rv: v8::ReturnValue<'_, v8::Value>,
) {
    let time_stamp = super::base::event_time_stamp(scope, args.this());
    rv.set(v8::Number::new(scope, time_stamp).into());
}