/rust/git/checkouts/mozjs-fa11ffc7d4f1cc2d/d90edd1/mozjs-sys/src/lib.rs
Line | Count | Source |
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 http://mozilla.org/MPL/2.0/. */ |
4 | | |
5 | | #![allow(unused_extern_crates)] |
6 | | |
7 | | // These extern crates are needed for linking |
8 | | extern crate encoding_c; |
9 | | extern crate encoding_c_mem; |
10 | | extern crate icu_capi; |
11 | | extern crate libz_sys; |
12 | | |
13 | | // The jsimpls module just implements traits so can be private |
14 | | mod jsimpls; |
15 | | |
16 | | // Modules with public definitions |
17 | | pub mod glue; |
18 | | pub mod jsgc; |
19 | | pub mod jsid; |
20 | | pub mod jsval; |
21 | | |
22 | | // Reexport the bindings in the jsapi module |
23 | | pub use crate::generated::root as jsapi; |
24 | | |
25 | | // The bindings generated by bindgen |
26 | | #[doc(hidden)] |
27 | | mod generated { |
28 | | include!(concat!(env!("OUT_DIR"), "/build/jsapi.rs")); |
29 | | } |
30 | | |
31 | | /*fn panic_hook(info: &std::panic::PanicInfo) { |
32 | | eprint!("Panic from mozjs: {}", info); |
33 | | }*/ |
34 | | |
35 | | /// Configure a panic hook to redirect rust panics to MFBT's MOZ_Crash. |
36 | | /// See <https://searchfox.org/mozilla-esr115/source/mozglue/static/rust/lib.rs#106> |
37 | | #[no_mangle] |
38 | 1 | pub extern "C" fn install_rust_hooks() { |
39 | 1 | //std::panic::set_hook(Box::new(panic_hook)); |
40 | 1 | #[cfg(feature = "oom_with_hook")] |
41 | 1 | oom_hook::install(); |
42 | 1 | } |
43 | | |
44 | | #[cfg(feature = "oom_with_hook")] |
45 | | mod oom_hook { |
46 | | use std::alloc::{set_alloc_error_hook, Layout}; |
47 | | |
48 | | extern "C" { |
49 | | pub fn RustHandleOOM(size: usize) -> !; |
50 | | } |
51 | | |
52 | | pub fn hook(layout: Layout) { |
53 | | unsafe { |
54 | | RustHandleOOM(layout.size()); |
55 | | } |
56 | | } |
57 | | |
58 | | pub fn install() { |
59 | | set_alloc_error_hook(hook); |
60 | | } |
61 | | } |