aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock7
-rw-r--r--components/script/Cargo.toml1
-rw-r--r--components/script/dom/bindings/mozmap.rs12
-rw-r--r--components/script/dom/bindings/trace.rs16
-rw-r--r--components/script/dom/urlsearchparams.rs32
-rw-r--r--components/script/dom/webidls/URLSearchParams.webidl4
-rw-r--r--tests/wpt/metadata/url/urlsearchparams-constructor.any.js.ini43
-rw-r--r--tests/wpt/metadata/xhr/send-entity-body-basic.htm.ini5
8 files changed, 53 insertions, 67 deletions
diff --git a/Cargo.lock b/Cargo.lock
index b998175a666..59cc45d04a9 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1587,7 +1587,7 @@ dependencies = [
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)",
"http 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)",
- "indexmap 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"slab 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"string 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1819,7 +1819,7 @@ dependencies = [
[[package]]
name = "indexmap"
-version = "1.0.1"
+version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@@ -3246,6 +3246,7 @@ dependencies = [
"hyper 0.12.14 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper_serde 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"image 0.20.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
"jstraceable_derive 0.0.1",
@@ -4950,7 +4951,7 @@ dependencies = [
"checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d"
"checksum image 0.20.1 (registry+https://github.com/rust-lang/crates.io-index)" = "44665b4395d1844c96e7dc8ed5754782a1cdfd9ef458a80bbe45702681450504"
"checksum immeta 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7371aa3c98fad60de2d9b517e2e1ed45593c32b0c77249310fa507749a2a318b"
-"checksum indexmap 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08173ba1e906efb6538785a8844dd496f5d34f0a2d88038e95195172fc667220"
+"checksum indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e81a7c05f79578dbc15793d8b619db9ba32b4577003ef3af1a91c416798c58d"
"checksum inflate 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6f53b811ee8e2057ccf9643ca6b4277de90efaf5e61e55fd5254576926bb4245"
"checksum influent 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8f06f65fa332019cbf57b927cd5a5da53cfce506109f38312fd597745a8a48c0"
"checksum io-surface 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5f9a33981dff54baaff80f4decb487a65d148a3c00facc97820d0f09128f74dd"
diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml
index ed8a0eb3b43..071c429d584 100644
--- a/components/script/Cargo.toml
+++ b/components/script/Cargo.toml
@@ -61,6 +61,7 @@ http = "0.1"
hyper = "0.12"
hyper_serde = "0.9"
image = "0.20"
+indexmap = "1.0.2"
ipc-channel = "0.11"
itertools = "0.7.6"
jstraceable_derive = {path = "../jstraceable_derive"}
diff --git a/components/script/dom/bindings/mozmap.rs b/components/script/dom/bindings/mozmap.rs
index 9658d0c0d5e..db46debc58e 100644
--- a/components/script/dom/bindings/mozmap.rs
+++ b/components/script/dom/bindings/mozmap.rs
@@ -7,6 +7,7 @@
use crate::dom::bindings::conversions::jsid_to_string;
use crate::dom::bindings::error::report_pending_exception;
use crate::dom::bindings::str::DOMString;
+use indexmap::IndexMap;
use js::conversions::{ConversionResult, FromJSValConvertible, ToJSValConvertible};
use js::jsapi::JSContext;
use js::jsapi::JS_NewPlainObject;
@@ -22,28 +23,27 @@ use js::rust::wrappers::JS_GetPropertyById;
use js::rust::HandleValue;
use js::rust::IdVector;
use js::rust::MutableHandleValue;
-use std::collections::HashMap;
use std::ops::Deref;
/// The `MozMap` (open-ended dictionary) type.
#[derive(Clone, JSTraceable)]
pub struct MozMap<T> {
- map: HashMap<DOMString, T>,
+ map: IndexMap<DOMString, T>,
}
impl<T> MozMap<T> {
/// Create an empty `MozMap`.
pub fn new() -> Self {
MozMap {
- map: HashMap::new(),
+ map: IndexMap::new(),
}
}
}
impl<T> Deref for MozMap<T> {
- type Target = HashMap<DOMString, T>;
+ type Target = IndexMap<DOMString, T>;
- fn deref(&self) -> &HashMap<DOMString, T> {
+ fn deref(&self) -> &IndexMap<DOMString, T> {
&self.map
}
}
@@ -82,7 +82,7 @@ where
));
}
- let mut map = HashMap::new();
+ let mut map = IndexMap::new();
for id in &*ids {
rooted!(in(cx) let id = *id);
diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs
index 4fecf083737..ae1a9e6e3b4 100644
--- a/components/script/dom/bindings/trace.rs
+++ b/components/script/dom/bindings/trace.rs
@@ -61,6 +61,7 @@ use html5ever::{LocalName, Namespace, Prefix, QualName};
use http::header::HeaderMap;
use hyper::Method;
use hyper::StatusCode;
+use indexmap::IndexMap;
use ipc_channel::ipc::{IpcReceiver, IpcSender};
use js::glue::{CallObjectTracer, CallValueTracer};
use js::jsapi::{GCTraceKindToAscii, Heap, JSObject, JSTracer, TraceKind};
@@ -356,6 +357,21 @@ unsafe impl<K: Ord + JSTraceable, V: JSTraceable> JSTraceable for BTreeMap<K, V>
}
}
+unsafe impl<K, V, S> JSTraceable for IndexMap<K, V, S>
+where
+ K: Hash + Eq + JSTraceable,
+ V: JSTraceable,
+ S: BuildHasher,
+{
+ #[inline]
+ unsafe fn trace(&self, trc: *mut JSTracer) {
+ for (k, v) in &*self {
+ k.trace(trc);
+ v.trace(trc);
+ }
+ }
+}
+
unsafe impl<A: JSTraceable, B: JSTraceable> JSTraceable for (A, B) {
#[inline]
unsafe fn trace(&self, trc: *mut JSTracer) {
diff --git a/components/script/dom/urlsearchparams.rs b/components/script/dom/urlsearchparams.rs
index 5be91c9304c..9a4e6b54765 100644
--- a/components/script/dom/urlsearchparams.rs
+++ b/components/script/dom/urlsearchparams.rs
@@ -5,8 +5,8 @@
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::URLSearchParamsBinding::URLSearchParamsMethods;
use crate::dom::bindings::codegen::Bindings::URLSearchParamsBinding::URLSearchParamsWrap;
-use crate::dom::bindings::codegen::UnionTypes::USVStringOrURLSearchParams;
-use crate::dom::bindings::error::Fallible;
+use crate::dom::bindings::codegen::UnionTypes::USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString;
+use crate::dom::bindings::error::{Error, Fallible};
use crate::dom::bindings::iterable::Iterable;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::DomRoot;
@@ -47,13 +47,30 @@ impl URLSearchParams {
// https://url.spec.whatwg.org/#dom-urlsearchparams-urlsearchparams
pub fn Constructor(
global: &GlobalScope,
- init: Option<USVStringOrURLSearchParams>,
+ init: Option<USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString>,
) -> Fallible<DomRoot<URLSearchParams>> {
// Step 1.
let query = URLSearchParams::new(global, None);
match init {
- Some(USVStringOrURLSearchParams::USVString(init)) => {
+ Some(USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString::USVStringSequenceSequence(init)) => {
// Step 2.
+
+ // Step 2-1.
+ if init.iter().any(|pair| pair.len() != 2) {
+ return Err(Error::Type("Sequence initializer must only contain pair elements.".to_string()));
+ }
+
+ // Step 2-2.
+ *query.list.borrow_mut() =
+ init.iter().map(|pair| (pair[0].to_string(), pair[1].to_string())).collect::<Vec<_>>();
+ },
+ Some(USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString::USVStringUSVStringRecord(init)) => {
+ // Step 3.
+ *query.list.borrow_mut() =
+ (*init).iter().map(|(name, value)| (name.to_string(), value.to_string())).collect::<Vec<_>>();
+ },
+ Some(USVStringSequenceSequenceOrUSVStringUSVStringRecordOrUSVString::USVString(init)) => {
+ // Step 4.
let init_bytes = match init.0.chars().next() {
Some(first_char) if first_char == '?' => {
let (_, other_bytes) = init.0.as_bytes().split_at(1);
@@ -66,13 +83,10 @@ impl URLSearchParams {
*query.list.borrow_mut() =
form_urlencoded::parse(init_bytes).into_owned().collect();
},
- Some(USVStringOrURLSearchParams::URLSearchParams(init)) => {
- // Step 3.
- *query.list.borrow_mut() = init.list.borrow().clone();
- },
None => {},
}
- // Step 4.
+
+ // Step 5.
Ok(query)
}
diff --git a/components/script/dom/webidls/URLSearchParams.webidl b/components/script/dom/webidls/URLSearchParams.webidl
index 341e6fb2fba..8e72b207c0c 100644
--- a/components/script/dom/webidls/URLSearchParams.webidl
+++ b/components/script/dom/webidls/URLSearchParams.webidl
@@ -6,7 +6,9 @@
* https://url.spec.whatwg.org/#interface-urlsearchparams
*/
-[Constructor(optional (USVString or URLSearchParams) init/* = ""*/), Exposed=(Window,Worker)]
+[Constructor(
+ optional (sequence<sequence<USVString>> or record<USVString, USVString> or USVString) init/* = ""*/
+), Exposed=(Window,Worker)]
interface URLSearchParams {
void append(USVString name, USVString value);
void delete(USVString name);
diff --git a/tests/wpt/metadata/url/urlsearchparams-constructor.any.js.ini b/tests/wpt/metadata/url/urlsearchparams-constructor.any.js.ini
index f62df6a0576..09df91b6479 100644
--- a/tests/wpt/metadata/url/urlsearchparams-constructor.any.js.ini
+++ b/tests/wpt/metadata/url/urlsearchparams-constructor.any.js.ini
@@ -1,51 +1,8 @@
[urlsearchparams-constructor.any.worker.html]
- [Construct with object with two keys]
- expected: FAIL
-
- [Construct with object with NULL, non-ASCII, and surrogate keys]
- expected: FAIL
-
- [URLSearchParams constructor, {} as argument]
- expected: FAIL
-
- [Custom [Symbol.iterator\]]
- expected: FAIL
-
[URLSearchParams constructor, DOMException as argument]
expected: FAIL
- [Constructor with sequence of sequences of strings]
- expected: FAIL
-
- [Construct with object with +]
- expected: FAIL
-
- [Construct with array with two keys]
- expected: FAIL
-
[urlsearchparams-constructor.any.html]
- [Construct with object with two keys]
- expected: FAIL
-
- [Construct with object with NULL, non-ASCII, and surrogate keys]
- expected: FAIL
-
- [URLSearchParams constructor, {} as argument]
- expected: FAIL
-
- [Custom [Symbol.iterator\]]
- expected: FAIL
-
[URLSearchParams constructor, DOMException as argument]
expected: FAIL
-
- [Constructor with sequence of sequences of strings]
- expected: FAIL
-
- [Construct with object with +]
- expected: FAIL
-
- [Construct with array with two keys]
- expected: FAIL
-
diff --git a/tests/wpt/metadata/xhr/send-entity-body-basic.htm.ini b/tests/wpt/metadata/xhr/send-entity-body-basic.htm.ini
deleted file mode 100644
index 17882081cb3..00000000000
--- a/tests/wpt/metadata/xhr/send-entity-body-basic.htm.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[send-entity-body-basic.htm]
- type: testharness
- [XMLHttpRequest: send() - data argument (1=2&3=4)]
- expected: FAIL
-