Nacre/vendor/servo-script/dom/bindings/like.rs
astar76 0ecfd0f573 S031: root due timers in vendored servo-script (R5-01 SIGSEGV), crash-adblock regression smoke
fire_timer moved due timers into an unrooted Vec; a GC inside one callback swept
the functions of the timers still waiting. Heavy-web reruns and cargo test still pending.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-12 20:38:47 -06:00

103 lines
3 KiB
Rust

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//! Implementation of `setlike<...>` and `maplike<..., ...>` WebIDL declarations.
/// Usage:
/// ```rust
/// pub(crate) struct TestBindingSetlike {
/// // setlike<DOMString>
/// internal: DomRefCell<IndexSet<DOMString>>,
/// }
/// impl Setlike for TestBindingSetlike {
/// type Key = DOMString;
/// setlike!(self, internal);
/// }
/// ```
#[macro_export]
macro_rules! setlike {
( $self:ident, $x:ident ) => {
#[inline(always)]
fn get_index(&$self, cx: &mut ::js::context::JSContext, index: u32) -> Option<Self::Key> {
$self.$x.get_index(cx, index)
}
#[inline(always)]
fn size(&$self, cx: &mut ::js::context::JSContext) -> u32 {
$self.$x.size(cx)
}
#[inline(always)]
fn add(&$self, cx: &mut ::js::context::JSContext, key: Self::Key) {
$self.$x.add(cx, key)
}
#[inline(always)]
fn has(&$self, cx: &mut ::js::context::JSContext, key: Self::Key) -> bool {
$self.$x.has(cx, key)
}
#[inline(always)]
fn clear(&$self, cx: &mut ::js::context::JSContext) {
$self.$x.clear(cx)
}
#[inline(always)]
fn delete(&$self, cx: &mut ::js::context::JSContext, key: Self::Key) -> bool {
$self.$x.delete(cx, key)
}
};
}
/// Usage:
/// ```rust
/// pub(crate) struct TestBindingMaplike {
/// // maplike<DOMString, long>
/// internal: DomRefCell<IndexMap<DOMString, i32>>,
/// }
/// impl Maplike for TestBindingSetlike {
/// type Key = DOMString;
/// type Value = i32;
/// maplike!(self, internal);
/// }
/// ```
#[macro_export]
macro_rules! maplike {
( $self:ident, $internal:ident ) => {
#[inline(always)]
fn get_index(&$self, cx: &mut ::js::context::JSContext, index: u32) -> Option<(Self::Key, Self::Value)> {
$self.$internal.get_index(cx, index)
}
#[inline(always)]
fn get(&$self, cx: &mut ::js::context::JSContext, key: Self::Key) -> Option<Self::Value> {
$self.$internal.get(cx, key)
}
#[inline(always)]
fn size(&$self, cx: &mut ::js::context::JSContext) -> u32 {
$self.$internal.size(cx)
}
#[inline(always)]
fn set(&$self, cx: &mut ::js::context::JSContext, key: Self::Key, value: Self::Value) {
$self.$internal.set(cx, key, value)
}
#[inline(always)]
fn has(&$self, cx: &mut ::js::context::JSContext, key: Self::Key) -> bool {
$self.$internal.has(cx, key)
}
#[inline(always)]
fn clear(&$self, cx: &mut ::js::context::JSContext) {
$self.$internal.clear(cx)
}
#[inline(always)]
fn delete(&$self, cx: &mut ::js::context::JSContext, key: Self::Key) -> bool {
$self.$internal.delete(cx, key)
}
};
}