Skip to content

Commit

Permalink
implement document charset
Browse files Browse the repository at this point in the history
- pre-compute the adjusted encoding name

Fix build errors and update test expectations
  • Loading branch information
vectorijk authored and KiChjang committed Dec 21, 2015
1 parent 5b91daa commit c559270
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 270 deletions.
37 changes: 35 additions & 2 deletions components/script/dom/document.rs
Expand Up @@ -379,7 +379,35 @@ impl Document {
}

pub fn set_encoding_name(&self, name: DOMString) {
*self.encoding_name.borrow_mut() = name;
*self.encoding_name.borrow_mut() = DOMString::from(
match name.as_ref() {
"utf-8" => "UTF-8",
"ibm866" => "IBM866",
"iso-8859-2" => "ISO-8859-2",
"iso-8859-3" => "ISO-8859-3",
"iso-8859-4" => "ISO-8859-4",
"iso-8859-5" => "ISO-8859-5",
"iso-8859-6" => "ISO-8859-6",
"iso-8859-7" => "ISO-8859-7",
"iso-8859-8" => "ISO-8859-8",
"iso-8859-8-i" => "ISO-8859-8-I",
"iso-8859-10" => "ISO-8859-10",
"iso-8859-13" => "ISO-8859-13",
"iso-8859-14" => "ISO-8859-14",
"iso-8859-15" => "ISO-8859-15",
"iso-8859-16" => "ISO-8859-16",
"koi8-r" => "KOI8-R",
"koi8-u" => "KOI8-U",
"gbk" => "GBK",
"big5" => "Big5",
"euc-jp" => "EUC-JP",
"iso-2022-jp" => "ISO-2022-JP",
"shift_jis" => "Shift_JIS",
"euc-kr" => "EUC-KR",
"utf-16be" => "UTF-16BE",
"utf-16le" => "UTF-16LE",
_ => &*name
});
}

pub fn content_changed(&self, node: &Node, damage: NodeDamage) {
Expand Down Expand Up @@ -1719,9 +1747,14 @@ impl DocumentMethods for Document {
self.encoding_name.borrow().clone()
}

// https://dom.spec.whatwg.org/#dom-document-charset
fn Charset(&self) -> DOMString {
self.CharacterSet()
}

// https://dom.spec.whatwg.org/#dom-document-inputencoding
fn InputEncoding(&self) -> DOMString {
self.encoding_name.borrow().clone()
self.CharacterSet()
}

// https://dom.spec.whatwg.org/#dom-document-content_type
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/webidls/Document.webidl
Expand Up @@ -20,6 +20,7 @@ interface Document : Node {
readonly attribute DOMString documentURI;
readonly attribute DOMString compatMode;
readonly attribute DOMString characterSet;
readonly attribute DOMString charset; // legacy alias of .characterSet
readonly attribute DOMString inputEncoding; // legacy alias of .characterSet
[Constant]
readonly attribute DOMString contentType;
Expand Down
6 changes: 0 additions & 6 deletions tests/wpt/metadata/dom/interfaces.html.ini
Expand Up @@ -207,12 +207,6 @@
[DOMSettableTokenList interface: attribute value]
expected: FAIL
[Document interface: attribute charset]
expected: FAIL
[Document interface: xmlDoc must inherit property "charset" with the proper type (6)]
expected: FAIL
[Document interface: xmlDoc must inherit property "query" with the proper type (35)]
expected: FAIL
Expand Down
239 changes: 0 additions & 239 deletions tests/wpt/metadata/dom/nodes/DOMImplementation-createDocument.html.ini

This file was deleted.

Expand Up @@ -3,6 +3,3 @@
[createHTMLDocument(): URL parsing]
expected: FAIL

[createHTMLDocument(): characterSet aliases]
expected: FAIL

3 changes: 0 additions & 3 deletions tests/wpt/metadata/dom/nodes/Document-constructor.html.ini
Expand Up @@ -3,6 +3,3 @@
[new Document(): URL parsing]
expected: FAIL

[new Document(): characterSet aliases]
expected: FAIL

11 changes: 0 additions & 11 deletions tests/wpt/metadata/dom/nodes/Node-properties.html.ini

This file was deleted.

Expand Up @@ -3,6 +3,3 @@
[Location value]
expected: FAIL

[charset]
expected: FAIL

3 changes: 0 additions & 3 deletions tests/wpt/metadata/html/dom/interfaces.html.ini
Expand Up @@ -8922,9 +8922,6 @@
[Document interface: iframe.contentDocument must inherit property "onwaiting" with the proper type (156)]
expected: FAIL
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "charset" with the proper type (6)]
expected: FAIL
[Document interface: document.implementation.createDocument(null, "", null) must inherit property "styleSheets" with the proper type (28)]
expected: FAIL
Expand Down

0 comments on commit c559270

Please sign in to comment.