Convert CGTraitInterface to use safe JSContext instead of raw JSContext

This commit is contained in:
marmeladema 2019-07-22 01:09:24 +01:00
parent 808fa65aef
commit 2c5d0a6ebc
43 changed files with 443 additions and 528 deletions

View file

@ -9,8 +9,9 @@ use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::{DOMString, USVString};
use crate::dom::globalscope::GlobalScope;
use crate::script_runtime::JSContext;
use dom_struct::dom_struct;
use js::jsapi::{JSContext, JSObject};
use js::jsapi::JSObject;
use js::typedarray::{CreateWith, Uint8Array};
use std::ptr;
use std::ptr::NonNull;
@ -49,14 +50,17 @@ impl TextEncoderMethods for TextEncoder {
#[allow(unsafe_code)]
// https://encoding.spec.whatwg.org/#dom-textencoder-encode
unsafe fn Encode(&self, cx: *mut JSContext, input: USVString) -> NonNull<JSObject> {
fn Encode(&self, cx: JSContext, input: USVString) -> NonNull<JSObject> {
let encoded = input.0.as_bytes();
rooted!(in(cx) let mut js_object = ptr::null_mut::<JSObject>());
assert!(
Uint8Array::create(cx, CreateWith::Slice(&encoded), js_object.handle_mut()).is_ok()
);
unsafe {
rooted!(in(*cx) let mut js_object = ptr::null_mut::<JSObject>());
assert!(
Uint8Array::create(*cx, CreateWith::Slice(&encoded), js_object.handle_mut())
.is_ok()
);
NonNull::new_unchecked(js_object.get())
NonNull::new_unchecked(js_object.get())
}
}
}