Skip to content

Commit 19fee8b

Browse files
jeremyromanCommit Bot
authored andcommitted
Expose v8::TypedArray::kMaxLength.
There is an API check failure if values larger than i::Smi::kMaxValue are provided, but it is inconvenient for API users to know what this value is (and SIZE_MAX and INT_MAX are both incorrect). This is analogous to v8::String::kMaxLength. Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng Bug: chromium:750788 Change-Id: Ic3e0da62aeacfeb996122595232aa0ea8744517e Reviewed-on: https://chromium-review.googlesource.com/594677 Reviewed-by: Jakob Kummerow <[email protected]> Commit-Queue: Jeremy Roman <[email protected]> Cr-Commit-Position: refs/heads/master@{#47099}
1 parent 74edfcc commit 19fee8b

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

include/v8.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4492,6 +4492,12 @@ class V8_EXPORT ArrayBufferView : public Object {
44924492
*/
44934493
class V8_EXPORT TypedArray : public ArrayBufferView {
44944494
public:
4495+
/*
4496+
* The largest typed array size that can be constructed using New.
4497+
*/
4498+
static constexpr size_t kMaxLength =
4499+
sizeof(void*) == 4 ? (1u << 30) - 1 : (1u << 31) - 1;
4500+
44954501
/**
44964502
* Number of elements in this typed array
44974503
* (e.g. for Int16Array, |ByteLength|/2).

src/api.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8041,13 +8041,16 @@ size_t v8::TypedArray::Length() {
80418041
return static_cast<size_t>(obj->length_value());
80428042
}
80438043

8044+
static_assert(v8::TypedArray::kMaxLength == i::Smi::kMaxValue,
8045+
"v8::TypedArray::kMaxLength must match i::Smi::kMaxValue");
8046+
80448047
#define TYPED_ARRAY_NEW(Type, type, TYPE, ctype, size) \
80458048
Local<Type##Array> Type##Array::New(Local<ArrayBuffer> array_buffer, \
80468049
size_t byte_offset, size_t length) { \
80478050
i::Isolate* isolate = Utils::OpenHandle(*array_buffer)->GetIsolate(); \
80488051
LOG_API(isolate, Type##Array, New); \
80498052
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); \
8050-
if (!Utils::ApiCheck(length <= static_cast<size_t>(i::Smi::kMaxValue), \
8053+
if (!Utils::ApiCheck(length <= kMaxLength, \
80518054
"v8::" #Type \
80528055
"Array::New(Local<ArrayBuffer>, size_t, size_t)", \
80538056
"length exceeds max allowed value")) { \
@@ -8067,7 +8070,7 @@ size_t v8::TypedArray::Length() {
80678070
LOG_API(isolate, Type##Array, New); \
80688071
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); \
80698072
if (!Utils::ApiCheck( \
8070-
length <= static_cast<size_t>(i::Smi::kMaxValue), \
8073+
length <= kMaxLength, \
80718074
"v8::" #Type \
80728075
"Array::New(Local<SharedArrayBuffer>, size_t, size_t)", \
80738076
"length exceeds max allowed value")) { \

0 commit comments

Comments
 (0)