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] length:DataView中的元素数量。[in] arraybuffer:DataView所基于的ArrayBuffer。[in] byte_offset:ArrayBuffer内用于开始映射DataView的字节偏移量。[out] result:一个napi_value,表示 JavaScript 的DataView。
如果 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 语言规范的 部分 数据视图对象 中有描述。
【JavaScript DataView objects are described in
Section DataView objects of the ECMAScript Language Specification.】