Update js.

This commit is contained in:
Ms2ger 2016-11-15 10:55:32 +01:00 committed by Anthony Ramine
parent 1888ffdb42
commit e367822b3e
7 changed files with 18 additions and 62 deletions

View file

@ -2377,8 +2377,8 @@ class CGAbstractMethod(CGThing):
if self.catchPanic:
body = CGWrapper(CGIndenter(body),
pre="return wrap_panic(|| {\n",
post=("""}, %s);""" % ("()" if self.returnType == "void" else "false")))
pre="return wrap_panic(panic::AssertUnwindSafe(|| {\n",
post=("""}), %s);""" % ("()" if self.returnType == "void" else "false")))
return CGWrapper(CGIndenter(body),
pre=self.definition_prologue(),
@ -5496,6 +5496,8 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
'js::glue::RUST_JSID_IS_STRING',
'js::glue::RUST_SYMBOL_TO_JSID',
'js::glue::int_to_jsid',
'js::panic::maybe_resume_unwind',
'js::panic::wrap_panic',
'js::rust::GCMethods',
'js::rust::define_methods',
'js::rust::define_properties',
@ -5547,7 +5549,6 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
'dom::bindings::utils::resolve_global',
'dom::bindings::utils::set_dictionary_property',
'dom::bindings::utils::trace_global',
'dom::bindings::utils::wrap_panic',
'dom::bindings::trace::JSTraceable',
'dom::bindings::trace::RootedTraceable',
'dom::bindings::callback::CallSetup',
@ -5599,7 +5600,6 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
'mem::heap_size_of_raw_self_and_children',
'libc',
'util::prefs::PREFS',
'script_runtime::maybe_take_panic_result',
'std::borrow::ToOwned',
'std::cmp',
'std::mem',
@ -6596,9 +6596,7 @@ class CallbackMethod(CallbackMember):
" length_: ${argc} as ::libc::size_t,\n"
" elements_: ${argv}\n"
" }, rval.handle_mut());\n"
"if let Some(error) = maybe_take_panic_result() {\n"
" panic::resume_unwind(error);\n"
"}\n"
"maybe_resume_unwind();\n"
"if !ok {\n"
" return Err(JSFailed);\n"
"}\n").substitute(replacements)

View file

@ -32,11 +32,8 @@ use js::jsapi::{JS_StringHasLatin1Chars, MutableHandleValue, ObjectOpResult};
use js::jsval::{JSVal, UndefinedValue};
use js::rust::{GCMethods, ToString};
use libc;
use script_runtime::store_panic_result;
use std::ffi::CString;
use std::os::raw::c_void;
use std::panic;
use std::panic::AssertUnwindSafe;
use std::ptr;
use std::slice;
@ -516,15 +513,3 @@ unsafe extern "C" fn instance_class_has_proto_at_depth(clasp: *const js::jsapi::
pub const DOM_CALLBACKS: DOMCallbacks = DOMCallbacks {
instanceClassMatchesProto: Some(instance_class_has_proto_at_depth),
};
/// Generic wrapper for JS engine callbacks panic-catching
pub fn wrap_panic<T: FnMut() -> R, R>(function: T, generic_return_type: R) -> R {
let result = panic::catch_unwind(AssertUnwindSafe(function));
match result {
Ok(result) => result,
Err(error) => {
store_panic_result(error);
generic_return_type
}
}
}

View file

@ -26,13 +26,13 @@ use js::jsapi::{CurrentGlobalOrNull, GetGlobalForObjectCrossCompartment};
use js::jsapi::{HandleValue, Evaluate2, JSAutoCompartment, JSContext};
use js::jsapi::{JSObject, JS_GetClass, JS_GetContext};
use js::jsapi::{JS_GetObjectRuntime, MutableHandleValue};
use js::panic::maybe_resume_unwind;
use js::rust::CompileOptionsWrapper;
use libc;
use msg::constellation_msg::PipelineId;
use net_traits::{CoreResourceThread, ResourceThreads, IpcSend};
use profile_traits::{mem, time};
use script_runtime::{CommonScriptMsg, EnqueuedPromiseCallback, ScriptChan};
use script_runtime::{ScriptPort, maybe_take_panic_result};
use script_runtime::{CommonScriptMsg, EnqueuedPromiseCallback, ScriptChan, ScriptPort};
use script_thread::{MainThreadScriptChan, RunnableWrapper, ScriptThread};
use script_traits::{MsDuration, ScriptMsg as ConstellationMsg, TimerEvent};
use script_traits::{TimerEventId, TimerEventRequest, TimerSource};
@ -41,7 +41,6 @@ use std::cell::Cell;
use std::collections::HashMap;
use std::collections::hash_map::Entry;
use std::ffi::CString;
use std::panic;
use task_source::file_reading::FileReadingTaskSource;
use task_source::networking::NetworkingTaskSource;
use time::{Timespec, get_time};
@ -376,9 +375,7 @@ impl GlobalScope {
}
}
if let Some(error) = maybe_take_panic_result() {
panic::resume_unwind(error);
}
maybe_resume_unwind();
}
)
}

View file

@ -26,17 +26,17 @@ use fetch;
use ipc_channel::ipc::IpcSender;
use js::jsapi::{HandleValue, JSAutoCompartment, JSContext, JSRuntime};
use js::jsval::UndefinedValue;
use js::panic::maybe_resume_unwind;
use js::rust::Runtime;
use net_traits::{IpcSend, load_whole_resource};
use net_traits::request::{CredentialsMode, Destination, RequestInit as NetRequestInit, Type as RequestType};
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort, maybe_take_panic_result};
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort};
use script_runtime::{ScriptThreadEventCategory, PromiseJobQueue, EnqueuedPromiseCallback};
use script_thread::{Runnable, RunnableWrapper};
use script_traits::{TimerEvent, TimerEventId};
use script_traits::WorkerGlobalScopeInit;
use servo_url::ServoUrl;
use std::default::Default;
use std::panic;
use std::rc::Rc;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
@ -232,9 +232,7 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope {
let result = self.runtime.evaluate_script(
self.reflector().get_jsobject(), &source, url.as_str(), 1, rval.handle_mut());
if let Some(error) = maybe_take_panic_result() {
panic::resume_unwind(error);
}
maybe_resume_unwind();
match result {
Ok(_) => (),

View file

@ -20,17 +20,17 @@ use js::jsapi::{JSGCInvocationKind, JSGCStatus, JS_AddExtraGCRootsTracer, JS_Set
use js::jsapi::{JSGCMode, JSGCParamKey, JS_SetGCParameter, JS_SetGlobalJitCompilerOption};
use js::jsapi::{JSJitCompilerOption, JS_SetOffthreadIonCompilationEnabled, JS_SetParallelParsingEnabled};
use js::jsapi::{JSObject, RuntimeOptionsRef, SetPreserveWrapperCallback, SetEnqueuePromiseJobCallback};
use js::panic::wrap_panic;
use js::rust::Runtime;
use msg::constellation_msg::PipelineId;
use profile_traits::mem::{Report, ReportKind, ReportsChan};
use script_thread::{Runnable, STACK_ROOTS, trace_thread};
use std::any::Any;
use std::cell::{RefCell, Cell};
use std::cell::Cell;
use std::io::{Write, stdout};
use std::marker::PhantomData;
use std::os;
use std::os::raw::c_void;
use std::panic::{self, AssertUnwindSafe};
use std::panic::AssertUnwindSafe;
use std::ptr;
use std::rc::Rc;
use style::thread_state;
@ -176,7 +176,7 @@ unsafe extern "C" fn enqueue_job(_cx: *mut JSContext,
job: HandleObject,
_allocation_site: HandleObject,
_data: *mut c_void) -> bool {
let result = panic::catch_unwind(AssertUnwindSafe(|| {
wrap_panic(AssertUnwindSafe(|| {
let global = GlobalScope::from_object(job.get());
let pipeline = global.pipeline_id();
global.enqueue_promise_job(EnqueuedPromiseCallback {
@ -184,14 +184,7 @@ unsafe extern "C" fn enqueue_job(_cx: *mut JSContext,
pipeline: pipeline,
});
true
}));
match result {
Ok(result) => result,
Err(error) => {
store_panic_result(error);
return false;
}
}
}), false)
}
#[allow(unsafe_code)]
@ -421,21 +414,6 @@ pub fn get_reports(cx: *mut JSContext, path_seg: String) -> Vec<Report> {
reports
}
thread_local!(static PANIC_RESULT: RefCell<Option<Box<Any + Send>>> = RefCell::new(None));
pub fn store_panic_result(error: Box<Any + Send>) {
PANIC_RESULT.with(|result| {
assert!(result.borrow().is_none());
*result.borrow_mut() = Some(error);
});
}
pub fn maybe_take_panic_result() -> Option<Box<Any + Send>> {
PANIC_RESULT.with(|result| {
result.borrow_mut().take()
})
}
thread_local!(static GC_CYCLE_START: Cell<Option<Tm>> = Cell::new(None));
thread_local!(static GC_SLICE_START: Cell<Option<Tm>> = Cell::new(None));