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

Wrap all the code in Runtime::new in a single unsafe block. #250

Merged
merged 1 commit into from Mar 30, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -109,33 +109,25 @@ pub struct Runtime {
impl Runtime {
/// Creates a new `JSRuntime` and `JSContext`.
pub fn new() -> Runtime {
let js_runtime = unsafe {
JS_NewRuntime(default_heapsize, ChunkSize as u32, ptr::null_mut())
};
assert!(!js_runtime.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 {
let js_runtime = JS_NewRuntime(default_heapsize, ChunkSize as u32, ptr::null_mut());
assert!(!js_runtime.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.
JS_SetGCParameter(js_runtime, JSGCParamKey::JSGC_MAX_BYTES, u32::MAX);
}

unsafe {
JS_SetNativeStackQuota(js_runtime,
STACK_QUOTA,
STACK_QUOTA - SYSTEM_CODE_BUFFER,
STACK_QUOTA - SYSTEM_CODE_BUFFER - TRUSTED_SCRIPT_BUFFER);
}

let js_context = unsafe {
JS_NewContext(js_runtime, default_stacksize as size_t)
};
assert!(!js_context.is_null());
let js_context = JS_NewContext(js_runtime, default_stacksize as size_t);
assert!(!js_context.is_null());

unsafe {
let runtimeopts = RuntimeOptionsRef(js_runtime);
let contextopts = ContextOptionsRef(js_context);

@@ -147,11 +139,11 @@ impl Runtime {
(*contextopts).set_dontReportUncaught_(true);
(*contextopts).set_autoJSAPIOwnsErrorReporting_(true);
JS_SetErrorReporter(js_runtime, Some(reportError));
}

Runtime {
rt: js_runtime,
cx: js_context,
Runtime {
rt: js_runtime,
cx: js_context,
}
}
}

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