Make History attributes and methods throw

This commit is contained in:
Connor Brewster 2017-05-02 11:22:36 -06:00
parent 5e2d383274
commit 5c53f5b7fa
2 changed files with 26 additions and 12 deletions

View file

@ -6,7 +6,7 @@ use dom::bindings::codegen::Bindings::HistoryBinding;
use dom::bindings::codegen::Bindings::HistoryBinding::HistoryMethods; use dom::bindings::codegen::Bindings::HistoryBinding::HistoryMethods;
use dom::bindings::codegen::Bindings::LocationBinding::LocationBinding::LocationMethods; use dom::bindings::codegen::Bindings::LocationBinding::LocationBinding::LocationMethods;
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use dom::bindings::error::Fallible; use dom::bindings::error::{Error, ErrorResult, Fallible};
use dom::bindings::inheritance::Castable; use dom::bindings::inheritance::Castable;
use dom::bindings::js::{JS, Root}; use dom::bindings::js::{JS, Root};
use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::bindings::reflector::{Reflector, reflect_dom_object};
@ -40,27 +40,34 @@ impl History {
} }
impl History { impl History {
fn traverse_history(&self, direction: TraversalDirection) { fn traverse_history(&self, direction: TraversalDirection) -> ErrorResult {
if !self.window.Document().is_fully_active() {
return Err(Error::Security);
}
let global_scope = self.window.upcast::<GlobalScope>(); let global_scope = self.window.upcast::<GlobalScope>();
let pipeline = global_scope.pipeline_id(); let pipeline = global_scope.pipeline_id();
let msg = ConstellationMsg::TraverseHistory(Some(pipeline), direction); let msg = ConstellationMsg::TraverseHistory(Some(pipeline), direction);
let _ = global_scope.constellation_chan().send(msg); let _ = global_scope.constellation_chan().send(msg);
Ok(())
} }
} }
impl HistoryMethods for History { impl HistoryMethods for History {
// https://html.spec.whatwg.org/multipage/#dom-history-length // https://html.spec.whatwg.org/multipage/#dom-history-length
fn Length(&self) -> u32 { fn GetLength(&self) -> Fallible<u32> {
if !self.window.Document().is_fully_active() {
return Err(Error::Security);
}
let global_scope = self.window.upcast::<GlobalScope>(); let global_scope = self.window.upcast::<GlobalScope>();
let pipeline = global_scope.pipeline_id(); let pipeline = global_scope.pipeline_id();
let (sender, recv) = ipc::channel().expect("Failed to create channel to send jsh length."); let (sender, recv) = ipc::channel().expect("Failed to create channel to send jsh length.");
let msg = ConstellationMsg::JointSessionHistoryLength(pipeline, sender); let msg = ConstellationMsg::JointSessionHistoryLength(pipeline, sender);
let _ = global_scope.constellation_chan().send(msg); let _ = global_scope.constellation_chan().send(msg);
recv.recv().unwrap() Ok(recv.recv().unwrap())
} }
// https://html.spec.whatwg.org/multipage/#dom-history-go // https://html.spec.whatwg.org/multipage/#dom-history-go
fn Go(&self, delta: i32) -> Fallible<()> { fn Go(&self, delta: i32) -> ErrorResult {
let direction = if delta > 0 { let direction = if delta > 0 {
TraversalDirection::Forward(delta as usize) TraversalDirection::Forward(delta as usize)
} else if delta < 0 { } else if delta < 0 {
@ -69,17 +76,16 @@ impl HistoryMethods for History {
return self.window.Location().Reload(); return self.window.Location().Reload();
}; };
self.traverse_history(direction); self.traverse_history(direction)
Ok(())
} }
// https://html.spec.whatwg.org/multipage/#dom-history-back // https://html.spec.whatwg.org/multipage/#dom-history-back
fn Back(&self) { fn Back(&self) -> ErrorResult {
self.traverse_history(TraversalDirection::Back(1)); self.traverse_history(TraversalDirection::Back(1))
} }
// https://html.spec.whatwg.org/multipage/#dom-history-forward // https://html.spec.whatwg.org/multipage/#dom-history-forward
fn Forward(&self) { fn Forward(&self) -> ErrorResult {
self.traverse_history(TraversalDirection::Forward(1)); self.traverse_history(TraversalDirection::Forward(1))
} }
} }

View file

@ -7,12 +7,20 @@
// https://html.spec.whatwg.org/multipage/#the-history-interface // https://html.spec.whatwg.org/multipage/#the-history-interface
[Exposed=(Window,Worker)] [Exposed=(Window,Worker)]
interface History { interface History {
[Throws]
readonly attribute unsigned long length; readonly attribute unsigned long length;
// [Throws]
// attribute ScrollRestoration scrollRestoration; // attribute ScrollRestoration scrollRestoration;
// [Throws]
// readonly attribute any state; // readonly attribute any state;
[Throws] void go(optional long delta = 0); [Throws]
void go(optional long delta = 0);
[Throws]
void back(); void back();
[Throws]
void forward(); void forward();
// [Throws]
// void pushState(any data, DOMString title, optional USVString? url = null); // void pushState(any data, DOMString title, optional USVString? url = null);
// [Throws]
// void replaceState(any data, DOMString title, optional USVString? url = null); // void replaceState(any data, DOMString title, optional USVString? url = null);
}; };