Remove some usage of unsafe code in History

This commit is contained in:
marmeladema 2019-07-27 15:31:06 +01:00
parent 51e22fbc26
commit d1282dc8cc

View file

@ -18,9 +18,9 @@ use crate::dom::globalscope::GlobalScope;
use crate::dom::hashchangeevent::HashChangeEvent; use crate::dom::hashchangeevent::HashChangeEvent;
use crate::dom::popstateevent::PopStateEvent; use crate::dom::popstateevent::PopStateEvent;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::script_runtime::JSContext as SafeJSContext; use crate::script_runtime::JSContext;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use js::jsapi::{Heap, JSContext}; use js::jsapi::Heap;
use js::jsval::{JSVal, NullValue, UndefinedValue}; use js::jsval::{JSVal, NullValue, UndefinedValue};
use js::rust::HandleValue; use js::rust::HandleValue;
use msg::constellation_msg::{HistoryStateId, TraversalDirection}; use msg::constellation_msg::{HistoryStateId, TraversalDirection};
@ -165,7 +165,7 @@ impl History {
// https://html.spec.whatwg.org/multipage/#dom-history-replacestate // https://html.spec.whatwg.org/multipage/#dom-history-replacestate
fn push_or_replace_state( fn push_or_replace_state(
&self, &self,
cx: *mut JSContext, cx: JSContext,
data: HandleValue, data: HandleValue,
_title: DOMString, _title: DOMString,
url: Option<USVString>, url: Option<USVString>,
@ -185,7 +185,7 @@ impl History {
// TODO: Step 4 // TODO: Step 4
// Step 5 // Step 5
let serialized_data = StructuredCloneData::write(cx, data)?.move_to_arraybuffer(); let serialized_data = StructuredCloneData::write(*cx, data)?.move_to_arraybuffer();
let new_url: ServoUrl = match url { let new_url: ServoUrl = match url {
// Step 6 // Step 6
@ -265,7 +265,7 @@ impl History {
// Step 11 // Step 11
let global_scope = self.window.upcast::<GlobalScope>(); let global_scope = self.window.upcast::<GlobalScope>();
rooted!(in(cx) let mut state = UndefinedValue()); rooted!(in(*cx) let mut state = UndefinedValue());
StructuredCloneData::Vector(serialized_data).read(&global_scope, state.handle_mut()); StructuredCloneData::Vector(serialized_data).read(&global_scope, state.handle_mut());
// Step 12 // Step 12
@ -280,7 +280,7 @@ impl History {
impl HistoryMethods for History { impl HistoryMethods for History {
// https://html.spec.whatwg.org/multipage/#dom-history-state // https://html.spec.whatwg.org/multipage/#dom-history-state
fn GetState(&self, _cx: SafeJSContext) -> Fallible<JSVal> { fn GetState(&self, _cx: JSContext) -> Fallible<JSVal> {
if !self.window.Document().is_fully_active() { if !self.window.Document().is_fully_active() {
return Err(Error::Security); return Err(Error::Security);
} }
@ -329,22 +329,22 @@ impl HistoryMethods for History {
// https://html.spec.whatwg.org/multipage/#dom-history-pushstate // https://html.spec.whatwg.org/multipage/#dom-history-pushstate
fn PushState( fn PushState(
&self, &self,
cx: SafeJSContext, cx: JSContext,
data: HandleValue, data: HandleValue,
title: DOMString, title: DOMString,
url: Option<USVString>, url: Option<USVString>,
) -> ErrorResult { ) -> ErrorResult {
self.push_or_replace_state(*cx, data, title, url, PushOrReplace::Push) self.push_or_replace_state(cx, data, title, url, PushOrReplace::Push)
} }
// https://html.spec.whatwg.org/multipage/#dom-history-replacestate // https://html.spec.whatwg.org/multipage/#dom-history-replacestate
fn ReplaceState( fn ReplaceState(
&self, &self,
cx: SafeJSContext, cx: JSContext,
data: HandleValue, data: HandleValue,
title: DOMString, title: DOMString,
url: Option<USVString>, url: Option<USVString>,
) -> ErrorResult { ) -> ErrorResult {
self.push_or_replace_state(*cx, data, title, url, PushOrReplace::Replace) self.push_or_replace_state(cx, data, title, url, PushOrReplace::Replace)
} }
} }