Repository navigation
buffer: add DataView support to isUtf8, isAscii, and stringLength - #67179
ShakilUrRehman21 wants to merge 1 commit into
Conversation
ECMAScript defines both TypedArray and DataView as subclasses of ArrayBufferView. While methods like `Buffer.byteLength()` accept any ArrayBufferView (including DataView), `buffer.isUtf8()`, `buffer.isAscii()`, and `Buffer.stringLength()` restricted their argument checks to `isTypedArray()` and `IsTypedArray()`, rejecting DataView with an ERR_INVALID_ARG_TYPE TypeError. The underlying C++ helper `ArrayBufferViewContents<T>` already natively supports any `v8::ArrayBufferView`. This commit updates: - `lib/buffer.js` to validate with `isArrayBufferView()` instead of `isTypedArray()`, and include 'DataView' in the ERR_INVALID_ARG_TYPE expected type list. - `src/node_buffer.cc` to check `IsArrayBufferView()` instead of `IsTypedArray()`. - `doc/api/buffer.md` to document DataView support. - Tests in `test-buffer-isutf8.js`, `test-buffer-isascii.js`, and `test-buffer-stringlength.js` to cover DataView instances. Signed-off-by: shakilurrehman21 <rehmanshakil21@gmail.com>
|
Welcome to Node.js, and thank you for your first contribution! Before review, please take a moment to read:
Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal. |
|
The recommendations in: advise you should tackle only one issue at a time and that you should not open any new PRs until your first PR has been approved. You already have unapproved PR #67178 open at this time which you opened just before this PR. Until the first PR has been approved and has landed in the Waiting until the first PR has landed ensures that you as a contributor have experienced the complete process from PR submission to successful landing. After this has been completed, any new PRs or new commits to an existing PR are treated to rules for regular Contributors. GitHub Actions CI workflows are then run automatically without intervention by a team member. |
Thank you for pointing that out and for the guidance! That makes complete sense. I've converted this PR to draft for now so the team can focus on first PR. |
| static void IsUtf8(const FunctionCallbackInfo<Value>& args) { | ||
| CHECK_EQ(args.Length(), 1); | ||
| CHECK(args[0]->IsTypedArray() || args[0]->IsArrayBuffer() || | ||
| CHECK(args[0]->IsArrayBufferView() || args[0]->IsArrayBuffer() || |
There was a problem hiding this comment.
these changes require updates to typings folder as well...
Description
ECMAScript defines both
TypedArrayandDataViewas subclasses ofArrayBufferView(ArrayBuffer.isView(x)returnstruefor both).While other buffer methods like
Buffer.byteLength()accept anyArrayBufferView(includingDataView),buffer.isUtf8(),buffer.isAscii(), andBuffer.stringLength()restricted their argument validation toisTypedArray()andIsTypedArray(). Passing aDataViewthrewTypeError [ERR_INVALID_ARG_TYPE].The underlying C++ helper
ArrayBufferViewContents<T>insrc/util-inl.halready natively supportsv8::ArrayBufferView(includingDataView).This PR:
lib/buffer.jsto validate withisArrayBufferView()instead ofisTypedArray(), and includes'DataView'in theERR_INVALID_ARG_TYPEexpected types.src/node_buffer.ccto checkIsArrayBufferView()instead ofIsTypedArray().doc/api/buffer.mdto documentDataViewsupport.DataViewintest-buffer-isutf8.js,test-buffer-isascii.js, andtest-buffer-stringlength.js.Refs: #64503
Refs: #64504
Refs: #66064
Checklist
testpasses