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

JS Error Event Interface (NCSU Team: ronak, shreya, sayali) #3821

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

added ErrorEvent WebIDL and errorevent.rs

  • Loading branch information
RonakNisher committed Oct 25, 2014
commit 6d0748b27f594e1cc1bb6a403dd7b174679b8290
@@ -0,0 +1,107 @@
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
use dom::bindings::codegen::Bindings::ErrorEventBinding;
use dom::bindings::codegen::Bindings::ErrorEventBinding::ErrorEventMethods;
use dom::bindings::codegen::InheritTypes::{EventCast, ErrorEventDerived};
use dom::bindings::error::Fallible;
use dom::bindings::global::GlobalRef;
use dom::bindings::global;
use dom::bindings::js::{MutNullableJS, JSRef, RootedReference, Temporary, OptionalSettable};

use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::event::{Event, EventTypeId, ErrorEventTypeId};
use dom::window::Window;
use servo_util::str::DOMString;

use std::cell::Cell;
use std::default::Default;
use std::any::{Any, AnyRefExt};

#[dom_struct]
pub struct ErrorEvent {
event: Event,
message: Cell<DOMString>,
filename: Cell<DOMString>,
lineno: Cell<u64>,
colno: Cell<u64>,
any: Cell<Any>
}

impl ErrorEventDerived for Event {
fn is_errorevent(&self) -> bool {
*self.type_id() == ErrorEventTypeId
}
}

impl ErrorEvent {
pub fn new_inherited(type_id: EventTypeId) -> ErrorEvent {
ErrorEvent {
event: Event::new_inherited(type_id),
message: Cell::new("".to_string()),
filename: Cell::new("".to_string()),
lineno: Cell::new(0),
colno: Cell::new(0),
error: Cell::new()
}
}

pub fn new_uninitialized(window: JSRef<Window>) -> Temporary<ErrorEvent> {
reflect_dom_object(box ErrorEvent::new_inherited(ErrorEventTypeId),
&global::Window(window),
ErrorEventBinding::Wrap)
}

pub fn new(window: JSRef<Window>,
type_: DOMString,
can_bubble: bool,
cancelable: bool,
message: DOMString,
filename: DOMString,
lineno: u64,
colno: u64,
error: Any) -> Temporary<ErrorEvent> {
let ev = ErrorEvent::new_uninitialized(window).root();
ev.InitErrorEvent(type_, can_bubble, cancelable, message, filename, lineno, colno, error);
Temporary::from_rooted(*ev)
}

pub fn Constructor(global: &GlobalRef,
type_: DOMString,
init: &ErrorEventBinding::ErrorEventInit) -> Fallible<Temporary<ErrorEvent>> {
let event = ErrorEvent::new(global.as_window(), type_,
init.parent.bubbles, init.parent.cancelable,
init.view.root_ref(), init.detail);
Ok(event)
}

#[inline]
pub fn event<'a>(&'a self) -> &'a Event {
&self.event
}
}

impl<'a> ErrorEventMethods for JSRef<'a, ErrorEvent> {

fn InitErrorEvent(self,
type_: DOMString,
can_bubble: bool,
cancelable: bool,
message: DOMString,
filename: DOMString,
lineno: u64,
colno: u64,
error: Any) {
let event: JSRef<Event> = EventCast::from_ref(self);
event.InitEvent(type_, can_bubble, cancelable);
self.message.set(message);
self.filename.set(filename);
self.lineno.set(lineno);
self.colno.set(colno);
}
}

impl Reflectable for ErrorEvent {
fn reflector<'a>(&'a self) -> &'a Reflector {
self.event.reflector()
}
}

@@ -32,7 +32,8 @@ pub enum EventTypeId {
MessageEventTypeId,
MouseEventTypeId,
ProgressEventTypeId,
UIEventTypeId
UIEventTypeId,
ErrorEventTypeId
}

#[deriving(PartialEq)]
@@ -0,0 +1,22 @@
[Constructor(DOMString type, optional ErrorEventInit eventInitDict)/*, Exposed=(Window,Worker)*/]
interface ErrorEvent : Event {
readonly attribute DOMString message;
readonly attribute DOMString filename;
readonly attribute unsigned long lineno;
readonly attribute unsigned long colno;
readonly attribute any error;
};

dictionary ErrorEventInit : EventInit {
DOMString message;
DOMString filename;
unsigned long lineno;
unsigned long colno;
any error;
};

partial interface ErrorEvent {
// Deprecated in DOM Level 3
void initErrorEvent (DOMString typeArg, boolean bubblesArg, boolean cancelableArg, DOMString messageArg, DOMString filenameArg,
unsigned long linenoArg, unsigned long colnoArg, any errorArg);
};
@@ -101,6 +101,7 @@ pub mod dom {
pub mod domparser;
pub mod domtokenlist;
pub mod element;
pub mod errorevent;
pub mod event;
pub mod eventdispatcher;
pub mod eventtarget;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.