1use crate::ArrayBuffer;
3use crate::HandleScope;
4use crate::Local;
5
6macro_rules! typed_array {
7 ($name:ident, $func:ident) => {
8 use crate::$name;
9 impl $name {
10 pub fn new<'s>(
11 scope: &mut HandleScope<'s>,
12 buf: Local<ArrayBuffer>,
13 byte_offset: usize,
14 length: usize,
15 ) -> Option<Local<'s, $name>> {
16 extern "C" {
17 fn $func(
18 buf_ptr: *const ArrayBuffer,
19 byte_offset: usize,
20 length: usize,
21 ) -> *const $name;
22 }
23 unsafe { scope.cast_local(|_| $func(&*buf, byte_offset, length)) }
24 }
25 }
26 };
27}
28
29typed_array!(Uint8Array, v8__Uint8Array__New);
30typed_array!(Uint8ClampedArray, v8__Uint8ClampedArray__New);
31typed_array!(Int8Array, v8__Int8Array__New);
32typed_array!(Uint16Array, v8__Uint16Array__New);
33typed_array!(Int16Array, v8__Int16Array__New);
34typed_array!(Uint32Array, v8__Uint32Array__New);
35typed_array!(Int32Array, v8__Int32Array__New);
36typed_array!(Float32Array, v8__Float32Array__New);
37typed_array!(Float64Array, v8__Float64Array__New);
38typed_array!(BigUint64Array, v8__BigUint64Array__New);
39typed_array!(BigInt64Array, v8__BigInt64Array__New);