Implement DOMStringMap

This commit is contained in:
Bruno de Oliveira Abinader 2014-11-04 10:39:53 -08:00
parent b50cfa56a9
commit 5c76502b91
5 changed files with 76 additions and 9 deletions

View file

@ -0,0 +1,62 @@
/* 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::DOMStringMapBinding;
use dom::bindings::codegen::Bindings::DOMStringMapBinding::DOMStringMapMethods;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use servo_util::str::DOMString;
use std::collections::hashmap::HashMap;
#[dom_struct]
pub struct DOMStringMap {
map: DOMRefCell<HashMap<DOMString, DOMString>>,
reflector_: Reflector,
}
impl DOMStringMap {
fn new_inherited() -> DOMStringMap {
DOMStringMap {
map: DOMRefCell::new(HashMap::new()),
reflector_: Reflector::new(),
}
}
pub fn new(global: &GlobalRef) -> Temporary<DOMStringMap> {
reflect_dom_object(box DOMStringMap::new_inherited(),
global, DOMStringMapBinding::Wrap)
}
}
impl<'a> DOMStringMapMethods for JSRef<'a, DOMStringMap> {
fn NamedCreator(self, name: DOMString, value: DOMString) {
self.map.borrow_mut().insert(name, value);
}
fn NamedSetter(self, name: DOMString, value: DOMString) {
self.map.borrow_mut().insert(name, value);
}
fn NamedGetter(self, name: DOMString, found: &mut bool) -> DOMString {
match self.map.borrow().find(&name) {
Some(value) => {
*found = true;
value.clone()
},
None => {
*found = false;
String::new()
}
}
}
}
impl Reflectable for DOMStringMap {
fn reflector<'a>(&'a self) -> &'a Reflector {
&self.reflector_
}
}

View file

@ -0,0 +1,12 @@
/* -*- 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/. */
// https://html.spec.whatwg.org/#the-domstringmap-interface
[OverrideBuiltins]
interface DOMStringMap {
getter DOMString (DOMString name);
setter creator void (DOMString name, DOMString value);
//deleter void (DOMString name);
};

View file

@ -89,6 +89,7 @@ pub mod dom {
pub mod characterdata;
pub mod domrect;
pub mod domrectlist;
pub mod domstringmap;
pub mod comment;
pub mod console;
mod create;

View file

@ -67,6 +67,7 @@ var interfaceNamesInGlobalScope = [
"DOMImplementation",
"DOMParser",
"DOMTokenList",
"DOMStringMap",
"Element",
"Event",
"EventTarget",

View file

@ -1692,18 +1692,9 @@
[PropertyNodeList interface: operation getValues()]
expected: FAIL
[DOMStringMap interface: existence and properties of interface object]
expected: FAIL
[DOMStringMap interface object length]
expected: FAIL
[DOMStringMap interface: existence and properties of interface prototype object]
expected: FAIL
[DOMStringMap interface: existence and properties of interface prototype object\'s "constructor" property]
expected: FAIL
[DOMStringMap must be primary interface of document.head.dataset]
expected: FAIL