aboutsummaryrefslogtreecommitdiff
path: root/deps/v8/src/objects/js-array-buffer.h
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/objects/js-array-buffer.h')
-rw-r--r--deps/v8/src/objects/js-array-buffer.h106
1 files changed, 54 insertions, 52 deletions
diff --git a/deps/v8/src/objects/js-array-buffer.h b/deps/v8/src/objects/js-array-buffer.h
index 109aacbc47..3f0dd064fa 100644
--- a/deps/v8/src/objects/js-array-buffer.h
+++ b/deps/v8/src/objects/js-array-buffer.h
@@ -5,7 +5,7 @@
#ifndef V8_OBJECTS_JS_ARRAY_BUFFER_H_
#define V8_OBJECTS_JS_ARRAY_BUFFER_H_
-#include "src/objects.h"
+#include "src/objects/js-objects.h"
// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"
@@ -14,12 +14,22 @@ namespace v8 {
namespace internal {
// Whether a JSArrayBuffer is a SharedArrayBuffer or not.
-enum class SharedFlag { kNotShared, kShared };
+enum class SharedFlag : uint32_t { kNotShared, kShared };
class JSArrayBuffer : public JSObject {
public:
+// The maximum length for JSArrayBuffer's supported by V8.
+// On 32-bit architectures we limit this to 2GiB, so that
+// we can continue to use CheckBounds with the Unsigned31
+// restriction for the length.
+#if V8_HOST_ARCH_32_BIT
+ static constexpr size_t kMaxByteLength = kMaxInt;
+#else
+ static constexpr size_t kMaxByteLength = kMaxSafeInteger;
+#endif
+
// [byte_length]: length in bytes
- DECL_ACCESSORS(byte_length, Object)
+ DECL_PRIMITIVE_ACCESSORS(byte_length, size_t)
// [backing_store]: backing memory for this array
DECL_ACCESSORS(backing_store, void)
@@ -29,26 +39,39 @@ class JSArrayBuffer : public JSObject {
inline size_t allocation_length() const;
inline void* allocation_base() const;
- inline uint32_t bit_field() const;
- inline void set_bit_field(uint32_t bits);
+ // [bit_field]: boolean flags
+ DECL_PRIMITIVE_ACCESSORS(bit_field, uint32_t)
+
+// Bit positions for [bit_field].
+#define JS_ARRAY_BUFFER_BIT_FIELD_FIELDS(V, _) \
+ V(IsExternalBit, bool, 1, _) \
+ V(IsNeuterableBit, bool, 1, _) \
+ V(WasNeuteredBit, bool, 1, _) \
+ V(IsSharedBit, bool, 1, _) \
+ V(IsGrowableBit, bool, 1, _) \
+ V(IsWasmMemoryBit, bool, 1, _)
+ DEFINE_BIT_FIELDS(JS_ARRAY_BUFFER_BIT_FIELD_FIELDS)
+#undef JS_ARRAY_BUFFER_BIT_FIELD_FIELDS
// [is_external]: true indicates that the embedder is in charge of freeing the
// backing_store, while is_external == false means that v8 will free the
// memory block once all ArrayBuffers referencing it are collected by the GC.
- inline bool is_external();
- inline void set_is_external(bool value);
+ DECL_BOOLEAN_ACCESSORS(is_external)
+
+ // [is_neuterable]: false indicates that this buffer cannot be detached.
+ DECL_BOOLEAN_ACCESSORS(is_neuterable)
- inline bool is_neuterable();
- inline void set_is_neuterable(bool value);
+ // [was_neutered]: true if the buffer was previously detached.
+ DECL_BOOLEAN_ACCESSORS(was_neutered)
- inline bool was_neutered();
- inline void set_was_neutered(bool value);
+ // [is_shared]: tells whether this is an ArrayBuffer or a SharedArrayBuffer.
+ DECL_BOOLEAN_ACCESSORS(is_shared)
- inline bool is_shared();
- inline void set_is_shared(bool value);
+ // [is_growable]: indicates whether it's possible to grow this buffer.
+ DECL_BOOLEAN_ACCESSORS(is_growable)
- inline bool is_growable();
- inline void set_is_growable(bool value);
+ // [is_wasm_memory]: whether the buffer is tracked by the WasmMemoryTracker.
+ DECL_BOOLEAN_ACCESSORS(is_wasm_memory)
DECL_CAST(JSArrayBuffer)
@@ -68,39 +91,30 @@ class JSArrayBuffer : public JSObject {
bool is_wasm_memory;
};
- // Returns whether the buffer is tracked by the WasmMemoryTracker.
- inline bool is_wasm_memory() const;
-
- // Sets whether the buffer is tracked by the WasmMemoryTracker.
- void set_is_wasm_memory(bool is_wasm_memory);
-
- // Removes the backing store from the WasmMemoryTracker and sets
- // |is_wasm_memory| to false.
- void StopTrackingWasmMemory(Isolate* isolate);
-
void FreeBackingStoreFromMainThread();
static void FreeBackingStore(Isolate* isolate, Allocation allocation);
V8_EXPORT_PRIVATE static void Setup(
Handle<JSArrayBuffer> array_buffer, Isolate* isolate, bool is_external,
void* data, size_t allocated_length,
- SharedFlag shared = SharedFlag::kNotShared, bool is_wasm_memory = false);
+ SharedFlag shared_flag = SharedFlag::kNotShared,
+ bool is_wasm_memory = false);
// Returns false if array buffer contents could not be allocated.
// In this case, |array_buffer| will not be set up.
static bool SetupAllocatingData(
Handle<JSArrayBuffer> array_buffer, Isolate* isolate,
size_t allocated_length, bool initialize = true,
- SharedFlag shared = SharedFlag::kNotShared) V8_WARN_UNUSED_RESULT;
+ SharedFlag shared_flag = SharedFlag::kNotShared) V8_WARN_UNUSED_RESULT;
// Dispatched behavior.
DECL_PRINTER(JSArrayBuffer)
DECL_VERIFIER(JSArrayBuffer)
- static const int kByteLengthOffset = JSObject::kHeaderSize;
- // The rest of the fields are not JSObjects, so they are not iterated over in
+ // The fields are not pointers into our heap, so they are not iterated over in
// objects-body-descriptors-inl.h.
- static const int kBackingStoreOffset = kByteLengthOffset + kPointerSize;
+ static const int kByteLengthOffset = JSObject::kHeaderSize;
+ static const int kBackingStoreOffset = kByteLengthOffset + kUIntptrSize;
static const int kBitFieldSlot = kBackingStoreOffset + kPointerSize;
#if V8_TARGET_LITTLE_ENDIAN || !V8_HOST_ARCH_64_BIT
static const int kBitFieldOffset = kBitFieldSlot;
@@ -115,15 +129,6 @@ class JSArrayBuffer : public JSObject {
// Iterates all fields in the object including internal ones except
// kBackingStoreOffset and kBitFieldSlot.
class BodyDescriptor;
- // No weak fields.
- typedef BodyDescriptor BodyDescriptorWeak;
-
- class IsExternal : public BitField<bool, 1, 1> {};
- class IsNeuterable : public BitField<bool, 2, 1> {};
- class WasNeutered : public BitField<bool, 3, 1> {};
- class IsShared : public BitField<bool, 4, 1> {};
- class IsGrowable : public BitField<bool, 5, 1> {};
- class IsWasmMemory : public BitField<bool, 6, 1> {};
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(JSArrayBuffer);
@@ -135,10 +140,10 @@ class JSArrayBufferView : public JSObject {
DECL_ACCESSORS(buffer, Object)
// [byte_offset]: offset of typed array in bytes.
- DECL_ACCESSORS(byte_offset, Object)
+ DECL_PRIMITIVE_ACCESSORS(byte_offset, size_t)
// [byte_length]: length of typed array in bytes.
- DECL_ACCESSORS(byte_length, Object)
+ DECL_PRIMITIVE_ACCESSORS(byte_length, size_t)
DECL_CAST(JSArrayBufferView)
@@ -148,15 +153,14 @@ class JSArrayBufferView : public JSObject {
static const int kBufferOffset = JSObject::kHeaderSize;
static const int kByteOffsetOffset = kBufferOffset + kPointerSize;
- static const int kByteLengthOffset = kByteOffsetOffset + kPointerSize;
- static const int kViewSize = kByteLengthOffset + kPointerSize;
+ static const int kByteLengthOffset = kByteOffsetOffset + kUIntptrSize;
+ static const int kHeaderSize = kByteLengthOffset + kUIntptrSize;
- private:
-#ifdef VERIFY_HEAP
- DECL_ACCESSORS(raw_byte_offset, Object)
- DECL_ACCESSORS(raw_byte_length, Object)
-#endif
+ // Iterates all fields in the object including internal ones except
+ // kByteOffset and kByteLengthOffset.
+ class BodyDescriptor;
+ private:
DISALLOW_IMPLICIT_CONSTRUCTORS(JSArrayBufferView);
};
@@ -189,9 +193,8 @@ class JSTypedArray : public JSArrayBufferView {
DECL_PRINTER(JSTypedArray)
DECL_VERIFIER(JSTypedArray)
- static const int kLengthOffset = kViewSize;
+ static const int kLengthOffset = JSArrayBufferView::kHeaderSize;
static const int kSize = kLengthOffset + kPointerSize;
-
static const int kSizeWithEmbedderFields =
kSize + v8::ArrayBufferView::kEmbedderFieldCount * kPointerSize;
@@ -213,8 +216,7 @@ class JSDataView : public JSArrayBufferView {
DECL_PRINTER(JSDataView)
DECL_VERIFIER(JSDataView)
- static const int kSize = kViewSize;
-
+ static const int kSize = JSArrayBufferView::kHeaderSize;
static const int kSizeWithEmbedderFields =
kSize + v8::ArrayBufferView::kEmbedderFieldCount * kPointerSize;