Enable OpenEndedDictionary in Headers

Expected wpt results are updated as well.
This commit is contained in:
Jeena Lee 2016-09-20 14:37:55 -07:00
parent 2b1a39c2ae
commit 3b75d223f1
16 changed files with 65 additions and 77 deletions

View file

@ -23,6 +23,7 @@ use std::collections::HashMap;
use std::ops::Deref; use std::ops::Deref;
/// The `MozMap` (open-ended dictionary) type. /// The `MozMap` (open-ended dictionary) type.
#[derive(Clone)]
pub struct MozMap<T> { pub struct MozMap<T> {
map: HashMap<DOMString, T>, map: HashMap<DOMString, T>,
} }

View file

@ -3,10 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::cell::DOMRefCell; use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::HeadersBinding; use dom::bindings::codegen::Bindings::HeadersBinding::{HeadersInit, HeadersMethods, HeadersWrap};
use dom::bindings::codegen::Bindings::HeadersBinding::HeadersMethods;
use dom::bindings::codegen::Bindings::HeadersBinding::HeadersWrap;
use dom::bindings::codegen::UnionTypes::HeadersOrByteStringSequenceSequence;
use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::error::{Error, ErrorResult, Fallible};
use dom::bindings::global::GlobalRef; use dom::bindings::global::GlobalRef;
use dom::bindings::iterable::Iterable; use dom::bindings::iterable::Iterable;
@ -51,7 +48,7 @@ impl Headers {
} }
// https://fetch.spec.whatwg.org/#dom-headers // https://fetch.spec.whatwg.org/#dom-headers
pub fn Constructor(global: GlobalRef, init: Option<HeadersBinding::HeadersInit>) pub fn Constructor(global: GlobalRef, init: Option<HeadersInit>)
-> Fallible<Root<Headers>> { -> Fallible<Root<Headers>> {
let dom_headers_new = Headers::new(global); let dom_headers_new = Headers::new(global);
try!(dom_headers_new.fill(init)); try!(dom_headers_new.fill(init));
@ -169,10 +166,10 @@ impl HeadersMethods for Headers {
impl Headers { impl Headers {
// https://fetch.spec.whatwg.org/#concept-headers-fill // https://fetch.spec.whatwg.org/#concept-headers-fill
pub fn fill(&self, filler: Option<HeadersBinding::HeadersInit>) -> ErrorResult { pub fn fill(&self, filler: Option<HeadersInit>) -> ErrorResult {
match filler { match filler {
// Step 1 // Step 1
Some(HeadersOrByteStringSequenceSequence::Headers(h)) => { Some(HeadersInit::Headers(h)) => {
for header in h.header_list.borrow().iter() { for header in h.header_list.borrow().iter() {
try!(self.Append( try!(self.Append(
ByteString::new(Vec::from(header.name())), ByteString::new(Vec::from(header.name())),
@ -182,7 +179,7 @@ impl Headers {
Ok(()) Ok(())
}, },
// Step 2 // Step 2
Some(HeadersOrByteStringSequenceSequence::ByteStringSequenceSequence(v)) => { Some(HeadersInit::ByteStringSequenceSequence(v)) => {
for mut seq in v { for mut seq in v {
if seq.len() == 2 { if seq.len() == 2 {
let val = seq.pop().unwrap(); let val = seq.pop().unwrap();
@ -196,7 +193,14 @@ impl Headers {
} }
Ok(()) Ok(())
}, },
// Step 3 TODO constructor for when init is an open-ended dictionary Some(HeadersInit::ByteStringMozMap(m)) => {
for (key, value) in m.iter() {
let key_vec = key.as_ref().to_string().into();
let headers_key = ByteString::new(key_vec);
try!(self.Append(headers_key, value.clone()));
}
Ok(())
},
None => Ok(()), None => Ok(()),
} }
} }

View file

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::cell::DOMRefCell; use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::HeadersBinding::HeadersInit;
use dom::bindings::codegen::Bindings::RequestBinding; use dom::bindings::codegen::Bindings::RequestBinding;
use dom::bindings::codegen::Bindings::RequestBinding::ReferrerPolicy; use dom::bindings::codegen::Bindings::RequestBinding::ReferrerPolicy;
use dom::bindings::codegen::Bindings::RequestBinding::RequestCache; use dom::bindings::codegen::Bindings::RequestBinding::RequestCache;
@ -14,7 +15,6 @@ use dom::bindings::codegen::Bindings::RequestBinding::RequestMethods;
use dom::bindings::codegen::Bindings::RequestBinding::RequestMode; use dom::bindings::codegen::Bindings::RequestBinding::RequestMode;
use dom::bindings::codegen::Bindings::RequestBinding::RequestRedirect; use dom::bindings::codegen::Bindings::RequestBinding::RequestRedirect;
use dom::bindings::codegen::Bindings::RequestBinding::RequestType; use dom::bindings::codegen::Bindings::RequestBinding::RequestType;
use dom::bindings::codegen::UnionTypes::HeadersOrByteStringSequenceSequence;
use dom::bindings::error::{Error, Fallible}; use dom::bindings::error::{Error, Fallible};
use dom::bindings::global::GlobalRef; use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JS, MutNullableHeap, Root}; use dom::bindings::js::{JS, MutNullableHeap, Root};
@ -312,7 +312,7 @@ impl Request {
// Step 28 // Step 28
if let Some(possible_header) = init.headers.as_ref() { if let Some(possible_header) = init.headers.as_ref() {
if let &HeadersOrByteStringSequenceSequence::Headers(ref init_headers) = possible_header { if let &HeadersInit::Headers(ref init_headers) = possible_header {
headers_copy = init_headers.clone(); headers_copy = init_headers.clone();
} }
} }
@ -337,7 +337,7 @@ impl Request {
} }
// Step 31 // Step 31
try!(r.Headers().fill(Some(HeadersOrByteStringSequenceSequence::Headers(headers_copy)))); try!(r.Headers().fill(Some(HeadersInit::Headers(headers_copy))));
// Step 32 // Step 32
let input_body = if let RequestInfo::Request(ref input_request) = input { let input_body = if let RequestInfo::Request(ref input_request) = input {
@ -796,13 +796,15 @@ impl Into<RequestRedirect> for NetTraitsRequestRedirect {
} }
} }
impl Clone for HeadersOrByteStringSequenceSequence { impl Clone for HeadersInit {
fn clone(&self) -> HeadersOrByteStringSequenceSequence { fn clone(&self) -> HeadersInit {
match self { match self {
&HeadersOrByteStringSequenceSequence::Headers(ref h) => &HeadersInit::Headers(ref h) =>
HeadersOrByteStringSequenceSequence::Headers(h.clone()), HeadersInit::Headers(h.clone()),
&HeadersOrByteStringSequenceSequence::ByteStringSequenceSequence(ref b) => &HeadersInit::ByteStringSequenceSequence(ref b) =>
HeadersOrByteStringSequenceSequence::ByteStringSequenceSequence(b.clone()), HeadersInit::ByteStringSequenceSequence(b.clone()),
&HeadersInit::ByteStringMozMap(ref m) =>
HeadersInit::ByteStringMozMap(m.clone()),
} }
} }
} }

View file

@ -4,8 +4,7 @@
// https://fetch.spec.whatwg.org/#headers-class // https://fetch.spec.whatwg.org/#headers-class
// TODO support OpenEndedDictionary<ByteString> typedef (Headers or sequence<sequence<ByteString>> or MozMap<ByteString>) HeadersInit;
typedef (Headers or sequence<sequence<ByteString>>) HeadersInit;
[Constructor(optional HeadersInit init), [Constructor(optional HeadersInit init),
Exposed=(Window,Worker)] Exposed=(Window,Worker)]

View file

@ -1,35 +0,0 @@
[headers-basic.html]
type: testharness
[Create headers from empty object]
expected: FAIL
[Create headers with OpenEndedDictionary]
expected: FAIL
[Create headers with existing headers]
expected: FAIL
[Check has method]
expected: FAIL
[Check delete method]
expected: FAIL
[Check get method]
expected: FAIL
[Check keys method]
expected: FAIL
[Check values method]
expected: FAIL
[Check entries method]
expected: FAIL
[Check Symbol.iterator method]
expected: FAIL
[Check forEach method]
expected: FAIL

View file

@ -1,5 +0,0 @@
[headers-casing.html]
type: testharness
[Create headers, names use characters with different case]
expected: FAIL

View file

@ -1,5 +0,0 @@
[headers-normalize.html]
type: testharness
[Create headers with not normalized values]
expected: FAIL

View file

@ -1,3 +1,8 @@
[request-clone.sub.html] [request-clone.sub.html]
type: testharness type: testharness
expected: ERROR [Check cloning a request]
expected: FAIL
[Check cloning a request copies the headers]
expected: FAIL

View file

@ -1,8 +1,5 @@
[request-init-002.html] [request-init-002.html]
type: testharness type: testharness
[Initialize Request with headers values]
expected: FAIL
[Initialize Request's body with undefined] [Initialize Request's body with undefined]
expected: FAIL expected: FAIL

View file

@ -1,3 +1,14 @@
[request-init-003.sub.html] [request-init-003.sub.html]
type: testharness type: testharness
expected: ERROR [Check request values when initialized from Request]
expected: FAIL
[Check request values when initialized from Request and init values]
expected: FAIL
[Check request values when initialized from url string]
expected: FAIL
[Check request values when initialized from url and init values]
expected: FAIL

View file

@ -15,9 +15,6 @@
[Request has text method] [Request has text method]
expected: FAIL expected: FAIL
[Check headers attribute]
expected: FAIL
[Check referrer attribute] [Check referrer attribute]
expected: FAIL expected: FAIL

View file

@ -1,3 +1,20 @@
[response-clone.html] [response-clone.html]
type: testharness type: testharness
expected: ERROR [Check Response's clone has the expected attribute values]
expected: FAIL
[Check orginal response's body after cloning]
expected: FAIL
[Check cloned response's body]
expected: FAIL
[Cannot clone a disturbed response]
expected: FAIL
[Cloned responses should provide the same data]
expected: FAIL
[Cancelling stream should not affect cloned one]
expected: FAIL

View file

@ -1,8 +1,5 @@
[response-init-002.html] [response-init-002.html]
type: testharness type: testharness
[Initialize Response with headers values]
expected: FAIL
[Initialize Response's body with application/octet-binary] [Initialize Response's body with application/octet-binary]
expected: FAIL expected: FAIL

View file

@ -10664,3 +10664,4 @@
[Navigator interface: window.navigator must inherit property "hardwareConcurrency" with the proper type (22)] [Navigator interface: window.navigator must inherit property "hardwareConcurrency" with the proper type (22)]
expected: FAIL expected: FAIL

View file

@ -301,3 +301,4 @@
[WebGL test #49: Property either does not exist or is not a function: validateProgram] [WebGL test #49: Property either does not exist or is not a function: validateProgram]
expected: FAIL expected: FAIL

View file

@ -8,3 +8,4 @@
[WebGL test #85: getError expected: NO_ERROR. Was INVALID_ENUM : there should be no errors] [WebGL test #85: getError expected: NO_ERROR. Was INVALID_ENUM : there should be no errors]
expected: FAIL expected: FAIL