summaryrefslogtreecommitdiffstats
path: root/js/rust/tests/runtime.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /js/rust/tests/runtime.rs
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--js/rust/tests/runtime.rs59
1 files changed, 59 insertions, 0 deletions
diff --git a/js/rust/tests/runtime.rs b/js/rust/tests/runtime.rs
new file mode 100644
index 0000000000..ac69f5034b
--- /dev/null
+++ b/js/rust/tests/runtime.rs
@@ -0,0 +1,59 @@
+/* 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 http://mozilla.org/MPL/2.0/. */
+
+#[macro_use]
+extern crate js;
+extern crate libc;
+
+use js::jsapi::*;
+use js::rust::{Runtime, SIMPLE_GLOBAL_CLASS};
+use std::ptr;
+
+#[test]
+fn runtime() {
+ unsafe {
+ let runtime = Runtime::new(false).unwrap();
+
+ let cx = runtime.cx();
+ let h_option = JS::OnNewGlobalHookOption::FireOnNewGlobalHook;
+ let c_option = JS::RealmOptions::default();
+
+ rooted!(in(cx) let global = JS_NewGlobalObject(cx,
+ &SIMPLE_GLOBAL_CLASS,
+ ptr::null_mut(),
+ h_option,
+ &c_option));
+ let _ar = js::ar::AutoRealm::with_obj(cx, global.get());
+ rooted!(in(cx) let _object = JS_NewObject(cx, &CLASS as *const _));
+ }
+
+ assert!(Runtime::new(false).is_err());
+}
+
+unsafe extern "C" fn finalize(_fop: *mut JSFreeOp, _object: *mut JSObject) {
+ assert!(!Runtime::get().is_null());
+}
+
+static CLASS_OPS: JSClassOps = JSClassOps {
+ addProperty: None,
+ delProperty: None,
+ enumerate: None,
+ newEnumerate: None,
+ resolve: None,
+ mayResolve: None,
+ finalize: Some(finalize),
+ call: None,
+ hasInstance: None,
+ construct: None,
+ trace: None,
+};
+
+static CLASS: JSClass = JSClass {
+ name: b"EventTargetPrototype\0" as *const u8 as *const libc::c_char,
+ flags: 0 | JSCLASS_FOREGROUND_FINALIZE,
+ cOps: &CLASS_OPS as *const JSClassOps,
+ spec: 0 as *mut _,
+ ext: 0 as *mut _,
+ oOps: 0 as *mut _,
+};