mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Introduce GlobalScope::report_an_error
This commit is contained in:
parent
d4fccbace4
commit
86d2008137
6 changed files with 65 additions and 101 deletions
|
@ -8,7 +8,7 @@ use dom::bindings::codegen::Bindings::DOMExceptionBinding::DOMExceptionMethods;
|
|||
use dom::bindings::codegen::PrototypeList::proto_id_to_name;
|
||||
use dom::bindings::conversions::{ConversionResult, FromJSValConvertible, ToJSValConvertible};
|
||||
use dom::bindings::conversions::root_from_object;
|
||||
use dom::bindings::global::global_root_from_context;
|
||||
use dom::bindings::global::global_scope_from_context;
|
||||
use dom::bindings::str::USVString;
|
||||
use dom::domexception::{DOMErrorName, DOMException};
|
||||
use dom::globalscope::GlobalScope;
|
||||
|
@ -246,8 +246,8 @@ pub unsafe fn report_pending_exception(cx: *mut JSContext, dispatch_event: bool)
|
|||
error_info.message);
|
||||
|
||||
if dispatch_event {
|
||||
let global = global_root_from_context(cx);
|
||||
global.r().report_an_error(error_info, value.handle());
|
||||
let global = global_scope_from_context(cx);
|
||||
global.report_an_error(error_info, value.handle());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
//! code that works in workers as well as window scopes.
|
||||
|
||||
use dom::bindings::conversions::root_from_object;
|
||||
use dom::bindings::error::{ErrorInfo, report_pending_exception};
|
||||
use dom::bindings::error::report_pending_exception;
|
||||
use dom::bindings::inheritance::Castable;
|
||||
use dom::bindings::js::Root;
|
||||
use dom::bindings::reflector::{Reflectable, Reflector};
|
||||
|
@ -18,8 +18,8 @@ use dom::workerglobalscope::WorkerGlobalScope;
|
|||
use js::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL};
|
||||
use js::glue::{IsWrapper, UnwrapObject};
|
||||
use js::jsapi::{CurrentGlobalOrNull, Evaluate2, GetGlobalForObjectCrossCompartment};
|
||||
use js::jsapi::{HandleValue, JS_GetClass, JSAutoCompartment, JSContext};
|
||||
use js::jsapi::{JSObject, MutableHandleValue};
|
||||
use js::jsapi::{JSAutoCompartment, JSContext, JSObject};
|
||||
use js::jsapi::{JS_GetClass, MutableHandleValue};
|
||||
use js::rust::CompileOptionsWrapper;
|
||||
use libc;
|
||||
use net_traits::{CoreResourceThread, IpcSend, ResourceThreads};
|
||||
|
@ -220,14 +220,6 @@ impl<'a> GlobalRef<'a> {
|
|||
GlobalRef::Worker(ref worker) => worker.flush_promise_jobs(),
|
||||
}
|
||||
}
|
||||
|
||||
/// https://html.spec.whatwg.org/multipage/#report-the-error
|
||||
pub fn report_an_error(&self, error_info: ErrorInfo, value: HandleValue) {
|
||||
match *self {
|
||||
GlobalRef::Window(ref window) => window.report_an_error(error_info, value),
|
||||
GlobalRef::Worker(ref worker) => worker.report_an_error(error_info, value),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Reflectable for GlobalRef<'a> {
|
||||
|
@ -296,6 +288,13 @@ pub unsafe fn global_root_from_object(obj: *mut JSObject) -> GlobalRoot {
|
|||
global_root_from_global(global)
|
||||
}
|
||||
|
||||
/// Returns the global scope for the given JSContext
|
||||
#[allow(unrooted_must_root)]
|
||||
pub unsafe fn global_scope_from_context(cx: *mut JSContext) -> Root<GlobalScope> {
|
||||
let global = CurrentGlobalOrNull(cx);
|
||||
global_scope_from_global(global)
|
||||
}
|
||||
|
||||
/// Returns the global object for the given JSContext
|
||||
#[allow(unrooted_must_root)]
|
||||
pub unsafe fn global_root_from_context(cx: *mut JSContext) -> GlobalRoot {
|
||||
|
|
|
@ -5,16 +5,21 @@
|
|||
use devtools_traits::{ScriptToDevtoolsControlMsg, WorkerId};
|
||||
use dom::bindings::cell::DOMRefCell;
|
||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||
use dom::bindings::error::ErrorInfo;
|
||||
use dom::bindings::inheritance::Castable;
|
||||
use dom::bindings::js::{JS, MutNullableHeap, Root};
|
||||
use dom::bindings::reflector::Reflectable;
|
||||
use dom::bindings::str::DOMString;
|
||||
use dom::crypto::Crypto;
|
||||
use dom::dedicatedworkerglobalscope::DedicatedWorkerGlobalScope;
|
||||
use dom::errorevent::ErrorEvent;
|
||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||
use dom::eventdispatcher::EventStatus;
|
||||
use dom::eventtarget::EventTarget;
|
||||
use dom::window::Window;
|
||||
use dom::workerglobalscope::WorkerGlobalScope;
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use js::jsapi::{JS_GetContext, JS_GetObjectRuntime, JSContext};
|
||||
use js::jsapi::{HandleValue, JS_GetContext, JS_GetObjectRuntime, JSContext};
|
||||
use msg::constellation_msg::PipelineId;
|
||||
use profile_traits::{mem, time};
|
||||
use script_traits::{ScriptMsg as ConstellationMsg, TimerEventRequest};
|
||||
|
@ -58,6 +63,9 @@ pub struct GlobalScope {
|
|||
|
||||
#[ignore_heap_size_of = "channels are hard"]
|
||||
scheduler_chan: IpcSender<TimerEventRequest>,
|
||||
|
||||
/// https://html.spec.whatwg.org/multipage/#in-error-reporting-mode
|
||||
in_error_reporting_mode: Cell<bool>,
|
||||
}
|
||||
|
||||
impl GlobalScope {
|
||||
|
@ -81,6 +89,7 @@ impl GlobalScope {
|
|||
time_profiler_chan: time_profiler_chan,
|
||||
constellation_chan: constellation_chan,
|
||||
scheduler_chan: scheduler_chan,
|
||||
in_error_reporting_mode: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -195,6 +204,42 @@ impl GlobalScope {
|
|||
pub fn as_window(&self) -> &Window {
|
||||
self.downcast::<Window>().expect("expected a Window scope")
|
||||
}
|
||||
|
||||
/// https://html.spec.whatwg.org/multipage/#report-the-error
|
||||
pub fn report_an_error(&self, error_info: ErrorInfo, value: HandleValue) {
|
||||
// Step 1.
|
||||
if self.in_error_reporting_mode.get() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Step 2.
|
||||
self.in_error_reporting_mode.set(true);
|
||||
|
||||
// Steps 3-12.
|
||||
// FIXME(#13195): muted errors.
|
||||
let event = ErrorEvent::new(self,
|
||||
atom!("error"),
|
||||
EventBubbles::DoesNotBubble,
|
||||
EventCancelable::Cancelable,
|
||||
error_info.message.as_str().into(),
|
||||
error_info.filename.as_str().into(),
|
||||
error_info.lineno,
|
||||
error_info.column,
|
||||
value);
|
||||
|
||||
// Step 13.
|
||||
let event_status = event.upcast::<Event>().fire(self.upcast::<EventTarget>());
|
||||
|
||||
// Step 15
|
||||
if event_status == EventStatus::NotCanceled {
|
||||
if let Some(dedicated) = self.downcast::<DedicatedWorkerGlobalScope>() {
|
||||
dedicated.forward_error_to_worker_object(error_info);
|
||||
}
|
||||
}
|
||||
|
||||
// Step 14
|
||||
self.in_error_reporting_mode.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
fn timestamp_in_ms(time: Timespec) -> u64 {
|
||||
|
|
|
@ -16,7 +16,7 @@ use dom::bindings::codegen::Bindings::RequestBinding::RequestInit;
|
|||
use dom::bindings::codegen::Bindings::WindowBinding::{self, FrameRequestCallback, WindowMethods};
|
||||
use dom::bindings::codegen::Bindings::WindowBinding::{ScrollBehavior, ScrollToOptions};
|
||||
use dom::bindings::codegen::UnionTypes::RequestOrUSVString;
|
||||
use dom::bindings::error::{Error, ErrorInfo, ErrorResult, Fallible};
|
||||
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||
use dom::bindings::global::{GlobalRef, global_root_from_object};
|
||||
use dom::bindings::inheritance::Castable;
|
||||
use dom::bindings::js::{JS, MutNullableHeap, Root};
|
||||
|
@ -31,9 +31,7 @@ use dom::crypto::Crypto;
|
|||
use dom::cssstyledeclaration::{CSSModificationAccess, CSSStyleDeclaration};
|
||||
use dom::document::Document;
|
||||
use dom::element::Element;
|
||||
use dom::errorevent::ErrorEvent;
|
||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||
use dom::eventtarget::EventTarget;
|
||||
use dom::event::Event;
|
||||
use dom::globalscope::GlobalScope;
|
||||
use dom::history::History;
|
||||
use dom::htmliframeelement::build_mozbrowser_custom_event;
|
||||
|
@ -242,9 +240,6 @@ pub struct Window {
|
|||
|
||||
/// A list of scroll offsets for each scrollable element.
|
||||
scroll_offsets: DOMRefCell<HashMap<UntrustedNodeAddress, Point2D<f32>>>,
|
||||
|
||||
/// https://html.spec.whatwg.org/multipage/#in-error-reporting-mode
|
||||
in_error_reporting_mode: Cell<bool>,
|
||||
}
|
||||
|
||||
impl Window {
|
||||
|
@ -1634,40 +1629,10 @@ impl Window {
|
|||
ignore_further_async_events: Arc::new(AtomicBool::new(false)),
|
||||
error_reporter: error_reporter,
|
||||
scroll_offsets: DOMRefCell::new(HashMap::new()),
|
||||
in_error_reporting_mode: Cell::new(false),
|
||||
};
|
||||
|
||||
WindowBinding::Wrap(runtime.cx(), win)
|
||||
}
|
||||
|
||||
/// https://html.spec.whatwg.org/multipage/#report-the-error
|
||||
pub fn report_an_error(&self, error_info: ErrorInfo, value: HandleValue) {
|
||||
// Step 1.
|
||||
if self.in_error_reporting_mode.get() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Step 2.
|
||||
self.in_error_reporting_mode.set(true);
|
||||
|
||||
// Steps 3-12.
|
||||
// FIXME(#13195): muted errors.
|
||||
let event = ErrorEvent::new(self.upcast(),
|
||||
atom!("error"),
|
||||
EventBubbles::DoesNotBubble,
|
||||
EventCancelable::Cancelable,
|
||||
error_info.message.into(),
|
||||
error_info.filename.into(),
|
||||
error_info.lineno,
|
||||
error_info.column,
|
||||
value);
|
||||
|
||||
// Step 13.
|
||||
event.upcast::<Event>().fire(self.upcast::<EventTarget>());
|
||||
|
||||
// Step 14.
|
||||
self.in_error_reporting_mode.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
fn should_move_clip_rect(clip_rect: Rect<Au>, new_viewport: Rect<f32>) -> bool {
|
||||
|
|
|
@ -145,8 +145,8 @@ impl Worker {
|
|||
|
||||
#[allow(unsafe_code)]
|
||||
fn dispatch_error(&self, error_info: ErrorInfo) {
|
||||
let global = self.global();
|
||||
let event = ErrorEvent::new(global.r().as_global_scope(),
|
||||
let global = self.global_scope();
|
||||
let event = ErrorEvent::new(&global,
|
||||
atom!("error"),
|
||||
EventBubbles::DoesNotBubble,
|
||||
EventCancelable::Cancelable,
|
||||
|
@ -161,7 +161,7 @@ impl Worker {
|
|||
return;
|
||||
}
|
||||
|
||||
global.r().report_an_error(error_info, unsafe { NullHandleValue });
|
||||
global.report_an_error(error_info, unsafe { NullHandleValue });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ use dom::bindings::codegen::Bindings::FunctionBinding::Function;
|
|||
use dom::bindings::codegen::Bindings::RequestBinding::RequestInit;
|
||||
use dom::bindings::codegen::Bindings::WorkerGlobalScopeBinding::WorkerGlobalScopeMethods;
|
||||
use dom::bindings::codegen::UnionTypes::RequestOrUSVString;
|
||||
use dom::bindings::error::{Error, ErrorInfo, ErrorResult, Fallible, report_pending_exception};
|
||||
use dom::bindings::error::{Error, ErrorResult, Fallible, report_pending_exception};
|
||||
use dom::bindings::global::{GlobalRef, GlobalRoot};
|
||||
use dom::bindings::inheritance::Castable;
|
||||
use dom::bindings::js::{JS, MutNullableHeap, Root};
|
||||
|
@ -17,10 +17,6 @@ use dom::bindings::reflector::Reflectable;
|
|||
use dom::bindings::str::DOMString;
|
||||
use dom::crypto::Crypto;
|
||||
use dom::dedicatedworkerglobalscope::DedicatedWorkerGlobalScope;
|
||||
use dom::errorevent::ErrorEvent;
|
||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||
use dom::eventdispatcher::EventStatus;
|
||||
use dom::eventtarget::EventTarget;
|
||||
use dom::globalscope::GlobalScope;
|
||||
use dom::promise::Promise;
|
||||
use dom::serviceworkerglobalscope::ServiceWorkerGlobalScope;
|
||||
|
@ -40,7 +36,6 @@ use script_runtime::{ScriptThreadEventCategory, PromiseJobQueue, EnqueuedPromise
|
|||
use script_thread::{Runnable, RunnableWrapper};
|
||||
use script_traits::{MsDuration, TimerEvent, TimerEventId, TimerSource};
|
||||
use script_traits::WorkerGlobalScopeInit;
|
||||
use std::cell::Cell;
|
||||
use std::default::Default;
|
||||
use std::panic;
|
||||
use std::rc::Rc;
|
||||
|
@ -104,9 +99,6 @@ pub struct WorkerGlobalScope {
|
|||
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
|
||||
|
||||
promise_job_queue: PromiseJobQueue,
|
||||
|
||||
/// https://html.spec.whatwg.org/multipage/#in-error-reporting-mode
|
||||
in_error_reporting_mode: Cell<bool>
|
||||
}
|
||||
|
||||
impl WorkerGlobalScope {
|
||||
|
@ -137,7 +129,6 @@ impl WorkerGlobalScope {
|
|||
from_devtools_sender: init.from_devtools_sender,
|
||||
from_devtools_receiver: from_devtools_receiver,
|
||||
promise_job_queue: PromiseJobQueue::new(),
|
||||
in_error_reporting_mode: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -431,42 +422,6 @@ impl WorkerGlobalScope {
|
|||
closing.store(true, Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
|
||||
/// https://html.spec.whatwg.org/multipage/#report-the-error
|
||||
pub fn report_an_error(&self, error_info: ErrorInfo, value: HandleValue) {
|
||||
// Step 1.
|
||||
if self.in_error_reporting_mode.get() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Step 2.
|
||||
self.in_error_reporting_mode.set(true);
|
||||
|
||||
// Steps 3-12.
|
||||
// FIXME(#13195): muted errors.
|
||||
let event = ErrorEvent::new(self.upcast(),
|
||||
atom!("error"),
|
||||
EventBubbles::DoesNotBubble,
|
||||
EventCancelable::Cancelable,
|
||||
error_info.message.as_str().into(),
|
||||
error_info.filename.as_str().into(),
|
||||
error_info.lineno,
|
||||
error_info.column,
|
||||
value);
|
||||
|
||||
// Step 13.
|
||||
let event_status = event.upcast::<Event>().fire(self.upcast::<EventTarget>());
|
||||
|
||||
// Step 15
|
||||
if event_status == EventStatus::NotCanceled {
|
||||
if let Some(dedicated) = self.downcast::<DedicatedWorkerGlobalScope>() {
|
||||
dedicated.forward_error_to_worker_object(error_info);
|
||||
}
|
||||
}
|
||||
|
||||
// Step 14
|
||||
self.in_error_reporting_mode.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
struct FlushPromiseJobs {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue