Remove some usage of rust-encoding

This commit is contained in:
Simon Sapin 2017-05-22 02:24:42 +02:00
parent b0c7c71729
commit 6ac106ca76
7 changed files with 8 additions and 22 deletions

View file

@ -11,9 +11,6 @@ use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::bindings::str::{DOMString, USVString};
use dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
use encoding::EncoderTrap;
use encoding::Encoding;
use encoding::all::UTF_8;
use js::jsapi::{JSContext, JSObject};
use js::typedarray::{Uint8Array, CreateWith};
use std::ptr;
@ -45,13 +42,13 @@ impl TextEncoder {
impl TextEncoderMethods for TextEncoder {
// https://encoding.spec.whatwg.org/#dom-textencoder-encoding
fn Encoding(&self) -> DOMString {
DOMString::from(UTF_8.name())
DOMString::from("utf-8")
}
#[allow(unsafe_code)]
// https://encoding.spec.whatwg.org/#dom-textencoder-encode
unsafe fn Encode(&self, cx: *mut JSContext, input: USVString) -> NonZero<*mut JSObject> {
let encoded = UTF_8.encode(&input.0, EncoderTrap::Strict).unwrap();
let encoded = input.0.as_bytes();
rooted!(in(cx) let mut js_object = ptr::null_mut());
assert!(Uint8Array::create(cx, CreateWith::Slice(&encoded), js_object.handle_mut()).is_ok());