Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various cleanup. #145

Merged
merged 3 commits into from May 9, 2015
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Inline JSContext creation into Runtime::new().

There is no reason for any consumer to call these functions manually.
  • Loading branch information
Ms2ger committed May 9, 2015
commit 524350ce333031871310393a5ad9a5be738f979a
@@ -49,10 +49,14 @@ impl Runtime {
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()
let js_context = unsafe {
JS_NewContext(js_runtime.ptr, default_stacksize as size_t)
};
assert!(!js_context.is_null());

let js_context = rc::Rc::new(Cx {
ptr: js_context,
rt: js_runtime.clone(),
});
js_context.set_default_options_and_version();
js_context.set_logging_error_reporter();
@@ -97,19 +101,6 @@ pub fn new_runtime(p: *mut JSRuntime) -> rt {
})
}

pub trait RtUtils {
fn cx(&self) -> rc::Rc<Cx>;
}

impl RtUtils for rc::Rc<rt_rsrc> {
fn cx(&self) -> rc::Rc<Cx> {
unsafe {
new_context(JS_NewContext(self.ptr,
default_stacksize as size_t), self.clone())
}
}
}

pub fn rt() -> rt {
unsafe {
let runtime = JS_Init(default_heapsize);
@@ -133,13 +124,6 @@ impl Drop for Cx {
}
}

pub fn new_context(ptr: *mut JSContext, rt: rt) -> rc::Rc<Cx> {
return rc::Rc::new(Cx {
ptr: ptr,
rt: rt,
})
}

impl Cx {
pub fn set_default_options_and_version(&self) {
self.set_options(JSOPTION_VAROBJFIX | JSOPTION_METHODJIT |
@@ -228,15 +212,13 @@ pub fn with_compartment<R, F: FnMut() -> R>(cx: *mut JSContext, object: *mut JSO

#[cfg(test)]
pub mod test {
use super::rt;
use super::RtUtils;
use super::Runtime;

#[test]
pub fn dummy() {
let rt = rt();
let cx = rt.cx();
cx.deref().set_default_options_and_version();
cx.deref().set_logging_error_reporter();
let rt = Runtime::new();
rt.cx.set_default_options_and_version();
rt.cx.set_logging_error_reporter();
}

}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.