Skip to content

armgit / moli

Public Imported from GitHub
0

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

3.4 KB
Raw Blame
use super::*;
use crate::native_bridge::node::{
    node_compare_document_position_callback, node_contains_callback, node_is_equal_node_callback,
    node_is_same_node_callback,
};
use crate::web_api_interfaces;
use moli_webapi_declare::WebApiObject;

#[derive(Default, WebApiObject)]
#[webapi(fragment, prototype = "Node")]
struct DetachedNodeMethodsDeclaration {
    #[webapi(method, callback = detached_append_child_method_callback)]
    append_child: (),

    #[webapi(method, callback = detached_insert_before_method_callback)]
    insert_before: (),

    #[webapi(method, length = 1, callback = detached_remove_child_method_callback, receiver = web_api_interfaces::Node::is_instance)]
    remove_child: (),

    #[webapi(method, callback = detached_remove_method_callback)]
    remove: (),

    #[webapi(method, callback = detached_replace_child_method_callback)]
    replace_child: (),

    #[webapi(method, callback = detached_has_child_nodes_method_callback)]
    has_child_nodes: (),

    #[webapi(method, callback = detached_get_root_node_method_callback)]
    get_root_node: (),

    #[webapi(
        method = "lookupNamespaceURI",
        callback = detached_lookup_namespace_uri_method_callback
    )]
    lookup_namespace_uri: (),

    #[webapi(method, length = 1, callback = node_contains_callback, receiver = web_api_interfaces::Node::is_instance)]
    contains: (),

    #[webapi(method, length = 1, callback = node_is_same_node_callback, receiver = web_api_interfaces::Node::is_instance)]
    is_same_node: (),

    #[webapi(method, length = 1, callback = node_is_equal_node_callback, receiver = web_api_interfaces::Node::is_instance)]
    is_equal_node: (),

    #[webapi(method, length = 1, callback = node_compare_document_position_callback, receiver = web_api_interfaces::Node::is_instance)]
    compare_document_position: (),

    #[webapi(method, callback = detached_clone_node_method_callback)]
    clone_node: (),

    #[webapi(method, callback = detached_append_method_callback)]
    append: (),

    #[webapi(method, callback = detached_prepend_method_callback)]
    prepend: (),

    #[webapi(method, callback = detached_replace_children_method_callback)]
    replace_children: (),

    #[webapi(method, callback = detached_before_method_callback)]
    before: (),

    #[webapi(method, callback = detached_after_method_callback)]
    after: (),

    #[webapi(method, callback = detached_replace_with_method_callback)]
    replace_with: (),

    #[webapi(method, callback = detached_normalize_method_callback)]
    normalize: (),
}

pub(super) fn install_detached_parent_node_move_before<'s>(
    scope: &mut v8::PinScope<'s, '_>,
    prototype: v8::Local<'s, v8::Object>,
) {
    #[derive(Default, WebApiObject)]
    #[webapi(fragment, prototype = "ParentNode")]
    struct DetachedParentNodeMoveBeforeDeclaration {
        #[webapi(method, length = 2, callback = detached_move_before_method_callback)]
        move_before: (),
    }

    DetachedParentNodeMoveBeforeDeclaration::default()
        .initialize(scope, prototype)
        .expect("detached ParentNode moveBefore declaration should initialize");
}

pub(super) fn install_detached_node_methods<'s>(
    scope: &mut v8::PinScope<'s, '_>,
    prototypes: &[v8::Local<'s, v8::Object>],
) {
    for prototype in prototypes {
        DetachedNodeMethodsDeclaration::default()
            .initialize(scope, *prototype)
            .expect("detached Node method declaration should initialize");
    }
}