Skip to main content

v8/
fixed_array.rs

1// Copyright 2019-2021 the Deno authors. All rights reserved. MIT license.
2
3use crate::Data;
4use crate::FixedArray;
5use crate::Local;
6use crate::scope::PinScope;
7use crate::support::int;
8
9unsafe extern "C" {
10  fn v8__FixedArray__Length(this: *const FixedArray) -> int;
11
12  fn v8__FixedArray__Get(this: *const FixedArray, index: int) -> *const Data;
13}
14
15impl FixedArray {
16  #[inline(always)]
17  pub fn length(&self) -> usize {
18    unsafe { v8__FixedArray__Length(self) as usize }
19  }
20
21  #[inline(always)]
22  pub fn get<'s>(
23    &self,
24    scope: &PinScope<'s, '_>,
25    index: usize,
26  ) -> Option<Local<'s, Data>> {
27    if index >= self.length() {
28      return None;
29    }
30
31    unsafe { scope.cast_local(|_| v8__FixedArray__Get(self, index as int)) }
32  }
33}