aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2017-05-22 02:24:42 +0200
committerSimon Sapin <simon.sapin@exyr.org>2017-05-27 13:34:23 +0200
commit6ac106ca76afc2793c1030d9941b29836db14bd2 (patch)
tree2ac2c8d850e66252723d8686fd63ca8007e227d6 /components/script
parentb0c7c71729e6423cea9387030306a86654cb33de (diff)
downloadservo-6ac106ca76afc2793c1030d9941b29836db14bd2.tar.gz
servo-6ac106ca76afc2793c1030d9941b29836db14bd2.zip
Remove some usage of rust-encoding
Diffstat (limited to 'components/script')
-rw-r--r--components/script/body.rs7
-rw-r--r--components/script/dom/blob.rs9
-rw-r--r--components/script/dom/textencoder.rs7
3 files changed, 7 insertions, 16 deletions
diff --git a/components/script/body.rs b/components/script/body.rs
index 1967d69cf50..80c9be5d49f 100644
--- a/components/script/body.rs
+++ b/components/script/body.rs
@@ -11,8 +11,6 @@ use dom::blob::{Blob, BlobImpl};
use dom::formdata::FormData;
use dom::globalscope::GlobalScope;
use dom::promise::Promise;
-use encoding::all::UTF_8;
-use encoding::types::{DecoderTrap, Encoding};
use js::jsapi::JSContext;
use js::jsapi::JS_ClearPendingException;
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> {
- let text = UTF_8.decode(&bytes, DecoderTrap::Replace).unwrap();
- Ok(FetchedData::Text(text))
+ Ok(FetchedData::Text(String::from_utf8_lossy(&bytes).into_owned()))
}
#[allow(unsafe_code)]
fn run_json_data_algorithm(cx: *mut JSContext,
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();
rooted!(in(cx) let mut rval = UndefinedValue());
unsafe {
diff --git a/components/script/dom/blob.rs b/components/script/dom/blob.rs
index c076282dcc1..ddf14fc8096 100644
--- a/components/script/dom/blob.rs
+++ b/components/script/dom/blob.rs
@@ -12,8 +12,6 @@ use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
use dom::bindings::str::DOMString;
use dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
-use encoding::all::UTF_8;
-use encoding::types::{EncoderTrap, Encoding};
use ipc_channel::ipc;
use net_traits::{CoreResourceMsg, IpcSend};
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 {
match blobpart {
&BlobOrString::String(ref s) => {
- let mut bytes = UTF_8.encode(s, EncoderTrap::Replace).map_err(|_|())?;
- ret.append(&mut bytes);
+ ret.extend(s.as_bytes());
},
&BlobOrString::Blob(ref b) => {
- let mut bytes = b.get_bytes().unwrap_or(vec![]);
- ret.append(&mut bytes);
+ let bytes = b.get_bytes().unwrap_or(vec![]);
+ ret.extend(bytes);
},
}
}
diff --git a/components/script/dom/textencoder.rs b/components/script/dom/textencoder.rs
index 765c95ade0b..5cdbeca1dd3 100644
--- a/components/script/dom/textencoder.rs
+++ b/components/script/dom/textencoder.rs
@@ -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());