Conversation
Contributor
Author
|
@RedDwarfian and @dcodeIO thoughts on this pull request? |
Contributor
|
It is not clear in the Naive |
Contributor
Author
|
We might like to pull the ASCII encoding pull request first. #27 Otherwise, this is ready for review. |
jtenner
commented
Mar 13, 2020
assembly/buffer/index.ts
Outdated
| if (i32(byteOffset < 0) | i32(byteOffset > buffer.byteLength - length)) throw new RangeError(E_INDEXOUTOFRANGE); | ||
| if (length == 0) return new Buffer(0); | ||
|
|
||
| return assembleBuffer(changetype<usize>(buffer), <usize>byteOffset, <u32>length); |
Contributor
Author
There was a problem hiding this comment.
@MaxGraey should this be min(length, buffer.byteLength - byteOffset)?
jtenner
commented
Mar 13, 2020
| return assembleBuffer(changetype<usize>(buffer), 0, buffer.byteLength); | ||
| } | ||
|
|
||
| public static fromArray<T extends ArrayBufferView>(value: T, offset: i32 = 0, length: i32 = -1): Buffer { |
Contributor
Author
There was a problem hiding this comment.
@dcodeIO what is going to happen to this extends clause? Are we going to detach Array from ArrayBufferView?
jtenner
commented
Mar 13, 2020
|
|
||
| // return and retain | ||
| return changetype<Buffer>(result); | ||
| // @ts-ignore: Buffer returns on all valid branches |
Contributor
Author
There was a problem hiding this comment.
We can suppress this error by returning changetype<Buffer>(null) at the bottom here after the ERROR. What is the right way to do this?
MaxGraey
reviewed
Mar 13, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements
Buffer.from<T>(value: T)and a few other convenience functions.There are lots of obvious problems with not having the function overloads, but there are different paths we can take.
For instance, because there are no optional parameters, we must assume that the default encoding for strings is
UTF8.Things to note about this function:
String[]objects do something complicated: string -> f64 -> u8 to remain compatible with node.Stringobjects need to be converted toUTF8Bufferobjects share their view of the sameArrayBufferArrayBufferobjects are simply attached to a newBufferArrayBufferViewobjects need to convert their values tou8.