diff options
author | 2023-07-02 08:01:52 +0800 | |
---|---|---|
committer | 2023-07-01 17:01:52 -0700 | |
commit | 4720fa1207d374a2447d457ad478f9f8911b959a (patch) | |
tree | e8268b3c91ea992842682afd94f32747668a136f /src/js | |
parent | df10252979aa3d87a8d127707a23678b76a15583 (diff) | |
download | bun-4720fa1207d374a2447d457ad478f9f8911b959a.tar.gz bun-4720fa1207d374a2447d457ad478f9f8911b959a.tar.zst bun-4720fa1207d374a2447d457ad478f9f8911b959a.zip |
[WIP]Fix calling `Buffer.toString` with `(offset, length, encoding)` (#3467)
* Allow `toString` to be called with `(offset, length, encoding)`.
Close: #3085
* handle undefined value
* add tests for buffer.xxxSlice
* fix parameters
* fix offset and length
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/builtins/JSBufferPrototype.ts | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/js/builtins/JSBufferPrototype.ts b/src/js/builtins/JSBufferPrototype.ts index 97b25b9b2..f5d6a7bfb 100644 --- a/src/js/builtins/JSBufferPrototype.ts +++ b/src/js/builtins/JSBufferPrototype.ts @@ -427,29 +427,29 @@ export function hexWrite(this: BufferExt, text, offset, length) { return this.write(text, offset, length, "hex"); } -export function utf8Slice(this: BufferExt, offset, length) { - return this.toString(offset, length, "utf8"); +export function utf8Slice(this: BufferExt, start, end) { + return this.toString("utf8", start, end); } -export function ucs2Slice(this: BufferExt, offset, length) { - return this.toString(offset, length, "ucs2"); +export function ucs2Slice(this: BufferExt, start, end) { + return this.toString("ucs2", start, end); } -export function utf16leSlice(this: BufferExt, offset, length) { - return this.toString(offset, length, "utf16le"); +export function utf16leSlice(this: BufferExt, start, end) { + return this.toString("utf16le", start, end); } -export function latin1Slice(this: BufferExt, offset, length) { - return this.toString(offset, length, "latin1"); +export function latin1Slice(this: BufferExt, start, end) { + return this.toString("latin1", start, end); } -export function asciiSlice(this: BufferExt, offset, length) { - return this.toString(offset, length, "ascii"); +export function asciiSlice(this: BufferExt, start, end) { + return this.toString("ascii", start, end); } -export function base64Slice(this: BufferExt, offset, length) { - return this.toString(offset, length, "base64"); +export function base64Slice(this: BufferExt, start, end) { + return this.toString("base64", start, end); } -export function base64urlSlice(this: BufferExt, offset, length) { - return this.toString(offset, length, "base64url"); +export function base64urlSlice(this: BufferExt, start, end) { + return this.toString("base64url", start, end); } -export function hexSlice(this: BufferExt, offset, length) { - return this.toString(offset, length, "hex"); +export function hexSlice(this: BufferExt, start, end) { + return this.toString("hex", start, end); } export function toJSON(this: BufferExt) { |