napi_create_dataview
napi_status napi_create_dataview(napi_env env,
size_t byte_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] length:DataView中的元素数。¥
[in] length: Number of elements in theDataView. -
[in] arraybuffer:ArrayBuffer是DataView的基础。¥
[in] arraybuffer:ArrayBufferunderlying theDataView. -
[in] byte_offset:ArrayBuffer中开始投影DataView的字节偏移量。¥
[in] byte_offset: The byte offset within theArrayBufferfrom which to start projecting theDataView. -
[out] result:代表 JavaScriptDataView的napi_value。¥
[out] result: Anapi_valuerepresenting a JavaScriptDataView.
如果 API 成功,则返回 napi_ok。
¥Returns napi_ok if the API succeeded.
此 API 在现有的 ArrayBuffer 上创建一个 JavaScript DataView 对象。DataView 对象在底层数据缓冲区上提供类似数组的视图,但在 ArrayBuffer 中允许不同大小和类型的项目。
¥This API creates a JavaScript DataView object over an existing ArrayBuffer.
DataView objects provide an array-like view over an underlying data buffer,
but one which allows items of different size and type in the ArrayBuffer.
要求 byte_length + byte_offset 小于或等于传入数组的字节大小。如果不是,则引发 RangeError 异常。
¥It is required that byte_length + byte_offset is less than or equal to the
size in bytes of the array passed in. If not, a RangeError exception is
raised.
JavaScript DataView 对象在 ECMAScript 语言规范的 DataView 对象部分 中进行了描述。
¥JavaScript DataView objects are described in
Section DataView objects of the ECMAScript Language Specification.