|
1 | 1 | # ArrayBuffer
|
2 | 2 |
|
3 |
| -The `ArrayBuffer` class corresponds to the |
| 3 | +The `Napi::ArrayBuffer` class corresponds to the |
4 | 4 | [JavaScript `ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
|
5 | 5 | class.
|
6 | 6 |
|
7 | 7 | ## Methods
|
8 | 8 |
|
9 | 9 | ### New
|
10 | 10 |
|
11 |
| -Allocates a new `ArrayBuffer` instance with a given length. |
| 11 | +Allocates a new `Napi::ArrayBuffer` instance with a given length. |
12 | 12 |
|
13 | 13 | ```cpp
|
14 |
| -static ArrayBuffer New(napi_env env, size_t byteLength); |
| 14 | +static Napi::ArrayBuffer Napi::ArrayBuffer::New(napi_env env, size_t byteLength); |
15 | 15 | ```
|
16 | 16 |
|
17 |
| -- `[in] env`: The environment in which to create the `ArrayBuffer` instance. |
| 17 | +- `[in] env`: The environment in which to create the `Napi::ArrayBuffer` instance. |
18 | 18 | - `[in] byteLength`: The length to be allocated, in bytes.
|
19 | 19 |
|
20 |
| -Returns a new `ArrayBuffer` instance. |
| 20 | +Returns a new `Napi::ArrayBuffer` instance. |
21 | 21 |
|
22 | 22 | ### New
|
23 | 23 |
|
24 |
| -Wraps the provided external data into a new `ArrayBuffer` instance. |
| 24 | +Wraps the provided external data into a new `Napi::ArrayBuffer` instance. |
25 | 25 |
|
26 |
| -The `ArrayBuffer` instance does not assume ownership for the data and expects it |
27 |
| -to be valid for the lifetime of the instance. Since the `ArrayBuffer` is subject |
28 |
| -to garbage collection this overload is only suitable for data which is static |
29 |
| -and never needs to be freed. |
| 26 | +The `Napi::ArrayBuffer` instance does not assume ownership for the data and |
| 27 | +expects it to be valid for the lifetime of the instance. Since the |
| 28 | +`Napi::ArrayBuffer` is subject to garbage collection this overload is only |
| 29 | +suitable for data which is static and never needs to be freed. |
30 | 30 |
|
31 | 31 | ```cpp
|
32 |
| -static ArrayBuffer New(napi_env env, void* externalData, size_t byteLength); |
| 32 | +static Napi::ArrayBuffer Napi::ArrayBuffer::New(napi_env env, void* externalData, size_t byteLength); |
33 | 33 | ```
|
34 | 34 |
|
35 |
| -- `[in] env`: The environment in which to create the `ArrayBuffer` instance. |
| 35 | +- `[in] env`: The environment in which to create the `Napi::ArrayBuffer` instance. |
36 | 36 | - `[in] externalData`: The pointer to the external data to wrap.
|
37 | 37 | - `[in] byteLength`: The length of the `externalData`, in bytes.
|
38 | 38 |
|
39 |
| -Returns a new `ArrayBuffer` instance. |
| 39 | +Returns a new `Napi::ArrayBuffer` instance. |
40 | 40 |
|
41 | 41 | ### New
|
42 | 42 |
|
43 |
| -Wraps the provided external data into a new `ArrayBuffer` instance. |
| 43 | +Wraps the provided external data into a new `Napi::ArrayBuffer` instance. |
44 | 44 |
|
45 |
| -The `ArrayBuffer` instance does not assume ownership for the data and expects it |
46 |
| -to be valid for the lifetime of the instance. The data can only be freed once |
47 |
| -the `finalizeCallback` is invoked to indicate that the `ArrayBuffer` has been |
48 |
| -released. |
| 45 | +The `Napi::ArrayBuffer` instance does not assume ownership for the data and |
| 46 | +expects it to be valid for the lifetime of the instance. The data can only be |
| 47 | +freed once the `finalizeCallback` is invoked to indicate that the |
| 48 | +`Napi::ArrayBuffer` has been released. |
49 | 49 |
|
50 | 50 | ```cpp
|
51 | 51 | template <typename Finalizer>
|
52 |
| -static ArrayBuffer New(napi_env env, |
| 52 | +static Napi::ArrayBuffer Napi::ArrayBuffer::New(napi_env env, |
53 | 53 | void* externalData,
|
54 | 54 | size_t byteLength,
|
55 | 55 | Finalizer finalizeCallback);
|
56 | 56 | ```
|
57 | 57 |
|
58 |
| -- `[in] env`: The environment in which to create the `ArrayBuffer` instance. |
| 58 | +- `[in] env`: The environment in which to create the `Napi::ArrayBuffer` instance. |
59 | 59 | - `[in] externalData`: The pointer to the external data to wrap.
|
60 | 60 | - `[in] byteLength`: The length of the `externalData`, in bytes.
|
61 |
| -- `[in] finalizeCallback`: A function to be called when the `ArrayBuffer` is |
| 61 | +- `[in] finalizeCallback`: A function to be called when the `Napi::ArrayBuffer` is |
62 | 62 | destroyed. It must implement `operator()`, accept a `void*` (which is the
|
63 | 63 | `externalData` pointer), and return `void`.
|
64 | 64 |
|
65 |
| -Returns a new `ArrayBuffer` instance. |
| 65 | +Returns a new `Napi::ArrayBuffer` instance. |
66 | 66 |
|
67 | 67 | ### New
|
68 | 68 |
|
69 |
| -Wraps the provided external data into a new `ArrayBuffer` instance. |
| 69 | +Wraps the provided external data into a new `Napi::ArrayBuffer` instance. |
70 | 70 |
|
71 |
| -The `ArrayBuffer` instance does not assume ownership for the data and expects it |
| 71 | +The `Napi::ArrayBuffer` instance does not assume ownership for the data and expects it |
72 | 72 | to be valid for the lifetime of the instance. The data can only be freed once
|
73 |
| -the `finalizeCallback` is invoked to indicate that the `ArrayBuffer` has been |
| 73 | +the `finalizeCallback` is invoked to indicate that the `Napi::ArrayBuffer` has been |
74 | 74 | released.
|
75 | 75 |
|
76 | 76 | ```cpp
|
77 | 77 | template <typename Finalizer, typename Hint>
|
78 |
| -static ArrayBuffer New(napi_env env, |
| 78 | +static Napi::ArrayBuffer Napi::ArrayBuffer::New(napi_env env, |
79 | 79 | void* externalData,
|
80 | 80 | size_t byteLength,
|
81 | 81 | Finalizer finalizeCallback,
|
82 | 82 | Hint* finalizeHint);
|
83 | 83 | ```
|
84 | 84 |
|
85 |
| -- `[in] env`: The environment in which to create the `ArrayBuffer` instance. |
| 85 | +- `[in] env`: The environment in which to create the `Napi::ArrayBuffer` instance. |
86 | 86 | - `[in] externalData`: The pointer to the external data to wrap.
|
87 | 87 | - `[in] byteLength`: The length of the `externalData`, in bytes.
|
88 |
| -- `[in] finalizeCallback`: The function to be called when the `ArrayBuffer` is |
| 88 | +- `[in] finalizeCallback`: The function to be called when the `Napi::ArrayBuffer` is |
89 | 89 | destroyed. It must implement `operator()`, accept a `void*` (which is the
|
90 | 90 | `externalData` pointer) and `Hint*`, and return `void`.
|
91 | 91 | - `[in] finalizeHint`: The hint to be passed as the second parameter of the
|
92 | 92 | finalize callback.
|
93 | 93 |
|
94 |
| -Returns a new `ArrayBuffer` instance. |
| 94 | +Returns a new `Napi::ArrayBuffer` instance. |
95 | 95 |
|
96 | 96 | ### Constructor
|
97 | 97 |
|
98 |
| -Initializes an empty instance of the `ArrayBuffer` class. |
| 98 | +Initializes an empty instance of the `Napi::ArrayBuffer` class. |
99 | 99 |
|
100 | 100 | ```cpp
|
101 |
| -ArrayBuffer(); |
| 101 | +Napi::ArrayBuffer::ArrayBuffer(); |
102 | 102 | ```
|
103 | 103 |
|
104 | 104 | ### Constructor
|
105 | 105 |
|
106 |
| -Initializes a wrapper instance of an existing `ArrayBuffer` object. |
| 106 | +Initializes a wrapper instance of an existing `Napi::ArrayBuffer` object. |
107 | 107 |
|
108 | 108 | ```cpp
|
109 |
| -ArrayBuffer(napi_env env, napi_value value); |
| 109 | +Napi::ArrayBuffer::ArrayBuffer(napi_env env, napi_value value); |
110 | 110 | ```
|
111 | 111 |
|
112 |
| -- `[in] env`: The environment in which to create the `ArrayBuffer` instance. |
113 |
| -- `[in] value`: The `ArrayBuffer` reference to wrap. |
| 112 | +- `[in] env`: The environment in which to create the `Napi::ArrayBuffer` instance. |
| 113 | +- `[in] value`: The `Napi::ArrayBuffer` reference to wrap. |
114 | 114 |
|
115 | 115 | ### ByteLength
|
116 | 116 |
|
117 | 117 | ```cpp
|
118 |
| -size_t ByteLength() const; |
| 118 | +size_t Napi::ArrayBuffer::ByteLength() const; |
119 | 119 | ```
|
120 | 120 |
|
121 | 121 | Returns the length of the wrapped data, in bytes.
|
122 | 122 |
|
123 | 123 | ### Data
|
124 | 124 |
|
125 | 125 | ```cpp
|
126 |
| -T* Data() const; |
| 126 | +T* Napi::ArrayBuffer::Data() const; |
127 | 127 | ```
|
128 | 128 |
|
129 | 129 | Returns a pointer the wrapped data.
|
0 commit comments