2017-09-05 19:26:21 +03:00
|
|
|
/* 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 {
|
2017-11-27 23:58:00 +03:00
|
|
|
let runtime = Runtime::new(false).unwrap();
|
2017-09-05 19:26:21 +03:00
|
|
|
|
|
|
|
let cx = runtime.cx();
|
|
|
|
let h_option = JS::OnNewGlobalHookOption::FireOnNewGlobalHook;
|
2018-05-17 11:59:45 +03:00
|
|
|
let c_option = JS::RealmOptions::default();
|
2017-09-05 19:26:21 +03:00
|
|
|
|
|
|
|
rooted!(in(cx) let global = JS_NewGlobalObject(cx,
|
|
|
|
&SIMPLE_GLOBAL_CLASS,
|
|
|
|
ptr::null_mut(),
|
|
|
|
h_option,
|
|
|
|
&c_option));
|
2018-08-14 15:25:48 +03:00
|
|
|
let _ar = js::ar::AutoRealm::with_obj(cx, global.get());
|
2017-09-05 19:26:21 +03:00
|
|
|
rooted!(in(cx) let _object = JS_NewObject(cx, &CLASS as *const _));
|
|
|
|
}
|
|
|
|
|
2017-11-27 23:58:00 +03:00
|
|
|
assert!(Runtime::new(false).is_err());
|
2017-09-05 19:26:21 +03:00
|
|
|
}
|
|
|
|
|
2020-02-27 13:29:46 +03:00
|
|
|
unsafe extern "C" fn finalize(_fop: *mut JSFreeOp, _object: *mut JSObject) {
|
2017-09-05 19:26:21 +03:00
|
|
|
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,
|
2019-08-15 11:32:22 +03:00
|
|
|
spec: 0 as *mut _,
|
|
|
|
ext: 0 as *mut _,
|
2020-02-27 13:29:46 +03:00
|
|
|
oOps: 0 as *mut _,
|
2017-09-05 19:26:21 +03:00
|
|
|
};
|