mirror of
https://github.com/denoland/rusty_v8.git
synced 2025-01-13 09:33:02 -05:00
41 lines
862 B
Rust
41 lines
862 B
Rust
// Copyright 2019-2021 the Deno authors. All rights reserved. MIT license.
|
|
use crate::support::int;
|
|
use crate::Context;
|
|
use crate::Data;
|
|
use crate::FixedArray;
|
|
use crate::HandleScope;
|
|
use crate::Local;
|
|
|
|
extern "C" {
|
|
fn v8__FixedArray__Length(this: *const FixedArray) -> int;
|
|
|
|
fn v8__FixedArray__Get(
|
|
this: *const FixedArray,
|
|
context: *const Context,
|
|
index: int,
|
|
) -> *const Data;
|
|
}
|
|
|
|
impl FixedArray {
|
|
#[inline(always)]
|
|
pub fn length(&self) -> usize {
|
|
unsafe { v8__FixedArray__Length(self) as usize }
|
|
}
|
|
|
|
#[inline(always)]
|
|
pub fn get<'s>(
|
|
&self,
|
|
scope: &mut HandleScope<'s>,
|
|
index: usize,
|
|
) -> Option<Local<'s, Data>> {
|
|
if index >= self.length() {
|
|
return None;
|
|
}
|
|
|
|
unsafe {
|
|
scope.cast_local(|sd| {
|
|
v8__FixedArray__Get(self, &*sd.get_current_context(), index as int)
|
|
})
|
|
}
|
|
}
|
|
}
|