mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
commit
2c51d0ef53
13 changed files with 144 additions and 88 deletions
|
@ -37,6 +37,7 @@ pub enum EventTypeId {
|
|||
MessageEvent,
|
||||
MouseEvent,
|
||||
ProgressEvent,
|
||||
StorageEvent,
|
||||
UIEvent,
|
||||
ErrorEvent
|
||||
}
|
||||
|
|
|
@ -310,6 +310,7 @@ pub mod range;
|
|||
pub mod screen;
|
||||
pub mod servohtmlparser;
|
||||
pub mod storage;
|
||||
pub mod storageevent;
|
||||
pub mod text;
|
||||
pub mod treewalker;
|
||||
pub mod uievent;
|
||||
|
|
113
components/script/dom/storageevent.rs
Normal file
113
components/script/dom/storageevent.rs
Normal file
|
@ -0,0 +1,113 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::bindings::cell::DOMRefCell;
|
||||
use dom::bindings::codegen::Bindings::EventBinding::{EventMethods};
|
||||
use dom::bindings::codegen::Bindings::StorageEventBinding;
|
||||
use dom::bindings::codegen::Bindings::StorageEventBinding::{StorageEventMethods};
|
||||
|
||||
use dom::bindings::codegen::InheritTypes::{EventCast};
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::{MutNullableJS, JSRef, RootedReference, Temporary};
|
||||
use dom::bindings::utils::{reflect_dom_object};
|
||||
use dom::event::{Event, EventTypeId, EventBubbles, EventCancelable};
|
||||
use dom::storage::Storage;
|
||||
use util::str::DOMString;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct StorageEvent {
|
||||
event: Event,
|
||||
key: DOMRefCell<Option<DOMString>>,
|
||||
oldValue: DOMRefCell<Option<DOMString>>,
|
||||
newValue: DOMRefCell<Option<DOMString>>,
|
||||
url: DOMRefCell<DOMString>,
|
||||
storageArea: MutNullableJS<Storage>
|
||||
}
|
||||
|
||||
|
||||
impl StorageEvent {
|
||||
pub fn new_inherited(type_id: EventTypeId,
|
||||
key: Option<DOMString>,
|
||||
oldValue: Option<DOMString>,
|
||||
newValue: Option<DOMString>,
|
||||
url: DOMString,
|
||||
storageArea: Option<JSRef<Storage>>) -> StorageEvent {
|
||||
StorageEvent {
|
||||
event: Event::new_inherited(type_id),
|
||||
key: DOMRefCell::new(key),
|
||||
oldValue: DOMRefCell::new(oldValue),
|
||||
newValue: DOMRefCell::new(newValue),
|
||||
url: DOMRefCell::new(url),
|
||||
storageArea: MutNullableJS::new(storageArea)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(global: GlobalRef,
|
||||
type_: DOMString,
|
||||
bubbles: EventBubbles,
|
||||
cancelable: EventCancelable,
|
||||
key: Option<DOMString>,
|
||||
oldValue: Option<DOMString>,
|
||||
newValue: Option<DOMString>,
|
||||
url: DOMString,
|
||||
storageArea: Option<JSRef<Storage>>) -> Temporary<StorageEvent> {
|
||||
let ev = reflect_dom_object(box StorageEvent::new_inherited(EventTypeId::StorageEvent,
|
||||
key, oldValue, newValue,
|
||||
url, storageArea),
|
||||
global,
|
||||
StorageEventBinding::Wrap).root();
|
||||
let event: JSRef<Event> = EventCast::from_ref(ev.r());
|
||||
event.InitEvent(type_, bubbles == EventBubbles::Bubbles, cancelable == EventCancelable::Cancelable);
|
||||
Temporary::from_rooted(ev.r())
|
||||
}
|
||||
|
||||
pub fn Constructor(global: GlobalRef,
|
||||
type_: DOMString,
|
||||
init: &StorageEventBinding::StorageEventInit) -> Fallible<Temporary<StorageEvent>> {
|
||||
let key = init.key.clone();
|
||||
let oldValue = init.oldValue.clone();
|
||||
let newValue = init.newValue.clone();
|
||||
let url = init.url.clone();
|
||||
let storageArea = init.storageArea.r();
|
||||
let bubbles = if init.parent.bubbles { EventBubbles::Bubbles } else { EventBubbles::DoesNotBubble };
|
||||
let cancelable = if init.parent.cancelable { EventCancelable::Cancelable } else { EventCancelable::NotCancelable };
|
||||
let event = StorageEvent::new(global, type_,
|
||||
bubbles, cancelable,
|
||||
key, oldValue, newValue,
|
||||
url, storageArea);
|
||||
Ok(event)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> StorageEventMethods for JSRef<'a, StorageEvent> {
|
||||
fn GetKey(self) -> Option<DOMString> {
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let key = self.key.borrow();
|
||||
key.clone()
|
||||
}
|
||||
|
||||
fn GetOldValue(self) -> Option<DOMString> {
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let oldValue = self.oldValue.borrow();
|
||||
oldValue.clone()
|
||||
}
|
||||
|
||||
fn GetNewValue(self) -> Option<DOMString> {
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let newValue = self.newValue.borrow();
|
||||
newValue.clone()
|
||||
}
|
||||
|
||||
fn Url(self) -> DOMString {
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let url = self.url.borrow();
|
||||
url.clone()
|
||||
}
|
||||
|
||||
fn GetStorageArea(self) -> Option<Temporary<Storage>> {
|
||||
self.storageArea.get()
|
||||
}
|
||||
|
||||
}
|
28
components/script/dom/webidls/StorageEvent.webidl
Normal file
28
components/script/dom/webidls/StorageEvent.webidl
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* Interface for a client side storage. See
|
||||
* https://html.spec.whatwg.org/multipage/webstorage.html#the-storageevent-interface
|
||||
* for more information.
|
||||
*
|
||||
* Event sent to a window when a storage area changes.
|
||||
*/
|
||||
|
||||
[Constructor(DOMString type, optional StorageEventInit eventInitDict)]
|
||||
interface StorageEvent : Event {
|
||||
readonly attribute DOMString? key;
|
||||
readonly attribute DOMString? oldValue;
|
||||
readonly attribute DOMString? newValue;
|
||||
readonly attribute DOMString url;
|
||||
readonly attribute Storage? storageArea;
|
||||
};
|
||||
|
||||
dictionary StorageEventInit : EventInit {
|
||||
DOMString? key = null;
|
||||
DOMString? oldValue = null;
|
||||
DOMString? newValue = null;
|
||||
DOMString url = "";
|
||||
Storage? storageArea = null;
|
||||
};
|
|
@ -163,6 +163,7 @@ var interfaceNamesInGlobalScope = [
|
|||
"Range",
|
||||
"Screen",
|
||||
"Storage",
|
||||
"StorageEvent",
|
||||
"TestBinding", // XXX
|
||||
"Text",
|
||||
"TreeWalker",
|
||||
|
|
|
@ -9285,27 +9285,6 @@
|
|||
[StorageEvent interface object length]
|
||||
expected: FAIL
|
||||
|
||||
[StorageEvent interface: existence and properties of interface prototype object]
|
||||
expected: FAIL
|
||||
|
||||
[StorageEvent interface: existence and properties of interface prototype object\'s "constructor" property]
|
||||
expected: FAIL
|
||||
|
||||
[StorageEvent interface: attribute key]
|
||||
expected: FAIL
|
||||
|
||||
[StorageEvent interface: attribute oldValue]
|
||||
expected: FAIL
|
||||
|
||||
[StorageEvent interface: attribute newValue]
|
||||
expected: FAIL
|
||||
|
||||
[StorageEvent interface: attribute url]
|
||||
expected: FAIL
|
||||
|
||||
[StorageEvent interface: attribute storageArea]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLAppletElement interface: existence and properties of interface object]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
[event_constructor.html]
|
||||
type: testharness
|
||||
expected: TIMEOUT
|
||||
[Web Storage]
|
||||
expected: FAIL
|
||||
|
||||
[storageeventinit test]
|
||||
expected: NOTRUN
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
[event_constructor_js.html]
|
||||
type: testharness
|
||||
expected: TIMEOUT
|
||||
[Web Storage]
|
||||
expected: FAIL
|
||||
|
||||
[StorageEvent constructor and nulls]
|
||||
expected: NOTRUN
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
[event_local_storageeventinit.html]
|
||||
type: testharness
|
||||
expected: TIMEOUT
|
||||
[Web Storage]
|
||||
expected: FAIL
|
||||
|
||||
[storageeventinit test]
|
||||
expected: NOTRUN
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
[event_session_storageeventinit.html]
|
||||
type: testharness
|
||||
expected: TIMEOUT
|
||||
[Web Storage]
|
||||
expected: FAIL
|
||||
|
||||
[storageeventinit test]
|
||||
expected: NOTRUN
|
||||
|
|
@ -12,27 +12,6 @@
|
|||
[StorageEvent interface object length]
|
||||
expected: FAIL
|
||||
|
||||
[StorageEvent interface: existence and properties of interface prototype object]
|
||||
expected: FAIL
|
||||
|
||||
[StorageEvent interface: existence and properties of interface prototype object\'s "constructor" property]
|
||||
expected: FAIL
|
||||
|
||||
[StorageEvent interface: attribute key]
|
||||
expected: FAIL
|
||||
|
||||
[StorageEvent interface: attribute oldValue]
|
||||
expected: FAIL
|
||||
|
||||
[StorageEvent interface: attribute newValue]
|
||||
expected: FAIL
|
||||
|
||||
[StorageEvent interface: attribute url]
|
||||
expected: FAIL
|
||||
|
||||
[StorageEvent interface: attribute storageArea]
|
||||
expected: FAIL
|
||||
|
||||
[Window interface: attribute sessionStorage]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
[missing_arguments.html]
|
||||
type: testharness
|
||||
[Should throw TypeError for function "function () { new StorageEvent(); }".]
|
||||
expected: FAIL
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
[storage_local_key.html]
|
||||
type: testharness
|
||||
[Web Storage 3]
|
||||
expected: FAIL
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue