fix(ext/node): correct kMaxLength value of node:buffer (#29504)

This commit is contained in:
Yoshiya Hinosawa 2025-05-30 11:37:34 +09:00 committed by GitHub
parent b27f88239d
commit 4a80e1d29b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 9 deletions

View file

@ -113,7 +113,7 @@ float32Array[0] = -1; // 0xBF800000
// check this with `os.endianness()` because that is determined at compile time.
export const bigEndian = uInt8Float32Array[3] === 0;
export const kMaxLength = 2147483647;
export const kMaxLength = NumberMAX_SAFE_INTEGER;
export const kStringMaxLength = 536870888;
const MAX_UINT32 = 2 ** 32;

View file

@ -22,7 +22,6 @@
"test-assert-fail.js",
"test-assert.js",
"test-blocklist.js",
"test-buffer-alloc.js",
"test-buffer-arraybuffer.js",
"test-buffer-backing-arraybuffer.js",
"test-buffer-includes.js",

View file

@ -2,7 +2,7 @@
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 18.12.1
// Taken from Node 23.9.0
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
@ -11,13 +11,16 @@ const common = require('../common');
const assert = require('assert');
const vm = require('vm');
const SlowBuffer = require('buffer').SlowBuffer;
const {
SlowBuffer,
kMaxLength,
} = require('buffer');
// Verify the maximum Uint8Array size.
// (see https://github.com/tc39/ecma262/pull/3052).
// Verify the maximum Uint8Array size. There is no concrete limit by spec. The
// internal limits should be updated if this fails.
assert.throws(
() => new Uint8Array(2 ** 53),
{ message: 'Invalid typed array length: 9007199254740992' }
() => new Uint8Array(kMaxLength + 1),
{ message: `Invalid typed array length: ${kMaxLength + 1}` },
);
const b = Buffer.allocUnsafe(1024);
@ -1154,7 +1157,6 @@ assert.throws(() => {
// Regression test to verify that an empty ArrayBuffer does not throw.
Buffer.from(new ArrayBuffer());
// Test that ArrayBuffer from a different context is detected correctly.
const arrayBuf = vm.runInNewContext('new ArrayBuffer()');
Buffer.from(arrayBuf);