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

1
Cargo.lock generated
View file

@ -632,7 +632,6 @@ name = "devtools"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"devtools_traits 0.0.1", "devtools_traits 0.0.1",
"encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper 0.10.10 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.10.10 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper_serde 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "hyper_serde 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "ipc-channel 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -11,7 +11,6 @@ path = "lib.rs"
[dependencies] [dependencies]
devtools_traits = {path = "../devtools_traits"} devtools_traits = {path = "../devtools_traits"}
encoding = "0.2"
hyper = "0.10" hyper = "0.10"
hyper_serde = "0.6" hyper_serde = "0.6"
ipc-channel = "0.7" ipc-channel = "0.7"

View file

@ -9,8 +9,6 @@
use actor::{Actor, ActorMessageStatus, ActorRegistry}; use actor::{Actor, ActorMessageStatus, ActorRegistry};
use devtools_traits::HttpRequest as DevtoolsHttpRequest; use devtools_traits::HttpRequest as DevtoolsHttpRequest;
use devtools_traits::HttpResponse as DevtoolsHttpResponse; use devtools_traits::HttpResponse as DevtoolsHttpResponse;
use encoding::all::UTF_8;
use encoding::types::{DecoderTrap, Encoding};
use hyper::header::{ContentType, Cookie}; use hyper::header::{ContentType, Cookie};
use hyper::header::Headers; use hyper::header::Headers;
use hyper::http::RawStatus; use hyper::http::RawStatus;
@ -361,7 +359,7 @@ impl NetworkEventActor {
pub fn add_response(&mut self, response: DevtoolsHttpResponse) { pub fn add_response(&mut self, response: DevtoolsHttpResponse) {
self.response.headers = response.headers.clone(); self.response.headers = response.headers.clone();
self.response.status = response.status.as_ref().map(|&(s, ref st)| { self.response.status = response.status.as_ref().map(|&(s, ref st)| {
let status_text = UTF_8.decode(st, DecoderTrap::Replace).unwrap(); let status_text = String::from_utf8_lossy(st).into_owned();
RawStatus(s, Cow::from(status_text)) RawStatus(s, Cow::from(status_text))
}); });
self.response.body = response.body.clone(); self.response.body = response.body.clone();

View file

@ -15,7 +15,6 @@
#![feature(box_syntax)] #![feature(box_syntax)]
extern crate devtools_traits; extern crate devtools_traits;
extern crate encoding;
extern crate hyper; extern crate hyper;
extern crate ipc_channel; extern crate ipc_channel;
#[macro_use] #[macro_use]

View file

@ -11,8 +11,6 @@ use dom::blob::{Blob, BlobImpl};
use dom::formdata::FormData; use dom::formdata::FormData;
use dom::globalscope::GlobalScope; use dom::globalscope::GlobalScope;
use dom::promise::Promise; use dom::promise::Promise;
use encoding::all::UTF_8;
use encoding::types::{DecoderTrap, Encoding};
use js::jsapi::JSContext; use js::jsapi::JSContext;
use js::jsapi::JS_ClearPendingException; use js::jsapi::JS_ClearPendingException;
use js::jsapi::JS_ParseJSON; use js::jsapi::JS_ParseJSON;
@ -110,14 +108,13 @@ fn run_package_data_algorithm<T: BodyOperations + DomObject>(object: &T,
} }
fn run_text_data_algorithm(bytes: Vec<u8>) -> Fallible<FetchedData> { fn run_text_data_algorithm(bytes: Vec<u8>) -> Fallible<FetchedData> {
let text = UTF_8.decode(&bytes, DecoderTrap::Replace).unwrap(); Ok(FetchedData::Text(String::from_utf8_lossy(&bytes).into_owned()))
Ok(FetchedData::Text(text))
} }
#[allow(unsafe_code)] #[allow(unsafe_code)]
fn run_json_data_algorithm(cx: *mut JSContext, fn run_json_data_algorithm(cx: *mut JSContext,
bytes: Vec<u8>) -> Fallible<FetchedData> { bytes: Vec<u8>) -> Fallible<FetchedData> {
let json_text = UTF_8.decode(&bytes, DecoderTrap::Replace).unwrap(); let json_text = String::from_utf8_lossy(&bytes);
let json_text: Vec<u16> = json_text.encode_utf16().collect(); let json_text: Vec<u16> = json_text.encode_utf16().collect();
rooted!(in(cx) let mut rval = UndefinedValue()); rooted!(in(cx) let mut rval = UndefinedValue());
unsafe { unsafe {

View file

@ -12,8 +12,6 @@ use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
use dom::bindings::str::DOMString; use dom::bindings::str::DOMString;
use dom::globalscope::GlobalScope; use dom::globalscope::GlobalScope;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use encoding::all::UTF_8;
use encoding::types::{EncoderTrap, Encoding};
use ipc_channel::ipc; use ipc_channel::ipc;
use net_traits::{CoreResourceMsg, IpcSend}; use net_traits::{CoreResourceMsg, IpcSend};
use net_traits::blob_url_store::{BlobBuf, get_blob_origin}; use net_traits::blob_url_store::{BlobBuf, get_blob_origin};
@ -337,12 +335,11 @@ pub fn blob_parts_to_bytes(blobparts: Vec<BlobOrString>) -> Result<Vec<u8>, ()>
for blobpart in &blobparts { for blobpart in &blobparts {
match blobpart { match blobpart {
&BlobOrString::String(ref s) => { &BlobOrString::String(ref s) => {
let mut bytes = UTF_8.encode(s, EncoderTrap::Replace).map_err(|_|())?; ret.extend(s.as_bytes());
ret.append(&mut bytes);
}, },
&BlobOrString::Blob(ref b) => { &BlobOrString::Blob(ref b) => {
let mut bytes = b.get_bytes().unwrap_or(vec![]); let bytes = b.get_bytes().unwrap_or(vec![]);
ret.append(&mut bytes); ret.extend(bytes);
}, },
} }
} }

View file

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