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] lengthDataView 中的元素数。

    ¥[in] length: Number of elements in the DataView.

  • [in] arraybufferArrayBufferDataView 的基础。

    ¥[in] arraybuffer: ArrayBuffer underlying the DataView.

  • [in] byte_offsetArrayBuffer 中开始投影 DataView 的字节偏移量。

    ¥[in] byte_offset: The byte offset within the ArrayBuffer from which to start projecting the DataView.

  • [out] result:代表 JavaScript DataViewnapi_value

    ¥[out] result: A napi_value representing a 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 语言规范的 第 24.3 节 中进行了描述。

¥JavaScript DataView objects are described in Section 24.3 of the ECMAScript Language Specification.