Commit 19fee8b2 authored by Jeremy Roman's avatar Jeremy Roman Committed by Commit Bot

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/594677Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47099}
parent 74edfccd
......@@ -4492,6 +4492,12 @@ class V8_EXPORT ArrayBufferView : public Object {
*/
class V8_EXPORT TypedArray : public ArrayBufferView {
public:
/*
* The largest typed array size that can be constructed using New.
*/
static constexpr size_t kMaxLength =
sizeof(void*) == 4 ? (1u << 30) - 1 : (1u << 31) - 1;
/**
* Number of elements in this typed array
* (e.g. for Int16Array, |ByteLength|/2).
......
......@@ -8041,13 +8041,16 @@ size_t v8::TypedArray::Length() {
return static_cast<size_t>(obj->length_value());
}
static_assert(v8::TypedArray::kMaxLength == i::Smi::kMaxValue,
"v8::TypedArray::kMaxLength must match i::Smi::kMaxValue");
#define TYPED_ARRAY_NEW(Type, type, TYPE, ctype, size) \
Local<Type##Array> Type##Array::New(Local<ArrayBuffer> array_buffer, \
size_t byte_offset, size_t length) { \
i::Isolate* isolate = Utils::OpenHandle(*array_buffer)->GetIsolate(); \
LOG_API(isolate, Type##Array, New); \
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); \
if (!Utils::ApiCheck(length <= static_cast<size_t>(i::Smi::kMaxValue), \
if (!Utils::ApiCheck(length <= kMaxLength, \
"v8::" #Type \
"Array::New(Local<ArrayBuffer>, size_t, size_t)", \
"length exceeds max allowed value")) { \
......@@ -8067,7 +8070,7 @@ size_t v8::TypedArray::Length() {
LOG_API(isolate, Type##Array, New); \
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); \
if (!Utils::ApiCheck( \
length <= static_cast<size_t>(i::Smi::kMaxValue), \
length <= kMaxLength, \
"v8::" #Type \
"Array::New(Local<SharedArrayBuffer>, size_t, size_t)", \
"length exceeds max allowed value")) { \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment