Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #4768.
- Loading branch information
Showing
23 changed files
with
1,372 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* 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::TextEncoderBinding; | ||
use dom::bindings::codegen::Bindings::TextEncoderBinding::TextEncoderMethods; | ||
use dom::bindings::global::GlobalRef; | ||
use dom::bindings::error::Fallible; | ||
use dom::bindings::error::Error::IndexSize; | ||
use dom::bindings::js::{JSRef, Temporary}; | ||
use dom::bindings::str::USVString; | ||
use dom::bindings::utils::{Reflector, reflect_dom_object}; | ||
|
||
use util::str::DOMString; | ||
|
||
use std::borrow::ToOwned; | ||
use std::ascii::AsciiExt; | ||
use std::ptr; | ||
|
||
use encoding::types::EncodingRef; | ||
use encoding::{Encoding, EncoderTrap}; | ||
use encoding::label::encoding_from_whatwg_label; | ||
|
||
use libc::uint8_t; | ||
use js::jsapi::{JSContext, JSObject}; | ||
use js::jsfriendapi::bindgen::{JS_NewUint8Array, JS_GetUint8ArrayData}; | ||
|
||
#[dom_struct] | ||
pub struct TextEncoder { | ||
reflector_: Reflector, | ||
encoding: DOMString, | ||
encoder: EncodingRef, | ||
} | ||
|
||
impl TextEncoder { | ||
fn new_inherited(encoding: DOMString, encoder: EncodingRef) -> TextEncoder { | ||
TextEncoder { | ||
reflector_: Reflector::new(), | ||
encoding: encoding, | ||
encoder: encoder, | ||
} | ||
} | ||
|
||
pub fn new(global: GlobalRef, encoding: DOMString, encoder: EncodingRef) -> Temporary<TextEncoder> { | ||
reflect_dom_object(box TextEncoder::new_inherited(encoding, encoder), | ||
global, | ||
TextEncoderBinding::Wrap) | ||
} | ||
|
||
// https://encoding.spec.whatwg.org/#dom-textencoder | ||
pub fn Constructor(global: GlobalRef, | ||
label: DOMString) -> Fallible<Temporary<TextEncoder>> { | ||
let encoding = match encoding_from_whatwg_label(label.trim().as_slice().to_ascii_lowercase().as_slice()) { | ||
Some(enc) => enc, | ||
None => { | ||
debug!("Encoding Label Not Supported"); | ||
// TODO: should throw RangeError | ||
return Err(IndexSize) | ||
} | ||
}; | ||
|
||
match encoding.name() { | ||
"utf-8" | "utf-16be" | "utf-16le" => { | ||
Ok(TextEncoder::new(global, encoding.name().to_owned(), encoding)) | ||
} | ||
_ => { | ||
debug!("Encoding Not UTF"); | ||
// TODO: should throw RangeError | ||
Err(IndexSize) | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl<'a> TextEncoderMethods for JSRef<'a, TextEncoder> { | ||
// https://encoding.spec.whatwg.org/#dom-textencoder-encoding | ||
fn Encoding(self) -> DOMString { | ||
self.encoding.clone() | ||
} | ||
|
||
// https://encoding.spec.whatwg.org/#dom-textencoder-encode | ||
#[allow(unsafe_code)] | ||
fn Encode(self, cx: *mut JSContext, input: USVString) -> *mut JSObject { | ||
unsafe { | ||
let output = self.encoder.encode(input.0.as_slice(), EncoderTrap::Strict).unwrap(); | ||
let length = output.len() as u32; | ||
let js_object: *mut JSObject = JS_NewUint8Array(cx, length); | ||
|
||
let js_object_data: *mut uint8_t = JS_GetUint8ArrayData(js_object, cx); | ||
ptr::copy_nonoverlapping(js_object_data, output.as_ptr(), length as usize); | ||
return js_object; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* -*- 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-textencoder */ | ||
[Constructor(optional DOMString utfLabel = "utf-8")/*, Exposed=Window,Worker */] | ||
interface TextEncoder { | ||
readonly attribute DOMString encoding; | ||
[NewObject] | ||
Uint8Array encode(optional USVString input = ""); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,3 +95,5 @@ skip: true | |
skip: true | ||
[webstorage] | ||
skip: false | ||
[encoding] | ||
skip: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[api-basics.html] | ||
type: testharness | ||
[Default encodings] | ||
expected: FAIL | ||
|
||
[Default inputs] | ||
expected: FAIL | ||
|
||
[Encode/decode round trip: utf-8] | ||
expected: FAIL | ||
|
||
[Encode/decode round trip: utf-16le] | ||
expected: FAIL | ||
|
||
[Encode/decode round trip: utf-16be] | ||
expected: FAIL | ||
|
||
[Encode/decode round trip: utf-16] | ||
expected: FAIL | ||
|
20 changes: 20 additions & 0 deletions
20
tests/wpt/metadata/encoding/api-replacement-encodings.html.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[api-replacement-encodings.html] | ||
type: testharness | ||
[The "replacement" label should not be a known encoding.] | ||
expected: FAIL | ||
|
||
[Label for "replacement" should be rejected by API: csiso2022kr] | ||
expected: FAIL | ||
|
||
[Label for "replacement" should be rejected by API: hz-gb-2312] | ||
expected: FAIL | ||
|
||
[Label for "replacement" should be rejected by API: iso-2022-cn] | ||
expected: FAIL | ||
|
||
[Label for "replacement" should be rejected by API: iso-2022-cn-ext] | ||
expected: FAIL | ||
|
||
[Label for "replacement" should be rejected by API: iso-2022-kr] | ||
expected: FAIL | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[gb18030-encoder.html] | ||
type: testharness | ||
[gb18030 encoder: very basic] | ||
expected: FAIL | ||
|
||
[gb18030 encoder: Euro] | ||
expected: FAIL | ||
|
||
[gb18030 encoder: character] | ||
expected: FAIL | ||
|
||
[gb18030 encoder: PUA] | ||
expected: FAIL | ||
|
||
[gb18030 encoder: PUA #2] | ||
expected: FAIL | ||
|
||
[gb18030 encoder: poo] | ||
expected: FAIL | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[gbk-encoder.html] | ||
type: testharness | ||
[gbk encoder: very basic] | ||
expected: FAIL | ||
|
||
[gbk encoder: Euro] | ||
expected: FAIL | ||
|
||
[gbk encoder: character] | ||
expected: FAIL | ||
|
||
[gbk encoder: PUA] | ||
expected: FAIL | ||
|
||
[gbk encoder: PUA #2] | ||
expected: FAIL | ||
|
||
[gbk encoder: poo] | ||
expected: FAIL | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
[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 | ||
[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 | ||
[TextEncoder interface: operation encode(USVString)] | ||
expected: FAIL |
104 changes: 104 additions & 0 deletions
104
tests/wpt/metadata/encoding/iso-2022-jp-decoder.html.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
[iso-2022-jp-decoder.html] | ||
type: testharness | ||
[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 | ||
|
||
[iso-2022-jp decoder: Roman ESC, characters] | ||
expected: FAIL | ||
|
||
[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 | ||
|
||
[iso-2022-jp decoder: Katakana ESC, error ESC, character] | ||
expected: FAIL | ||
|
||
[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 | ||
|
||
[iso-2022-jp decoder: Double multibyte ESC] | ||
expected: FAIL | ||
|
||
[iso-2022-jp decoder: Double multibyte ESC, character] | ||
expected: FAIL | ||
|
||
[iso-2022-jp decoder: Double multibyte ESC #2, character] | ||
expected: FAIL | ||
|
||
[iso-2022-jp decoder: Multibyte ESC, error ESC #2, character] | ||
expected: FAIL | ||
|
||
[iso-2022-jp decoder: Multibyte ESC, single byte, multibyte ESC, character] | ||
expected: FAIL | ||
|
||
[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 | ||
|
Oops, something went wrong.
9cd976a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from jdm
at mbrubeck@9cd976a
9cd976a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging mbrubeck/servo/yodalee-issue4768-textencoder = 9cd976a into auto
9cd976a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mbrubeck/servo/yodalee-issue4768-textencoder = 9cd976a merged ok, testing candidate = f86d18c
9cd976a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some tests failed:
failure: http://build.servo.org/builders/linux2/builds/1232
9cd976a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from jdm
at mbrubeck@9cd976a
9cd976a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging mbrubeck/servo/yodalee-issue4768-textencoder = 9cd976a into auto
9cd976a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mbrubeck/servo/yodalee-issue4768-textencoder = 9cd976a merged ok, testing candidate = 4846607
9cd976a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all tests pass:
success: http://build.servo.org/builders/linux1/builds/1236
success: http://build.servo.org/builders/linux2/builds/1234
success: http://build.servo.org/builders/android/builds/1270
success: http://build.servo.org/builders/mac1/builds/1449
success: http://build.servo.org/builders/mac2/builds/1452
success: http://build.servo.org/builders/gonk/builds/416
9cd976a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fast-forwarding master to auto = 4846607