Implement Storage::SupportedPropertyNames

This commit is contained in:
Mathieu Rheaume 2015-09-20 22:24:00 -04:00
parent f30f40b12d
commit e7a3220bc1
5 changed files with 50 additions and 3 deletions

View file

@ -53,6 +53,9 @@ impl StorageManager {
StorageTaskMsg::Key(sender, url, storage_type, index) => {
self.key(sender, url, storage_type, index)
}
StorageTaskMsg::Keys(sender, url, storage_type) => {
self.keys(sender, url, storage_type)
}
StorageTaskMsg::SetItem(sender, url, storage_type, name, value) => {
self.set_item(sender, url, storage_type, name, value)
}
@ -106,6 +109,18 @@ impl StorageManager {
.map(|key| key.clone())).unwrap();
}
fn keys(&self,
sender: IpcSender<Vec<DOMString>>,
url: Url,
storage_type: StorageType) {
let origin = self.origin_as_string(url);
let data = self.select_data(storage_type);
let keys = data.get(&origin)
.map_or(vec![], |entry| entry.keys().cloned().collect());
sender.send(keys).unwrap();
}
/// Sends Some(old_value) in case there was a previous value with the same key name but with different
/// value name, otherwise sends None
fn set_item(&mut self,

View file

@ -21,6 +21,9 @@ pub enum StorageTaskMsg {
/// gets the name of the key at the specified index in the associated storage data
Key(IpcSender<Option<DOMString>>, Url, StorageType, u32),
/// Gets the available keys in the associated storage data
Keys(IpcSender<Vec<DOMString>>, Url, StorageType),
/// gets the value associated with the given key in the associated storage data
GetItem(IpcSender<Option<DOMString>>, Url, StorageType, DOMString),

View file

@ -116,8 +116,10 @@ impl StorageMethods for Storage {
// https://html.spec.whatwg.org/multipage/#the-storage-interface:supported-property-names
fn SupportedPropertyNames(&self) -> Vec<DOMString> {
// FIXME: unimplemented (https://github.com/servo/servo/issues/7273)
vec![]
let (sender, receiver) = ipc::channel().unwrap();
self.get_storage_task().send(StorageTaskMsg::Keys(sender, self.get_url(), self.storage_type)).unwrap();
receiver.recv().unwrap()
}
// check-tidy: no specs after this line

View file

@ -13139,6 +13139,10 @@
"path": "dom/collections/HTMLCollection-supported-property-names.html",
"url": "/dom/collections/HTMLCollection-supported-property-names.html"
},
{
"path": "dom/collections/storage-supported-property-names.html",
"url": "/dom/collections/storage-supported-property-names.html"
},
{
"path": "dom/events/Event-constants.html",
"url": "/dom/events/Event-constants.html"

View file

@ -0,0 +1,23 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Storage Test: Supported property names</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
["localStorage", "sessionStorage"].forEach(function(name) {
test(function() {
var storage = window[name];
storage.clear();
storage["name"] = "user1";
assert_array_equals(Object.getOwnPropertyNames(storage), ['name']);
}, "Object.getOwnPropertyNames on " + name + " Storage");
test(function() {
var storage = window[name];
storage.clear();
assert_array_equals(Object.getOwnPropertyNames(storage), []);
}, "Object.getOwnPropertyNames on " + name + " storage with empty collection");
});
</script>