From 4e5ab246545b474c5fc6dc705826e1c97bd05bd0 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Sat, 14 Feb 2015 17:17:44 +0800 Subject: [PATCH 1/3] Implement TextDecoder (fixes #4769). --- components/script/dom/mod.rs | 1 + components/script/dom/textdecoder.rs | 65 ++ .../script/dom/webidls/TextDecoder.webidl | 19 + .../wpt/metadata/encoding/api-basics.html.ini | 3 - .../wpt/metadata/encoding/idlharness.html.ini | 27 - .../encoding/textdecoder-fatal.html.ini | 107 ---- .../encoding/textdecoder-labels.html.ini | 600 ------------------ .../textdecoder-utf16-surrogates.html.ini | 15 - .../textencoder-constructor-non-utf.html.ini | 6 - 9 files changed, 85 insertions(+), 758 deletions(-) create mode 100644 components/script/dom/textdecoder.rs create mode 100644 components/script/dom/webidls/TextDecoder.webidl delete mode 100644 tests/wpt/metadata/encoding/textdecoder-fatal.html.ini diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs index d1dd72a30b6..6c7204f7765 100644 --- a/components/script/dom/mod.rs +++ b/components/script/dom/mod.rs @@ -315,6 +315,7 @@ pub mod servohtmlparser; pub mod storage; pub mod storageevent; pub mod text; +pub mod textdecoder; pub mod textencoder; pub mod treewalker; pub mod uievent; diff --git a/components/script/dom/textdecoder.rs b/components/script/dom/textdecoder.rs new file mode 100644 index 00000000000..7aa6b4f92bc --- /dev/null +++ b/components/script/dom/textdecoder.rs @@ -0,0 +1,65 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +use dom::bindings::codegen::Bindings::TextDecoderBinding; +use dom::bindings::codegen::Bindings::TextDecoderBinding::TextDecoderMethods; +use dom::bindings::error::{Error, Fallible}; +use dom::bindings::global::GlobalRef; +use dom::bindings::js::{JSRef, Temporary}; +use dom::bindings::trace::JSTraceable; +use dom::bindings::utils::{Reflector, reflect_dom_object}; + +use util::str::DOMString; + +use encoding::Encoding; +use encoding::types::EncodingRef; +use encoding::label::encoding_from_whatwg_label; + +use std::borrow::ToOwned; + +#[dom_struct] +pub struct TextDecoder { + reflector_: Reflector, + encoding: EncodingRef, + fatal: bool, +} + +impl TextDecoder { + fn new_inherited(encoding: EncodingRef, fatal: bool) -> TextDecoder { + TextDecoder { + reflector_: Reflector::new(), + encoding: encoding, + fatal: fatal, + } + } + + pub fn new(global: GlobalRef, encoding: EncodingRef, fatal: bool) -> Temporary { + reflect_dom_object(box TextDecoder::new_inherited(encoding, fatal), + global, + TextDecoderBinding::Wrap) + } + + /// https://encoding.spec.whatwg.org/#dom-textdecoder + pub fn Constructor(global: GlobalRef, + label: DOMString, + options: &TextDecoderBinding::TextDecoderOptions) + -> Fallible> { + let encoding = match encoding_from_whatwg_label(&label) { + Some(enc) => enc, + // FIXME: Should throw a RangeError as per spec + None => return Err(Error::Syntax), + }; + Ok(TextDecoder::new(global, encoding, options.fatal)) + } +} + +impl<'a> TextDecoderMethods for JSRef<'a, TextDecoder> { + fn Encoding(self) -> DOMString { + self.encoding.whatwg_name().unwrap().to_owned() + } + + fn Fatal(self) -> bool { + self.fatal + } +} diff --git a/components/script/dom/webidls/TextDecoder.webidl b/components/script/dom/webidls/TextDecoder.webidl new file mode 100644 index 00000000000..6450c2ef0b6 --- /dev/null +++ b/components/script/dom/webidls/TextDecoder.webidl @@ -0,0 +1,19 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// https://encoding.spec.whatwg.org/#interface-textdecoder +dictionary TextDecoderOptions { + boolean fatal = false; + //boolean ignoreBOM = false; +}; + +[Constructor(optional DOMString label = "utf-8", optional TextDecoderOptions options)/*, + Exposed=Window,Worker*/] +interface TextDecoder { + readonly attribute DOMString encoding; + readonly attribute boolean fatal; + //readonly attribute boolean ignoreBOM; + //USVString decode(optional BufferSource input, optional TextDecodeOptions options); +}; diff --git a/tests/wpt/metadata/encoding/api-basics.html.ini b/tests/wpt/metadata/encoding/api-basics.html.ini index 03947330276..0045f9e5794 100644 --- a/tests/wpt/metadata/encoding/api-basics.html.ini +++ b/tests/wpt/metadata/encoding/api-basics.html.ini @@ -1,8 +1,5 @@ [api-basics.html] type: testharness - [Default encodings] - expected: FAIL - [Default inputs] expected: FAIL diff --git a/tests/wpt/metadata/encoding/idlharness.html.ini b/tests/wpt/metadata/encoding/idlharness.html.ini index 2c00e08d92e..f7c414c2d63 100644 --- a/tests/wpt/metadata/encoding/idlharness.html.ini +++ b/tests/wpt/metadata/encoding/idlharness.html.ini @@ -1,41 +1,14 @@ [idlharness.html] type: testharness - [TextDecoder interface: existence and properties of interface object] - expected: FAIL - [TextDecoder interface object length] expected: FAIL - [TextDecoder interface: existence and properties of interface prototype object] - expected: FAIL - - [TextDecoder interface: existence and properties of interface prototype object\'s "constructor" property] - expected: FAIL - - [TextDecoder interface: attribute encoding] - expected: FAIL - - [TextDecoder interface: attribute fatal] - expected: FAIL - [TextDecoder interface: attribute ignoreBOM] expected: FAIL [TextDecoder interface: operation decode(BufferSource,TextDecodeOptions)] expected: FAIL - [TextDecoder must be primary interface of new TextDecoder()] - expected: FAIL - - [Stringification of new TextDecoder()] - expected: FAIL - - [TextDecoder interface: new TextDecoder() must inherit property "encoding" with the proper type (0)] - expected: FAIL - - [TextDecoder interface: new TextDecoder() must inherit property "fatal" with the proper type (1)] - expected: FAIL - [TextDecoder interface: new TextDecoder() must inherit property "ignoreBOM" with the proper type (2)] expected: FAIL diff --git a/tests/wpt/metadata/encoding/textdecoder-fatal.html.ini b/tests/wpt/metadata/encoding/textdecoder-fatal.html.ini deleted file mode 100644 index 3f7dc6f45f6..00000000000 --- a/tests/wpt/metadata/encoding/textdecoder-fatal.html.ini +++ /dev/null @@ -1,107 +0,0 @@ -[textdecoder-fatal.html] - type: testharness - [Fatal flag: utf-8 - invalid code] - expected: FAIL - - [Fatal flag: utf-8 - ends early] - expected: FAIL - - [Fatal flag: utf-8 - ends early 2] - expected: FAIL - - [Fatal flag: utf-8 - invalid trail] - expected: FAIL - - [Fatal flag: utf-8 - invalid trail 2] - expected: FAIL - - [Fatal flag: utf-8 - invalid trail 3] - expected: FAIL - - [Fatal flag: utf-8 - invalid trail 4] - expected: FAIL - - [Fatal flag: utf-8 - invalid trail 5] - expected: FAIL - - [Fatal flag: utf-8 - invalid trail 6] - expected: FAIL - - [Fatal flag: utf-8 - > 0x10FFFF] - expected: FAIL - - [Fatal flag: utf-8 - obsolete lead byte] - expected: FAIL - - [Fatal flag: utf-8 - overlong U+0000 - 2 bytes] - expected: FAIL - - [Fatal flag: utf-8 - overlong U+0000 - 3 bytes] - expected: FAIL - - [Fatal flag: utf-8 - overlong U+0000 - 4 bytes] - expected: FAIL - - [Fatal flag: utf-8 - overlong U+0000 - 5 bytes] - expected: FAIL - - [Fatal flag: utf-8 - overlong U+0000 - 6 bytes] - expected: FAIL - - [Fatal flag: utf-8 - overlong U+007F - 2 bytes] - expected: FAIL - - [Fatal flag: utf-8 - overlong U+007F - 3 bytes] - expected: FAIL - - [Fatal flag: utf-8 - overlong U+007F - 4 bytes] - expected: FAIL - - [Fatal flag: utf-8 - overlong U+007F - 5 bytes] - expected: FAIL - - [Fatal flag: utf-8 - overlong U+007F - 6 bytes] - expected: FAIL - - [Fatal flag: utf-8 - overlong U+07FF - 3 bytes] - expected: FAIL - - [Fatal flag: utf-8 - overlong U+07FF - 4 bytes] - expected: FAIL - - [Fatal flag: utf-8 - overlong U+07FF - 5 bytes] - expected: FAIL - - [Fatal flag: utf-8 - overlong U+07FF - 6 bytes] - expected: FAIL - - [Fatal flag: utf-8 - overlong U+FFFF - 4 bytes] - expected: FAIL - - [Fatal flag: utf-8 - overlong U+FFFF - 5 bytes] - expected: FAIL - - [Fatal flag: utf-8 - overlong U+FFFF - 6 bytes] - expected: FAIL - - [Fatal flag: utf-8 - overlong U+10FFFF - 5 bytes] - expected: FAIL - - [Fatal flag: utf-8 - overlong U+10FFFF - 6 bytes] - expected: FAIL - - [Fatal flag: utf-8 - lead surrogate] - expected: FAIL - - [Fatal flag: utf-8 - trail surrogate] - expected: FAIL - - [Fatal flag: utf-8 - surrogate pair] - expected: FAIL - - [Fatal flag: utf-16le - truncated code unit] - expected: FAIL - - [The fatal attribute of TextDecoder] - expected: FAIL - diff --git a/tests/wpt/metadata/encoding/textdecoder-labels.html.ini b/tests/wpt/metadata/encoding/textdecoder-labels.html.ini index 61506476753..4f3fd8edbbf 100644 --- a/tests/wpt/metadata/encoding/textdecoder-labels.html.ini +++ b/tests/wpt/metadata/encoding/textdecoder-labels.html.ini @@ -1,515 +1,5 @@ [textdecoder-labels.html] type: testharness - [name=utf-8 label=unicode-1-1-utf-8] - expected: FAIL - - [name=utf-8 label=utf-8] - expected: FAIL - - [name=utf-8 label=utf8] - expected: FAIL - - [name=ibm866 label=866] - expected: FAIL - - [name=ibm866 label=cp866] - expected: FAIL - - [name=ibm866 label=csibm866] - expected: FAIL - - [name=ibm866 label=ibm866] - expected: FAIL - - [name=iso-8859-2 label=csisolatin2] - expected: FAIL - - [name=iso-8859-2 label=iso-8859-2] - expected: FAIL - - [name=iso-8859-2 label=iso-ir-101] - expected: FAIL - - [name=iso-8859-2 label=iso8859-2] - expected: FAIL - - [name=iso-8859-2 label=iso88592] - expected: FAIL - - [name=iso-8859-2 label=iso_8859-2] - expected: FAIL - - [name=iso-8859-2 label=iso_8859-2:1987] - expected: FAIL - - [name=iso-8859-2 label=l2] - expected: FAIL - - [name=iso-8859-2 label=latin2] - expected: FAIL - - [name=iso-8859-3 label=csisolatin3] - expected: FAIL - - [name=iso-8859-3 label=iso-8859-3] - expected: FAIL - - [name=iso-8859-3 label=iso-ir-109] - expected: FAIL - - [name=iso-8859-3 label=iso8859-3] - expected: FAIL - - [name=iso-8859-3 label=iso88593] - expected: FAIL - - [name=iso-8859-3 label=iso_8859-3] - expected: FAIL - - [name=iso-8859-3 label=iso_8859-3:1988] - expected: FAIL - - [name=iso-8859-3 label=l3] - expected: FAIL - - [name=iso-8859-3 label=latin3] - expected: FAIL - - [name=iso-8859-4 label=csisolatin4] - expected: FAIL - - [name=iso-8859-4 label=iso-8859-4] - expected: FAIL - - [name=iso-8859-4 label=iso-ir-110] - expected: FAIL - - [name=iso-8859-4 label=iso8859-4] - expected: FAIL - - [name=iso-8859-4 label=iso88594] - expected: FAIL - - [name=iso-8859-4 label=iso_8859-4] - expected: FAIL - - [name=iso-8859-4 label=iso_8859-4:1988] - expected: FAIL - - [name=iso-8859-4 label=l4] - expected: FAIL - - [name=iso-8859-4 label=latin4] - expected: FAIL - - [name=iso-8859-5 label=csisolatincyrillic] - expected: FAIL - - [name=iso-8859-5 label=cyrillic] - expected: FAIL - - [name=iso-8859-5 label=iso-8859-5] - expected: FAIL - - [name=iso-8859-5 label=iso-ir-144] - expected: FAIL - - [name=iso-8859-5 label=iso8859-5] - expected: FAIL - - [name=iso-8859-5 label=iso88595] - expected: FAIL - - [name=iso-8859-5 label=iso_8859-5] - expected: FAIL - - [name=iso-8859-5 label=iso_8859-5:1988] - expected: FAIL - - [name=iso-8859-6 label=arabic] - expected: FAIL - - [name=iso-8859-6 label=asmo-708] - expected: FAIL - - [name=iso-8859-6 label=csiso88596e] - expected: FAIL - - [name=iso-8859-6 label=csiso88596i] - expected: FAIL - - [name=iso-8859-6 label=csisolatinarabic] - expected: FAIL - - [name=iso-8859-6 label=ecma-114] - expected: FAIL - - [name=iso-8859-6 label=iso-8859-6] - expected: FAIL - - [name=iso-8859-6 label=iso-8859-6-e] - expected: FAIL - - [name=iso-8859-6 label=iso-8859-6-i] - expected: FAIL - - [name=iso-8859-6 label=iso-ir-127] - expected: FAIL - - [name=iso-8859-6 label=iso8859-6] - expected: FAIL - - [name=iso-8859-6 label=iso88596] - expected: FAIL - - [name=iso-8859-6 label=iso_8859-6] - expected: FAIL - - [name=iso-8859-6 label=iso_8859-6:1987] - expected: FAIL - - [name=iso-8859-7 label=csisolatingreek] - expected: FAIL - - [name=iso-8859-7 label=ecma-118] - expected: FAIL - - [name=iso-8859-7 label=elot_928] - expected: FAIL - - [name=iso-8859-7 label=greek] - expected: FAIL - - [name=iso-8859-7 label=greek8] - expected: FAIL - - [name=iso-8859-7 label=iso-8859-7] - expected: FAIL - - [name=iso-8859-7 label=iso-ir-126] - expected: FAIL - - [name=iso-8859-7 label=iso8859-7] - expected: FAIL - - [name=iso-8859-7 label=iso88597] - expected: FAIL - - [name=iso-8859-7 label=iso_8859-7] - expected: FAIL - - [name=iso-8859-7 label=iso_8859-7:1987] - expected: FAIL - - [name=iso-8859-7 label=sun_eu_greek] - expected: FAIL - - [name=iso-8859-8 label=csiso88598e] - expected: FAIL - - [name=iso-8859-8 label=csisolatinhebrew] - expected: FAIL - - [name=iso-8859-8 label=hebrew] - expected: FAIL - - [name=iso-8859-8 label=iso-8859-8] - expected: FAIL - - [name=iso-8859-8 label=iso-8859-8-e] - expected: FAIL - - [name=iso-8859-8 label=iso-ir-138] - expected: FAIL - - [name=iso-8859-8 label=iso8859-8] - expected: FAIL - - [name=iso-8859-8 label=iso88598] - expected: FAIL - - [name=iso-8859-8 label=iso_8859-8] - expected: FAIL - - [name=iso-8859-8 label=iso_8859-8:1988] - expected: FAIL - - [name=iso-8859-8 label=visual] - expected: FAIL - - [name=iso-8859-8-i label=csiso88598i] - expected: FAIL - - [name=iso-8859-8-i label=iso-8859-8-i] - expected: FAIL - - [name=iso-8859-8-i label=logical] - expected: FAIL - - [name=iso-8859-10 label=csisolatin6] - expected: FAIL - - [name=iso-8859-10 label=iso-8859-10] - expected: FAIL - - [name=iso-8859-10 label=iso-ir-157] - expected: FAIL - - [name=iso-8859-10 label=iso8859-10] - expected: FAIL - - [name=iso-8859-10 label=iso885910] - expected: FAIL - - [name=iso-8859-10 label=l6] - expected: FAIL - - [name=iso-8859-10 label=latin6] - expected: FAIL - - [name=iso-8859-13 label=iso-8859-13] - expected: FAIL - - [name=iso-8859-13 label=iso8859-13] - expected: FAIL - - [name=iso-8859-13 label=iso885913] - expected: FAIL - - [name=iso-8859-14 label=iso-8859-14] - expected: FAIL - - [name=iso-8859-14 label=iso8859-14] - expected: FAIL - - [name=iso-8859-14 label=iso885914] - expected: FAIL - - [name=iso-8859-15 label=csisolatin9] - expected: FAIL - - [name=iso-8859-15 label=iso-8859-15] - expected: FAIL - - [name=iso-8859-15 label=iso8859-15] - expected: FAIL - - [name=iso-8859-15 label=iso885915] - expected: FAIL - - [name=iso-8859-15 label=iso_8859-15] - expected: FAIL - - [name=iso-8859-15 label=l9] - expected: FAIL - - [name=iso-8859-16 label=iso-8859-16] - expected: FAIL - - [name=koi8-r label=cskoi8r] - expected: FAIL - - [name=koi8-r label=koi] - expected: FAIL - - [name=koi8-r label=koi8] - expected: FAIL - - [name=koi8-r label=koi8-r] - expected: FAIL - - [name=koi8-r label=koi8_r] - expected: FAIL - - [name=koi8-u label=koi8-u] - expected: FAIL - - [name=macintosh label=csmacintosh] - expected: FAIL - - [name=macintosh label=mac] - expected: FAIL - - [name=macintosh label=macintosh] - expected: FAIL - - [name=macintosh label=x-mac-roman] - expected: FAIL - - [name=windows-874 label=dos-874] - expected: FAIL - - [name=windows-874 label=iso-8859-11] - expected: FAIL - - [name=windows-874 label=iso8859-11] - expected: FAIL - - [name=windows-874 label=iso885911] - expected: FAIL - - [name=windows-874 label=tis-620] - expected: FAIL - - [name=windows-874 label=windows-874] - expected: FAIL - - [name=windows-1250 label=cp1250] - expected: FAIL - - [name=windows-1250 label=windows-1250] - expected: FAIL - - [name=windows-1250 label=x-cp1250] - expected: FAIL - - [name=windows-1251 label=cp1251] - expected: FAIL - - [name=windows-1251 label=windows-1251] - expected: FAIL - - [name=windows-1251 label=x-cp1251] - expected: FAIL - - [name=windows-1252 label=ansi_x3.4-1968] - expected: FAIL - - [name=windows-1252 label=ascii] - expected: FAIL - - [name=windows-1252 label=cp1252] - expected: FAIL - - [name=windows-1252 label=cp819] - expected: FAIL - - [name=windows-1252 label=csisolatin1] - expected: FAIL - - [name=windows-1252 label=ibm819] - expected: FAIL - - [name=windows-1252 label=iso-8859-1] - expected: FAIL - - [name=windows-1252 label=iso-ir-100] - expected: FAIL - - [name=windows-1252 label=iso8859-1] - expected: FAIL - - [name=windows-1252 label=iso88591] - expected: FAIL - - [name=windows-1252 label=iso_8859-1] - expected: FAIL - - [name=windows-1252 label=iso_8859-1:1987] - expected: FAIL - - [name=windows-1252 label=l1] - expected: FAIL - - [name=windows-1252 label=latin1] - expected: FAIL - - [name=windows-1252 label=us-ascii] - expected: FAIL - - [name=windows-1252 label=windows-1252] - expected: FAIL - - [name=windows-1252 label=x-cp1252] - expected: FAIL - - [name=windows-1253 label=cp1253] - expected: FAIL - - [name=windows-1253 label=windows-1253] - expected: FAIL - - [name=windows-1253 label=x-cp1253] - expected: FAIL - - [name=windows-1254 label=cp1254] - expected: FAIL - - [name=windows-1254 label=csisolatin5] - expected: FAIL - - [name=windows-1254 label=iso-8859-9] - expected: FAIL - - [name=windows-1254 label=iso-ir-148] - expected: FAIL - - [name=windows-1254 label=iso8859-9] - expected: FAIL - - [name=windows-1254 label=iso88599] - expected: FAIL - - [name=windows-1254 label=iso_8859-9] - expected: FAIL - - [name=windows-1254 label=iso_8859-9:1989] - expected: FAIL - - [name=windows-1254 label=l5] - expected: FAIL - - [name=windows-1254 label=latin5] - expected: FAIL - - [name=windows-1254 label=windows-1254] - expected: FAIL - - [name=windows-1254 label=x-cp1254] - expected: FAIL - - [name=windows-1255 label=cp1255] - expected: FAIL - - [name=windows-1255 label=windows-1255] - expected: FAIL - - [name=windows-1255 label=x-cp1255] - expected: FAIL - - [name=windows-1256 label=cp1256] - expected: FAIL - - [name=windows-1256 label=windows-1256] - expected: FAIL - - [name=windows-1256 label=x-cp1256] - expected: FAIL - - [name=windows-1257 label=cp1257] - expected: FAIL - - [name=windows-1257 label=windows-1257] - expected: FAIL - - [name=windows-1257 label=x-cp1257] - expected: FAIL - - [name=windows-1258 label=cp1258] - expected: FAIL - - [name=windows-1258 label=windows-1258] - expected: FAIL - - [name=windows-1258 label=x-cp1258] - expected: FAIL - - [name=x-mac-cyrillic label=x-mac-cyrillic] - expected: FAIL - - [name=x-mac-cyrillic label=x-mac-ukrainian] - expected: FAIL - [name=gbk label=chinese] expected: FAIL @@ -537,99 +27,9 @@ [name=gbk label=x-gbk] expected: FAIL - [name=gb18030 label=gb18030] - expected: FAIL - - [name=big5 label=big5] - expected: FAIL - - [name=big5 label=big5-hkscs] - expected: FAIL - - [name=big5 label=cn-big5] - expected: FAIL - - [name=big5 label=csbig5] - expected: FAIL - - [name=big5 label=x-x-big5] - expected: FAIL - - [name=euc-jp label=cseucpkdfmtjapanese] - expected: FAIL - - [name=euc-jp label=euc-jp] - expected: FAIL - - [name=euc-jp label=x-euc-jp] - expected: FAIL - - [name=iso-2022-jp label=csiso2022jp] - expected: FAIL - - [name=iso-2022-jp label=iso-2022-jp] - expected: FAIL - - [name=shift_jis label=csshiftjis] - expected: FAIL - - [name=shift_jis label=ms_kanji] - expected: FAIL - - [name=shift_jis label=shift-jis] - expected: FAIL - - [name=shift_jis label=shift_jis] - expected: FAIL - - [name=shift_jis label=sjis] - expected: FAIL - - [name=shift_jis label=windows-31j] - expected: FAIL - - [name=shift_jis label=x-sjis] - expected: FAIL - - [name=euc-kr label=cseuckr] - expected: FAIL - - [name=euc-kr label=csksc56011987] - expected: FAIL - - [name=euc-kr label=euc-kr] - expected: FAIL - - [name=euc-kr label=iso-ir-149] - expected: FAIL - - [name=euc-kr label=korean] - expected: FAIL - - [name=euc-kr label=ks_c_5601-1987] - expected: FAIL - - [name=euc-kr label=ks_c_5601-1989] - expected: FAIL - - [name=euc-kr label=ksc5601] - expected: FAIL - - [name=euc-kr label=ksc_5601] - expected: FAIL - - [name=euc-kr label=windows-949] - expected: FAIL - - [name=utf-16be label=utf-16be] - expected: FAIL - [name=utf-16le label=utf-16] expected: FAIL [name=utf-16le label=utf-16le] expected: FAIL - [name=x-user-defined label=x-user-defined] - expected: FAIL - diff --git a/tests/wpt/metadata/encoding/textdecoder-utf16-surrogates.html.ini b/tests/wpt/metadata/encoding/textdecoder-utf16-surrogates.html.ini index 0630043c8c7..9c32d21843c 100644 --- a/tests/wpt/metadata/encoding/textdecoder-utf16-surrogates.html.ini +++ b/tests/wpt/metadata/encoding/textdecoder-utf16-surrogates.html.ini @@ -3,30 +3,15 @@ [utf-16le - lone surrogate lead] expected: FAIL - [utf-16le - lone surrogate lead (fatal flag set)] - expected: FAIL - [utf-16le - lone surrogate trail] expected: FAIL - [utf-16le - lone surrogate trail (fatal flag set)] - expected: FAIL - [utf-16le - unmatched surrogate lead] expected: FAIL - [utf-16le - unmatched surrogate lead (fatal flag set)] - expected: FAIL - [utf-16le - unmatched surrogate trail] expected: FAIL - [utf-16le - unmatched surrogate trail (fatal flag set)] - expected: FAIL - [utf-16le - swapped surrogate pair] expected: FAIL - [utf-16le - swapped surrogate pair (fatal flag set)] - expected: FAIL - diff --git a/tests/wpt/metadata/encoding/textencoder-constructor-non-utf.html.ini b/tests/wpt/metadata/encoding/textencoder-constructor-non-utf.html.ini index 1af7e7f02b9..4d846b4443c 100644 --- a/tests/wpt/metadata/encoding/textencoder-constructor-non-utf.html.ini +++ b/tests/wpt/metadata/encoding/textencoder-constructor-non-utf.html.ini @@ -1,8 +1,5 @@ [textencoder-constructor-non-utf.html] type: testharness - [UTF encodings are supported for encode and decode: utf-8] - expected: FAIL - [Non-UTF encodings supported only for decode, not encode: ibm866] expected: FAIL @@ -108,9 +105,6 @@ [Non-UTF encodings supported only for decode, not encode: euc-kr] expected: FAIL - [UTF encodings are supported for encode and decode: utf-16be] - expected: FAIL - [UTF encodings are supported for encode and decode: utf-16le] expected: FAIL From c0d4e27d794636541dff7db91a1f3d2397602d1e Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 8 Apr 2015 16:50:51 +0200 Subject: [PATCH 2/3] Update js. --- components/servo/Cargo.lock | 4 ++-- ports/cef/Cargo.lock | 4 ++-- ports/gonk/Cargo.lock | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 83800fc7709..d61b2571292 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -479,7 +479,7 @@ dependencies = [ [[package]] name = "js" version = "0.1.0" -source = "git+https://github.com/servo/rust-mozjs#879b256e6bc5b38f792b68da130eb7a70633769b" +source = "git+https://github.com/servo/rust-mozjs#9512c3c770774ed73a2fdcc635eee178cbd02ab1" dependencies = [ "libc 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "mozjs_sys 0.0.0 (git+https://github.com/servo/mozjs)", @@ -617,7 +617,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "mozjs_sys" version = "0.0.0" -source = "git+https://github.com/servo/mozjs#40e0680008cb129ddf9ccf40c6b0095e14d1cd97" +source = "git+https://github.com/servo/mozjs#19edb950930f03f0ad305ffbd9548b92fdb0a250" [[package]] name = "msg" diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index 7cd06499343..3fcab77d28b 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -482,7 +482,7 @@ dependencies = [ [[package]] name = "js" version = "0.1.0" -source = "git+https://github.com/servo/rust-mozjs#879b256e6bc5b38f792b68da130eb7a70633769b" +source = "git+https://github.com/servo/rust-mozjs#9512c3c770774ed73a2fdcc635eee178cbd02ab1" dependencies = [ "libc 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "mozjs_sys 0.0.0 (git+https://github.com/servo/mozjs)", @@ -620,7 +620,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "mozjs_sys" version = "0.0.0" -source = "git+https://github.com/servo/mozjs#40e0680008cb129ddf9ccf40c6b0095e14d1cd97" +source = "git+https://github.com/servo/mozjs#19edb950930f03f0ad305ffbd9548b92fdb0a250" [[package]] name = "msg" diff --git a/ports/gonk/Cargo.lock b/ports/gonk/Cargo.lock index ddc5afd7988..7de597c61f9 100644 --- a/ports/gonk/Cargo.lock +++ b/ports/gonk/Cargo.lock @@ -415,7 +415,7 @@ dependencies = [ [[package]] name = "js" version = "0.1.0" -source = "git+https://github.com/servo/rust-mozjs#879b256e6bc5b38f792b68da130eb7a70633769b" +source = "git+https://github.com/servo/rust-mozjs#9512c3c770774ed73a2fdcc635eee178cbd02ab1" dependencies = [ "libc 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "mozjs_sys 0.0.0 (git+https://github.com/servo/mozjs)", @@ -545,7 +545,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "mozjs_sys" version = "0.0.0" -source = "git+https://github.com/servo/mozjs#40e0680008cb129ddf9ccf40c6b0095e14d1cd97" +source = "git+https://github.com/servo/mozjs#19edb950930f03f0ad305ffbd9548b92fdb0a250" [[package]] name = "msg" From e2929403eff482b83f044218919f40919015358d Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Wed, 8 Apr 2015 14:26:42 +0200 Subject: [PATCH 3/3] Implement TextDecoder#decode. --- components/script/dom/textdecoder.rs | 36 ++++++++++++- .../script/dom/webidls/TextDecoder.webidl | 2 + .../encoding/api-surrogates-utf8.html.ini | 20 -------- .../wpt/metadata/encoding/idlharness.html.ini | 6 --- .../encoding/iso-2022-jp-decoder.html.ini | 51 ------------------- .../encoding/textdecoder-streaming.html.ini | 27 ---------- .../textdecoder-utf16-surrogates.html.ini | 17 ------- .../textencoder-utf16-surrogates.html.ini | 20 -------- 8 files changed, 37 insertions(+), 142 deletions(-) delete mode 100644 tests/wpt/metadata/encoding/api-surrogates-utf8.html.ini delete mode 100644 tests/wpt/metadata/encoding/textdecoder-utf16-surrogates.html.ini delete mode 100644 tests/wpt/metadata/encoding/textencoder-utf16-surrogates.html.ini diff --git a/components/script/dom/textdecoder.rs b/components/script/dom/textdecoder.rs index 7aa6b4f92bc..714200f9a8f 100644 --- a/components/script/dom/textdecoder.rs +++ b/components/script/dom/textdecoder.rs @@ -7,16 +7,21 @@ use dom::bindings::codegen::Bindings::TextDecoderBinding::TextDecoderMethods; use dom::bindings::error::{Error, Fallible}; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JSRef, Temporary}; +use dom::bindings::str::USVString; use dom::bindings::trace::JSTraceable; use dom::bindings::utils::{Reflector, reflect_dom_object}; use util::str::DOMString; use encoding::Encoding; -use encoding::types::EncodingRef; +use encoding::types::{EncodingRef, DecoderTrap}; use encoding::label::encoding_from_whatwg_label; +use js::jsapi::{JSContext, JSObject}; +use js::jsfriendapi::bindgen::JS_GetObjectAsArrayBufferView; use std::borrow::ToOwned; +use std::ptr; +use std::slice; #[dom_struct] pub struct TextDecoder { @@ -62,4 +67,33 @@ impl<'a> TextDecoderMethods for JSRef<'a, TextDecoder> { fn Fatal(self) -> bool { self.fatal } + + #[allow(unsafe_code)] + fn Decode(self, cx: *mut JSContext, input: Option<*mut JSObject>) + -> Fallible { + let input = match input { + Some(input) => input, + None => return Ok(USVString("".to_owned())), + }; + + let mut length = 0; + let mut data = ptr::null_mut(); + if unsafe { JS_GetObjectAsArrayBufferView(cx, input, &mut length, &mut data).is_null() } { + return Err(Error::Type("Argument to TextDecoder.decode is not an ArrayBufferView".to_owned())); + } + + let buffer = unsafe { + slice::from_raw_parts(data as *const _, length as usize) + }; + let trap = if self.fatal { + DecoderTrap::Strict + } else { + DecoderTrap::Replace + }; + match self.encoding.decode(buffer, trap) { + Ok(s) => Ok(USVString(s)), + Err(_) => Err(Error::Type("Decoding failed".to_owned())), + } + } + } diff --git a/components/script/dom/webidls/TextDecoder.webidl b/components/script/dom/webidls/TextDecoder.webidl index 6450c2ef0b6..4ec66f07d7a 100644 --- a/components/script/dom/webidls/TextDecoder.webidl +++ b/components/script/dom/webidls/TextDecoder.webidl @@ -16,4 +16,6 @@ interface TextDecoder { readonly attribute boolean fatal; //readonly attribute boolean ignoreBOM; //USVString decode(optional BufferSource input, optional TextDecodeOptions options); + [Throws] + USVString decode(optional object input); }; diff --git a/tests/wpt/metadata/encoding/api-surrogates-utf8.html.ini b/tests/wpt/metadata/encoding/api-surrogates-utf8.html.ini deleted file mode 100644 index 76324a435ae..00000000000 --- a/tests/wpt/metadata/encoding/api-surrogates-utf8.html.ini +++ /dev/null @@ -1,20 +0,0 @@ -[api-surrogates-utf8.html] - type: testharness - [Invalid surrogates encoded into UTF-8: Sanity check] - expected: FAIL - - [Invalid surrogates encoded into UTF-8: Surrogate half (low)] - expected: FAIL - - [Invalid surrogates encoded into UTF-8: Surrogate half (high)] - expected: FAIL - - [Invalid surrogates encoded into UTF-8: Surrogate half (low), in a string] - expected: FAIL - - [Invalid surrogates encoded into UTF-8: Surrogate half (high), in a string] - expected: FAIL - - [Invalid surrogates encoded into UTF-8: Wrong order] - expected: FAIL - diff --git a/tests/wpt/metadata/encoding/idlharness.html.ini b/tests/wpt/metadata/encoding/idlharness.html.ini index f7c414c2d63..28ad8fba868 100644 --- a/tests/wpt/metadata/encoding/idlharness.html.ini +++ b/tests/wpt/metadata/encoding/idlharness.html.ini @@ -12,12 +12,6 @@ [TextDecoder interface: new TextDecoder() must inherit property "ignoreBOM" with the proper type (2)] expected: FAIL - [TextDecoder interface: new TextDecoder() must inherit property "decode" with the proper type (3)] - expected: FAIL - - [TextDecoder interface: calling decode(BufferSource,TextDecodeOptions) on new TextDecoder() with too few arguments must throw TypeError] - expected: FAIL - [TextEncoder interface object length] expected: FAIL diff --git a/tests/wpt/metadata/encoding/iso-2022-jp-decoder.html.ini b/tests/wpt/metadata/encoding/iso-2022-jp-decoder.html.ini index 4651cfad0d9..ace8b904e2b 100644 --- a/tests/wpt/metadata/encoding/iso-2022-jp-decoder.html.ini +++ b/tests/wpt/metadata/encoding/iso-2022-jp-decoder.html.ini @@ -3,21 +3,12 @@ [iso-2022-jp decoder: Error ESC] expected: FAIL - [iso-2022-jp decoder: Error ESC, character] - expected: FAIL - [iso-2022-jp decoder: ASCII ESC, character] expected: FAIL [iso-2022-jp decoder: Double ASCII ESC, character] expected: FAIL - [iso-2022-jp decoder: character, ASCII ESC, character] - expected: FAIL - - [iso-2022-jp decoder: characters] - expected: FAIL - [iso-2022-jp decoder: SO / SI] expected: FAIL @@ -27,12 +18,6 @@ [iso-2022-jp decoder: Roman ESC, SO / SI] expected: FAIL - [iso-2022-jp decoder: Roman ESC, error ESC, Katakana ESC] - expected: FAIL - - [iso-2022-jp decoder: Katakana ESC, character] - expected: FAIL - [iso-2022-jp decoder: Katakana ESC, multibyte ESC, character] expected: FAIL @@ -42,18 +27,6 @@ [iso-2022-jp decoder: Katakana ESC, error ESC #2, character] expected: FAIL - [iso-2022-jp decoder: Katakana ESC, character, Katakana ESC, character] - expected: FAIL - - [iso-2022-jp decoder: Katakana ESC, SO / SI] - expected: FAIL - - [iso-2022-jp decoder: Multibyte ESC, character] - expected: FAIL - - [iso-2022-jp decoder: Multibyte ESC #2, character] - expected: FAIL - [iso-2022-jp decoder: Multibyte ESC, error ESC, character] expected: FAIL @@ -75,30 +48,6 @@ [iso-2022-jp decoder: Multibyte ESC, lead error byte] expected: FAIL - [iso-2022-jp decoder: Multibyte ESC, trail error byte] - expected: FAIL - - [iso-2022-jp decoder: character, error ESC] - expected: FAIL - [iso-2022-jp decoder: character, error ESC #2] expected: FAIL - [iso-2022-jp decoder: character, error ESC #3] - expected: FAIL - - [iso-2022-jp decoder: character, ASCII ESC] - expected: FAIL - - [iso-2022-jp decoder: character, Roman ESC] - expected: FAIL - - [iso-2022-jp decoder: character, Katakana ESC] - expected: FAIL - - [iso-2022-jp decoder: character, Multibyte ESC] - expected: FAIL - - [iso-2022-jp decoder: character, Multibyte ESC #2] - expected: FAIL - diff --git a/tests/wpt/metadata/encoding/textdecoder-streaming.html.ini b/tests/wpt/metadata/encoding/textdecoder-streaming.html.ini index 8f34fafe58b..401997d8036 100644 --- a/tests/wpt/metadata/encoding/textdecoder-streaming.html.ini +++ b/tests/wpt/metadata/encoding/textdecoder-streaming.html.ini @@ -1,47 +1,20 @@ [textdecoder-streaming.html] type: testharness - [Streaming decode: utf-8, 1 byte window] - expected: FAIL - - [Streaming decode: utf-8, 2 byte window] - expected: FAIL - - [Streaming decode: utf-8, 3 byte window] - expected: FAIL - - [Streaming decode: utf-8, 4 byte window] - expected: FAIL - - [Streaming decode: utf-8, 5 byte window] - expected: FAIL - [Streaming decode: utf-16le, 1 byte window] expected: FAIL - [Streaming decode: utf-16le, 2 byte window] - expected: FAIL - [Streaming decode: utf-16le, 3 byte window] expected: FAIL - [Streaming decode: utf-16le, 4 byte window] - expected: FAIL - [Streaming decode: utf-16le, 5 byte window] expected: FAIL [Streaming decode: utf-16be, 1 byte window] expected: FAIL - [Streaming decode: utf-16be, 2 byte window] - expected: FAIL - [Streaming decode: utf-16be, 3 byte window] expected: FAIL - [Streaming decode: utf-16be, 4 byte window] - expected: FAIL - [Streaming decode: utf-16be, 5 byte window] expected: FAIL diff --git a/tests/wpt/metadata/encoding/textdecoder-utf16-surrogates.html.ini b/tests/wpt/metadata/encoding/textdecoder-utf16-surrogates.html.ini deleted file mode 100644 index 9c32d21843c..00000000000 --- a/tests/wpt/metadata/encoding/textdecoder-utf16-surrogates.html.ini +++ /dev/null @@ -1,17 +0,0 @@ -[textdecoder-utf16-surrogates.html] - type: testharness - [utf-16le - lone surrogate lead] - expected: FAIL - - [utf-16le - lone surrogate trail] - expected: FAIL - - [utf-16le - unmatched surrogate lead] - expected: FAIL - - [utf-16le - unmatched surrogate trail] - expected: FAIL - - [utf-16le - swapped surrogate pair] - expected: FAIL - diff --git a/tests/wpt/metadata/encoding/textencoder-utf16-surrogates.html.ini b/tests/wpt/metadata/encoding/textencoder-utf16-surrogates.html.ini deleted file mode 100644 index 45d49ee6a37..00000000000 --- a/tests/wpt/metadata/encoding/textencoder-utf16-surrogates.html.ini +++ /dev/null @@ -1,20 +0,0 @@ -[textencoder-utf16-surrogates.html] - type: testharness - [USVString handling: lone surrogate lead] - expected: FAIL - - [USVString handling: lone surrogate trail] - expected: FAIL - - [USVString handling: unmatched surrogate lead] - expected: FAIL - - [USVString handling: unmatched surrogate trail] - expected: FAIL - - [USVString handling: swapped surrogate pair] - expected: FAIL - - [USVString handling: properly encoded MUSICAL SYMBOL G CLEF (U+1D11E)] - expected: FAIL -