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

Move Request handling into Runtime. #263

Merged
merged 2 commits into from May 13, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Move Request handling into Runtime (fixes #259).

  • Loading branch information
Ms2ger committed May 13, 2016
commit b52a19a67d64f971741129c9e37be3b6f970b2f1
@@ -31,7 +31,7 @@ use jsapi::{MutableHandleValue, HandleValue, HandleObject, HandleBase};
use jsapi::AutoObjectVector;
use jsapi::{ToBooleanSlow, ToNumberSlow, ToStringSlow};
use jsapi::{ToInt32Slow, ToUint32Slow, ToUint16Slow, ToInt64Slow, ToUint64Slow};
use jsapi::{JSAutoRequest, JS_BeginRequest, JS_EndRequest};
use jsapi::{JS_BeginRequest, JS_EndRequest};
use jsapi::{JSAutoCompartment, JS_EnterCompartment, JS_LeaveCompartment};
use jsapi::{JSJitMethodCallArgs, JSJitGetterCallArgs, JSJitSetterCallArgs, CallArgs};
use jsapi::{NullHandleValue, UndefinedHandleValue, JSID_VOID};
@@ -146,6 +146,8 @@ impl Runtime {
(*contextopts).set_autoJSAPIOwnsErrorReporting_(true);
JS_SetErrorReporter(js_runtime, Some(reportError));

JS_BeginRequest(js_context);

Runtime {
rt: js_runtime,
cx: js_context,
@@ -176,7 +178,6 @@ impl Runtime {
(script_utf16.as_ptr(), script_utf16.len() as c_uint)
};
assert!(!ptr.is_null());
let _ar = JSAutoRequest::new(self.cx());
let _ac = JSAutoCompartment::new(self.cx(), glob.get());
let options = CompileOptionsWrapper::new(self.cx(), filename_cstr.as_ptr(), line_num);

@@ -197,6 +198,7 @@ impl Runtime {
impl Drop for Runtime {
fn drop(&mut self) {
unsafe {
JS_EndRequest(self.cx);
JS_DestroyContext(self.cx);
JS_DestroyRuntime(self.rt);
}
@@ -559,24 +561,6 @@ impl<T: GCMethods<T> + Copy> Drop for Heap<T> {
// ___________________________________________________________________________
// Implementations for various things in jsapi.rs

impl JSAutoRequest {
pub fn new(cx: *mut JSContext) -> JSAutoRequest {
unsafe { JS_BeginRequest(cx); }
JSAutoRequest {
mContext: cx
}
}
}

impl Drop for JSAutoRequest {
fn drop(&mut self) {
if self.mContext as usize == mem::POST_DROP_USIZE {
return;
}
unsafe { JS_EndRequest(self.mContext); }
}
}

impl JSAutoCompartment {
pub fn new(cx: *mut JSContext, target: *mut JSObject) -> JSAutoCompartment {
JSAutoCompartment {
@@ -8,7 +8,6 @@ extern crate libc;
use js::jsapi::CallArgs;
use js::jsapi::CompartmentOptions;
use js::jsapi::JSAutoCompartment;
use js::jsapi::JSAutoRequest;
use js::jsapi::JSContext;
use js::jsapi::JS_DefineFunction;
use js::jsapi::JS_EncodeStringToUTF8;
@@ -36,7 +35,6 @@ fn callback() {

let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook;
let c_option = CompartmentOptions::default();
let _ar = JSAutoRequest::new(context);
let global = JS_NewGlobalObject(context, &SIMPLE_GLOBAL_CLASS, ptr::null_mut(), h_option, &c_option);
let global_root = Rooted::new(context, global);
let global = global_root.handle();
@@ -6,7 +6,6 @@ extern crate js;
extern crate libc;

use js::jsapi::CompartmentOptions;
use js::jsapi::JSAutoRequest;
use js::jsapi::JS_Init;
use js::jsapi::JS_NewGlobalObject;
use js::jsapi::OnNewGlobalHookOption;
@@ -23,7 +22,6 @@ fn evaluate() {
assert!(JS_Init());
let rt = Runtime::new();
let cx = rt.cx();
let _ar = JSAutoRequest::new(cx);

let global = RootedObject::new(cx,
JS_NewGlobalObject(cx, &SIMPLE_GLOBAL_CLASS, ptr::null_mut(),
@@ -5,7 +5,6 @@
extern crate js;

use js::jsapi::CompartmentOptions;
use js::jsapi::JSAutoRequest;
use js::jsapi::JS_Init;
use js::jsapi::JS_NewGlobalObject;
use js::jsapi::OnNewGlobalHookOption;
@@ -23,7 +22,6 @@ fn stack_limit() {

let rt = Runtime::new();
let cx = rt.cx();
let _ar = JSAutoRequest::new(cx);

let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook;
let c_option = CompartmentOptions::default();
@@ -9,7 +9,6 @@ use js::conversions::FromJSValConvertible;
use js::conversions::ToJSValConvertible;
use js::jsapi::CompartmentOptions;
use js::jsapi::JSAutoCompartment;
use js::jsapi::JSAutoRequest;
use js::jsapi::JS_Init;
use js::jsapi::JS_NewGlobalObject;
use js::jsapi::OnNewGlobalHookOption;
@@ -27,7 +26,6 @@ fn vec_conversion() {

let rt = Runtime::new();
let cx = rt.cx();
let _ar = JSAutoRequest::new(cx);

let h_option = OnNewGlobalHookOption::FireOnNewGlobalHook;
let c_option = CompartmentOptions::default();
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.