mirror of
https://github.com/servo/servo.git
synced 2025-08-02 12:10:29 +01:00
Refactor Error enum usage to consistently be qualified
This commit is contained in:
parent
94816bb3b4
commit
ba86131cd5
19 changed files with 139 additions and 161 deletions
|
@ -5,8 +5,7 @@
|
|||
//! This module implements structured cloning, as defined by [HTML]
|
||||
//! (https://html.spec.whatwg.org/multipage/#safe-passing-of-structured-data).
|
||||
|
||||
use dom::bindings::error::Error::DataClone;
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::bindings::error::{Error, Fallible};
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use js::glue::JS_STRUCTURED_CLONE_VERSION;
|
||||
use js::jsapi::{HandleValue, MutableHandleValue};
|
||||
|
@ -34,7 +33,7 @@ impl StructuredCloneData {
|
|||
};
|
||||
if result == 0 {
|
||||
unsafe { JS_ClearPendingException(cx); }
|
||||
return Err(DataClone);
|
||||
return Err(Error::DataClone);
|
||||
}
|
||||
Ok(StructuredCloneData {
|
||||
data: data,
|
||||
|
|
|
@ -6,8 +6,7 @@ use canvas_traits::{CanvasGradientStop, FillOrStrokeStyle, LinearGradientStyle,
|
|||
use dom::bindings::cell::DOMRefCell;
|
||||
use dom::bindings::codegen::Bindings::CanvasGradientBinding;
|
||||
use dom::bindings::codegen::Bindings::CanvasGradientBinding::CanvasGradientMethods;
|
||||
use dom::bindings::error::Error::{IndexSize, Syntax};
|
||||
use dom::bindings::error::ErrorResult;
|
||||
use dom::bindings::error::{Error, ErrorResult};
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::Root;
|
||||
use dom::bindings::num::Finite;
|
||||
|
@ -47,12 +46,12 @@ impl CanvasGradientMethods for CanvasGradient {
|
|||
// https://html.spec.whatwg.org/multipage/#dom-canvasgradient-addcolorstop
|
||||
fn AddColorStop(&self, offset: Finite<f64>, color: String) -> ErrorResult {
|
||||
if *offset < 0f64 || *offset > 1f64 {
|
||||
return Err(IndexSize);
|
||||
return Err(Error::IndexSize);
|
||||
}
|
||||
|
||||
let color = match parse_color(&color) {
|
||||
Ok(color) => color,
|
||||
_ => return Err(Syntax)
|
||||
_ => return Err(Error::Syntax)
|
||||
};
|
||||
|
||||
self.stops.borrow_mut().push(CanvasGradientStop {
|
||||
|
|
|
@ -15,8 +15,7 @@ use dom::bindings::codegen::Bindings::ImageDataBinding::ImageDataMethods;
|
|||
use dom::bindings::codegen::InheritTypes::NodeCast;
|
||||
use dom::bindings::codegen::UnionTypes::HTMLImageElementOrHTMLCanvasElementOrCanvasRenderingContext2D;
|
||||
use dom::bindings::codegen::UnionTypes::StringOrCanvasGradientOrCanvasPattern;
|
||||
use dom::bindings::error::Error::{IndexSize, InvalidState, Syntax};
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::bindings::error::{Error, Fallible};
|
||||
use dom::bindings::global::{GlobalField, GlobalRef};
|
||||
use dom::bindings::js::{JS, LayoutJS, Root};
|
||||
use dom::bindings::num::Finite;
|
||||
|
@ -252,7 +251,7 @@ impl CanvasRenderingContext2D {
|
|||
let size = Size2D::new(size.width as f64, size.height as f64);
|
||||
(data, size)
|
||||
},
|
||||
None => return Err(InvalidState),
|
||||
None => return Err(Error::InvalidState),
|
||||
};
|
||||
let dw = dw.unwrap_or(image_size.width);
|
||||
let dh = dh.unwrap_or(image_size.height);
|
||||
|
@ -272,7 +271,7 @@ impl CanvasRenderingContext2D {
|
|||
dx: f64, dy: f64, dw: Option<f64>, dh: Option<f64>) -> Fallible<()> {
|
||||
// 1. Check the usability of the image argument
|
||||
if !canvas.is_valid() {
|
||||
return Err(InvalidState)
|
||||
return Err(Error::InvalidState)
|
||||
}
|
||||
|
||||
let canvas_size = canvas.get_size();
|
||||
|
@ -286,7 +285,7 @@ impl CanvasRenderingContext2D {
|
|||
let (source_rect, dest_rect) = self.adjust_source_dest_rects(image_size, sx, sy, sw, sh, dx, dy, dw, dh);
|
||||
|
||||
if !is_rect_valid(source_rect) || !is_rect_valid(dest_rect) {
|
||||
return Err(IndexSize)
|
||||
return Err(Error::IndexSize)
|
||||
}
|
||||
|
||||
let smoothing_enabled = self.state.borrow().image_smoothing_enabled;
|
||||
|
@ -297,7 +296,7 @@ impl CanvasRenderingContext2D {
|
|||
} else { // Source and target canvases are different
|
||||
let context = match canvas.get_or_init_2d_context() {
|
||||
Some(context) => context,
|
||||
None => return Err(InvalidState),
|
||||
None => return Err(Error::InvalidState),
|
||||
};
|
||||
|
||||
let renderer = context.r().get_ipc_renderer();
|
||||
|
@ -326,7 +325,7 @@ impl CanvasRenderingContext2D {
|
|||
let (source_rect, dest_rect) = self.adjust_source_dest_rects(image_size, sx, sy, sw, sh, dx, dy, dw, dh);
|
||||
|
||||
if !is_rect_valid(source_rect) || !is_rect_valid(dest_rect) {
|
||||
return Err(IndexSize)
|
||||
return Err(Error::IndexSize)
|
||||
}
|
||||
|
||||
let smoothing_enabled = self.state.borrow().image_smoothing_enabled;
|
||||
|
@ -715,7 +714,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
|||
}
|
||||
|
||||
if r < 0.0 {
|
||||
return Err(IndexSize);
|
||||
return Err(Error::IndexSize);
|
||||
}
|
||||
|
||||
let msg = CanvasMsg::Canvas2d(
|
||||
|
@ -733,7 +732,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
|||
return Ok(());
|
||||
}
|
||||
if r < 0.0 {
|
||||
return Err(IndexSize);
|
||||
return Err(Error::IndexSize);
|
||||
}
|
||||
|
||||
let msg = CanvasMsg::Canvas2d(
|
||||
|
@ -839,7 +838,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
|||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-createimagedata
|
||||
fn CreateImageData(&self, sw: Finite<f64>, sh: Finite<f64>) -> Fallible<Root<ImageData>> {
|
||||
if *sw == 0.0 || *sh == 0.0 {
|
||||
return Err(IndexSize)
|
||||
return Err(Error::IndexSize)
|
||||
}
|
||||
|
||||
let sw = cmp::max(1, sw.abs().to_u32().unwrap());
|
||||
|
@ -864,7 +863,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
|||
let mut sh = *sh;
|
||||
|
||||
if sw == 0.0 || sh == 0.0 {
|
||||
return Err(IndexSize)
|
||||
return Err(Error::IndexSize)
|
||||
}
|
||||
|
||||
if sw < 0.0 {
|
||||
|
@ -935,7 +934,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
|||
x1: Finite<f64>, y1: Finite<f64>, r1: Finite<f64>)
|
||||
-> Fallible<Root<CanvasGradient>> {
|
||||
if *r0 < 0. || *r1 < 0. {
|
||||
return Err(IndexSize);
|
||||
return Err(Error::IndexSize);
|
||||
}
|
||||
|
||||
Ok(CanvasGradient::new(self.global.root().r(),
|
||||
|
@ -954,7 +953,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
|||
// then throw an InvalidStateError exception
|
||||
match self.fetch_image_data(&image_element) {
|
||||
Some((data, size)) => (data, size),
|
||||
None => return Err(InvalidState),
|
||||
None => return Err(Error::InvalidState),
|
||||
}
|
||||
},
|
||||
HTMLImageElementOrHTMLCanvasElementOrCanvasRenderingContext2D::eHTMLCanvasElement(canvas) => {
|
||||
|
@ -963,7 +962,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
|||
|
||||
match canvas.fetch_all_data() {
|
||||
Some((data, size)) => (data, size),
|
||||
None => return Err(InvalidState),
|
||||
None => return Err(Error::InvalidState),
|
||||
}
|
||||
},
|
||||
HTMLImageElementOrHTMLCanvasElementOrCanvasRenderingContext2D::eCanvasRenderingContext2D(context) => {
|
||||
|
@ -973,7 +972,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
|||
|
||||
match canvas.fetch_all_data() {
|
||||
Some((data, size)) => (data, size),
|
||||
None => return Err(InvalidState),
|
||||
None => return Err(Error::InvalidState),
|
||||
}
|
||||
},
|
||||
};
|
||||
|
@ -984,7 +983,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
|
|||
image_size,
|
||||
rep));
|
||||
}
|
||||
return Err(Syntax);
|
||||
return Err(Error::Syntax);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linewidth
|
||||
|
|
|
@ -9,8 +9,7 @@ use dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods
|
|||
use dom::bindings::codegen::InheritTypes::NodeCast;
|
||||
use dom::bindings::codegen::InheritTypes::{CharacterDataDerived, ElementCast};
|
||||
use dom::bindings::codegen::UnionTypes::NodeOrString;
|
||||
use dom::bindings::error::Error::IndexSize;
|
||||
use dom::bindings::error::{ErrorResult, Fallible};
|
||||
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||
use dom::bindings::js::{LayoutJS, Root};
|
||||
use dom::document::Document;
|
||||
use dom::element::Element;
|
||||
|
@ -69,7 +68,7 @@ impl CharacterDataMethods for CharacterData {
|
|||
let data_from_offset = match find_utf16_code_unit_offset(&data, offset) {
|
||||
Some(offset_bytes) => &data[offset_bytes..],
|
||||
// Step 2.
|
||||
None => return Err(IndexSize)
|
||||
None => return Err(Error::IndexSize)
|
||||
};
|
||||
let substring = match find_utf16_code_unit_offset(data_from_offset, count) {
|
||||
// Steps 3.
|
||||
|
@ -102,7 +101,7 @@ impl CharacterDataMethods for CharacterData {
|
|||
let (prefix, data_from_offset) = match find_utf16_code_unit_offset(&data, offset) {
|
||||
Some(offset_bytes) => data.split_at(offset_bytes),
|
||||
// Step 2.
|
||||
None => return Err(IndexSize)
|
||||
None => return Err(Error::IndexSize)
|
||||
};
|
||||
let suffix = match find_utf16_code_unit_offset(data_from_offset, count) {
|
||||
// Steps 3.
|
||||
|
|
|
@ -25,9 +25,7 @@ use dom::bindings::codegen::InheritTypes::{HTMLAreaElementDerived, HTMLEmbedElem
|
|||
use dom::bindings::codegen::InheritTypes::{HTMLFormElementDerived, HTMLImageElementDerived};
|
||||
use dom::bindings::codegen::InheritTypes::{HTMLScriptElementDerived, HTMLTitleElementDerived};
|
||||
use dom::bindings::codegen::UnionTypes::NodeOrString;
|
||||
use dom::bindings::error::Error::HierarchyRequest;
|
||||
use dom::bindings::error::Error::{InvalidCharacter, NotSupported, Security};
|
||||
use dom::bindings::error::{ErrorResult, Fallible};
|
||||
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::RootedReference;
|
||||
use dom::bindings::js::{JS, LayoutJS, MutNullableHeap, Root};
|
||||
|
@ -1265,7 +1263,7 @@ impl DocumentMethods for Document {
|
|||
fn CreateElement(&self, mut local_name: DOMString) -> Fallible<Root<Element>> {
|
||||
if xml_name_type(&local_name) == InvalidXMLName {
|
||||
debug!("Not a valid element name");
|
||||
return Err(InvalidCharacter);
|
||||
return Err(Error::InvalidCharacter);
|
||||
}
|
||||
if self.is_html_document {
|
||||
local_name.make_ascii_lowercase();
|
||||
|
@ -1288,7 +1286,7 @@ impl DocumentMethods for Document {
|
|||
fn CreateAttribute(&self, local_name: DOMString) -> Fallible<Root<Attr>> {
|
||||
if xml_name_type(&local_name) == InvalidXMLName {
|
||||
debug!("Not a valid element name");
|
||||
return Err(InvalidCharacter);
|
||||
return Err(Error::InvalidCharacter);
|
||||
}
|
||||
|
||||
let window = self.window.root();
|
||||
|
@ -1332,12 +1330,12 @@ impl DocumentMethods for Document {
|
|||
Fallible<Root<ProcessingInstruction>> {
|
||||
// Step 1.
|
||||
if xml_name_type(&target) == InvalidXMLName {
|
||||
return Err(InvalidCharacter);
|
||||
return Err(Error::InvalidCharacter);
|
||||
}
|
||||
|
||||
// Step 2.
|
||||
if data.contains("?>") {
|
||||
return Err(InvalidCharacter);
|
||||
return Err(Error::InvalidCharacter);
|
||||
}
|
||||
|
||||
// Step 3.
|
||||
|
@ -1348,7 +1346,7 @@ impl DocumentMethods for Document {
|
|||
fn ImportNode(&self, node: &Node, deep: bool) -> Fallible<Root<Node>> {
|
||||
// Step 1.
|
||||
if node.is_document() {
|
||||
return Err(NotSupported);
|
||||
return Err(Error::NotSupported);
|
||||
}
|
||||
|
||||
// Step 2.
|
||||
|
@ -1364,7 +1362,7 @@ impl DocumentMethods for Document {
|
|||
fn AdoptNode(&self, node: &Node) -> Fallible<Root<Node>> {
|
||||
// Step 1.
|
||||
if node.is_document() {
|
||||
return Err(NotSupported);
|
||||
return Err(Error::NotSupported);
|
||||
}
|
||||
|
||||
// Step 2.
|
||||
|
@ -1392,7 +1390,7 @@ impl DocumentMethods for Document {
|
|||
KeyboardEvent::new_uninitialized(window.r()))),
|
||||
"messageevent" => Ok(EventCast::from_root(
|
||||
MessageEvent::new_uninitialized(GlobalRef::Window(window.r())))),
|
||||
_ => Err(NotSupported)
|
||||
_ => Err(Error::NotSupported)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1535,14 +1533,14 @@ impl DocumentMethods for Document {
|
|||
// Step 1.
|
||||
let new_body = match new_body {
|
||||
Some(new_body) => new_body,
|
||||
None => return Err(HierarchyRequest),
|
||||
None => return Err(Error::HierarchyRequest),
|
||||
};
|
||||
|
||||
let node = NodeCast::from_ref(new_body);
|
||||
match node.type_id() {
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLBodyElement)) |
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLFrameSetElement)) => {}
|
||||
_ => return Err(HierarchyRequest)
|
||||
_ => return Err(Error::HierarchyRequest)
|
||||
}
|
||||
|
||||
// Step 2.
|
||||
|
@ -1561,7 +1559,7 @@ impl DocumentMethods for Document {
|
|||
},
|
||||
|
||||
// Step 4.
|
||||
(None, _) => return Err(HierarchyRequest),
|
||||
(None, _) => return Err(Error::HierarchyRequest),
|
||||
|
||||
// Step 5.
|
||||
(Some(ref root), &None) => {
|
||||
|
@ -1730,7 +1728,7 @@ impl DocumentMethods for Document {
|
|||
//TODO: return empty string for cookie-averse Document
|
||||
let url = self.url();
|
||||
if !is_scheme_host_port_tuple(&url) {
|
||||
return Err(Security);
|
||||
return Err(Error::Security);
|
||||
}
|
||||
let window = self.window.root();
|
||||
let (tx, rx) = ipc::channel().unwrap();
|
||||
|
@ -1744,7 +1742,7 @@ impl DocumentMethods for Document {
|
|||
//TODO: ignore for cookie-averse Document
|
||||
let url = self.url();
|
||||
if !is_scheme_host_port_tuple(url) {
|
||||
return Err(Security);
|
||||
return Err(Error::Security);
|
||||
}
|
||||
let window = self.window.root();
|
||||
let _ = window.r().resource_task().send(SetCookiesForUrl((*url).clone(), cookie, NonHTTP));
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
use dom::attr::Attr;
|
||||
use dom::bindings::codegen::Bindings::DOMTokenListBinding;
|
||||
use dom::bindings::codegen::Bindings::DOMTokenListBinding::DOMTokenListMethods;
|
||||
use dom::bindings::error::Error::{InvalidCharacter, Syntax};
|
||||
use dom::bindings::error::{ErrorResult, Fallible};
|
||||
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::{JS, Root};
|
||||
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
||||
|
@ -46,8 +45,8 @@ impl DOMTokenList {
|
|||
|
||||
fn check_token_exceptions(&self, token: &str) -> Fallible<Atom> {
|
||||
match token {
|
||||
"" => Err(Syntax),
|
||||
slice if slice.find(HTML_SPACE_CHARACTERS).is_some() => Err(InvalidCharacter),
|
||||
"" => Err(Error::Syntax),
|
||||
slice if slice.find(HTML_SPACE_CHARACTERS).is_some() => Err(Error::InvalidCharacter),
|
||||
slice => Ok(Atom::from_slice(slice))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,9 +28,7 @@ use dom::bindings::codegen::InheritTypes::{HTMLTableRowElementCast, HTMLTableSec
|
|||
use dom::bindings::codegen::InheritTypes::{HTMLTemplateElementCast, HTMLTextAreaElementCast};
|
||||
use dom::bindings::codegen::InheritTypes::{NodeCast, TextCast};
|
||||
use dom::bindings::codegen::UnionTypes::NodeOrString;
|
||||
use dom::bindings::error::Error::NoModificationAllowed;
|
||||
use dom::bindings::error::Error::{InvalidCharacter, Syntax};
|
||||
use dom::bindings::error::{ErrorResult, Fallible};
|
||||
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||
use dom::bindings::js::{JS, LayoutJS, MutNullableHeap};
|
||||
use dom::bindings::js::{Root, RootedReference};
|
||||
use dom::bindings::utils::XMLName::InvalidXMLName;
|
||||
|
@ -909,7 +907,7 @@ impl Element {
|
|||
pub fn set_custom_attribute(&self, name: DOMString, value: DOMString) -> ErrorResult {
|
||||
// Step 1.
|
||||
match xml_name_type(&name) {
|
||||
InvalidXMLName => return Err(InvalidCharacter),
|
||||
InvalidXMLName => return Err(Error::InvalidCharacter),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
|
@ -1174,7 +1172,7 @@ impl ElementMethods for Element {
|
|||
value: DOMString) -> ErrorResult {
|
||||
// Step 1.
|
||||
if xml_name_type(&name) == InvalidXMLName {
|
||||
return Err(InvalidCharacter);
|
||||
return Err(Error::InvalidCharacter);
|
||||
}
|
||||
|
||||
// Step 2.
|
||||
|
@ -1341,7 +1339,7 @@ impl ElementMethods for Element {
|
|||
|
||||
let parent = match context_parent.r().type_id() {
|
||||
// Step 3.
|
||||
NodeTypeId::Document => return Err(NoModificationAllowed),
|
||||
NodeTypeId::Document => return Err(Error::NoModificationAllowed),
|
||||
|
||||
// Step 4.
|
||||
NodeTypeId::DocumentFragment => {
|
||||
|
@ -1440,7 +1438,7 @@ impl ElementMethods for Element {
|
|||
// https://dom.spec.whatwg.org/#dom-element-matches
|
||||
fn Matches(&self, selectors: DOMString) -> Fallible<bool> {
|
||||
match parse_author_origin_selector_list_from_str(&selectors) {
|
||||
Err(()) => Err(Syntax),
|
||||
Err(()) => Err(Error::Syntax),
|
||||
Ok(ref selectors) => {
|
||||
Ok(matches(selectors, &Root::from_ref(self), None))
|
||||
}
|
||||
|
@ -1450,7 +1448,7 @@ impl ElementMethods for Element {
|
|||
// https://dom.spec.whatwg.org/#dom-element-closest
|
||||
fn Closest(&self, selectors: DOMString) -> Fallible<Option<Root<Element>>> {
|
||||
match parse_author_origin_selector_list_from_str(&selectors) {
|
||||
Err(()) => Err(Syntax),
|
||||
Err(()) => Err(Error::Syntax),
|
||||
Ok(ref selectors) => {
|
||||
let root = NodeCast::from_ref(self);
|
||||
for element in root.inclusive_ancestors() {
|
||||
|
|
|
@ -8,8 +8,7 @@ use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
|||
use dom::bindings::codegen::Bindings::EventListenerBinding::EventListener;
|
||||
use dom::bindings::codegen::Bindings::EventTargetBinding::EventTargetMethods;
|
||||
use dom::bindings::conversions::get_dom_class;
|
||||
use dom::bindings::error::Error::InvalidState;
|
||||
use dom::bindings::error::{Fallible, report_pending_exception};
|
||||
use dom::bindings::error::{Error, Fallible, report_pending_exception};
|
||||
use dom::bindings::utils::{Reflectable, Reflector};
|
||||
use dom::event::Event;
|
||||
use dom::eventdispatcher::dispatch_event;
|
||||
|
@ -333,7 +332,7 @@ impl EventTargetMethods for EventTarget {
|
|||
// https://dom.spec.whatwg.org/#dom-eventtarget-dispatchevent
|
||||
fn DispatchEvent(&self, event: &Event) -> Fallible<bool> {
|
||||
if event.dispatching() || !event.initialized() {
|
||||
return Err(InvalidState);
|
||||
return Err(Error::InvalidState);
|
||||
}
|
||||
event.set_trusted(false);
|
||||
Ok(self.dispatch_event(event))
|
||||
|
|
|
@ -6,8 +6,7 @@ use dom::bindings::codegen::Bindings::BlobBinding::BlobMethods;
|
|||
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
||||
use dom::bindings::codegen::Bindings::FileReaderBinding::{self, FileReaderConstants, FileReaderMethods};
|
||||
use dom::bindings::codegen::InheritTypes::{EventCast, EventTargetCast};
|
||||
use dom::bindings::error::Error::InvalidState;
|
||||
use dom::bindings::error::{ErrorResult, Fallible};
|
||||
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||
use dom::bindings::global::{GlobalField, GlobalRef};
|
||||
use dom::bindings::js::{JS, MutNullableHeap, Root};
|
||||
use dom::bindings::refcounted::Trusted;
|
||||
|
@ -341,7 +340,7 @@ impl FileReader {
|
|||
let global = root.r();
|
||||
// Step 1
|
||||
if self.ready_state.get() == FileReaderReadyState::Loading {
|
||||
return Err(InvalidState);
|
||||
return Err(Error::InvalidState);
|
||||
}
|
||||
// Step 2
|
||||
if blob.IsClosed() {
|
||||
|
|
|
@ -12,8 +12,7 @@ use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
|||
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLFrameSetElementDerived};
|
||||
use dom::bindings::codegen::InheritTypes::{EventTargetCast, HTMLInputElementCast, NodeCast};
|
||||
use dom::bindings::codegen::InheritTypes::{HTMLBodyElementDerived, HTMLElementDerived, HTMLHtmlElementDerived};
|
||||
use dom::bindings::error::Error::Syntax;
|
||||
use dom::bindings::error::ErrorResult;
|
||||
use dom::bindings::error::{Error, ErrorResult};
|
||||
use dom::bindings::js::{JS, MutNullableHeap, Root};
|
||||
use dom::bindings::utils::Reflectable;
|
||||
use dom::cssstyledeclaration::{CSSModificationAccess, CSSStyleDeclaration};
|
||||
|
@ -289,7 +288,7 @@ impl HTMLElement {
|
|||
if name.chars()
|
||||
.skip_while(|&ch| ch != '\u{2d}')
|
||||
.nth(1).map_or(false, |ch| ch >= 'a' && ch <= 'z') {
|
||||
return Err(Syntax);
|
||||
return Err(Error::Syntax);
|
||||
}
|
||||
let element = ElementCast::from_ref(self);
|
||||
element.set_custom_attribute(to_snake_case(name), value)
|
||||
|
|
|
@ -10,8 +10,7 @@ use dom::bindings::codegen::InheritTypes::HTMLIFrameElementDerived;
|
|||
use dom::bindings::codegen::InheritTypes::{ElementCast, EventCast, NodeCast};
|
||||
use dom::bindings::codegen::InheritTypes::{EventTargetCast, HTMLElementCast};
|
||||
use dom::bindings::conversions::ToJSValConvertible;
|
||||
use dom::bindings::error::Error::NotSupported;
|
||||
use dom::bindings::error::{ErrorResult, Fallible};
|
||||
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::{Root};
|
||||
use dom::bindings::utils::Reflectable;
|
||||
|
@ -232,7 +231,7 @@ pub fn Navigate(iframe: &HTMLIFrameElement, direction: NavigationDirection) -> F
|
|||
Ok(())
|
||||
} else {
|
||||
debug!("this frame is not mozbrowser (or experimental_enabled is false)");
|
||||
Err(NotSupported)
|
||||
Err(Error::NotSupported)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -329,12 +328,12 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement {
|
|||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/reload
|
||||
fn Reload(&self, _hardReload: bool) -> Fallible<()> {
|
||||
Err(NotSupported)
|
||||
Err(Error::NotSupported)
|
||||
}
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/stop
|
||||
fn Stop(&self) -> Fallible<()> {
|
||||
Err(NotSupported)
|
||||
Err(Error::NotSupported)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-dim-width
|
||||
|
|
|
@ -25,8 +25,7 @@ use dom::bindings::codegen::InheritTypes::{HTMLOptGroupElementDerived, NodeBase,
|
|||
use dom::bindings::codegen::InheritTypes::{ProcessingInstructionCast, TextCast, TextDerived};
|
||||
use dom::bindings::codegen::UnionTypes::NodeOrString;
|
||||
use dom::bindings::conversions;
|
||||
use dom::bindings::error::Error::{HierarchyRequest, NotFound, Syntax};
|
||||
use dom::bindings::error::{ErrorResult, Fallible};
|
||||
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::Root;
|
||||
use dom::bindings::js::RootedReference;
|
||||
|
@ -807,7 +806,7 @@ impl Node {
|
|||
// Step 1.
|
||||
match parse_author_origin_selector_list_from_str(&selectors) {
|
||||
// Step 2.
|
||||
Err(()) => Err(Syntax),
|
||||
Err(()) => Err(Error::Syntax),
|
||||
// Step 3.
|
||||
Ok(ref selectors) => {
|
||||
Ok(self.traverse_preorder().filter_map(ElementCast::to_root).find(|element| {
|
||||
|
@ -827,7 +826,7 @@ impl Node {
|
|||
// Step 1.
|
||||
match parse_author_origin_selector_list_from_str(&selectors) {
|
||||
// Step 2.
|
||||
Err(()) => Err(Syntax),
|
||||
Err(()) => Err(Error::Syntax),
|
||||
// Step 3.
|
||||
Ok(selectors) => {
|
||||
Ok(QuerySelectorIterator::new(self.traverse_preorder(), selectors))
|
||||
|
@ -1432,18 +1431,18 @@ impl Node {
|
|||
NodeTypeId::Document |
|
||||
NodeTypeId::DocumentFragment |
|
||||
NodeTypeId::Element(..) => (),
|
||||
_ => return Err(HierarchyRequest)
|
||||
_ => return Err(Error::HierarchyRequest)
|
||||
}
|
||||
|
||||
// Step 2.
|
||||
if node.is_inclusive_ancestor_of(parent) {
|
||||
return Err(HierarchyRequest);
|
||||
return Err(Error::HierarchyRequest);
|
||||
}
|
||||
|
||||
// Step 3.
|
||||
if let Some(child) = child {
|
||||
if !parent.is_parent_of(child) {
|
||||
return Err(NotFound);
|
||||
return Err(Error::NotFound);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1451,19 +1450,19 @@ impl Node {
|
|||
match node.type_id() {
|
||||
NodeTypeId::CharacterData(CharacterDataTypeId::Text) => {
|
||||
if parent.is_document() {
|
||||
return Err(HierarchyRequest);
|
||||
return Err(Error::HierarchyRequest);
|
||||
}
|
||||
},
|
||||
NodeTypeId::DocumentType => {
|
||||
if !parent.is_document() {
|
||||
return Err(HierarchyRequest);
|
||||
return Err(Error::HierarchyRequest);
|
||||
}
|
||||
},
|
||||
NodeTypeId::DocumentFragment |
|
||||
NodeTypeId::Element(_) |
|
||||
NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction) |
|
||||
NodeTypeId::CharacterData(CharacterDataTypeId::Comment) => (),
|
||||
NodeTypeId::Document => return Err(HierarchyRequest)
|
||||
NodeTypeId::Document => return Err(Error::HierarchyRequest)
|
||||
}
|
||||
|
||||
// Step 6.
|
||||
|
@ -1475,35 +1474,35 @@ impl Node {
|
|||
if node.children()
|
||||
.any(|c| c.r().is_text())
|
||||
{
|
||||
return Err(HierarchyRequest);
|
||||
return Err(Error::HierarchyRequest);
|
||||
}
|
||||
match node.child_elements().count() {
|
||||
0 => (),
|
||||
// Step 6.1.2
|
||||
1 => {
|
||||
if !parent.child_elements().is_empty() {
|
||||
return Err(HierarchyRequest);
|
||||
return Err(Error::HierarchyRequest);
|
||||
}
|
||||
if let Some(child) = child {
|
||||
if child.inclusively_following_siblings()
|
||||
.any(|child| child.r().is_doctype()) {
|
||||
return Err(HierarchyRequest);
|
||||
return Err(Error::HierarchyRequest);
|
||||
}
|
||||
}
|
||||
},
|
||||
// Step 6.1.1(a)
|
||||
_ => return Err(HierarchyRequest),
|
||||
_ => return Err(Error::HierarchyRequest),
|
||||
}
|
||||
},
|
||||
// Step 6.2
|
||||
NodeTypeId::Element(_) => {
|
||||
if !parent.child_elements().is_empty() {
|
||||
return Err(HierarchyRequest);
|
||||
return Err(Error::HierarchyRequest);
|
||||
}
|
||||
if let Some(ref child) = child {
|
||||
if child.inclusively_following_siblings()
|
||||
.any(|child| child.r().is_doctype()) {
|
||||
return Err(HierarchyRequest);
|
||||
return Err(Error::HierarchyRequest);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -1512,7 +1511,7 @@ impl Node {
|
|||
if parent.children()
|
||||
.any(|c| c.r().is_doctype())
|
||||
{
|
||||
return Err(HierarchyRequest);
|
||||
return Err(Error::HierarchyRequest);
|
||||
}
|
||||
match child {
|
||||
Some(child) => {
|
||||
|
@ -1520,12 +1519,12 @@ impl Node {
|
|||
.take_while(|c| c.r() != child)
|
||||
.any(|c| c.r().is_element())
|
||||
{
|
||||
return Err(HierarchyRequest);
|
||||
return Err(Error::HierarchyRequest);
|
||||
}
|
||||
},
|
||||
None => {
|
||||
if !parent.child_elements().is_empty() {
|
||||
return Err(HierarchyRequest);
|
||||
return Err(Error::HierarchyRequest);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@ -1647,8 +1646,8 @@ impl Node {
|
|||
fn pre_remove(child: &Node, parent: &Node) -> Fallible<Root<Node>> {
|
||||
// Step 1.
|
||||
match child.GetParentNode() {
|
||||
Some(ref node) if node.r() != parent => return Err(NotFound),
|
||||
None => return Err(NotFound),
|
||||
Some(ref node) if node.r() != parent => return Err(Error::NotFound),
|
||||
None => return Err(Error::NotFound),
|
||||
_ => ()
|
||||
}
|
||||
|
||||
|
@ -2070,25 +2069,25 @@ impl NodeMethods for Node {
|
|||
NodeTypeId::Document |
|
||||
NodeTypeId::DocumentFragment |
|
||||
NodeTypeId::Element(..) => (),
|
||||
_ => return Err(HierarchyRequest)
|
||||
_ => return Err(Error::HierarchyRequest)
|
||||
}
|
||||
|
||||
// Step 2.
|
||||
if node.is_inclusive_ancestor_of(self) {
|
||||
return Err(HierarchyRequest);
|
||||
return Err(Error::HierarchyRequest);
|
||||
}
|
||||
|
||||
// Step 3.
|
||||
if !self.is_parent_of(child) {
|
||||
return Err(NotFound);
|
||||
return Err(Error::NotFound);
|
||||
}
|
||||
|
||||
// Step 4-5.
|
||||
match node.type_id() {
|
||||
NodeTypeId::CharacterData(CharacterDataTypeId::Text) if self.is_document() =>
|
||||
return Err(HierarchyRequest),
|
||||
NodeTypeId::DocumentType if !self.is_document() => return Err(HierarchyRequest),
|
||||
NodeTypeId::Document => return Err(HierarchyRequest),
|
||||
return Err(Error::HierarchyRequest),
|
||||
NodeTypeId::DocumentType if !self.is_document() => return Err(Error::HierarchyRequest),
|
||||
NodeTypeId::Document => return Err(Error::HierarchyRequest),
|
||||
_ => ()
|
||||
}
|
||||
|
||||
|
@ -2101,7 +2100,7 @@ impl NodeMethods for Node {
|
|||
if node.children()
|
||||
.any(|c| c.is_text())
|
||||
{
|
||||
return Err(HierarchyRequest);
|
||||
return Err(Error::HierarchyRequest);
|
||||
}
|
||||
match node.child_elements().count() {
|
||||
0 => (),
|
||||
|
@ -2109,27 +2108,27 @@ impl NodeMethods for Node {
|
|||
1 => {
|
||||
if self.child_elements()
|
||||
.any(|c| NodeCast::from_ref(c.r()) != child) {
|
||||
return Err(HierarchyRequest);
|
||||
return Err(Error::HierarchyRequest);
|
||||
}
|
||||
if child.following_siblings()
|
||||
.any(|child| child.is_doctype()) {
|
||||
return Err(HierarchyRequest);
|
||||
return Err(Error::HierarchyRequest);
|
||||
}
|
||||
},
|
||||
// Step 6.1.1(a)
|
||||
_ => return Err(HierarchyRequest)
|
||||
_ => return Err(Error::HierarchyRequest)
|
||||
}
|
||||
},
|
||||
// Step 6.2
|
||||
NodeTypeId::Element(..) => {
|
||||
if self.child_elements()
|
||||
.any(|c| NodeCast::from_ref(c.r()) != child) {
|
||||
return Err(HierarchyRequest);
|
||||
return Err(Error::HierarchyRequest);
|
||||
}
|
||||
if child.following_siblings()
|
||||
.any(|child| child.is_doctype())
|
||||
{
|
||||
return Err(HierarchyRequest);
|
||||
return Err(Error::HierarchyRequest);
|
||||
}
|
||||
},
|
||||
// Step 6.3
|
||||
|
@ -2138,13 +2137,13 @@ impl NodeMethods for Node {
|
|||
.any(|c| c.is_doctype() &&
|
||||
c.r() != child)
|
||||
{
|
||||
return Err(HierarchyRequest);
|
||||
return Err(Error::HierarchyRequest);
|
||||
}
|
||||
if self.children()
|
||||
.take_while(|c| c.r() != child)
|
||||
.any(|c| c.is_element())
|
||||
{
|
||||
return Err(HierarchyRequest);
|
||||
return Err(Error::HierarchyRequest);
|
||||
}
|
||||
},
|
||||
NodeTypeId::CharacterData(..) => (),
|
||||
|
|
|
@ -11,7 +11,6 @@ use dom::bindings::codegen::Bindings::RangeBinding::{self, RangeConstants};
|
|||
use dom::bindings::codegen::Bindings::TextBinding::TextMethods;
|
||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||
use dom::bindings::codegen::InheritTypes::{CharacterDataCast, NodeCast, TextCast, TextDerived};
|
||||
use dom::bindings::error::Error::HierarchyRequest;
|
||||
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::{JS, Root, RootedReference};
|
||||
|
@ -117,7 +116,7 @@ impl Range {
|
|||
|
||||
// Step 12.
|
||||
if contained_children.iter().any(|n| n.is_doctype()) {
|
||||
return Err(HierarchyRequest);
|
||||
return Err(Error::HierarchyRequest);
|
||||
}
|
||||
|
||||
Ok((first_contained_child, last_contained_child, contained_children))
|
||||
|
@ -597,7 +596,7 @@ impl RangeMethods for Range {
|
|||
match start_node.type_id() {
|
||||
// Handled under step 2.
|
||||
NodeTypeId::CharacterData(CharacterDataTypeId::Text) => (),
|
||||
NodeTypeId::CharacterData(_) => return Err(HierarchyRequest),
|
||||
NodeTypeId::CharacterData(_) => return Err(Error::HierarchyRequest),
|
||||
_ => ()
|
||||
}
|
||||
|
||||
|
@ -608,7 +607,7 @@ impl RangeMethods for Range {
|
|||
let parent = match start_node.GetParentNode() {
|
||||
Some(parent) => parent,
|
||||
// Step 1.
|
||||
None => return Err(HierarchyRequest)
|
||||
None => return Err(Error::HierarchyRequest)
|
||||
};
|
||||
// Step 5.
|
||||
(Some(Root::from_ref(start_node.r())), parent)
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
|
||||
use dom::bindings::codegen::Bindings::TextEncoderBinding;
|
||||
use dom::bindings::codegen::Bindings::TextEncoderBinding::TextEncoderMethods;
|
||||
use dom::bindings::error::Error::Range;
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::bindings::error::{Error, Fallible};
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::Root;
|
||||
use dom::bindings::str::USVString;
|
||||
|
@ -50,7 +49,7 @@ impl TextEncoder {
|
|||
Some(enc) => enc,
|
||||
None => {
|
||||
debug!("Encoding Label Not Supported");
|
||||
return Err(Range("The given encoding is not supported.".to_owned()))
|
||||
return Err(Error::Range("The given encoding is not supported.".to_owned()))
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -60,7 +59,7 @@ impl TextEncoder {
|
|||
}
|
||||
_ => {
|
||||
debug!("Encoding Not UTF");
|
||||
Err(Range("The encoding must be utf-8, utf-16le, or utf-16be.".to_owned()))
|
||||
Err(Error::Range("The encoding must be utf-8, utf-16le, or utf-16be.".to_owned()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ use dom::bindings::codegen::Bindings::WebSocketBinding::{BinaryType, WebSocketMe
|
|||
use dom::bindings::codegen::InheritTypes::EventCast;
|
||||
use dom::bindings::codegen::InheritTypes::EventTargetCast;
|
||||
use dom::bindings::conversions::ToJSValConvertible;
|
||||
use dom::bindings::error::Error::{InvalidAccess, Syntax};
|
||||
use dom::bindings::error::{Error, Fallible};
|
||||
use dom::bindings::global::{GlobalField, GlobalRef};
|
||||
use dom::bindings::js::Root;
|
||||
|
@ -146,15 +145,15 @@ impl WebSocket {
|
|||
// https://tools.ietf.org/html/rfc6455#section-4.1
|
||||
// Handshake requirements, step 10
|
||||
if protocol.is_empty() {
|
||||
return Err(Syntax);
|
||||
return Err(Error::Syntax);
|
||||
}
|
||||
|
||||
if protocols[i + 1..].iter().any(|p| p == protocol) {
|
||||
return Err(Syntax);
|
||||
return Err(Error::Syntax);
|
||||
}
|
||||
|
||||
if protocol.chars().any(|c| c < '\u{0021}' || c > '\u{007E}') {
|
||||
return Err(Syntax);
|
||||
return Err(Error::Syntax);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,8 +12,7 @@ use dom::bindings::codegen::Bindings::FunctionBinding::Function;
|
|||
use dom::bindings::codegen::Bindings::WindowBinding::{ScrollBehavior, ScrollToOptions};
|
||||
use dom::bindings::codegen::Bindings::WindowBinding::{self, FrameRequestCallback, WindowMethods};
|
||||
use dom::bindings::codegen::InheritTypes::{ElementCast, EventTargetCast, NodeCast, WindowDerived};
|
||||
use dom::bindings::error::Error::InvalidCharacter;
|
||||
use dom::bindings::error::{Fallible, report_pending_exception};
|
||||
use dom::bindings::error::{Error, Fallible, report_pending_exception};
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::global::global_object_for_js_object;
|
||||
use dom::bindings::js::RootedReference;
|
||||
|
@ -298,7 +297,7 @@ pub fn base64_btoa(input: DOMString) -> Fallible<DOMString> {
|
|||
// the method's first argument contains any character whose code point
|
||||
// is greater than U+00FF."
|
||||
if input.chars().any(|c: char| c > '\u{FF}') {
|
||||
Err(InvalidCharacter)
|
||||
Err(Error::InvalidCharacter)
|
||||
} else {
|
||||
// "Otherwise, the user agent must convert that argument to a
|
||||
// sequence of octets whose nth octet is the eight-bit
|
||||
|
@ -340,7 +339,7 @@ pub fn base64_atob(input: DOMString) -> Fallible<DOMString> {
|
|||
// "If the length of input divides by 4 leaving a remainder of 1,
|
||||
// throw an InvalidCharacterError exception and abort these steps."
|
||||
if input.len() % 4 == 1 {
|
||||
return Err(InvalidCharacter)
|
||||
return Err(Error::InvalidCharacter)
|
||||
}
|
||||
|
||||
// "If input contains a character that is not in the following list of
|
||||
|
@ -351,12 +350,12 @@ pub fn base64_atob(input: DOMString) -> Fallible<DOMString> {
|
|||
// U+002F SOLIDUS (/)
|
||||
// Alphanumeric ASCII characters"
|
||||
if input.chars().any(|c| c != '+' && c != '/' && !c.is_alphanumeric()) {
|
||||
return Err(InvalidCharacter)
|
||||
return Err(Error::InvalidCharacter)
|
||||
}
|
||||
|
||||
match input.from_base64() {
|
||||
Ok(data) => Ok(data.iter().map(|&b| b as char).collect::<String>()),
|
||||
Err(..) => Err(InvalidCharacter)
|
||||
Err(..) => Err(Error::InvalidCharacter)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,7 @@ use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
|||
use dom::bindings::codegen::Bindings::WorkerBinding;
|
||||
use dom::bindings::codegen::Bindings::WorkerBinding::WorkerMethods;
|
||||
use dom::bindings::codegen::InheritTypes::{EventCast, EventTargetCast};
|
||||
use dom::bindings::error::Error::Syntax;
|
||||
use dom::bindings::error::{ErrorResult, Fallible};
|
||||
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||
use dom::bindings::global::{GlobalField, GlobalRef};
|
||||
use dom::bindings::js::Root;
|
||||
use dom::bindings::refcounted::Trusted;
|
||||
|
@ -68,7 +67,7 @@ impl Worker {
|
|||
// Step 2-4.
|
||||
let worker_url = match UrlParser::new().base_url(&global.get_url()).parse(&script_url) {
|
||||
Ok(url) => url,
|
||||
Err(_) => return Err(Syntax),
|
||||
Err(_) => return Err(Error::Syntax),
|
||||
};
|
||||
|
||||
let resource_task = global.resource_task();
|
||||
|
|
|
@ -6,8 +6,7 @@ use devtools_traits::{DevtoolScriptControlMsg, ScriptToDevtoolsControlMsg};
|
|||
use dom::bindings::codegen::Bindings::FunctionBinding::Function;
|
||||
use dom::bindings::codegen::Bindings::WorkerGlobalScopeBinding::WorkerGlobalScopeMethods;
|
||||
use dom::bindings::codegen::InheritTypes::DedicatedWorkerGlobalScopeCast;
|
||||
use dom::bindings::error::Error::{JSFailed, Network, Syntax};
|
||||
use dom::bindings::error::{ErrorResult, Fallible, report_pending_exception};
|
||||
use dom::bindings::error::{Error, ErrorResult, Fallible, report_pending_exception};
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::{JS, MutNullableHeap, Root};
|
||||
use dom::bindings::utils::Reflectable;
|
||||
|
@ -177,13 +176,13 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope {
|
|||
.parse(&url);
|
||||
match url {
|
||||
Ok(url) => urls.push(url),
|
||||
Err(_) => return Err(Syntax),
|
||||
Err(_) => return Err(Error::Syntax),
|
||||
};
|
||||
}
|
||||
|
||||
for url in urls {
|
||||
let (url, source) = match load_whole_resource(&self.resource_task, url) {
|
||||
Err(_) => return Err(Network),
|
||||
Err(_) => return Err(Error::Network),
|
||||
Ok((metadata, bytes)) => {
|
||||
(metadata.final_url, String::from_utf8(bytes).unwrap())
|
||||
}
|
||||
|
@ -194,7 +193,7 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope {
|
|||
Ok(_) => (),
|
||||
Err(_) => {
|
||||
println!("evaluate_script failed");
|
||||
return Err(JSFailed);
|
||||
return Err(Error::JSFailed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,8 +14,6 @@ use dom::bindings::codegen::InheritTypes::{EventCast, EventTargetCast, XMLHttpRe
|
|||
use dom::bindings::codegen::UnionTypes::StringOrURLSearchParams;
|
||||
use dom::bindings::codegen::UnionTypes::StringOrURLSearchParams::{eString, eURLSearchParams};
|
||||
use dom::bindings::conversions::ToJSValConvertible;
|
||||
use dom::bindings::error::Error::{Abort, Network, Security, Syntax, Timeout};
|
||||
use dom::bindings::error::Error::{InvalidAccess, InvalidState};
|
||||
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||
use dom::bindings::global::{GlobalField, GlobalRef, GlobalRoot};
|
||||
use dom::bindings::js::Root;
|
||||
|
@ -94,7 +92,7 @@ pub enum XHRProgress {
|
|||
Loading(GenerationId, ByteString),
|
||||
/// Loading is done
|
||||
Done(GenerationId),
|
||||
/// There was an error (only Abort, Timeout or Network is used)
|
||||
/// There was an error (only Error::Abort, Error::Timeout or Error::Network is used)
|
||||
Errored(GenerationId, Error),
|
||||
}
|
||||
|
||||
|
@ -209,8 +207,8 @@ impl XMLHttpRequest {
|
|||
if response.network_error {
|
||||
let mut context = self.xhr.lock().unwrap();
|
||||
let xhr = context.xhr.root();
|
||||
xhr.r().process_partial_response(XHRProgress::Errored(context.gen_id, Network));
|
||||
*context.sync_status.borrow_mut() = Some(Err(Network));
|
||||
xhr.r().process_partial_response(XHRProgress::Errored(context.gen_id, Error::Network));
|
||||
*context.sync_status.borrow_mut() = Some(Err(Error::Network));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -315,12 +313,12 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
|
|||
// Step 2
|
||||
match maybe_method {
|
||||
// Step 4
|
||||
Some(Method::Connect) | Some(Method::Trace) => Err(Security),
|
||||
Some(Method::Extension(ref t)) if &**t == "TRACK" => Err(Security),
|
||||
Some(Method::Connect) | Some(Method::Trace) => Err(Error::Security),
|
||||
Some(Method::Extension(ref t)) if &**t == "TRACK" => Err(Error::Security),
|
||||
Some(parsed_method) => {
|
||||
// Step 3
|
||||
if !method.is_token() {
|
||||
return Err(Syntax)
|
||||
return Err(Error::Syntax)
|
||||
}
|
||||
|
||||
*self.request_method.borrow_mut() = parsed_method;
|
||||
|
@ -329,13 +327,13 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
|
|||
let base = self.global.root().r().get_url();
|
||||
let parsed_url = match UrlParser::new().base_url(&base).parse(&url) {
|
||||
Ok(parsed) => parsed,
|
||||
Err(_) => return Err(Syntax) // Step 7
|
||||
Err(_) => return Err(Error::Syntax) // Step 7
|
||||
};
|
||||
// XXXManishearth Do some handling of username/passwords
|
||||
if self.sync.get() {
|
||||
// FIXME: This should only happen if the global environment is a document environment
|
||||
if self.timeout.get() != 0 || self.with_credentials.get() || self.response_type.get() != _empty {
|
||||
return Err(InvalidAccess)
|
||||
return Err(Error::InvalidAccess)
|
||||
}
|
||||
}
|
||||
// abort existing requests
|
||||
|
@ -356,7 +354,7 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
|
|||
},
|
||||
// This includes cases where as_str() returns None, and when is_token() returns false,
|
||||
// both of which indicate invalid extension method names
|
||||
_ => Err(Syntax), // Step 3
|
||||
_ => Err(Error::Syntax), // Step 3
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -370,10 +368,10 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
|
|||
// https://xhr.spec.whatwg.org/#the-setrequestheader()-method
|
||||
fn SetRequestHeader(&self, name: ByteString, mut value: ByteString) -> ErrorResult {
|
||||
if self.ready_state.get() != XMLHttpRequestState::Opened || self.send_flag.get() {
|
||||
return Err(InvalidState); // Step 1, 2
|
||||
return Err(Error::InvalidState); // Step 1, 2
|
||||
}
|
||||
if !name.is_token() || !value.is_field_value() {
|
||||
return Err(Syntax); // Step 3, 4
|
||||
return Err(Error::Syntax); // Step 3, 4
|
||||
}
|
||||
let name_lower = name.to_lower();
|
||||
let name_str = match name_lower.as_str() {
|
||||
|
@ -393,7 +391,7 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
|
|||
_ => s
|
||||
}
|
||||
},
|
||||
None => return Err(Syntax)
|
||||
None => return Err(Error::Syntax)
|
||||
};
|
||||
|
||||
debug!("SetRequestHeader: name={:?}, value={:?}", name.as_str(), value.as_str());
|
||||
|
@ -426,7 +424,7 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
|
|||
fn SetTimeout(&self, timeout: u32) -> ErrorResult {
|
||||
if self.sync.get() {
|
||||
// FIXME: Not valid for a worker environment
|
||||
Err(InvalidAccess)
|
||||
Err(Error::InvalidAccess)
|
||||
} else {
|
||||
self.timeout.set(timeout);
|
||||
if self.send_flag.get() {
|
||||
|
@ -456,10 +454,10 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
|
|||
match self.ready_state.get() {
|
||||
XMLHttpRequestState::HeadersReceived |
|
||||
XMLHttpRequestState::Loading |
|
||||
XMLHttpRequestState::Done => Err(InvalidState),
|
||||
_ if self.send_flag.get() => Err(InvalidState),
|
||||
XMLHttpRequestState::Done => Err(Error::InvalidState),
|
||||
_ if self.send_flag.get() => Err(Error::InvalidState),
|
||||
_ => match self.global.root() {
|
||||
GlobalRoot::Window(_) if self.sync.get() => Err(InvalidAccess),
|
||||
GlobalRoot::Window(_) if self.sync.get() => Err(Error::InvalidAccess),
|
||||
_ => {
|
||||
self.with_credentials.set(with_credentials);
|
||||
Ok(())
|
||||
|
@ -476,7 +474,7 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
|
|||
// https://xhr.spec.whatwg.org/#the-send()-method
|
||||
fn Send(&self, data: Option<SendParam>) -> ErrorResult {
|
||||
if self.ready_state.get() != XMLHttpRequestState::Opened || self.send_flag.get() {
|
||||
return Err(InvalidState); // Step 1, 2
|
||||
return Err(Error::InvalidState); // Step 1, 2
|
||||
}
|
||||
|
||||
let data = match *self.request_method.borrow() {
|
||||
|
@ -613,7 +611,7 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
|
|||
state == XMLHttpRequestState::HeadersReceived ||
|
||||
state == XMLHttpRequestState::Loading {
|
||||
let gen_id = self.generation_id.get();
|
||||
self.process_partial_response(XHRProgress::Errored(gen_id, Abort));
|
||||
self.process_partial_response(XHRProgress::Errored(gen_id, Error::Abort));
|
||||
// If open was called in one of the handlers invoked by the
|
||||
// above call then we should terminate the abort sequence
|
||||
if self.generation_id.get() != gen_id {
|
||||
|
@ -665,8 +663,8 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
|
|||
_ => {}
|
||||
}
|
||||
match self.ready_state.get() {
|
||||
XMLHttpRequestState::Loading | XMLHttpRequestState::Done => Err(InvalidState),
|
||||
_ if self.sync.get() => Err(InvalidAccess),
|
||||
XMLHttpRequestState::Loading | XMLHttpRequestState::Done => Err(Error::InvalidState),
|
||||
_ if self.sync.get() => Err(Error::InvalidAccess),
|
||||
_ => {
|
||||
self.response_type.set(response_type);
|
||||
Ok(())
|
||||
|
@ -720,7 +718,7 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
|
|||
_ => Ok("".to_owned())
|
||||
}
|
||||
},
|
||||
_ => Err(InvalidState)
|
||||
_ => Err(Error::InvalidState)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -763,8 +761,8 @@ impl XMLHttpRequest {
|
|||
match metadata.headers {
|
||||
Some(ref h) if allow_cross_origin_request(req, h) => {},
|
||||
_ => {
|
||||
self.process_partial_response(XHRProgress::Errored(gen_id, Network));
|
||||
return Err(Network);
|
||||
self.process_partial_response(XHRProgress::Errored(gen_id, Error::Network));
|
||||
return Err(Error::Network);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -788,8 +786,8 @@ impl XMLHttpRequest {
|
|||
Ok(())
|
||||
},
|
||||
Err(_) => {
|
||||
self.process_partial_response(XHRProgress::Errored(gen_id, Network));
|
||||
Err(Network)
|
||||
self.process_partial_response(XHRProgress::Errored(gen_id, Error::Network));
|
||||
Err(Error::Network)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -892,8 +890,8 @@ impl XMLHttpRequest {
|
|||
return_if_fetch_was_terminated!();
|
||||
|
||||
let errormsg = match e {
|
||||
Abort => "abort",
|
||||
Timeout => "timeout",
|
||||
Error::Abort => "abort",
|
||||
Error::Timeout => "timeout",
|
||||
_ => "error",
|
||||
};
|
||||
|
||||
|
@ -968,7 +966,7 @@ impl XMLHttpRequest {
|
|||
let this = *self;
|
||||
let xhr = this.xhr.root();
|
||||
if xhr.r().ready_state.get() != XMLHttpRequestState::Done {
|
||||
xhr.r().process_partial_response(XHRProgress::Errored(this.gen_id, Timeout));
|
||||
xhr.r().process_partial_response(XHRProgress::Errored(this.gen_id, Error::Timeout));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1068,8 +1066,8 @@ impl XMLHttpRequest {
|
|||
Err(_) => {
|
||||
// Happens in case of cross-origin non-http URIs
|
||||
self.process_partial_response(XHRProgress::Errored(
|
||||
self.generation_id.get(), Network));
|
||||
return Err(Network);
|
||||
self.generation_id.get(), Error::Network));
|
||||
return Err(Error::Network);
|
||||
}
|
||||
Ok(req) => req,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue