mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Move Runtime to rust-mozjs.
This commit is contained in:
parent
2a5119ff37
commit
95e4e25924
4 changed files with 5 additions and 59 deletions
|
@ -74,11 +74,10 @@ use util::task_state;
|
||||||
use geom::Rect;
|
use geom::Rect;
|
||||||
use geom::point::Point2D;
|
use geom::point::Point2D;
|
||||||
use hyper::header::{LastModified, Headers};
|
use hyper::header::{LastModified, Headers};
|
||||||
use js::jsapi::{JS_SetWrapObjectCallbacks, JS_SetGCZeal, JS_SetExtraGCRootsTracer, JS_DEFAULT_ZEAL_FREQ};
|
use js::jsapi::{JS_SetWrapObjectCallbacks, JS_SetExtraGCRootsTracer};
|
||||||
use js::jsapi::{JSContext, JSRuntime, JSObject, JSTracer};
|
use js::jsapi::{JSContext, JSRuntime, JSObject, JSTracer};
|
||||||
use js::jsapi::{JS_SetGCParameter, JSGC_MAX_BYTES};
|
|
||||||
use js::jsapi::{JS_SetGCCallback, JSGCStatus, JSGC_BEGIN, JSGC_END};
|
use js::jsapi::{JS_SetGCCallback, JSGCStatus, JSGC_BEGIN, JSGC_END};
|
||||||
use js::rust::{Cx, RtUtils};
|
use js::rust::{Runtime, Cx, RtUtils};
|
||||||
use js;
|
use js;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
@ -93,7 +92,6 @@ use std::ptr;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::result::Result;
|
use std::result::Result;
|
||||||
use std::sync::mpsc::{channel, Sender, Receiver, Select};
|
use std::sync::mpsc::{channel, Sender, Receiver, Select};
|
||||||
use std::u32;
|
|
||||||
use time::Tm;
|
use time::Tm;
|
||||||
|
|
||||||
thread_local!(pub static STACK_ROOTS: Cell<Option<RootCollectionPtr>> = Cell::new(None));
|
thread_local!(pub static STACK_ROOTS: Cell<Option<RootCollectionPtr>> = Cell::new(None));
|
||||||
|
@ -240,58 +238,6 @@ impl Drop for StackRootTLS {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// A wrapper for the `JSRuntime` and `JSContext` structures in SpiderMonkey.
|
|
||||||
pub struct Runtime {
|
|
||||||
rt: js::rust::rt,
|
|
||||||
cx: Rc<Cx>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Runtime {
|
|
||||||
/// Creates a new `JSRuntime` and `JSContext`.
|
|
||||||
pub fn new() -> Runtime {
|
|
||||||
let js_runtime = js::rust::rt();
|
|
||||||
assert!({
|
|
||||||
let ptr: *mut JSRuntime = (*js_runtime).ptr;
|
|
||||||
!ptr.is_null()
|
|
||||||
});
|
|
||||||
|
|
||||||
// Unconstrain the runtime's threshold on nominal heap size, to avoid
|
|
||||||
// triggering GC too often if operating continuously near an arbitrary
|
|
||||||
// finite threshold. This leaves the maximum-JS_malloc-bytes threshold
|
|
||||||
// still in effect to cause periodical, and we hope hygienic,
|
|
||||||
// last-ditch GCs from within the GC's allocator.
|
|
||||||
unsafe {
|
|
||||||
JS_SetGCParameter(js_runtime.ptr, JSGC_MAX_BYTES, u32::MAX);
|
|
||||||
}
|
|
||||||
|
|
||||||
let js_context = js_runtime.cx();
|
|
||||||
assert!({
|
|
||||||
let ptr: *mut JSContext = (*js_context).ptr;
|
|
||||||
!ptr.is_null()
|
|
||||||
});
|
|
||||||
js_context.set_default_options_and_version();
|
|
||||||
js_context.set_logging_error_reporter();
|
|
||||||
unsafe {
|
|
||||||
JS_SetGCZeal((*js_context).ptr, 0, JS_DEFAULT_ZEAL_FREQ);
|
|
||||||
}
|
|
||||||
|
|
||||||
Runtime {
|
|
||||||
rt: js_runtime,
|
|
||||||
cx: js_context,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the `JSRuntime` object.
|
|
||||||
pub fn rt(&self) -> *mut JSRuntime {
|
|
||||||
self.rt.ptr
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the `JSContext` object.
|
|
||||||
pub fn cx(&self) -> *mut JSContext {
|
|
||||||
self.cx.ptr
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Information for an entire page. Pages are top-level browsing contexts and can contain multiple
|
/// Information for an entire page. Pages are top-level browsing contexts and can contain multiple
|
||||||
/// frames.
|
/// frames.
|
||||||
///
|
///
|
||||||
|
|
2
components/servo/Cargo.lock
generated
2
components/servo/Cargo.lock
generated
|
@ -479,7 +479,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "js"
|
name = "js"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/servo/rust-mozjs#9512c3c770774ed73a2fdcc635eee178cbd02ab1"
|
source = "git+https://github.com/servo/rust-mozjs#402b7b2db8816ffeccacfa9a8d316f4487e96ba0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"mozjs_sys 0.0.0 (git+https://github.com/servo/mozjs)",
|
"mozjs_sys 0.0.0 (git+https://github.com/servo/mozjs)",
|
||||||
|
|
2
ports/cef/Cargo.lock
generated
2
ports/cef/Cargo.lock
generated
|
@ -482,7 +482,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "js"
|
name = "js"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/servo/rust-mozjs#9512c3c770774ed73a2fdcc635eee178cbd02ab1"
|
source = "git+https://github.com/servo/rust-mozjs#402b7b2db8816ffeccacfa9a8d316f4487e96ba0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"mozjs_sys 0.0.0 (git+https://github.com/servo/mozjs)",
|
"mozjs_sys 0.0.0 (git+https://github.com/servo/mozjs)",
|
||||||
|
|
2
ports/gonk/Cargo.lock
generated
2
ports/gonk/Cargo.lock
generated
|
@ -415,7 +415,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "js"
|
name = "js"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/servo/rust-mozjs#9512c3c770774ed73a2fdcc635eee178cbd02ab1"
|
source = "git+https://github.com/servo/rust-mozjs#402b7b2db8816ffeccacfa9a8d316f4487e96ba0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"mozjs_sys 0.0.0 (git+https://github.com/servo/mozjs)",
|
"mozjs_sys 0.0.0 (git+https://github.com/servo/mozjs)",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue