diff --git a/src/bun.js/bindings/JSBuffer.cpp b/src/bun.js/bindings/JSBuffer.cpp index 7b70709dbb..229e6ad0fe 100644 --- a/src/bun.js/bindings/JSBuffer.cpp +++ b/src/bun.js/bindings/JSBuffer.cpp @@ -2292,7 +2292,7 @@ JSC_DEFINE_HOST_FUNCTION(constructJSBuffer, (JSC::JSGlobalObject * lexicalGlobal return {}; } return JSBuffer__bufferFromLength(lexicalGlobalObject, length); - } else if (distinguishingArg.isUndefinedOrNull()) { + } else if (distinguishingArg.isUndefinedOrNull() || distinguishingArg.isBoolean()) { auto arg_string = distinguishingArg.toWTFString(globalObject); auto message = makeString("The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received "_s, arg_string); throwTypeError(lexicalGlobalObject, throwScope, message); diff --git a/test/js/node/buffer.test.js b/test/js/node/buffer.test.js index fcc555145c..9bf3384eb6 100644 --- a/test/js/node/buffer.test.js +++ b/test/js/node/buffer.test.js @@ -2758,7 +2758,7 @@ it("new Buffer.from()", () => { describe("fuzzing constructors with new", () => { const zeroArray = new Uint32Array(10).fill(0); - const sizes = [1e20, 0, 0.1, -1, "a", undefined, null, NaN, 5n, Symbol("xyz")]; + const sizes = [1e20, 0, 0.1, -1, "a", undefined, null, NaN, 5n, Symbol("xyz"), true, () => {}, {}]; const allocators = [Buffer, SlowBuffer, Buffer.alloc, Buffer.allocUnsafe, Buffer.allocUnsafeSlow]; for (const allocator of allocators) { for (const size of sizes) { @@ -2776,7 +2776,7 @@ describe("fuzzing constructors with new", () => { describe("fuzzing constructors with call", () => { const zeroArray = new Uint32Array(10).fill(0); - const sizes = [1e20, 0, 0.1, -1, "a", undefined, null, NaN, 5n, Symbol("xyz")]; + const sizes = [1e20, 0, 0.1, -1, "a", undefined, null, NaN, 5n, Symbol("xyz"), true, () => {}, {}]; const allocators = [Buffer, SlowBuffer, Buffer.alloc, Buffer.allocUnsafe, Buffer.allocUnsafeSlow]; for (const allocator of allocators) { for (const size of sizes) {