node-fallbacks:buffer: fix numberIsNaN ReferenceError (#21527)

fixes https://github.com/oven-sh/bun/issues/21522
This commit is contained in:
Meghan Denny
2025-07-31 21:07:17 -08:00
committed by GitHub
parent 8efe7945eb
commit 2a6d018d73
2 changed files with 20 additions and 3 deletions

View File

@@ -357,7 +357,7 @@ function fromObject(obj) {
}
if (obj.length !== undefined) {
if (typeof obj.length !== "number" || numberIsNaN(obj.length)) {
if (typeof obj.length !== "number" || Number.isNaN(obj.length)) {
return createBuffer(0);
}
return fromArrayLike(obj);
@@ -659,7 +659,7 @@ Buffer.prototype.equals = function equals(b) {
Buffer.prototype.inspect = function inspect() {
let str = "";
const max = exports.INSPECT_MAX_BYTES;
const max = INSPECT_MAX_BYTES;
str = this.toString("hex", 0, max)
.replace(/(.{2})/g, "$1 ")
.trim();
@@ -886,7 +886,7 @@ function hexWrite(buf, string, offset, length) {
let i;
for (i = 0; i < length; ++i) {
const parsed = parseInt(string.substr(i * 2, 2), 16);
if (numberIsNaN(parsed)) return i;
if (Number.isNaN(parsed)) return i;
buf[offset + i] = parsed;
}
return i;

View File

@@ -41,6 +41,23 @@ describe("bundler", () => {
"zlib": "polyfill",
};
itBundled("browser/NodeBuffer#21522", {
files: {
"/entry.js": /* js */ `
import { Buffer } from "node:buffer";
const x = Buffer.alloc(5);
x.write("68656c6c6f", "hex");
console.log(x);
`,
},
target: "browser",
run: {
stdout: "<Buffer 68 65 6c 6c 6f>",
},
onAfterBundle(api) {
api.expectFile("out.js").not.toInclude("import ");
},
});
itBundled("browser/NodeBuffer#12272", {
files: {
"/entry.js": /* js */ `