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 document.characterSet #1604

Merged
merged 1 commit into from Feb 6, 2014
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Implement document.characterSet

  • Loading branch information
brunoabinader committed Feb 6, 2014
commit a6c897e445edf93f7ebd2230343d53789409e628
@@ -93,7 +93,8 @@ pub struct Document {
implementation: Option<@mut DOMImplementation>,
content_type: DOMString,
url: Url,
quirks_mode: QuirksMode
quirks_mode: QuirksMode,
encoding_name: DOMString,
}

impl Document {
@@ -140,7 +141,9 @@ impl Document {
Some(_url) => _url
},
// http://dom.spec.whatwg.org/#concept-document-quirks
quirks_mode: NoQuirks
quirks_mode: NoQuirks,
// http://dom.spec.whatwg.org/#concept-document-encoding
encoding_name: ~"utf-8",
}
}

@@ -207,6 +210,15 @@ impl Document {
self.quirks_mode = mode;
}

// http://dom.spec.whatwg.org/#dom-document-characterset
pub fn CharacterSet(&self) -> DOMString {
self.encoding_name.to_ascii_lower()
}

pub fn set_encoding_name(&mut self, name: DOMString) {
self.encoding_name = name;
}

// http://dom.spec.whatwg.org/#dom-document-content_type
pub fn ContentType(&self) -> DOMString {
self.content_type.clone()
@@ -30,7 +30,7 @@ interface Document : Node {
readonly attribute DOMString documentURI;
// readonly attribute DOMString origin;
readonly attribute DOMString compatMode;
// readonly attribute DOMString characterSet;
readonly attribute DOMString characterSet;
readonly attribute DOMString contentType;

readonly attribute DocumentType? doctype;
@@ -443,12 +443,13 @@ pub fn parse_html(cx: *JSContext,
add_attributes: |_node, _attributes| {
debug!("add attributes");
},
set_quirks_mode: |_mode| {
set_quirks_mode: |mode| {
debug!("set quirks mode");
document.mut_document().set_quirks_mode(_mode);
document.mut_document().set_quirks_mode(mode);
},
encoding_change: |_encname| {
encoding_change: |encname| {
debug!("encoding change");
document.mut_document().set_encoding_name(encname);
},
complete_script: |script| {
unsafe {
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<meta charset="UTF-8">
<html>
<head>
<script src="harness.js"></script>
<script>
// test1: characterSet
{
is(document.characterSet, "utf-8", "test1-0, characterSet");

var xmldoc = new Document;
is(xmldoc.characterSet, "utf-8", "test2-1, characterSet");

var htmldoc = document.implementation.createHTMLDocument("title");
is(htmldoc.characterSet, "utf-8", "test2-2, characterSet");
}

finish();
</script>
</head>
</html>
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<script src="harness.js"></script>
<script>
// test1: default characterSet
{
// FIXME: https://github.com/mozilla-servo/libhubbub/issues/5
is(document.characterSet, "utf-8", "test1-0, default characterSet");
}

finish();
</script>
</head>
</html>
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<meta charset="unknown-charset">
<html>
<head>
<script src="harness.js"></script>
<script>
// test1: unknown charset
{
is(document.characterSet, "utf-8", "test1-0, unknown charset");
}

finish();
</script>
</head>
</html>
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<html>
<head>
<script src="harness.js"></script>
<script>
// test1: long charset
{
is(document.characterSet, "windows-1252", "test1-0, long charset");
}

finish();
</script>
</head>
</html>
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<meta charset="iso-8859-1">
<html>
<head>
<script src="harness.js"></script>
<script>
// test1: short charset
{
is(document.characterSet, "windows-1252", "test1-0, short charset");
}

finish();
</script>
</head>
</html>
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.