Skip to main content

v8/
fixed_array.rs

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