Struct neon::types::JsArrayBuffer
source · #[repr(transparent)]pub struct JsArrayBuffer(_);
Expand description
The type of JavaScript
ArrayBuffer
objects.
Example
use neon::types::buffer::TypedArray;
fn make_sequence(mut cx: FunctionContext) -> JsResult<JsArrayBuffer> {
let len = cx.argument::<JsNumber>(0)?.value(&mut cx);
let mut buffer = cx.array_buffer(len as usize)?;
for (i, elem) in buffer.as_mut_slice(&mut cx).iter_mut().enumerate() {
*elem = i as u8;
}
Ok(buffer)
}
Implementations§
source§impl JsArrayBuffer
impl JsArrayBuffer
sourcepub fn new<'a, C: Context<'a>>(cx: &mut C, len: usize) -> JsResult<'a, Self>
pub fn new<'a, C: Context<'a>>(cx: &mut C, len: usize) -> JsResult<'a, Self>
Constructs a new JsArrayBuffer
object, safely zero-filled.
See also: Context::array_buffer
sourcepub fn from_slice<'cx, C>(cx: &mut C, slice: &[u8]) -> JsResult<'cx, Self>where
C: Context<'cx>,
pub fn from_slice<'cx, C>(cx: &mut C, slice: &[u8]) -> JsResult<'cx, Self>where C: Context<'cx>,
Constructs a JsArrayBuffer
from a slice by copying its contents.
This method is defined on JsArrayBuffer
as a convenience and delegates to
TypedArray::from_slice
.
sourcepub fn external<'a, C, T>(cx: &mut C, data: T) -> Handle<'a, Self>where
C: Context<'a>,
T: AsMut<[u8]> + Send + 'static,
Available on crate feature external-buffers
only.
pub fn external<'a, C, T>(cx: &mut C, data: T) -> Handle<'a, Self>where C: Context<'a>, T: AsMut<[u8]> + Send + 'static,
external-buffers
only.Construct a new JsArrayBuffer
from bytes allocated by Rust.
Compatibility Note
Some Node environments are built using V8’s sandboxed pointers functionality, which disallows the use of external buffers. In those environments, calling the underlying runtime function used by this method results in an immediate termination of the Node VM.
As a result, this API is disabled by default. If you are confident that your code will
only be used in environments that disable sandboxed pointers, you can make use of this
method by enabling the external-buffers
feature flag.
sourcepub fn region<'cx, T: Binary>(
buffer: &Handle<'cx, JsArrayBuffer>,
offset: usize,
len: usize
) -> Region<'cx, T>
pub fn region<'cx, T: Binary>( buffer: &Handle<'cx, JsArrayBuffer>, offset: usize, len: usize ) -> Region<'cx, T>
Returns a region of this buffer.
See also: Handle<JsArrayBuffer>::region()
for a more
ergonomic form of this method.
Trait Implementations§
source§impl Debug for JsArrayBuffer
impl Debug for JsArrayBuffer
source§impl Object for JsArrayBuffer
impl Object for JsArrayBuffer
source§fn get_opt<'a, V: Value, C: Context<'a>, K: PropertyKey>(
&self,
cx: &mut C,
key: K
) -> NeonResult<Option<Handle<'a, V>>>
fn get_opt<'a, V: Value, C: Context<'a>, K: PropertyKey>( &self, cx: &mut C, key: K ) -> NeonResult<Option<Handle<'a, V>>>
undefined
and
attempts to downcast the value if it existed.source§fn get_value<'a, C: Context<'a>, K: PropertyKey>(
&self,
cx: &mut C,
key: K
) -> NeonResult<Handle<'a, JsValue>>
fn get_value<'a, C: Context<'a>, K: PropertyKey>( &self, cx: &mut C, key: K ) -> NeonResult<Handle<'a, JsValue>>
source§fn get<'a, V: Value, C: Context<'a>, K: PropertyKey>(
&self,
cx: &mut C,
key: K
) -> NeonResult<Handle<'a, V>>
fn get<'a, V: Value, C: Context<'a>, K: PropertyKey>( &self, cx: &mut C, key: K ) -> NeonResult<Handle<'a, V>>
obj.get_value(&mut cx)?.downcast_or_throw(&mut cx)
. Read moresource§fn get_own_property_names<'a, C: Context<'a>>(
&self,
cx: &mut C
) -> JsResult<'a, JsArray>
fn get_own_property_names<'a, C: Context<'a>>( &self, cx: &mut C ) -> JsResult<'a, JsArray>
napi-6
only.