mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
Add links to spec for script::dom structs/methods
This commit is contained in:
parent
e70beca74b
commit
46f14449d0
10 changed files with 36 additions and 0 deletions
|
@ -17,6 +17,7 @@ pub enum NodeListType {
|
|||
Children(JS<Node>)
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#interface-nodelist
|
||||
#[dom_struct]
|
||||
pub struct NodeList {
|
||||
reflector_: Reflector,
|
||||
|
@ -47,6 +48,7 @@ impl NodeList {
|
|||
}
|
||||
|
||||
impl<'a> NodeListMethods for JSRef<'a, NodeList> {
|
||||
// https://dom.spec.whatwg.org/#dom-nodelist-length
|
||||
fn Length(self) -> u32 {
|
||||
match self.list_type {
|
||||
NodeListType::Simple(ref elems) => elems.len() as u32,
|
||||
|
@ -57,6 +59,7 @@ impl<'a> NodeListMethods for JSRef<'a, NodeList> {
|
|||
}
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-nodelist-item
|
||||
fn Item(self, index: u32) -> Option<Temporary<Node>> {
|
||||
match self.list_type {
|
||||
_ if index >= self.Length() => None,
|
||||
|
|
|
@ -64,14 +64,17 @@ impl TreeWalker {
|
|||
}
|
||||
|
||||
impl<'a> TreeWalkerMethods for JSRef<'a, TreeWalker> {
|
||||
// https://dom.spec.whatwg.org/#dom-treewalker-root
|
||||
fn Root(self) -> Temporary<Node> {
|
||||
Temporary::new(self.root_node)
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-treewalker-whattoshow
|
||||
fn WhatToShow(self) -> u32 {
|
||||
self.what_to_show
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-treewalker-filter
|
||||
fn GetFilter(self) -> Option<NodeFilter> {
|
||||
match self.filter {
|
||||
Filter::None => None,
|
||||
|
@ -80,38 +83,47 @@ impl<'a> TreeWalkerMethods for JSRef<'a, TreeWalker> {
|
|||
}
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-treewalker-currentnode
|
||||
fn CurrentNode(self) -> Temporary<Node> {
|
||||
Temporary::new(self.current_node.get())
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-treewalker-currentnode
|
||||
fn SetCurrentNode(self, node: JSRef<Node>) {
|
||||
self.current_node.set(JS::from_rooted(node));
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-treewalker-parentnode
|
||||
fn ParentNode(self) -> Fallible<Option<Temporary<Node>>> {
|
||||
self.parent_node()
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-treewalker-firstchild
|
||||
fn FirstChild(self) -> Fallible<Option<Temporary<Node>>> {
|
||||
self.first_child()
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-treewalker-lastchild
|
||||
fn LastChild(self) -> Fallible<Option<Temporary<Node>>> {
|
||||
self.last_child()
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-treewalker-previoussibling
|
||||
fn PreviousSibling(self) -> Fallible<Option<Temporary<Node>>> {
|
||||
self.prev_sibling()
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-treewalker-nextsibling
|
||||
fn NextSibling(self) -> Fallible<Option<Temporary<Node>>> {
|
||||
self.next_sibling()
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-treewalker-previousnode
|
||||
fn PreviousNode(self) -> Fallible<Option<Temporary<Node>>> {
|
||||
self.prev_node()
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-treewalker-nextnode
|
||||
fn NextNode(self) -> Fallible<Option<Temporary<Node>>> {
|
||||
self.next_node()
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ use util::str::DOMString;
|
|||
use std::cell::Cell;
|
||||
use std::default::Default;
|
||||
|
||||
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#interface-UIEvent
|
||||
#[dom_struct]
|
||||
pub struct UIEvent {
|
||||
event: Event,
|
||||
|
@ -70,10 +71,12 @@ impl UIEvent {
|
|||
}
|
||||
|
||||
impl<'a> UIEventMethods for JSRef<'a, UIEvent> {
|
||||
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#widl-UIEvent-view
|
||||
fn GetView(self) -> Option<Temporary<Window>> {
|
||||
self.view.get()
|
||||
}
|
||||
|
||||
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#widl-UIEvent-detail
|
||||
fn Detail(self) -> i32 {
|
||||
self.detail.get()
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ use encoding::types::{EncodingRef, EncoderTrap};
|
|||
use std::collections::HashMap;
|
||||
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
||||
|
||||
// https://url.spec.whatwg.org/#interface-urlsearchparams
|
||||
#[dom_struct]
|
||||
pub struct URLSearchParams {
|
||||
reflector_: Reflector,
|
||||
|
@ -39,6 +40,7 @@ impl URLSearchParams {
|
|||
URLSearchParamsBinding::Wrap)
|
||||
}
|
||||
|
||||
// https://url.spec.whatwg.org/#dom-urlsearchparams-urlsearchparams
|
||||
pub fn Constructor(global: GlobalRef, init: Option<StringOrURLSearchParams>) ->
|
||||
Fallible<Temporary<URLSearchParams>> {
|
||||
let usp = URLSearchParams::new(global).root();
|
||||
|
@ -65,6 +67,7 @@ impl URLSearchParams {
|
|||
}
|
||||
|
||||
impl<'a> URLSearchParamsMethods for JSRef<'a, URLSearchParams> {
|
||||
// https://url.spec.whatwg.org/#dom-urlsearchparams-append
|
||||
fn Append(self, name: DOMString, value: DOMString) {
|
||||
let mut data = self.data.borrow_mut();
|
||||
|
||||
|
@ -78,23 +81,27 @@ impl<'a> URLSearchParamsMethods for JSRef<'a, URLSearchParams> {
|
|||
self.update_steps();
|
||||
}
|
||||
|
||||
// https://url.spec.whatwg.org/#dom-urlsearchparams-delete
|
||||
fn Delete(self, name: DOMString) {
|
||||
self.data.borrow_mut().remove(&name);
|
||||
self.update_steps();
|
||||
}
|
||||
|
||||
// https://url.spec.whatwg.org/#dom-urlsearchparams-get
|
||||
fn Get(self, name: DOMString) -> Option<DOMString> {
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let data = self.data.borrow();
|
||||
data.get(&name).map(|v| v[0].clone())
|
||||
}
|
||||
|
||||
// https://url.spec.whatwg.org/#dom-urlsearchparams-has
|
||||
fn Has(self, name: DOMString) -> bool {
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let data = self.data.borrow();
|
||||
data.contains_key(&name)
|
||||
}
|
||||
|
||||
// https://url.spec.whatwg.org/#dom-urlsearchparams-set
|
||||
fn Set(self, name: DOMString, value: DOMString) {
|
||||
self.data.borrow_mut().insert(name, vec!(value));
|
||||
self.update_steps();
|
||||
|
|
|
@ -8,6 +8,7 @@ use dom::bindings::js::{JSRef, Temporary};
|
|||
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
||||
use dom::window::Window;
|
||||
|
||||
// https://html.spec.whatwg.org/#validitystate
|
||||
#[dom_struct]
|
||||
pub struct ValidityState {
|
||||
reflector_: Reflector,
|
||||
|
|
|
@ -11,6 +11,7 @@ use dom::bindings::utils::reflect_dom_object;
|
|||
use dom::eventtarget::{EventTarget, EventTargetTypeId};
|
||||
use util::str::DOMString;
|
||||
|
||||
// https://html.spec.whatwg.org/#the-websocket-interface
|
||||
#[dom_struct]
|
||||
pub struct WebSocket {
|
||||
eventtarget: EventTarget,
|
||||
|
@ -37,6 +38,7 @@ impl WebSocket {
|
|||
}
|
||||
|
||||
impl<'a> WebSocketMethods for JSRef<'a, WebSocket> {
|
||||
// https://html.spec.whatwg.org/#dom-websocket-url
|
||||
fn Url(self) -> DOMString {
|
||||
self.url.clone()
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ use std::sync::mpsc::{channel, Sender};
|
|||
|
||||
pub type TrustedWorkerAddress = Trusted<Worker>;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/workers.html#worker
|
||||
#[dom_struct]
|
||||
pub struct Worker {
|
||||
eventtarget: EventTarget,
|
||||
|
|
|
@ -39,6 +39,7 @@ pub enum WorkerGlobalScopeTypeId {
|
|||
DedicatedGlobalScope,
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/workers.html#the-workerglobalscope-common-interface
|
||||
#[dom_struct]
|
||||
pub struct WorkerGlobalScope {
|
||||
eventtarget: EventTarget,
|
||||
|
@ -96,16 +97,19 @@ impl WorkerGlobalScope {
|
|||
}
|
||||
|
||||
impl<'a> WorkerGlobalScopeMethods for JSRef<'a, WorkerGlobalScope> {
|
||||
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerglobalscope-self
|
||||
fn Self_(self) -> Temporary<WorkerGlobalScope> {
|
||||
Temporary::from_rooted(self)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerglobalscope-location
|
||||
fn Location(self) -> Temporary<WorkerLocation> {
|
||||
self.location.or_init(|| {
|
||||
WorkerLocation::new(self, self.worker_url.clone())
|
||||
})
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerglobalscope-importscripts
|
||||
fn ImportScripts(self, url_strings: Vec<DOMString>) -> ErrorResult {
|
||||
let mut urls = Vec::with_capacity(url_strings.len());
|
||||
for url in url_strings.into_iter() {
|
||||
|
@ -138,6 +142,7 @@ impl<'a> WorkerGlobalScopeMethods for JSRef<'a, WorkerGlobalScope> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/workers.html#dom-worker-navigator
|
||||
fn Navigator(self) -> Temporary<WorkerNavigator> {
|
||||
self.navigator.or_init(|| WorkerNavigator::new(self))
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ use dom::workerglobalscope::WorkerGlobalScope;
|
|||
|
||||
use url::Url;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/workers.html#worker-locations
|
||||
#[dom_struct]
|
||||
pub struct WorkerLocation {
|
||||
reflector_: Reflector,
|
||||
|
|
|
@ -11,6 +11,7 @@ use dom::navigatorinfo;
|
|||
use dom::workerglobalscope::WorkerGlobalScope;
|
||||
use util::str::DOMString;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/workers.html#workernavigator
|
||||
#[dom_struct]
|
||||
pub struct WorkerNavigator {
|
||||
reflector_: Reflector,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue