script_bindings/mem.rs
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5//! Routines for handling measuring the memory usage of arbitrary DOM nodes.
6
7use std::os::raw::c_void;
8
9use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
10
11/// Used by codegen to include the pointer to the `MallocSizeOf` implementation of each
12/// IDL interface. This way we don't have to find the most-derived interface of DOM
13/// objects by hand in code.
14#[allow(unsafe_code)]
15pub(crate) unsafe fn malloc_size_of_including_raw_self<T: MallocSizeOf>(
16 ops: &mut MallocSizeOfOps,
17 obj: *const c_void,
18) -> usize {
19 unsafe { ops.malloc_size_of(obj) + (*(obj as *const T)).size_of(ops) }
20}