mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
node-fallbacks:buffer: fix numberIsNaN ReferenceError (#21527)
fixes https://github.com/oven-sh/bun/issues/21522
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 */ `
|
||||
|
||||
Reference in New Issue
Block a user