Skip to content

Commit

Permalink
Enable OpenEndedDictionary in Headers
Browse files Browse the repository at this point in the history
Expected wpt results are updated as well.
  • Loading branch information
jeenalee committed Sep 22, 2016
1 parent 2b1a39c commit 3b75d22
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 77 deletions.
1 change: 1 addition & 0 deletions components/script/dom/bindings/mozmap.rs
Expand Up @@ -23,6 +23,7 @@ use std::collections::HashMap;
use std::ops::Deref;

/// The `MozMap` (open-ended dictionary) type.
#[derive(Clone)]
pub struct MozMap<T> {
map: HashMap<DOMString, T>,
}
Expand Down
22 changes: 13 additions & 9 deletions components/script/dom/headers.rs
Expand Up @@ -3,10 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::HeadersBinding;
use dom::bindings::codegen::Bindings::HeadersBinding::HeadersMethods;
use dom::bindings::codegen::Bindings::HeadersBinding::HeadersWrap;
use dom::bindings::codegen::UnionTypes::HeadersOrByteStringSequenceSequence;
use dom::bindings::codegen::Bindings::HeadersBinding::{HeadersInit, HeadersMethods, HeadersWrap};
use dom::bindings::error::{Error, ErrorResult, Fallible};
use dom::bindings::global::GlobalRef;
use dom::bindings::iterable::Iterable;
Expand Down Expand Up @@ -51,7 +48,7 @@ impl 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>> {
let dom_headers_new = Headers::new(global);
try!(dom_headers_new.fill(init));
Expand Down Expand Up @@ -169,10 +166,10 @@ impl HeadersMethods for Headers {

impl Headers {
// 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 {
// Step 1
Some(HeadersOrByteStringSequenceSequence::Headers(h)) => {
Some(HeadersInit::Headers(h)) => {
for header in h.header_list.borrow().iter() {
try!(self.Append(
ByteString::new(Vec::from(header.name())),
Expand All @@ -182,7 +179,7 @@ impl Headers {
Ok(())
},
// Step 2
Some(HeadersOrByteStringSequenceSequence::ByteStringSequenceSequence(v)) => {
Some(HeadersInit::ByteStringSequenceSequence(v)) => {
for mut seq in v {
if seq.len() == 2 {
let val = seq.pop().unwrap();
Expand All @@ -196,7 +193,14 @@ impl Headers {
}
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(()),
}
}
Expand Down
20 changes: 11 additions & 9 deletions components/script/dom/request.rs
Expand Up @@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::HeadersBinding::HeadersInit;
use dom::bindings::codegen::Bindings::RequestBinding;
use dom::bindings::codegen::Bindings::RequestBinding::ReferrerPolicy;
use dom::bindings::codegen::Bindings::RequestBinding::RequestCache;
Expand All @@ -14,7 +15,6 @@ use dom::bindings::codegen::Bindings::RequestBinding::RequestMethods;
use dom::bindings::codegen::Bindings::RequestBinding::RequestMode;
use dom::bindings::codegen::Bindings::RequestBinding::RequestRedirect;
use dom::bindings::codegen::Bindings::RequestBinding::RequestType;
use dom::bindings::codegen::UnionTypes::HeadersOrByteStringSequenceSequence;
use dom::bindings::error::{Error, Fallible};
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JS, MutNullableHeap, Root};
Expand Down Expand Up @@ -312,7 +312,7 @@ impl Request {

// Step 28
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();
}
}
Expand All @@ -337,7 +337,7 @@ impl Request {
}

// Step 31
try!(r.Headers().fill(Some(HeadersOrByteStringSequenceSequence::Headers(headers_copy))));
try!(r.Headers().fill(Some(HeadersInit::Headers(headers_copy))));

// Step 32
let input_body = if let RequestInfo::Request(ref input_request) = input {
Expand Down Expand Up @@ -796,13 +796,15 @@ impl Into<RequestRedirect> for NetTraitsRequestRedirect {
}
}

impl Clone for HeadersOrByteStringSequenceSequence {
fn clone(&self) -> HeadersOrByteStringSequenceSequence {
impl Clone for HeadersInit {
fn clone(&self) -> HeadersInit {
match self {
&HeadersOrByteStringSequenceSequence::Headers(ref h) =>
HeadersOrByteStringSequenceSequence::Headers(h.clone()),
&HeadersOrByteStringSequenceSequence::ByteStringSequenceSequence(ref b) =>
HeadersOrByteStringSequenceSequence::ByteStringSequenceSequence(b.clone()),
&HeadersInit::Headers(ref h) =>
HeadersInit::Headers(h.clone()),
&HeadersInit::ByteStringSequenceSequence(ref b) =>
HeadersInit::ByteStringSequenceSequence(b.clone()),
&HeadersInit::ByteStringMozMap(ref m) =>
HeadersInit::ByteStringMozMap(m.clone()),
}
}
}
3 changes: 1 addition & 2 deletions components/script/dom/webidls/Headers.webidl
Expand Up @@ -4,8 +4,7 @@

// https://fetch.spec.whatwg.org/#headers-class

// TODO support OpenEndedDictionary<ByteString>
typedef (Headers or sequence<sequence<ByteString>>) HeadersInit;
typedef (Headers or sequence<sequence<ByteString>> or MozMap<ByteString>) HeadersInit;

[Constructor(optional HeadersInit init),
Exposed=(Window,Worker)]
Expand Down
35 changes: 0 additions & 35 deletions tests/wpt/metadata/fetch/api/headers/headers-basic.html.ini

This file was deleted.

5 changes: 0 additions & 5 deletions tests/wpt/metadata/fetch/api/headers/headers-casing.html.ini

This file was deleted.

This file was deleted.

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

[Check cloning a request copies the headers]
expected: FAIL

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

[Initialize Request's body with undefined]
expected: FAIL
Expand Down
@@ -1,3 +1,14 @@
[request-init-003.sub.html]
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

Expand Up @@ -15,9 +15,6 @@
[Request has text method]
expected: FAIL

[Check headers attribute]
expected: FAIL

[Check referrer attribute]
expected: FAIL

19 changes: 18 additions & 1 deletion tests/wpt/metadata/fetch/api/response/response-clone.html.ini
@@ -1,3 +1,20 @@
[response-clone.html]
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
@@ -1,8 +1,5 @@
[response-init-002.html]
type: testharness
[Initialize Response with headers values]
expected: FAIL

[Initialize Response's body with application/octet-binary]
expected: FAIL
Expand Down
1 change: 1 addition & 0 deletions tests/wpt/metadata/html/dom/interfaces.html.ini
Expand Up @@ -10664,3 +10664,4 @@

[Navigator interface: window.navigator must inherit property "hardwareConcurrency" with the proper type (22)]
expected: FAIL

Expand Up @@ -301,3 +301,4 @@

[WebGL test #49: Property either does not exist or is not a function: validateProgram]
expected: FAIL

Expand Up @@ -8,3 +8,4 @@

[WebGL test #85: getError expected: NO_ERROR. Was INVALID_ENUM : there should be no errors]
expected: FAIL

0 comments on commit 3b75d22

Please sign in to comment.