aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/textencoder.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/textencoder.rs')
-rw-r--r--components/script/dom/textencoder.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/components/script/dom/textencoder.rs b/components/script/dom/textencoder.rs
index 84100e723ba..674243dded8 100644
--- a/components/script/dom/textencoder.rs
+++ b/components/script/dom/textencoder.rs
@@ -2,6 +2,7 @@
* 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 core::nonzero::NonZero;
use dom::bindings::codegen::Bindings::TextEncoderBinding;
use dom::bindings::codegen::Bindings::TextEncoderBinding::TextEncoderMethods;
use dom::bindings::error::{Error, Fallible};
@@ -70,16 +71,17 @@ impl TextEncoderMethods for TextEncoder {
#[allow(unsafe_code)]
// https://encoding.spec.whatwg.org/#dom-textencoder-encode
- fn Encode(&self, cx: *mut JSContext, input: USVString) -> *mut JSObject {
+ fn Encode(&self, cx: *mut JSContext, input: USVString) -> NonZero<*mut JSObject> {
unsafe {
let encoded = self.encoder.encode(&input.0, EncoderTrap::Strict).unwrap();
let length = encoded.len() as u32;
- let js_object: *mut JSObject = JS_NewUint8Array(cx, length);
+ rooted!(in(cx) let js_object = JS_NewUint8Array(cx, length));
+ assert!(!js_object.is_null());
let mut is_shared = false;
- let js_object_data: *mut uint8_t = JS_GetUint8ArrayData(js_object, &mut is_shared, ptr::null());
+ let js_object_data: *mut uint8_t = JS_GetUint8ArrayData(js_object.get(), &mut is_shared, ptr::null());
assert!(!is_shared);
ptr::copy_nonoverlapping(encoded.as_ptr(), js_object_data, length as usize);
- js_object
+ NonZero::new(js_object.get())
}
}
}