n-api: throw RangeError napi_create_typedarray()
According to the ECMA spec, we should throw a RangeError in the
following cases:
- `(length * elementSize) + offset` > the size of the array passed in
- `offset % elementSize` != `0`
In the current implementation, this check was omitted. So, the following
code will cause a crash.
```
napi_create_typedarray(env, napi_uint16_array, 2 /* length */,
buffer, 1 /* byte_offset */, &output_array);
```
This change fixes the problem and write some related tests.
Refs:
https://tc39.github.io/ecma262/#sec-typedarray-buffer-byteoffset-length
PR-URL: https://github.com/nodejs/node/pull/18037
Reviewed-By:
Colin Ihrig <cjihrig@gmail.com>
Reviewed-By:
James M Snell <jasnell@gmail.com>
Reviewed-By:
Michael Dawson <michael_dawson@ca.ibm.com>
parent
43197803
Please register or sign in to comment