Conversation
| if (offset !== undefined || length !== undefined) { | ||
| if (offset !== undefined) { | ||
| validateInteger(offset, 'offset') | ||
| if (offset >= view.length) return createBuffer(0) | ||
| } else { | ||
| offset = 0 | ||
| } | ||
|
|
||
| let end | ||
|
|
||
| if (length !== undefined) { | ||
| validateInteger(length, 'length') | ||
| end = offset + length | ||
| } else { | ||
| end = view.length | ||
| } | ||
|
|
||
| view = view.subarray(offset, end) | ||
| } | ||
|
|
||
| view = new Uint8Array(view.buffer, view.byteOffset, view.byteLength) | ||
|
|
||
| return fromArrayView(view) |
There was a problem hiding this comment.
| if (offset !== undefined || length !== undefined) { | |
| if (offset !== undefined) { | |
| validateInteger(offset, 'offset') | |
| if (offset >= view.length) return createBuffer(0) | |
| } else { | |
| offset = 0 | |
| } | |
| let end | |
| if (length !== undefined) { | |
| validateInteger(length, 'length') | |
| end = offset + length | |
| } else { | |
| end = view.length | |
| } | |
| view = view.subarray(offset, end) | |
| } | |
| view = new Uint8Array(view.buffer, view.byteOffset, view.byteLength) | |
| return fromArrayView(view) | |
| if (offset !== undefined || length !== undefined) { | |
| if (offset !== undefined) validateInteger(offset, 'offset') | |
| if (length !== undefined) validateInteger(length, 'length') | |
| const offset_ = offset ?? 0 | |
| if (offset_ >= view.length) return createBuffer(0) | |
| const end = offset_ + (length ?? view.length) | |
| view = view.subarray(offset_, end) | |
| } | |
| view = new Uint8Array(view.buffer, view.byteOffset, view.byteLength) | |
| return fromArrayView(view) |
There was a problem hiding this comment.
Generally, a preference for flat (preferably functional) style, even if the actual number of resulting branches is the same
There was a problem hiding this comment.
This code was ported from the node.js code as faithfully as possible to ensure accurate behavior. I can change it though.
While we're on the subject: what is the minimum ES version we support? Since the ?? operator is an ES2020 feature, it would be good to have clarity on that. BigInt is also an ES2020 feature, but we include graceful degradation for the bigint methods.
| u16[0] = 0; | ||
| assert.strictEqual(b16.length, 2); | ||
| assert.strictEqual(b16[0], 255); | ||
| assert.strictEqual(b16[1], 255); |
There was a problem hiding this comment.
How are semi's here? 🤔
Shouldn't the linter break on this?
There was a problem hiding this comment.
(no changes required, we can resolve this in another pull request)
There was a problem hiding this comment.
I think it's because I pulled these directly from the node.js tests. Maybe we don't lint the node tests?
There was a problem hiding this comment.
If these are directly from the node tests, can you add an please add a reference?
(and adhere to whatever LICENSE notice may be required if this is a copy)
There was a problem hiding this comment.
Is that not already accounted for? As far as I can tell, all of the tests in test/node are ripped straight from the node.js codebase, right down to the filenames. I even recognize these ones -- I wrote them. 😊
edit: Okay, after looking, I guess it isn't accounted for. Should I add a the node.js LICENSE file inside the test/node directory, or should I concatenate the existing LICENSE file with the node.js one?
There was a problem hiding this comment.
Thanks for hunting that down @chjj, everything should be MIT, so hopefully any effort here is simply about proper attribution.
I think an inline URL would be helpful too so others can verify the tests against the upstream
Implements Buffer.copyBytesFrom.
Also fixes a bug with
ERR_INVALID_ARG_TYPE.