mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Convert CGTraitInterface to use safe JSContext instead of raw JSContext
This commit is contained in:
parent
808fa65aef
commit
2c5d0a6ebc
43 changed files with 443 additions and 528 deletions
|
@ -13,8 +13,9 @@ use crate::dom::bindings::str::DOMString;
|
|||
use crate::dom::blob::Blob;
|
||||
use crate::dom::filereader::FileReaderSharedFunctionality;
|
||||
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::{ArrayBuffer, CreateWith};
|
||||
use std::ptr;
|
||||
use std::ptr::NonNull;
|
||||
|
@ -87,23 +88,21 @@ impl FileReaderSyncMethods for FileReaderSync {
|
|||
|
||||
#[allow(unsafe_code)]
|
||||
// https://w3c.github.io/FileAPI/#readAsArrayBufferSyncSection
|
||||
unsafe fn ReadAsArrayBuffer(
|
||||
&self,
|
||||
cx: *mut JSContext,
|
||||
blob: &Blob,
|
||||
) -> Fallible<NonNull<JSObject>> {
|
||||
fn ReadAsArrayBuffer(&self, cx: JSContext, blob: &Blob) -> Fallible<NonNull<JSObject>> {
|
||||
// step 1
|
||||
let blob_contents = FileReaderSync::get_blob_bytes(blob)?;
|
||||
|
||||
// step 2
|
||||
rooted!(in(cx) let mut array_buffer = ptr::null_mut::<JSObject>());
|
||||
assert!(ArrayBuffer::create(
|
||||
cx,
|
||||
CreateWith::Slice(&blob_contents),
|
||||
array_buffer.handle_mut()
|
||||
)
|
||||
.is_ok());
|
||||
unsafe {
|
||||
rooted!(in(*cx) let mut array_buffer = ptr::null_mut::<JSObject>());
|
||||
assert!(ArrayBuffer::create(
|
||||
*cx,
|
||||
CreateWith::Slice(&blob_contents),
|
||||
array_buffer.handle_mut()
|
||||
)
|
||||
.is_ok());
|
||||
|
||||
Ok(NonNull::new_unchecked(array_buffer.get()))
|
||||
Ok(NonNull::new_unchecked(array_buffer.get()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue