1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Copyright 2019-2020 the Deno authors. All rights reserved. MIT license.
use crate::ArrayBuffer;
use crate::HandleScope;
use crate::Local;
use crate::Uint8Array;

extern "C" {
  fn v8__Uint8Array__New(
    buf_ptr: *const ArrayBuffer,
    byte_offset: usize,
    length: usize,
  ) -> *const Uint8Array;
}

impl Uint8Array {
  pub fn new<'s>(
    scope: &mut HandleScope<'s>,
    buf: Local<ArrayBuffer>,
    byte_offset: usize,
    length: usize,
  ) -> Option<Local<'s, Uint8Array>> {
    unsafe {
      scope.cast_local(|_| v8__Uint8Array__New(&*buf, byte_offset, length))
    }
  }
}