napi_create_typedarray
napi_status napi_create_typedarray(napi_env env,
napi_typedarray_type type,
size_t length,
napi_value arraybuffer,
size_t byte_offset,
napi_value* result)
-
[in] env
:调用 API 的环境。¥
[in] env
: The environment that the API is invoked under. -
[in] type
:TypedArray
中元素的标量数据类型。¥
[in] type
: Scalar datatype of the elements within theTypedArray
. -
[in] length
:TypedArray
中的元素数。¥
[in] length
: Number of elements in theTypedArray
. -
[in] arraybuffer
:ArrayBuffer
是类型化数组的基础。¥
[in] arraybuffer
:ArrayBuffer
underlying the typed array. -
[in] byte_offset
:ArrayBuffer
中开始投影TypedArray
的字节偏移量。¥
[in] byte_offset
: The byte offset within theArrayBuffer
from which to start projecting theTypedArray
. -
[out] result
:代表 JavaScriptTypedArray
的napi_value
。¥
[out] result
: Anapi_value
representing a JavaScriptTypedArray
.
如果 API 成功,则返回 napi_ok
。
¥Returns napi_ok
if the API succeeded.
此 API 在现有的 ArrayBuffer
上创建一个 JavaScript TypedArray
对象。TypedArray
对象在底层数据缓冲区上提供类似数组的视图,其中每个元素都具有相同的底层二进制标量数据类型。
¥This API creates a JavaScript TypedArray
object over an existing
ArrayBuffer
. TypedArray
objects provide an array-like view over an
underlying data buffer where each element has the same underlying binary scalar
datatype.
要求 (length * size_of_element) + byte_offset
应该 <= 传入数组的大小(以字节为单位)。如果不是,则引发 RangeError
异常。
¥It's required that (length * size_of_element) + byte_offset
should
be <= the size in bytes of the array passed in. If not, a RangeError
exception
is raised.
JavaScript TypedArray
对象在 ECMAScript 语言规范的 第 22.2 节 中进行了描述。
¥JavaScript TypedArray
objects are described in
Section 22.2 of the ECMAScript Language Specification.