The V8 string size limit
import NodeBuffer from "node:buffer";
Represents the largest length that a string
primitive can have, counted in UTF-16 code units.
这一数值可能取决于正在使用的联合材料发动机。
对<条码>载条码>施加的限制并不涉及星数。 它的0-x1FFFE8(229-24)UTF-16单位,载于我的Node.js 20.1.0。
Node.js使用V8发动机。 A Javascript string composed of 2-octet (uint16_t
) UTF-16代码单位,以及在V8发动机中,这种装置的最大数量(string.length
) 是
- (2²⁸-16) (0x0FFFFFF0 UTF-16 code units / about 0.5 GiB) on a 32-bit system
- and (2²⁹-24) (0x1FFFFFE8 UTF-16 code units / about 1 GiB) on a 64-bit system.
const constants = ObjectDefineProperties({}, {
MAX_LENGTH: {
__proto__: null,
value: kMaxLength,
writable: false,
enumerable: true,
},
MAX_STRING_LENGTH: {
__proto__: null,
value: kStringMaxLength,
writable: false,
enumerable: true,
},
});
target
->Set(context,
FIXED_ONE_BYTE_STRING(isolate, "kStringMaxLength"),
Integer::New(isolate, String::kMaxLength))
.Check();
/**
* A JavaScript string value (ECMA-262, 4.3.17).
*/
class V8_EXPORT String : public Name {
public:
static constexpr int kMaxLength =
internal::kApiSystemPointerSize == 4 ? (1 << 28) - 16 : (1 << 29) - 24;
/**
* Configuration of tagging scheme.
*/
const int kApiSystemPointerSize = sizeof(void*);