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: if self.catchPanic:
body = CGWrapper(CGIndenter(body), body = CGWrapper(CGIndenter(body),
pre="return wrap_panic(|| {\n", pre="return wrap_panic(panic::AssertUnwindSafe(|| {\n",
post=("""}, %s);""" % ("()" if self.returnType == "void" else "false"))) post=("""}), %s);""" % ("()" if self.returnType == "void" else "false")))
return CGWrapper(CGIndenter(body), return CGWrapper(CGIndenter(body),
pre=self.definition_prologue(), 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_JSID_IS_STRING',
'js::glue::RUST_SYMBOL_TO_JSID', 'js::glue::RUST_SYMBOL_TO_JSID',
'js::glue::int_to_jsid', 'js::glue::int_to_jsid',
'js::panic::maybe_resume_unwind',
'js::panic::wrap_panic',
'js::rust::GCMethods', 'js::rust::GCMethods',
'js::rust::define_methods', 'js::rust::define_methods',
'js::rust::define_properties', '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::resolve_global',
'dom::bindings::utils::set_dictionary_property', 'dom::bindings::utils::set_dictionary_property',
'dom::bindings::utils::trace_global', 'dom::bindings::utils::trace_global',
'dom::bindings::utils::wrap_panic',
'dom::bindings::trace::JSTraceable', 'dom::bindings::trace::JSTraceable',
'dom::bindings::trace::RootedTraceable', 'dom::bindings::trace::RootedTraceable',
'dom::bindings::callback::CallSetup', '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', 'mem::heap_size_of_raw_self_and_children',
'libc', 'libc',
'util::prefs::PREFS', 'util::prefs::PREFS',
'script_runtime::maybe_take_panic_result',
'std::borrow::ToOwned', 'std::borrow::ToOwned',
'std::cmp', 'std::cmp',
'std::mem', 'std::mem',
@ -6596,9 +6596,7 @@ class CallbackMethod(CallbackMember):
" length_: ${argc} as ::libc::size_t,\n" " length_: ${argc} as ::libc::size_t,\n"
" elements_: ${argv}\n" " elements_: ${argv}\n"
" }, rval.handle_mut());\n" " }, rval.handle_mut());\n"
"if let Some(error) = maybe_take_panic_result() {\n" "maybe_resume_unwind();\n"
" panic::resume_unwind(error);\n"
"}\n"
"if !ok {\n" "if !ok {\n"
" return Err(JSFailed);\n" " return Err(JSFailed);\n"
"}\n").substitute(replacements) "}\n").substitute(replacements)

View file

@ -32,11 +32,8 @@ use js::jsapi::{JS_StringHasLatin1Chars, MutableHandleValue, ObjectOpResult};
use js::jsval::{JSVal, UndefinedValue}; use js::jsval::{JSVal, UndefinedValue};
use js::rust::{GCMethods, ToString}; use js::rust::{GCMethods, ToString};
use libc; use libc;
use script_runtime::store_panic_result;
use std::ffi::CString; use std::ffi::CString;
use std::os::raw::c_void; use std::os::raw::c_void;
use std::panic;
use std::panic::AssertUnwindSafe;
use std::ptr; use std::ptr;
use std::slice; 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 { pub const DOM_CALLBACKS: DOMCallbacks = DOMCallbacks {
instanceClassMatchesProto: Some(instance_class_has_proto_at_depth), 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::{HandleValue, Evaluate2, JSAutoCompartment, JSContext};
use js::jsapi::{JSObject, JS_GetClass, JS_GetContext}; use js::jsapi::{JSObject, JS_GetClass, JS_GetContext};
use js::jsapi::{JS_GetObjectRuntime, MutableHandleValue}; use js::jsapi::{JS_GetObjectRuntime, MutableHandleValue};
use js::panic::maybe_resume_unwind;
use js::rust::CompileOptionsWrapper; use js::rust::CompileOptionsWrapper;
use libc; use libc;
use msg::constellation_msg::PipelineId; use msg::constellation_msg::PipelineId;
use net_traits::{CoreResourceThread, ResourceThreads, IpcSend}; use net_traits::{CoreResourceThread, ResourceThreads, IpcSend};
use profile_traits::{mem, time}; use profile_traits::{mem, time};
use script_runtime::{CommonScriptMsg, EnqueuedPromiseCallback, ScriptChan}; use script_runtime::{CommonScriptMsg, EnqueuedPromiseCallback, ScriptChan, ScriptPort};
use script_runtime::{ScriptPort, maybe_take_panic_result};
use script_thread::{MainThreadScriptChan, RunnableWrapper, ScriptThread}; use script_thread::{MainThreadScriptChan, RunnableWrapper, ScriptThread};
use script_traits::{MsDuration, ScriptMsg as ConstellationMsg, TimerEvent}; use script_traits::{MsDuration, ScriptMsg as ConstellationMsg, TimerEvent};
use script_traits::{TimerEventId, TimerEventRequest, TimerSource}; use script_traits::{TimerEventId, TimerEventRequest, TimerSource};
@ -41,7 +41,6 @@ use std::cell::Cell;
use std::collections::HashMap; use std::collections::HashMap;
use std::collections::hash_map::Entry; use std::collections::hash_map::Entry;
use std::ffi::CString; use std::ffi::CString;
use std::panic;
use task_source::file_reading::FileReadingTaskSource; use task_source::file_reading::FileReadingTaskSource;
use task_source::networking::NetworkingTaskSource; use task_source::networking::NetworkingTaskSource;
use time::{Timespec, get_time}; use time::{Timespec, get_time};
@ -376,9 +375,7 @@ impl GlobalScope {
} }
} }
if let Some(error) = maybe_take_panic_result() { maybe_resume_unwind();
panic::resume_unwind(error);
}
} }
) )
} }

View file

@ -26,17 +26,17 @@ use fetch;
use ipc_channel::ipc::IpcSender; use ipc_channel::ipc::IpcSender;
use js::jsapi::{HandleValue, JSAutoCompartment, JSContext, JSRuntime}; use js::jsapi::{HandleValue, JSAutoCompartment, JSContext, JSRuntime};
use js::jsval::UndefinedValue; use js::jsval::UndefinedValue;
use js::panic::maybe_resume_unwind;
use js::rust::Runtime; use js::rust::Runtime;
use net_traits::{IpcSend, load_whole_resource}; use net_traits::{IpcSend, load_whole_resource};
use net_traits::request::{CredentialsMode, Destination, RequestInit as NetRequestInit, Type as RequestType}; 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_runtime::{ScriptThreadEventCategory, PromiseJobQueue, EnqueuedPromiseCallback};
use script_thread::{Runnable, RunnableWrapper}; use script_thread::{Runnable, RunnableWrapper};
use script_traits::{TimerEvent, TimerEventId}; use script_traits::{TimerEvent, TimerEventId};
use script_traits::WorkerGlobalScopeInit; use script_traits::WorkerGlobalScopeInit;
use servo_url::ServoUrl; use servo_url::ServoUrl;
use std::default::Default; use std::default::Default;
use std::panic;
use std::rc::Rc; use std::rc::Rc;
use std::sync::Arc; use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
@ -232,9 +232,7 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope {
let result = self.runtime.evaluate_script( let result = self.runtime.evaluate_script(
self.reflector().get_jsobject(), &source, url.as_str(), 1, rval.handle_mut()); self.reflector().get_jsobject(), &source, url.as_str(), 1, rval.handle_mut());
if let Some(error) = maybe_take_panic_result() { maybe_resume_unwind();
panic::resume_unwind(error);
}
match result { match result {
Ok(_) => (), 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::{JSGCMode, JSGCParamKey, JS_SetGCParameter, JS_SetGlobalJitCompilerOption};
use js::jsapi::{JSJitCompilerOption, JS_SetOffthreadIonCompilationEnabled, JS_SetParallelParsingEnabled}; use js::jsapi::{JSJitCompilerOption, JS_SetOffthreadIonCompilationEnabled, JS_SetParallelParsingEnabled};
use js::jsapi::{JSObject, RuntimeOptionsRef, SetPreserveWrapperCallback, SetEnqueuePromiseJobCallback}; use js::jsapi::{JSObject, RuntimeOptionsRef, SetPreserveWrapperCallback, SetEnqueuePromiseJobCallback};
use js::panic::wrap_panic;
use js::rust::Runtime; use js::rust::Runtime;
use msg::constellation_msg::PipelineId; use msg::constellation_msg::PipelineId;
use profile_traits::mem::{Report, ReportKind, ReportsChan}; use profile_traits::mem::{Report, ReportKind, ReportsChan};
use script_thread::{Runnable, STACK_ROOTS, trace_thread}; use script_thread::{Runnable, STACK_ROOTS, trace_thread};
use std::any::Any; use std::cell::Cell;
use std::cell::{RefCell, Cell};
use std::io::{Write, stdout}; use std::io::{Write, stdout};
use std::marker::PhantomData; use std::marker::PhantomData;
use std::os; use std::os;
use std::os::raw::c_void; use std::os::raw::c_void;
use std::panic::{self, AssertUnwindSafe}; use std::panic::AssertUnwindSafe;
use std::ptr; use std::ptr;
use std::rc::Rc; use std::rc::Rc;
use style::thread_state; use style::thread_state;
@ -176,7 +176,7 @@ unsafe extern "C" fn enqueue_job(_cx: *mut JSContext,
job: HandleObject, job: HandleObject,
_allocation_site: HandleObject, _allocation_site: HandleObject,
_data: *mut c_void) -> bool { _data: *mut c_void) -> bool {
let result = panic::catch_unwind(AssertUnwindSafe(|| { wrap_panic(AssertUnwindSafe(|| {
let global = GlobalScope::from_object(job.get()); let global = GlobalScope::from_object(job.get());
let pipeline = global.pipeline_id(); let pipeline = global.pipeline_id();
global.enqueue_promise_job(EnqueuedPromiseCallback { global.enqueue_promise_job(EnqueuedPromiseCallback {
@ -184,14 +184,7 @@ unsafe extern "C" fn enqueue_job(_cx: *mut JSContext,
pipeline: pipeline, pipeline: pipeline,
}); });
true true
})); }), false)
match result {
Ok(result) => result,
Err(error) => {
store_panic_result(error);
return false;
}
}
} }
#[allow(unsafe_code)] #[allow(unsafe_code)]
@ -421,21 +414,6 @@ pub fn get_reports(cx: *mut JSContext, path_seg: String) -> Vec<Report> {
reports 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_CYCLE_START: Cell<Option<Tm>> = Cell::new(None));
thread_local!(static GC_SLICE_START: Cell<Option<Tm>> = Cell::new(None)); thread_local!(static GC_SLICE_START: Cell<Option<Tm>> = Cell::new(None));

2
ports/cef/Cargo.lock generated
View file

@ -1089,7 +1089,7 @@ dependencies = [
[[package]] [[package]]
name = "js" name = "js"
version = "0.1.3" version = "0.1.3"
source = "git+https://github.com/servo/rust-mozjs#14cd66c0a3e8377cad30b9ba3fe71fe394607629" source = "git+https://github.com/servo/rust-mozjs#4f46b376a96dc3bcc53dfe2e394d09843b8a44eb"
dependencies = [ dependencies = [
"cmake 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", "cmake 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -1168,7 +1168,7 @@ dependencies = [
[[package]] [[package]]
name = "js" name = "js"
version = "0.1.3" version = "0.1.3"
source = "git+https://github.com/servo/rust-mozjs#14cd66c0a3e8377cad30b9ba3fe71fe394607629" source = "git+https://github.com/servo/rust-mozjs#4f46b376a96dc3bcc53dfe2e394d09843b8a44eb"
dependencies = [ dependencies = [
"cmake 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", "cmake 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",