Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Storage::SupportedPropertyNames #7693

Merged
merged 1 commit into from Oct 4, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -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,
@@ -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),

@@ -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
"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"
"rev": "0159b3ec9ba5355a3340621226e02ae026effd7f",
"url_base": "/",
"version": 2
}
}
@@ -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>
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.