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

Merge the context and runtime structs into Runtime. #149

Merged
merged 4 commits into from May 10, 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

Prev

Remove reference counting from the Runtime implementation.

It is now returned by value, as is customary in Rust.
  • Loading branch information
Ms2ger committed May 10, 2015
commit 18f507903856a814f12cce2ffda8065695d8f485
@@ -7,7 +7,6 @@
use libc::types::os::arch::c95::{size_t, c_uint};
use libc::c_char;
use std::ffi;
use std::rc;
use std::str;
use std::u32;
use jsapi::*;
@@ -26,10 +25,9 @@ use ERR;
// friendly Rustic API to runtimes

/// A wrapper for the `JSRuntime` and `JSContext` structures in SpiderMonkey.
#[derive(Clone)]
pub struct Runtime {
pub rt: rt,
pub cx: rc::Rc<Cx>,
rt: *mut JSRuntime,
cx: *mut JSContext,
}

impl Runtime {
@@ -67,13 +65,6 @@ impl Runtime {
JS_SetGCZeal(js_context, 0, JS_DEFAULT_ZEAL_FREQ);
}

let js_runtime = rc::Rc::new(rt_rsrc {
ptr: js_runtime
});
let js_context = rc::Rc::new(Cx {
ptr: js_context,
rt: js_runtime.clone(),
});
Runtime {
rt: js_runtime,
cx: js_context,
@@ -82,12 +73,12 @@ impl Runtime {

/// Returns the `JSRuntime` object.
pub fn rt(&self) -> *mut JSRuntime {
self.rt.ptr
self.rt
}

/// Returns the `JSContext` object.
pub fn cx(&self) -> *mut JSContext {
self.cx.ptr
self.cx
}

pub fn evaluate_script(&self, global: *mut JSObject, script: String,
@@ -125,32 +116,11 @@ impl Runtime {
}
}

pub type rt = rc::Rc<rt_rsrc>;

pub struct rt_rsrc {
pub ptr : *mut JSRuntime,
}

impl Drop for rt_rsrc {
fn drop(&mut self) {
unsafe {
JS_Finish(self.ptr);
}
}
}

// ___________________________________________________________________________
// contexts

pub struct Cx {
pub ptr: *mut JSContext,
pub rt: rt,
}

impl Drop for Cx {
impl Drop for Runtime {
fn drop(&mut self) {
unsafe {
JS_DestroyContext(self.ptr);
JS_DestroyContext(self.cx);
JS_Finish(self.rt);
}
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.