lib,test: do not hardcode Buffer.kMaxLength

V8 will soon support typed arrays as large as the maximum array buffer
length. This patch replaces hardcoded values related to
Buffer.kMaxLength with the actual constant.
It also fixes a test that was passing by accident.

Refs: 44b2995900
PR-URL: https://github.com/nodejs/node/pull/49876
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
This commit is contained in:
Michaël Zasso 2023-09-28 14:50:20 +02:00 committed by GitHub
parent cc725a653a
commit a4fdb1abe0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 25 deletions

View file

@ -24,6 +24,9 @@ const {
concat,
getDataObject,
} = internalBinding('blob');
const {
kMaxLength,
} = internalBinding('buffer');
const {
TextDecoder,
@ -62,7 +65,6 @@ const {
} = require('internal/errors');
const {
isUint32,
validateDictionary,
} = require('internal/validators');
@ -160,8 +162,8 @@ class Blob {
return src;
});
if (!isUint32(length))
throw new ERR_BUFFER_TOO_LARGE(0xFFFFFFFF);
if (length > kMaxLength)
throw new ERR_BUFFER_TOO_LARGE(kMaxLength);
this[kHandle] = _createBlob(sources_, length);
this[kLength] = length;