#include <AK/String.h>
#include <AK/TypeCasts.h>
#include <AK/Utf16String.h>
#include <LibJS/Runtime/Error.h>
#include <LibJS/Runtime/Promise.h>
#include <LibJS/Runtime/PropertyDescriptor.h>
#include <LibJS/Runtime/Value.h>
#include <LibJS/Runtime/ValueInlines.h>
#include <LibWeb/Bindings/ExceptionOrUtils.h>
#include <LibWeb/Bindings/Internals.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/CSS/CSSStyleSheet.h>
#include <LibWeb/DOM/Element.h>
#include <LibWeb/DOM/Event.h>
#include <LibWeb/DOM/EventTarget.h>
#include <LibWeb/DOM/Node.h>
#include <LibWeb/DOM/ShadowRoot.h>
#include <LibWeb/Geometry/DOMRect.h>
#include <LibWeb/HTML/HTMLElement.h>
#include <LibWeb/Internals/InternalAnimationTimeline.h>
#include <LibWeb/Internals/InternalGamepad.h>
#include <LibWeb/Internals/Internals.h>
#include <LibWeb/WebIDL/AbstractOperations.h>
#include <LibWeb/WebIDL/Promise.h>
#include <LibWeb/WebIDL/Tracing.h>
#include <LibWeb/WebIDL/Types.h>

namespace Web::Bindings {

void InternalsConstructor::initialize(JS::Realm& realm, JS::NativeFunction& object)
{
    auto& vm = realm.vm();
    [[maybe_unused]] u8 default_attributes = JS::Attribute::Enumerable;

    
    object.define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
    object.define_direct_property(vm.names.name, JS::PrimitiveString::create(vm, "Internals"_utf16), JS::Attribute::Configurable);
    object.define_direct_property(vm.names.prototype, &ensure_web_prototype<InternalsPrototype>(realm, "Internals"_fly_string), 0);

    // 1. FIXME: If const is not exposed in realm, then continue.
    // 2. Let value be the result of converting const’s IDL value to a JavaScript value.
    // 3. Let desc be the PropertyDescriptor{[[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false, [[Value]]: value}.
    // 4. Let id be const’s identifier.
    // 5. Perform ! DefinePropertyOrThrow(target, id, desc).
    object.define_direct_property("MOD_NONE"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedShort>(0)), JS::Attribute::Enumerable);
    // 1. FIXME: If const is not exposed in realm, then continue.
    // 2. Let value be the result of converting const’s IDL value to a JavaScript value.
    // 3. Let desc be the PropertyDescriptor{[[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false, [[Value]]: value}.
    // 4. Let id be const’s identifier.
    // 5. Perform ! DefinePropertyOrThrow(target, id, desc).
    object.define_direct_property("MOD_ALT"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedShort>(1)), JS::Attribute::Enumerable);
    // 1. FIXME: If const is not exposed in realm, then continue.
    // 2. Let value be the result of converting const’s IDL value to a JavaScript value.
    // 3. Let desc be the PropertyDescriptor{[[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false, [[Value]]: value}.
    // 4. Let id be const’s identifier.
    // 5. Perform ! DefinePropertyOrThrow(target, id, desc).
    object.define_direct_property("MOD_CTRL"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedShort>(2)), JS::Attribute::Enumerable);
    // 1. FIXME: If const is not exposed in realm, then continue.
    // 2. Let value be the result of converting const’s IDL value to a JavaScript value.
    // 3. Let desc be the PropertyDescriptor{[[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false, [[Value]]: value}.
    // 4. Let id be const’s identifier.
    // 5. Perform ! DefinePropertyOrThrow(target, id, desc).
    object.define_direct_property("MOD_SHIFT"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedShort>(4)), JS::Attribute::Enumerable);
    // 1. FIXME: If const is not exposed in realm, then continue.
    // 2. Let value be the result of converting const’s IDL value to a JavaScript value.
    // 3. Let desc be the PropertyDescriptor{[[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false, [[Value]]: value}.
    // 4. Let id be const’s identifier.
    // 5. Perform ! DefinePropertyOrThrow(target, id, desc).
    object.define_direct_property("MOD_SUPER"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedShort>(8)), JS::Attribute::Enumerable);
    // 1. FIXME: If const is not exposed in realm, then continue.
    // 2. Let value be the result of converting const’s IDL value to a JavaScript value.
    // 3. Let desc be the PropertyDescriptor{[[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false, [[Value]]: value}.
    // 4. Let id be const’s identifier.
    // 5. Perform ! DefinePropertyOrThrow(target, id, desc).
    object.define_direct_property("MOD_KEYPAD"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedShort>(16)), JS::Attribute::Enumerable);
    // 1. FIXME: If const is not exposed in realm, then continue.
    // 2. Let value be the result of converting const’s IDL value to a JavaScript value.
    // 3. Let desc be the PropertyDescriptor{[[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false, [[Value]]: value}.
    // 4. Let id be const’s identifier.
    // 5. Perform ! DefinePropertyOrThrow(target, id, desc).
    object.define_direct_property("BUTTON_LEFT"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedShort>(0)), JS::Attribute::Enumerable);
    // 1. FIXME: If const is not exposed in realm, then continue.
    // 2. Let value be the result of converting const’s IDL value to a JavaScript value.
    // 3. Let desc be the PropertyDescriptor{[[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false, [[Value]]: value}.
    // 4. Let id be const’s identifier.
    // 5. Perform ! DefinePropertyOrThrow(target, id, desc).
    object.define_direct_property("BUTTON_MIDDLE"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedShort>(1)), JS::Attribute::Enumerable);
    // 1. FIXME: If const is not exposed in realm, then continue.
    // 2. Let value be the result of converting const’s IDL value to a JavaScript value.
    // 3. Let desc be the PropertyDescriptor{[[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false, [[Value]]: value}.
    // 4. Let id be const’s identifier.
    // 5. Perform ! DefinePropertyOrThrow(target, id, desc).
    object.define_direct_property("BUTTON_RIGHT"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedShort>(2)), JS::Attribute::Enumerable);
}

JS::ThrowCompletionOr<GC::Ref<JS::Object>> InternalsConstructor::construct([[maybe_unused]] InterfaceConstructor& constructor, [[maybe_unused]] JS::FunctionObject& new_target)
{
    WebIDL::log_trace(constructor.vm(), "InternalsConstructor::construct");
    return constructor.vm().throw_completion<JS::TypeError>(JS::ErrorType::NotAConstructor, "Internals");
}

void InternalsPrototype::initialize(JS::Realm& realm, JS::Object& object)
{
    [[maybe_unused]] auto& vm = realm.vm();
    [[maybe_unused]] u8 default_attributes = JS::Attribute::Enumerable | JS::Attribute::Configurable | JS::Attribute::Writable;

    object.set_prototype(realm.intrinsics().object_prototype());

    auto headless_id = "headless"_utf16_fly_string;
    auto native_headless_getter = JS::NativeFunction::create(realm, headless_getter, 0, headless_id, &realm, "get"sv);
    GC::Ptr<JS::NativeFunction> native_headless_setter;

    // 4. Let configurable be false if attr is unforgeable and true otherwise.
    auto headless_attributes = default_attributes;

    // 5. Let desc be the PropertyDescriptor{[[Get]]: getter, [[Set]]: setter, [[Enumerable]]: true, [[Configurable]]: configurable}.

    // 7. Perform ! DefinePropertyOrThrow(target, id, desc).
    object.define_direct_accessor(headless_id, native_headless_getter, native_headless_setter, headless_attributes);

    // 8. FIXME: If attr’s type is an observable array type with type argument T, then set target’s backing observable array exotic object for attr to the result of creating an observable array exotic object in realm, given T, attr’s set an indexed value algorithm, and attr’s delete an indexed value algorithm.
    auto screen_wake_lock_active_id = "screenWakeLockActive"_utf16_fly_string;
    auto native_screen_wake_lock_active_getter = JS::NativeFunction::create(realm, screen_wake_lock_active_getter, 0, screen_wake_lock_active_id, &realm, "get"sv);
    GC::Ptr<JS::NativeFunction> native_screen_wake_lock_active_setter;

    // 4. Let configurable be false if attr is unforgeable and true otherwise.
    auto screen_wake_lock_active_attributes = default_attributes;

    // 5. Let desc be the PropertyDescriptor{[[Get]]: getter, [[Set]]: setter, [[Enumerable]]: true, [[Configurable]]: configurable}.

    // 7. Perform ! DefinePropertyOrThrow(target, id, desc).
    object.define_direct_accessor(screen_wake_lock_active_id, native_screen_wake_lock_active_getter, native_screen_wake_lock_active_setter, screen_wake_lock_active_attributes);

    // 8. FIXME: If attr’s type is an observable array type with type argument T, then set target’s backing observable array exotic object for attr to the result of creating an observable array exotic object in realm, given T, attr’s set an indexed value algorithm, and attr’s delete an indexed value algorithm.
    auto needs_repaint_id = "needsRepaint"_utf16_fly_string;
    auto native_needs_repaint_getter = JS::NativeFunction::create(realm, needs_repaint_getter, 0, needs_repaint_id, &realm, "get"sv);
    GC::Ptr<JS::NativeFunction> native_needs_repaint_setter;

    // 4. Let configurable be false if attr is unforgeable and true otherwise.
    auto needs_repaint_attributes = default_attributes;

    // 5. Let desc be the PropertyDescriptor{[[Get]]: getter, [[Set]]: setter, [[Enumerable]]: true, [[Configurable]]: configurable}.

    // 7. Perform ! DefinePropertyOrThrow(target, id, desc).
    object.define_direct_accessor(needs_repaint_id, native_needs_repaint_getter, native_needs_repaint_setter, needs_repaint_attributes);

    // 8. FIXME: If attr’s type is an observable array type with type argument T, then set target’s backing observable array exotic object for attr to the result of creating an observable array exotic object in realm, given T, attr’s set an indexed value algorithm, and attr’s delete an indexed value algorithm.
    object.define_native_function(realm, "signalTestIsDone"_utf16_fly_string, signal_test_is_done, 1, default_attributes);

    object.define_native_function(realm, "setTestTimeout"_utf16_fly_string, set_test_timeout, 1, default_attributes);

    object.define_native_function(realm, "forceIncompatibleVisualContextTreeRebuild"_utf16_fly_string, force_incompatible_visual_context_tree_rebuild, 0, default_attributes);

    object.define_native_function(realm, "loadReferenceTestMetadata"_utf16_fly_string, load_reference_test_metadata, 0, default_attributes);

    object.define_native_function(realm, "setTimeZone"_utf16_fly_string, set_time_zone, 1, default_attributes);

    object.define_native_function(realm, "gc"_utf16_fly_string, gc, 0, default_attributes);

    object.define_native_function(realm, "gcAsync"_utf16_fly_string, gc_async, 0, default_attributes);

    object.define_native_function(realm, "markAsGarbage"_utf16_fly_string, mark_as_garbage, 1, default_attributes);

    object.define_native_function(realm, "hitTest"_utf16_fly_string, hit_test, 2, default_attributes);

    object.define_native_function(realm, "sendText"_utf16_fly_string, send_text, 2, default_attributes);

    object.define_native_function(realm, "sendKey"_utf16_fly_string, send_key, 2, default_attributes);

    object.define_native_function(realm, "paste"_utf16_fly_string, paste, 2, default_attributes);

    object.define_native_function(realm, "commitText"_utf16_fly_string, commit_text, 0, default_attributes);

    object.define_native_function(realm, "mouseDown"_utf16_fly_string, mouse_down, 2, default_attributes);

    object.define_native_function(realm, "mouseUp"_utf16_fly_string, mouse_up, 2, default_attributes);

    object.define_native_function(realm, "mouseMove"_utf16_fly_string, mouse_move, 2, default_attributes);

    object.define_native_function(realm, "mouseLeave"_utf16_fly_string, mouse_leave, 0, default_attributes);

    object.define_native_function(realm, "click"_utf16_fly_string, click, 2, default_attributes);

    object.define_native_function(realm, "clickAndHold"_utf16_fly_string, click_and_hold, 2, default_attributes);

    object.define_native_function(realm, "wheel"_utf16_fly_string, wheel, 4, default_attributes);

    object.define_native_function(realm, "pinch"_utf16_fly_string, pinch, 3, default_attributes);

    object.define_native_function(realm, "currentCursor"_utf16_fly_string, current_cursor, 0, default_attributes);

    object.define_native_function(realm, "selectedTextForClipboard"_utf16_fly_string, selected_text_for_clipboard, 0, default_attributes);

    object.define_native_function(realm, "setMarkedTextFromInputMethod"_utf16_fly_string, set_marked_text_from_input_method, 1, default_attributes);

    object.define_native_function(realm, "commitTextFromInputMethod"_utf16_fly_string, commit_text_from_input_method, 1, default_attributes);

    object.define_native_function(realm, "unmarkTextFromInputMethod"_utf16_fly_string, unmark_text_from_input_method, 0, default_attributes);

    object.define_native_function(realm, "currentCaretRect"_utf16_fly_string, current_caret_rect, 0, default_attributes);

    object.define_native_function(realm, "dispatchUserActivatedEvent"_utf16_fly_string, dispatch_user_activated_event, 2, default_attributes);

    object.define_native_function(realm, "spoofCurrentURL"_utf16_fly_string, spoof_current_url, 1, default_attributes);

    object.define_native_function(realm, "loadURL"_utf16_fly_string, load_url, 1, default_attributes);

    object.define_native_function(realm, "createInternalAnimationTimeline"_utf16_fly_string, create_internal_animation_timeline, 0, default_attributes);

    object.define_native_function(realm, "simulateDragStart"_utf16_fly_string, simulate_drag_start, 4, default_attributes);

    object.define_native_function(realm, "simulateDragMove"_utf16_fly_string, simulate_drag_move, 2, default_attributes);

    object.define_native_function(realm, "simulateDrop"_utf16_fly_string, simulate_drop, 2, default_attributes);

    object.define_native_function(realm, "expireCookiesWithTimeOffset"_utf16_fly_string, expire_cookies_with_time_offset, 1, default_attributes);

    object.define_native_function(realm, "deleteAllCookies"_utf16_fly_string, delete_all_cookies, 0, default_attributes);

    object.define_native_function(realm, "setHttpMemoryCacheEnabled"_utf16_fly_string, set_http_memory_cache_enabled, 1, default_attributes);

    object.define_native_function(realm, "setContentBlockers"_utf16_fly_string, set_content_blockers, 1, default_attributes);

    object.define_native_function(realm, "setContentBlockingEnabled"_utf16_fly_string, set_content_blocking_enabled, 1, default_attributes);

    object.define_native_function(realm, "setAutoplayPolicy"_utf16_fly_string, set_autoplay_policy, 1, default_attributes);

    object.define_native_function(realm, "getComputedRole"_utf16_fly_string, get_computed_role, 1, default_attributes);

    object.define_native_function(realm, "getComputedLabel"_utf16_fly_string, get_computed_label, 1, default_attributes);

    object.define_native_function(realm, "getComputedAriaLevel"_utf16_fly_string, get_computed_aria_level, 1, default_attributes);

    object.define_native_function(realm, "getEchoServerPort"_utf16_fly_string, get_echo_server_port, 0, default_attributes);

    object.define_native_function(realm, "setHSTSPolicy"_utf16_fly_string, set_hsts_policy, 3, default_attributes);

    object.define_native_function(realm, "ingestHSTSHeader"_utf16_fly_string, ingest_hsts_header, 2, default_attributes);

    object.define_native_function(realm, "isKnownHSTSHost"_utf16_fly_string, is_known_hsts_host, 1, default_attributes);

    object.define_native_function(realm, "setBrowserZoom"_utf16_fly_string, set_browser_zoom, 1, default_attributes);

    object.define_native_function(realm, "setDevicePixelRatio"_utf16_fly_string, set_device_pixel_ratio, 1, default_attributes);

    object.define_native_function(realm, "dumpDisplayList"_utf16_fly_string, dump_display_list, 0, default_attributes);

    object.define_native_function(realm, "dumpAccessibilityTree"_utf16_fly_string, dump_accessibility_tree, 0, default_attributes);

    object.define_native_function(realm, "dumpLayoutTree"_utf16_fly_string, dump_layout_tree, 1, default_attributes);

    object.define_native_function(realm, "dumpPaintableTree"_utf16_fly_string, dump_paintable_tree, 1, default_attributes);

    object.define_native_function(realm, "dumpStackingContextTree"_utf16_fly_string, dump_stacking_context_tree, 0, default_attributes);

    object.define_native_function(realm, "dumpGCGraph"_utf16_fly_string, dump_gc_graph, 0, default_attributes);

    object.define_native_function(realm, "dumpSessionHistory"_utf16_fly_string, dump_session_history, 0, default_attributes);

    object.define_native_function(realm, "dumpUIProcessSessionHistory"_utf16_fly_string, dump_ui_process_session_history, 0, default_attributes);

    object.define_native_function(realm, "dumpSiteIsolationProcessTree"_utf16_fly_string, dump_site_isolation_process_tree, 0, default_attributes);

    object.define_native_function(realm, "flushSessionHistoryTraversalQueue"_utf16_fly_string, flush_session_history_traversal_queue, 0, default_attributes);

    object.define_native_function(realm, "clobberNextNavigationWithATraversal"_utf16_fly_string, clobber_next_navigation_with_a_traversal, 0, default_attributes);

    object.define_native_function(realm, "getShadowRoot"_utf16_fly_string, get_shadow_root, 1, default_attributes);

    object.define_native_function(realm, "handleSDLInputEvents"_utf16_fly_string, handle_sdl_input_events, 0, default_attributes);

    object.define_native_function(realm, "setEnvironmentsTopLevelURL"_utf16_fly_string, set_environments_top_level_url, 1, default_attributes);

    object.define_native_function(realm, "connectVirtualGamepad"_utf16_fly_string, connect_virtual_gamepad, 0, default_attributes);

    object.define_native_function(realm, "setHighlightedNode"_utf16_fly_string, set_highlighted_node, 1, default_attributes);

    object.define_native_function(realm, "clearElement"_utf16_fly_string, clear_element, 1, default_attributes);

    object.define_native_function(realm, "getStyleInvalidationCounters"_utf16_fly_string, get_style_invalidation_counters, 0, default_attributes);

    object.define_native_function(realm, "resetStyleInvalidationCounters"_utf16_fly_string, reset_style_invalidation_counters, 0, default_attributes);

    object.define_native_function(realm, "updateStyle"_utf16_fly_string, update_style, 0, default_attributes);

    object.define_native_function(realm, "setPreferredColorScheme"_utf16_fly_string, set_preferred_color_scheme, 1, default_attributes);

    object.define_native_function(realm, "setPageFocus"_utf16_fly_string, set_page_focus, 1, default_attributes);

    object.define_native_function(realm, "canvasColorScheme"_utf16_fly_string, canvas_color_scheme, 0, default_attributes);

    object.define_native_function(realm, "styleSheetMayHaveHasSelectors"_utf16_fly_string, style_sheet_may_have_has_selectors, 1, default_attributes);

    object.define_native_function(realm, "imageAnimationStateForURL"_utf16_fly_string, image_animation_state_for_url, 1, default_attributes);

    object.define_native_function(realm, "asyncScrollingState"_utf16_fly_string, async_scrolling_state, 0, default_attributes);

    object.define_native_function(realm, "asyncScrollingStateBlocksWheelEventAt"_utf16_fly_string, async_scrolling_state_blocks_wheel_event_at, 2, default_attributes);

    object.define_native_function(realm, "asyncScrollingStateCanWheelScrollAt"_utf16_fly_string, async_scrolling_state_can_wheel_scroll_at, 4, default_attributes);

    object.define_native_function(realm, "asyncScrollingStateWheelRoutingAdmission"_utf16_fly_string, async_scrolling_state_wheel_routing_admission, 0, default_attributes);

    object.define_native_function(realm, "asyncScrollingStateWheelScrollAdmissionAt"_utf16_fly_string, async_scrolling_state_wheel_scroll_admission_at, 4, default_attributes);

    object.define_native_function(realm, "asyncScrollingStateWheelTargetAt"_utf16_fly_string, async_scrolling_state_wheel_target_at, 4, default_attributes);


    // 1. FIXME: If const is not exposed in realm, then continue.
    // 2. Let value be the result of converting const’s IDL value to a JavaScript value.
    // 3. Let desc be the PropertyDescriptor{[[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false, [[Value]]: value}.
    // 4. Let id be const’s identifier.
    // 5. Perform ! DefinePropertyOrThrow(target, id, desc).
    object.define_direct_property("MOD_NONE"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedShort>(0)), JS::Attribute::Enumerable);
    // 1. FIXME: If const is not exposed in realm, then continue.
    // 2. Let value be the result of converting const’s IDL value to a JavaScript value.
    // 3. Let desc be the PropertyDescriptor{[[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false, [[Value]]: value}.
    // 4. Let id be const’s identifier.
    // 5. Perform ! DefinePropertyOrThrow(target, id, desc).
    object.define_direct_property("MOD_ALT"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedShort>(1)), JS::Attribute::Enumerable);
    // 1. FIXME: If const is not exposed in realm, then continue.
    // 2. Let value be the result of converting const’s IDL value to a JavaScript value.
    // 3. Let desc be the PropertyDescriptor{[[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false, [[Value]]: value}.
    // 4. Let id be const’s identifier.
    // 5. Perform ! DefinePropertyOrThrow(target, id, desc).
    object.define_direct_property("MOD_CTRL"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedShort>(2)), JS::Attribute::Enumerable);
    // 1. FIXME: If const is not exposed in realm, then continue.
    // 2. Let value be the result of converting const’s IDL value to a JavaScript value.
    // 3. Let desc be the PropertyDescriptor{[[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false, [[Value]]: value}.
    // 4. Let id be const’s identifier.
    // 5. Perform ! DefinePropertyOrThrow(target, id, desc).
    object.define_direct_property("MOD_SHIFT"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedShort>(4)), JS::Attribute::Enumerable);
    // 1. FIXME: If const is not exposed in realm, then continue.
    // 2. Let value be the result of converting const’s IDL value to a JavaScript value.
    // 3. Let desc be the PropertyDescriptor{[[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false, [[Value]]: value}.
    // 4. Let id be const’s identifier.
    // 5. Perform ! DefinePropertyOrThrow(target, id, desc).
    object.define_direct_property("MOD_SUPER"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedShort>(8)), JS::Attribute::Enumerable);
    // 1. FIXME: If const is not exposed in realm, then continue.
    // 2. Let value be the result of converting const’s IDL value to a JavaScript value.
    // 3. Let desc be the PropertyDescriptor{[[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false, [[Value]]: value}.
    // 4. Let id be const’s identifier.
    // 5. Perform ! DefinePropertyOrThrow(target, id, desc).
    object.define_direct_property("MOD_KEYPAD"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedShort>(16)), JS::Attribute::Enumerable);
    // 1. FIXME: If const is not exposed in realm, then continue.
    // 2. Let value be the result of converting const’s IDL value to a JavaScript value.
    // 3. Let desc be the PropertyDescriptor{[[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false, [[Value]]: value}.
    // 4. Let id be const’s identifier.
    // 5. Perform ! DefinePropertyOrThrow(target, id, desc).
    object.define_direct_property("BUTTON_LEFT"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedShort>(0)), JS::Attribute::Enumerable);
    // 1. FIXME: If const is not exposed in realm, then continue.
    // 2. Let value be the result of converting const’s IDL value to a JavaScript value.
    // 3. Let desc be the PropertyDescriptor{[[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false, [[Value]]: value}.
    // 4. Let id be const’s identifier.
    // 5. Perform ! DefinePropertyOrThrow(target, id, desc).
    object.define_direct_property("BUTTON_MIDDLE"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedShort>(1)), JS::Attribute::Enumerable);
    // 1. FIXME: If const is not exposed in realm, then continue.
    // 2. Let value be the result of converting const’s IDL value to a JavaScript value.
    // 3. Let desc be the PropertyDescriptor{[[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false, [[Value]]: value}.
    // 4. Let id be const’s identifier.
    // 5. Perform ! DefinePropertyOrThrow(target, id, desc).
    object.define_direct_property("BUTTON_RIGHT"_utf16_fly_string, JS::Value(static_cast<WebIDL::UnsignedShort>(2)), JS::Attribute::Enumerable);
    object.define_direct_property(vm.well_known_symbol_to_string_tag(), JS::PrimitiveString::create(vm, "Internals"_utf16), JS::Attribute::Configurable);
}

void InternalsPrototype::define_unforgeable_attributes(JS::Realm& realm, [[maybe_unused]] JS::Object& object)
{
    [[maybe_unused]] auto& vm = realm.vm();
    [[maybe_unused]] u8 default_attributes = JS::Attribute::Enumerable;
}

[[maybe_unused]] static JS::ThrowCompletionOr<Internals::Internals*> impl_from(JS::VM& vm, JS::Value js_value)
{

    if (auto impl = js_value.as_if<Internals::Internals>())
        return impl.ptr();
    return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "Internals");
}

[[maybe_unused]] static JS::ThrowCompletionOr<Internals::Internals*> impl_from(JS::VM& vm)
{
    auto this_value = vm.this_value();
    if (this_value.is_nullish())
        this_value = &vm.current_realm()->global_object();
    return impl_from(vm, this_value);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::headless_getter)
{
    WebIDL::log_trace(vm, "InternalsPrototype::headless_getter");
    [[maybe_unused]] auto& realm = *vm.current_realm();

    auto* idl_object = TRY(impl_from(vm));


    auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->headless(); }));

    return JS::Value(R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::screen_wake_lock_active_getter)
{
    WebIDL::log_trace(vm, "InternalsPrototype::screen_wake_lock_active_getter");
    [[maybe_unused]] auto& realm = *vm.current_realm();

    auto* idl_object = TRY(impl_from(vm));


    auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->screen_wake_lock_active(); }));

    return JS::Value(R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::needs_repaint_getter)
{
    WebIDL::log_trace(vm, "InternalsPrototype::needs_repaint_getter");
    [[maybe_unused]] auto& realm = *vm.current_realm();

    auto* idl_object = TRY(impl_from(vm));


    auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->needs_repaint(); }));

    return JS::Value(R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::signal_test_is_done)
{
    WebIDL::log_trace(vm, "InternalsPrototype::signal_test_is_done");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "signalTestIsDone");

    auto arg0 = vm.argument(0);
    auto text = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<String> {
        return TRY(WebIDL::to_string(vm, arg0));
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->signal_test_is_done(text); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::set_test_timeout)
{
    WebIDL::log_trace(vm, "InternalsPrototype::set_test_timeout");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "setTestTimeout");

    auto arg0 = vm.argument(0);
    auto milliseconds = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg0.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "milliseconds");
        return x;
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->set_test_timeout(milliseconds); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::force_incompatible_visual_context_tree_rebuild)
{
    WebIDL::log_trace(vm, "InternalsPrototype::force_incompatible_visual_context_tree_rebuild");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->force_incompatible_visual_context_tree_rebuild(); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::load_reference_test_metadata)
{
    WebIDL::log_trace(vm, "InternalsPrototype::load_reference_test_metadata");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->load_reference_test_metadata(); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::set_time_zone)
{
    WebIDL::log_trace(vm, "InternalsPrototype::set_time_zone");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "setTimeZone");

    auto arg0 = vm.argument(0);
    auto time_zone = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<String> {
        return TRY(WebIDL::to_string(vm, arg0));
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->set_time_zone(time_zone); }));
    return WebIDL::primitive_string_from_string(vm, R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::gc)
{
    WebIDL::log_trace(vm, "InternalsPrototype::gc");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->gc(); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::gc_async)
{
    WebIDL::log_trace(vm, "InternalsPrototype::gc_async");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    auto steps = [&realm, &vm]() -> JS::ThrowCompletionOr<GC::Ref<WebIDL::Promise>> {
        (void)realm;
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->gc_async(); }));
        return R;
    };

    auto maybe_R = steps();

    // And then, if an exception E was thrown:
    // 1. If op has a return type that is a promise type, then return ! Call(%Promise.reject%, %Promise%, «E»).
    // 2. Otherwise, end these steps and allow the exception to propagate.
    if (maybe_R.is_throw_completion())
        return WebIDL::create_rejected_promise(realm, maybe_R.error_value())->promise();

    return GC::Ref { as<JS::Promise>(*maybe_R.release_value()->promise()) };
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::mark_as_garbage)
{
    WebIDL::log_trace(vm, "InternalsPrototype::mark_as_garbage");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "markAsGarbage");

    auto arg0 = vm.argument(0);
    auto variable_name = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<String> {
        return TRY(WebIDL::to_string(vm, arg0));
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->mark_as_garbage(variable_name); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::hit_test)
{
    WebIDL::log_trace(vm, "InternalsPrototype::hit_test");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 2)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountMany, "hitTest", "2");

    auto arg0 = vm.argument(0);
    auto x = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg0.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "x");
        return x;
    }(); }));

    auto arg1 = vm.argument(1);
    auto y = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg1.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "y");
        return x;
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->hit_test(x, y); }));
    return JS::Value(R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::send_text)
{
    WebIDL::log_trace(vm, "InternalsPrototype::send_text");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 2)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountMany, "sendText", "2");

    auto arg0 = vm.argument(0);
    auto target = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<GC::Ref<HTML::HTMLElement>> {
        if (auto impl = arg0.as_if<HTML::HTMLElement>())
            return *impl;
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "HTMLElement");
    }(); }));

    auto arg1 = vm.argument(1);
    auto text = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<String> {
        return TRY(WebIDL::to_string(vm, arg1));
    }(); }));

    auto arg2 = vm.argument(2);
    WebIDL::UnsignedShort modifiers = 0;
    if (!arg2.is_undefined())
        modifiers = TRY(throw_dom_exception_if_needed(vm, [&] { return WebIDL::convert_to_int<WebIDL::UnsignedShort>(vm, arg2, WebIDL::EnforceRange::No, WebIDL::Clamp::No); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->send_text(target, text, modifiers); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::send_key)
{
    WebIDL::log_trace(vm, "InternalsPrototype::send_key");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 2)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountMany, "sendKey", "2");

    auto arg0 = vm.argument(0);
    auto target = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<GC::Ref<HTML::HTMLElement>> {
        if (auto impl = arg0.as_if<HTML::HTMLElement>())
            return *impl;
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "HTMLElement");
    }(); }));

    auto arg1 = vm.argument(1);
    auto key_name = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<String> {
        return TRY(WebIDL::to_string(vm, arg1));
    }(); }));

    auto arg2 = vm.argument(2);
    WebIDL::UnsignedShort modifiers = 0;
    if (!arg2.is_undefined())
        modifiers = TRY(throw_dom_exception_if_needed(vm, [&] { return WebIDL::convert_to_int<WebIDL::UnsignedShort>(vm, arg2, WebIDL::EnforceRange::No, WebIDL::Clamp::No); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->send_key(target, key_name, modifiers); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::paste)
{
    WebIDL::log_trace(vm, "InternalsPrototype::paste");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 2)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountMany, "paste", "2");

    auto arg0 = vm.argument(0);
    auto target = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<GC::Ref<HTML::HTMLElement>> {
        if (auto impl = arg0.as_if<HTML::HTMLElement>())
            return *impl;
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "HTMLElement");
    }(); }));

    auto arg1 = vm.argument(1);
    auto text = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<Utf16String> {
        return TRY(WebIDL::to_utf16_string(vm, arg1));
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->paste(target, text); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::commit_text)
{
    WebIDL::log_trace(vm, "InternalsPrototype::commit_text");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->commit_text(); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::mouse_down)
{
    WebIDL::log_trace(vm, "InternalsPrototype::mouse_down");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 2)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountMany, "mouseDown", "2");

    auto arg0 = vm.argument(0);
    auto x = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg0.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "x");
        return x;
    }(); }));

    auto arg1 = vm.argument(1);
    auto y = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg1.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "y");
        return x;
    }(); }));

    auto arg2 = vm.argument(2);
    WebIDL::UnsignedShort click_count = 1;
    if (!arg2.is_undefined())
        click_count = TRY(throw_dom_exception_if_needed(vm, [&] { return WebIDL::convert_to_int<WebIDL::UnsignedShort>(vm, arg2, WebIDL::EnforceRange::No, WebIDL::Clamp::No); }));

    auto arg3 = vm.argument(3);
    WebIDL::UnsignedShort button = 0;
    if (!arg3.is_undefined())
        button = TRY(throw_dom_exception_if_needed(vm, [&] { return WebIDL::convert_to_int<WebIDL::UnsignedShort>(vm, arg3, WebIDL::EnforceRange::No, WebIDL::Clamp::No); }));

    auto arg4 = vm.argument(4);
    WebIDL::UnsignedShort modifiers = 0;
    if (!arg4.is_undefined())
        modifiers = TRY(throw_dom_exception_if_needed(vm, [&] { return WebIDL::convert_to_int<WebIDL::UnsignedShort>(vm, arg4, WebIDL::EnforceRange::No, WebIDL::Clamp::No); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->mouse_down(x, y, click_count, button, modifiers); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::mouse_up)
{
    WebIDL::log_trace(vm, "InternalsPrototype::mouse_up");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 2)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountMany, "mouseUp", "2");

    auto arg0 = vm.argument(0);
    auto x = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg0.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "x");
        return x;
    }(); }));

    auto arg1 = vm.argument(1);
    auto y = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg1.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "y");
        return x;
    }(); }));

    auto arg2 = vm.argument(2);
    WebIDL::UnsignedShort button = 0;
    if (!arg2.is_undefined())
        button = TRY(throw_dom_exception_if_needed(vm, [&] { return WebIDL::convert_to_int<WebIDL::UnsignedShort>(vm, arg2, WebIDL::EnforceRange::No, WebIDL::Clamp::No); }));

    auto arg3 = vm.argument(3);
    WebIDL::UnsignedShort modifiers = 0;
    if (!arg3.is_undefined())
        modifiers = TRY(throw_dom_exception_if_needed(vm, [&] { return WebIDL::convert_to_int<WebIDL::UnsignedShort>(vm, arg3, WebIDL::EnforceRange::No, WebIDL::Clamp::No); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->mouse_up(x, y, button, modifiers); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::mouse_move)
{
    WebIDL::log_trace(vm, "InternalsPrototype::mouse_move");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 2)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountMany, "mouseMove", "2");

    auto arg0 = vm.argument(0);
    auto x = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg0.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "x");
        return x;
    }(); }));

    auto arg1 = vm.argument(1);
    auto y = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg1.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "y");
        return x;
    }(); }));

    auto arg2 = vm.argument(2);
    WebIDL::UnsignedShort modifiers = 0;
    if (!arg2.is_undefined())
        modifiers = TRY(throw_dom_exception_if_needed(vm, [&] { return WebIDL::convert_to_int<WebIDL::UnsignedShort>(vm, arg2, WebIDL::EnforceRange::No, WebIDL::Clamp::No); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->mouse_move(x, y, modifiers); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::mouse_leave)
{
    WebIDL::log_trace(vm, "InternalsPrototype::mouse_leave");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->mouse_leave(); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::click)
{
    WebIDL::log_trace(vm, "InternalsPrototype::click");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 2)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountMany, "click", "2");

    auto arg0 = vm.argument(0);
    auto x = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg0.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "x");
        return x;
    }(); }));

    auto arg1 = vm.argument(1);
    auto y = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg1.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "y");
        return x;
    }(); }));

    auto arg2 = vm.argument(2);
    WebIDL::UnsignedShort click_count = 1;
    if (!arg2.is_undefined())
        click_count = TRY(throw_dom_exception_if_needed(vm, [&] { return WebIDL::convert_to_int<WebIDL::UnsignedShort>(vm, arg2, WebIDL::EnforceRange::No, WebIDL::Clamp::No); }));

    auto arg3 = vm.argument(3);
    WebIDL::UnsignedShort button = 0;
    if (!arg3.is_undefined())
        button = TRY(throw_dom_exception_if_needed(vm, [&] { return WebIDL::convert_to_int<WebIDL::UnsignedShort>(vm, arg3, WebIDL::EnforceRange::No, WebIDL::Clamp::No); }));

    auto arg4 = vm.argument(4);
    WebIDL::UnsignedShort modifiers = 0;
    if (!arg4.is_undefined())
        modifiers = TRY(throw_dom_exception_if_needed(vm, [&] { return WebIDL::convert_to_int<WebIDL::UnsignedShort>(vm, arg4, WebIDL::EnforceRange::No, WebIDL::Clamp::No); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->click(x, y, click_count, button, modifiers); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::click_and_hold)
{
    WebIDL::log_trace(vm, "InternalsPrototype::click_and_hold");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 2)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountMany, "clickAndHold", "2");

    auto arg0 = vm.argument(0);
    auto x = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg0.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "x");
        return x;
    }(); }));

    auto arg1 = vm.argument(1);
    auto y = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg1.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "y");
        return x;
    }(); }));

    auto arg2 = vm.argument(2);
    WebIDL::UnsignedShort click_count = 1;
    if (!arg2.is_undefined())
        click_count = TRY(throw_dom_exception_if_needed(vm, [&] { return WebIDL::convert_to_int<WebIDL::UnsignedShort>(vm, arg2, WebIDL::EnforceRange::No, WebIDL::Clamp::No); }));

    auto arg3 = vm.argument(3);
    WebIDL::UnsignedShort button = 0;
    if (!arg3.is_undefined())
        button = TRY(throw_dom_exception_if_needed(vm, [&] { return WebIDL::convert_to_int<WebIDL::UnsignedShort>(vm, arg3, WebIDL::EnforceRange::No, WebIDL::Clamp::No); }));

    auto arg4 = vm.argument(4);
    WebIDL::UnsignedShort modifiers = 0;
    if (!arg4.is_undefined())
        modifiers = TRY(throw_dom_exception_if_needed(vm, [&] { return WebIDL::convert_to_int<WebIDL::UnsignedShort>(vm, arg4, WebIDL::EnforceRange::No, WebIDL::Clamp::No); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->click_and_hold(x, y, click_count, button, modifiers); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::wheel)
{
    WebIDL::log_trace(vm, "InternalsPrototype::wheel");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    auto steps = [&realm, &vm]() -> JS::ThrowCompletionOr<GC::Ref<WebIDL::Promise>> {
        (void)realm;
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 4)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountMany, "wheel", "4");

    auto arg0 = vm.argument(0);
    auto x = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg0.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "x");
        return x;
    }(); }));

    auto arg1 = vm.argument(1);
    auto y = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg1.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "y");
        return x;
    }(); }));

    auto arg2 = vm.argument(2);
    auto delta_x = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg2.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "deltaX");
        return x;
    }(); }));

    auto arg3 = vm.argument(3);
    auto delta_y = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg3.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "deltaY");
        return x;
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->wheel(x, y, delta_x, delta_y); }));
        return R;
    };

    auto maybe_R = steps();

    // And then, if an exception E was thrown:
    // 1. If op has a return type that is a promise type, then return ! Call(%Promise.reject%, %Promise%, «E»).
    // 2. Otherwise, end these steps and allow the exception to propagate.
    if (maybe_R.is_throw_completion())
        return WebIDL::create_rejected_promise(realm, maybe_R.error_value())->promise();

    return GC::Ref { as<JS::Promise>(*maybe_R.release_value()->promise()) };
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::pinch)
{
    WebIDL::log_trace(vm, "InternalsPrototype::pinch");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 3)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountMany, "pinch", "3");

    auto arg0 = vm.argument(0);
    auto x = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg0.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "x");
        return x;
    }(); }));

    auto arg1 = vm.argument(1);
    auto y = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg1.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "y");
        return x;
    }(); }));

    auto arg2 = vm.argument(2);
    auto scale_delta = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg2.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "scaleDelta");
        return x;
    }(); }));

    auto arg3 = vm.argument(3);
    WebIDL::UnsignedShort modifiers = 0;
    if (!arg3.is_undefined())
        modifiers = TRY(throw_dom_exception_if_needed(vm, [&] { return WebIDL::convert_to_int<WebIDL::UnsignedShort>(vm, arg3, WebIDL::EnforceRange::No, WebIDL::Clamp::No); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->pinch(x, y, scale_delta, modifiers); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::current_cursor)
{
    WebIDL::log_trace(vm, "InternalsPrototype::current_cursor");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->current_cursor(); }));
    return WebIDL::primitive_string_from_string(vm, R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::selected_text_for_clipboard)
{
    WebIDL::log_trace(vm, "InternalsPrototype::selected_text_for_clipboard");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->selected_text_for_clipboard(); }));
    return WebIDL::primitive_string_from_string(vm, R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::set_marked_text_from_input_method)
{
    WebIDL::log_trace(vm, "InternalsPrototype::set_marked_text_from_input_method");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "setMarkedTextFromInputMethod");

    auto arg0 = vm.argument(0);
    auto text = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<Utf16String> {
        return TRY(WebIDL::to_utf16_string(vm, arg0));
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->set_marked_text_from_input_method(text); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::commit_text_from_input_method)
{
    WebIDL::log_trace(vm, "InternalsPrototype::commit_text_from_input_method");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "commitTextFromInputMethod");

    auto arg0 = vm.argument(0);
    auto text = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<Utf16String> {
        return TRY(WebIDL::to_utf16_string(vm, arg0));
    }(); }));

    auto arg1 = vm.argument(1);
    WebIDL::Long replacement_start = 0;
    if (!arg1.is_undefined())
        replacement_start = TRY(throw_dom_exception_if_needed(vm, [&] { return WebIDL::convert_to_int<WebIDL::Long>(vm, arg1, WebIDL::EnforceRange::No, WebIDL::Clamp::No); }));

    auto arg2 = vm.argument(2);
    WebIDL::Long replacement_length = 0;
    if (!arg2.is_undefined())
        replacement_length = TRY(throw_dom_exception_if_needed(vm, [&] { return WebIDL::convert_to_int<WebIDL::Long>(vm, arg2, WebIDL::EnforceRange::No, WebIDL::Clamp::No); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->commit_text_from_input_method(text, replacement_start, replacement_length); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::unmark_text_from_input_method)
{
    WebIDL::log_trace(vm, "InternalsPrototype::unmark_text_from_input_method");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->unmark_text_from_input_method(); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::current_caret_rect)
{
    WebIDL::log_trace(vm, "InternalsPrototype::current_caret_rect");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->current_caret_rect(); }));
    return [&]() -> JS::Value {
        // 1. If the IDL nullable type T? value is null, then the JavaScript value is null.
        if (!R)
            return JS::js_null();

        // 2. Otherwise, the JavaScript value is the result of converting the IDL nullable type value to the inner IDL type T.
        return JS::Value(JS::Value(R));
    }();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::dispatch_user_activated_event)
{
    WebIDL::log_trace(vm, "InternalsPrototype::dispatch_user_activated_event");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 2)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountMany, "dispatchUserActivatedEvent", "2");

    auto arg0 = vm.argument(0);
    auto target = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<GC::Ref<DOM::EventTarget>> {
        if (auto impl = arg0.as_if<DOM::EventTarget>())
            return *impl;
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "EventTarget");
    }(); }));

    auto arg1 = vm.argument(1);
    auto event = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<GC::Ref<DOM::Event>> {
        if (auto impl = arg1.as_if<DOM::Event>())
            return *impl;
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "Event");
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->dispatch_user_activated_event(target, event); }));
    return JS::Value(R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::spoof_current_url)
{
    WebIDL::log_trace(vm, "InternalsPrototype::spoof_current_url");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "spoofCurrentURL");

    auto arg0 = vm.argument(0);
    auto url = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<String> {
        return TRY(WebIDL::to_usv_string(vm, arg0));
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->spoof_current_url(url); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::load_url)
{
    WebIDL::log_trace(vm, "InternalsPrototype::load_url");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "loadURL");

    auto arg0 = vm.argument(0);
    auto url = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<String> {
        return TRY(WebIDL::to_usv_string(vm, arg0));
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->load_url(url); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::create_internal_animation_timeline)
{
    WebIDL::log_trace(vm, "InternalsPrototype::create_internal_animation_timeline");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->create_internal_animation_timeline(); }));
    return JS::Value(R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::simulate_drag_start)
{
    WebIDL::log_trace(vm, "InternalsPrototype::simulate_drag_start");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 4)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountMany, "simulateDragStart", "4");

    auto arg0 = vm.argument(0);
    auto x = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg0.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "x");
        return x;
    }(); }));

    auto arg1 = vm.argument(1);
    auto y = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg1.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "y");
        return x;
    }(); }));

    auto arg2 = vm.argument(2);
    auto mime_type = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<String> {
        return TRY(WebIDL::to_string(vm, arg2));
    }(); }));

    auto arg3 = vm.argument(3);
    auto contents = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<String> {
        return TRY(WebIDL::to_string(vm, arg3));
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->simulate_drag_start(x, y, mime_type, contents); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::simulate_drag_move)
{
    WebIDL::log_trace(vm, "InternalsPrototype::simulate_drag_move");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 2)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountMany, "simulateDragMove", "2");

    auto arg0 = vm.argument(0);
    auto x = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg0.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "x");
        return x;
    }(); }));

    auto arg1 = vm.argument(1);
    auto y = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg1.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "y");
        return x;
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->simulate_drag_move(x, y); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::simulate_drop)
{
    WebIDL::log_trace(vm, "InternalsPrototype::simulate_drop");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 2)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountMany, "simulateDrop", "2");

    auto arg0 = vm.argument(0);
    auto x = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg0.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "x");
        return x;
    }(); }));

    auto arg1 = vm.argument(1);
    auto y = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg1.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "y");
        return x;
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->simulate_drop(x, y); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::expire_cookies_with_time_offset)
{
    WebIDL::log_trace(vm, "InternalsPrototype::expire_cookies_with_time_offset");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "expireCookiesWithTimeOffset");

    auto arg0 = vm.argument(0);
    auto seconds = TRY(throw_dom_exception_if_needed(vm, [&] { return WebIDL::convert_to_int<WebIDL::LongLong>(vm, arg0, WebIDL::EnforceRange::No, WebIDL::Clamp::No); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->expire_cookies_with_time_offset(seconds); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::delete_all_cookies)
{
    WebIDL::log_trace(vm, "InternalsPrototype::delete_all_cookies");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    auto steps = [&realm, &vm]() -> JS::ThrowCompletionOr<GC::Ref<WebIDL::Promise>> {
        (void)realm;
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->delete_all_cookies(); }));
        return R;
    };

    auto maybe_R = steps();

    // And then, if an exception E was thrown:
    // 1. If op has a return type that is a promise type, then return ! Call(%Promise.reject%, %Promise%, «E»).
    // 2. Otherwise, end these steps and allow the exception to propagate.
    if (maybe_R.is_throw_completion())
        return WebIDL::create_rejected_promise(realm, maybe_R.error_value())->promise();

    return GC::Ref { as<JS::Promise>(*maybe_R.release_value()->promise()) };
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::set_http_memory_cache_enabled)
{
    WebIDL::log_trace(vm, "InternalsPrototype::set_http_memory_cache_enabled");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "setHttpMemoryCacheEnabled");

    auto arg0 = vm.argument(0);
    auto enabled = TRY(throw_dom_exception_if_needed(vm, [&] { return arg0.to_boolean(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->set_http_memory_cache_enabled(enabled); }));
    return JS::Value(R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::set_content_blockers)
{
    WebIDL::log_trace(vm, "InternalsPrototype::set_content_blockers");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "setContentBlockers");

    auto arg0 = vm.argument(0);
    auto patterns = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<String> {
        return TRY(WebIDL::to_string(vm, arg0));
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->set_content_blockers(patterns); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::set_content_blocking_enabled)
{
    WebIDL::log_trace(vm, "InternalsPrototype::set_content_blocking_enabled");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "setContentBlockingEnabled");

    auto arg0 = vm.argument(0);
    auto enabled = TRY(throw_dom_exception_if_needed(vm, [&] { return arg0.to_boolean(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->set_content_blocking_enabled(enabled); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::set_autoplay_policy)
{
    WebIDL::log_trace(vm, "InternalsPrototype::set_autoplay_policy");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "setAutoplayPolicy");

    auto arg0 = vm.argument(0);
    auto policy = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<String> {
        return TRY(WebIDL::to_string(vm, arg0));
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->set_autoplay_policy(policy); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::get_computed_role)
{
    WebIDL::log_trace(vm, "InternalsPrototype::get_computed_role");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "getComputedRole");

    auto arg0 = vm.argument(0);
    auto element = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<GC::Ref<DOM::Element>> {
        if (auto impl = arg0.as_if<DOM::Element>())
            return *impl;
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "Element");
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->get_computed_role(element); }));
    return WebIDL::primitive_string_from_string(vm, R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::get_computed_label)
{
    WebIDL::log_trace(vm, "InternalsPrototype::get_computed_label");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "getComputedLabel");

    auto arg0 = vm.argument(0);
    auto element = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<GC::Ref<DOM::Element>> {
        if (auto impl = arg0.as_if<DOM::Element>())
            return *impl;
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "Element");
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->get_computed_label(element); }));
    return WebIDL::primitive_string_from_string(vm, R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::get_computed_aria_level)
{
    WebIDL::log_trace(vm, "InternalsPrototype::get_computed_aria_level");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "getComputedAriaLevel");

    auto arg0 = vm.argument(0);
    auto element = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<GC::Ref<DOM::Element>> {
        if (auto impl = arg0.as_if<DOM::Element>())
            return *impl;
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "Element");
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->get_computed_aria_level(element); }));
    return WebIDL::primitive_string_from_string(vm, R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::get_echo_server_port)
{
    WebIDL::log_trace(vm, "InternalsPrototype::get_echo_server_port");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->get_echo_server_port(); }));
    return JS::Value(static_cast<WebIDL::UnsignedShort>(R));
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::set_hsts_policy)
{
    WebIDL::log_trace(vm, "InternalsPrototype::set_hsts_policy");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 3)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountMany, "setHSTSPolicy", "3");

    auto arg0 = vm.argument(0);
    auto domain = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<String> {
        return TRY(WebIDL::to_string(vm, arg0));
    }(); }));

    auto arg1 = vm.argument(1);
    auto max_age = TRY(throw_dom_exception_if_needed(vm, [&] { return WebIDL::convert_to_int<WebIDL::UnsignedLongLong>(vm, arg1, WebIDL::EnforceRange::No, WebIDL::Clamp::No); }));

    auto arg2 = vm.argument(2);
    auto include_sub_domains = TRY(throw_dom_exception_if_needed(vm, [&] { return arg2.to_boolean(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->set_hsts_policy(domain, max_age, include_sub_domains); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::ingest_hsts_header)
{
    WebIDL::log_trace(vm, "InternalsPrototype::ingest_hsts_header");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 2)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountMany, "ingestHSTSHeader", "2");

    auto arg0 = vm.argument(0);
    auto url = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<String> {
        return TRY(WebIDL::to_usv_string(vm, arg0));
    }(); }));

    auto arg1 = vm.argument(1);
    auto header_value = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<String> {
        return TRY(WebIDL::to_string(vm, arg1));
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->ingest_hsts_header(url, header_value); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::is_known_hsts_host)
{
    WebIDL::log_trace(vm, "InternalsPrototype::is_known_hsts_host");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "isKnownHSTSHost");

    auto arg0 = vm.argument(0);
    auto domain = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<String> {
        return TRY(WebIDL::to_string(vm, arg0));
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->is_known_hsts_host(domain); }));
    return JS::Value(R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::set_browser_zoom)
{
    WebIDL::log_trace(vm, "InternalsPrototype::set_browser_zoom");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "setBrowserZoom");

    auto arg0 = vm.argument(0);
    auto factor = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg0.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "factor");
        return x;
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->set_browser_zoom(factor); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::set_device_pixel_ratio)
{
    WebIDL::log_trace(vm, "InternalsPrototype::set_device_pixel_ratio");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "setDevicePixelRatio");

    auto arg0 = vm.argument(0);
    auto ratio = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg0.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "ratio");
        return x;
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->set_device_pixel_ratio(ratio); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::dump_display_list)
{
    WebIDL::log_trace(vm, "InternalsPrototype::dump_display_list");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->dump_display_list(); }));
    return WebIDL::primitive_string_from_string(vm, R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::dump_accessibility_tree)
{
    WebIDL::log_trace(vm, "InternalsPrototype::dump_accessibility_tree");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->dump_accessibility_tree(); }));
    return WebIDL::primitive_string_from_string(vm, R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::dump_layout_tree)
{
    WebIDL::log_trace(vm, "InternalsPrototype::dump_layout_tree");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "dumpLayoutTree");

    auto arg0 = vm.argument(0);
    auto node = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<GC::Ref<DOM::Node>> {
        if (auto impl = arg0.as_if<DOM::Node>())
            return *impl;
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "Node");
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->dump_layout_tree(node); }));
    return WebIDL::primitive_string_from_string(vm, R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::dump_paintable_tree)
{
    WebIDL::log_trace(vm, "InternalsPrototype::dump_paintable_tree");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "dumpPaintableTree");

    auto arg0 = vm.argument(0);
    auto node = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<GC::Ref<DOM::Node>> {
        if (auto impl = arg0.as_if<DOM::Node>())
            return *impl;
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "Node");
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->dump_paintable_tree(node); }));
    return WebIDL::primitive_string_from_string(vm, R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::dump_stacking_context_tree)
{
    WebIDL::log_trace(vm, "InternalsPrototype::dump_stacking_context_tree");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->dump_stacking_context_tree(); }));
    return WebIDL::primitive_string_from_string(vm, R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::dump_gc_graph)
{
    WebIDL::log_trace(vm, "InternalsPrototype::dump_gc_graph");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->dump_gc_graph(); }));
    return WebIDL::primitive_string_from_string(vm, R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::dump_session_history)
{
    WebIDL::log_trace(vm, "InternalsPrototype::dump_session_history");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->dump_session_history(); }));
    return WebIDL::primitive_string_from_string(vm, R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::dump_ui_process_session_history)
{
    WebIDL::log_trace(vm, "InternalsPrototype::dump_ui_process_session_history");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->dump_ui_process_session_history(); }));
    return WebIDL::primitive_string_from_string(vm, R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::dump_site_isolation_process_tree)
{
    WebIDL::log_trace(vm, "InternalsPrototype::dump_site_isolation_process_tree");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->dump_site_isolation_process_tree(); }));
    return WebIDL::primitive_string_from_string(vm, R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::flush_session_history_traversal_queue)
{
    WebIDL::log_trace(vm, "InternalsPrototype::flush_session_history_traversal_queue");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    auto steps = [&realm, &vm]() -> JS::ThrowCompletionOr<GC::Ref<WebIDL::Promise>> {
        (void)realm;
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->flush_session_history_traversal_queue(); }));
        return R;
    };

    auto maybe_R = steps();

    // And then, if an exception E was thrown:
    // 1. If op has a return type that is a promise type, then return ! Call(%Promise.reject%, %Promise%, «E»).
    // 2. Otherwise, end these steps and allow the exception to propagate.
    if (maybe_R.is_throw_completion())
        return WebIDL::create_rejected_promise(realm, maybe_R.error_value())->promise();

    return GC::Ref { as<JS::Promise>(*maybe_R.release_value()->promise()) };
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::clobber_next_navigation_with_a_traversal)
{
    WebIDL::log_trace(vm, "InternalsPrototype::clobber_next_navigation_with_a_traversal");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->clobber_next_navigation_with_a_traversal(); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::get_shadow_root)
{
    WebIDL::log_trace(vm, "InternalsPrototype::get_shadow_root");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "getShadowRoot");

    auto arg0 = vm.argument(0);
    auto element = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<GC::Ref<DOM::Element>> {
        if (auto impl = arg0.as_if<DOM::Element>())
            return *impl;
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "Element");
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->get_shadow_root(element); }));
    return [&]() -> JS::Value {
        // 1. If the IDL nullable type T? value is null, then the JavaScript value is null.
        if (!R)
            return JS::js_null();

        // 2. Otherwise, the JavaScript value is the result of converting the IDL nullable type value to the inner IDL type T.
        return JS::Value(JS::Value(R));
    }();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::handle_sdl_input_events)
{
    WebIDL::log_trace(vm, "InternalsPrototype::handle_sdl_input_events");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->handle_sdl_input_events(); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::set_environments_top_level_url)
{
    WebIDL::log_trace(vm, "InternalsPrototype::set_environments_top_level_url");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "setEnvironmentsTopLevelURL");

    auto arg0 = vm.argument(0);
    auto url = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<String> {
        return TRY(WebIDL::to_usv_string(vm, arg0));
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->set_environments_top_level_url(url); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::connect_virtual_gamepad)
{
    WebIDL::log_trace(vm, "InternalsPrototype::connect_virtual_gamepad");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->connect_virtual_gamepad(); }));
    return JS::Value(R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::set_highlighted_node)
{
    WebIDL::log_trace(vm, "InternalsPrototype::set_highlighted_node");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "setHighlightedNode");

    auto arg0 = vm.argument(0);
    auto node = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<GC::Ptr<DOM::Node>> {
        GC::Ptr<DOM::Node> value;

        if (!arg0.is_nullish()) {

            value = TRY([&]() -> JS::ThrowCompletionOr<GC::Ref<DOM::Node>> {
        if (auto impl = arg0.as_if<DOM::Node>())
            return *impl;
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "Node");
    }());
        }
        return value;
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->set_highlighted_node(node); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::clear_element)
{
    WebIDL::log_trace(vm, "InternalsPrototype::clear_element");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "clearElement");

    auto arg0 = vm.argument(0);
    auto element = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<GC::Ref<HTML::HTMLElement>> {
        if (auto impl = arg0.as_if<HTML::HTMLElement>())
            return *impl;
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "HTMLElement");
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->clear_element(element); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::get_style_invalidation_counters)
{
    WebIDL::log_trace(vm, "InternalsPrototype::get_style_invalidation_counters");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->get_style_invalidation_counters(); }));
    return JS::Value(R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::reset_style_invalidation_counters)
{
    WebIDL::log_trace(vm, "InternalsPrototype::reset_style_invalidation_counters");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->reset_style_invalidation_counters(); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::update_style)
{
    WebIDL::log_trace(vm, "InternalsPrototype::update_style");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->update_style(); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::set_preferred_color_scheme)
{
    WebIDL::log_trace(vm, "InternalsPrototype::set_preferred_color_scheme");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "setPreferredColorScheme");

    auto arg0 = vm.argument(0);
    auto color_scheme = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<String> {
        return TRY(WebIDL::to_string(vm, arg0));
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->set_preferred_color_scheme(color_scheme); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::set_page_focus)
{
    WebIDL::log_trace(vm, "InternalsPrototype::set_page_focus");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "setPageFocus");

    auto arg0 = vm.argument(0);
    auto has_focus = TRY(throw_dom_exception_if_needed(vm, [&] { return arg0.to_boolean(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->set_page_focus(has_focus); }));
    return JS::js_undefined();
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::canvas_color_scheme)
{
    WebIDL::log_trace(vm, "InternalsPrototype::canvas_color_scheme");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->canvas_color_scheme(); }));
    return WebIDL::primitive_string_from_string(vm, R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::style_sheet_may_have_has_selectors)
{
    WebIDL::log_trace(vm, "InternalsPrototype::style_sheet_may_have_has_selectors");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "styleSheetMayHaveHasSelectors");

    auto arg0 = vm.argument(0);
    auto sheet = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<GC::Ref<CSS::CSSStyleSheet>> {
        if (auto impl = arg0.as_if<CSS::CSSStyleSheet>())
            return *impl;
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "CSSStyleSheet");
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->style_sheet_may_have_has_selectors(sheet); }));
    return JS::Value(R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::image_animation_state_for_url)
{
    WebIDL::log_trace(vm, "InternalsPrototype::image_animation_state_for_url");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 1)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "imageAnimationStateForURL");

    auto arg0 = vm.argument(0);
    auto url = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<String> {
        return TRY(WebIDL::to_usv_string(vm, arg0));
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->image_animation_state_for_url(url); }));
    return JS::Value(R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::async_scrolling_state)
{
    WebIDL::log_trace(vm, "InternalsPrototype::async_scrolling_state");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->async_scrolling_state(); }));
    return JS::Value(R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::async_scrolling_state_blocks_wheel_event_at)
{
    WebIDL::log_trace(vm, "InternalsPrototype::async_scrolling_state_blocks_wheel_event_at");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 2)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountMany, "asyncScrollingStateBlocksWheelEventAt", "2");

    auto arg0 = vm.argument(0);
    auto x = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg0.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "x");
        return x;
    }(); }));

    auto arg1 = vm.argument(1);
    auto y = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg1.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "y");
        return x;
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->async_scrolling_state_blocks_wheel_event_at(x, y); }));
    return JS::Value(R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::async_scrolling_state_can_wheel_scroll_at)
{
    WebIDL::log_trace(vm, "InternalsPrototype::async_scrolling_state_can_wheel_scroll_at");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 4)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountMany, "asyncScrollingStateCanWheelScrollAt", "4");

    auto arg0 = vm.argument(0);
    auto x = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg0.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "x");
        return x;
    }(); }));

    auto arg1 = vm.argument(1);
    auto y = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg1.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "y");
        return x;
    }(); }));

    auto arg2 = vm.argument(2);
    auto delta_x = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg2.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "deltaX");
        return x;
    }(); }));

    auto arg3 = vm.argument(3);
    auto delta_y = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg3.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "deltaY");
        return x;
    }(); }));

    auto arg4 = vm.argument(4);
    bool force_stale_wheel_event_regions = false;
    if (!arg4.is_undefined())
        force_stale_wheel_event_regions = TRY(throw_dom_exception_if_needed(vm, [&] { return arg4.to_boolean(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->async_scrolling_state_can_wheel_scroll_at(x, y, delta_x, delta_y, force_stale_wheel_event_regions); }));
    return JS::Value(R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::async_scrolling_state_wheel_routing_admission)
{
    WebIDL::log_trace(vm, "InternalsPrototype::async_scrolling_state_wheel_routing_admission");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->async_scrolling_state_wheel_routing_admission(); }));
    return WebIDL::primitive_string_from_string(vm, R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::async_scrolling_state_wheel_scroll_admission_at)
{
    WebIDL::log_trace(vm, "InternalsPrototype::async_scrolling_state_wheel_scroll_admission_at");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 4)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountMany, "asyncScrollingStateWheelScrollAdmissionAt", "4");

    auto arg0 = vm.argument(0);
    auto x = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg0.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "x");
        return x;
    }(); }));

    auto arg1 = vm.argument(1);
    auto y = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg1.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "y");
        return x;
    }(); }));

    auto arg2 = vm.argument(2);
    auto delta_x = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg2.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "deltaX");
        return x;
    }(); }));

    auto arg3 = vm.argument(3);
    auto delta_y = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg3.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "deltaY");
        return x;
    }(); }));

    auto arg4 = vm.argument(4);
    bool force_stale_wheel_event_regions = false;
    if (!arg4.is_undefined())
        force_stale_wheel_event_regions = TRY(throw_dom_exception_if_needed(vm, [&] { return arg4.to_boolean(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->async_scrolling_state_wheel_scroll_admission_at(x, y, delta_x, delta_y, force_stale_wheel_event_regions); }));
    return WebIDL::primitive_string_from_string(vm, R);
}

JS_DEFINE_NATIVE_FUNCTION(InternalsPrototype::async_scrolling_state_wheel_target_at)
{
    WebIDL::log_trace(vm, "InternalsPrototype::async_scrolling_state_wheel_target_at");
    [[maybe_unused]] auto& realm = *vm.current_realm();
    [[maybe_unused]] Internals::Internals* idl_object = TRY(impl_from(vm));

    if (vm.argument_count() < 4)
        return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountMany, "asyncScrollingStateWheelTargetAt", "4");

    auto arg0 = vm.argument(0);
    auto x = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg0.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "x");
        return x;
    }(); }));

    auto arg1 = vm.argument(1);
    auto y = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg1.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "y");
        return x;
    }(); }));

    auto arg2 = vm.argument(2);
    auto delta_x = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg2.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "deltaX");
        return x;
    }(); }));

    auto arg3 = vm.argument(3);
    auto delta_y = TRY(throw_dom_exception_if_needed(vm, [&] { return [&]() -> JS::ThrowCompletionOr<double> {
        auto x = TRY(arg3.to_double(vm));
        if (isinf(x) || isnan(x))
            return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidRestrictedFloatingPointParameter, "deltaY");
        return x;
    }(); }));

    [[maybe_unused]] auto R = TRY(throw_dom_exception_if_needed(vm, [&] { return idl_object->async_scrolling_state_wheel_target_at(x, y, delta_x, delta_y); }));
    return WebIDL::primitive_string_from_string(vm, R);
}

} // namespace Web::Bindings
