Auto merge of #7693 - ddrmanxbxfr:StorageSupportedAttributes, r=jdm

Implement Storage::SupportedPropertyNames

Hi guys,

This is a rough draft for issue #7670 .

It includes :
   - SupportedPropertyNames implementation
   - WPT with Object.supportedpropertynames with Local Storage and Session Storage.

The following link help me understood the issue :
http://www.w3.org/TR/webstorage/#the-storage-interface
https://html.spec.whatwg.org/multipage/infrastructure.html#supported-property-names

Thanks for looking into it.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7693)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-10-04 11:12:37 -06:00
commit 02da3a1e34
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"
@ -34616,4 +34620,4 @@
"rev": "0159b3ec9ba5355a3340621226e02ae026effd7f",
"url_base": "/",
"version": 2
}
}

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>