diff options
author | 2023-01-27 22:55:46 -0800 | |
---|---|---|
committer | 2023-01-27 22:55:46 -0800 | |
commit | aff91436c0998b0368f0970fa0da42afa09640fc (patch) | |
tree | 5b906088b4143c4c4963454246181fb1bf0728d5 /src/bun.js/builtins/js | |
parent | 80751586390cd0c73fab9b5ff2e9d48b7df54719 (diff) | |
download | bun-aff91436c0998b0368f0970fa0da42afa09640fc.tar.gz bun-aff91436c0998b0368f0970fa0da42afa09640fc.tar.zst bun-aff91436c0998b0368f0970fa0da42afa09640fc.zip |
`Buffer.from` doesn't need to be the Buffer constructor
Diffstat (limited to 'src/bun.js/builtins/js')
-rw-r--r-- | src/bun.js/builtins/js/JSBufferConstructor.js | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/bun.js/builtins/js/JSBufferConstructor.js b/src/bun.js/builtins/js/JSBufferConstructor.js index 10994394e..eecd52568 100644 --- a/src/bun.js/builtins/js/JSBufferConstructor.js +++ b/src/bun.js/builtins/js/JSBufferConstructor.js @@ -28,9 +28,6 @@ function from(items) { "use strict"; - if (!@isConstructor(this)) - @throwTypeError("Buffer.from requires |this| to be a constructor"); - if (@isUndefinedOrNull(items)) { @throwTypeError( "The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object.", @@ -49,13 +46,13 @@ function from(items) { ) { switch (@argumentCount()) { case 1: { - return new this(items); + return new @Buffer(items); } case 2: { - return new this(items, @argument(1)); + return new @Buffer(items, @argument(1)); } default: { - return new this(items, @argument(1), @argument(2)); + return new @Buffer(items, @argument(1), @argument(2)); } } } @@ -74,13 +71,13 @@ function from(items) { if (typeof primitive === "string") { switch (@argumentCount()) { case 1: { - return new this(primitive); + return new @Buffer(primitive); } case 2: { - return new this(primitive, @argument(1)); + return new @Buffer(primitive, @argument(1)); } default: { - return new this(primitive, @argument(1), @argument(2)); + return new @Buffer(primitive, @argument(1), @argument(2)); } } } @@ -96,5 +93,5 @@ function from(items) { // Don't pass the second argument because Node's Buffer.from doesn't accept // a function and Uint8Array.from requires it if it exists // That means we cannot use @tailCallFowrardArguments here, sadly - return new this(@Uint8Array.from(arrayLike).buffer); + return new @Buffer(@Uint8Array.from(arrayLike).buffer); } |