Index: include/v8.h |
diff --git a/include/v8.h b/include/v8.h |
index f41b6697404eb35f63bc79dbb0fab54185f87910..8a533dc90cdec8fa2e2243696c1950976710274b 100644 |
--- a/include/v8.h |
+++ b/include/v8.h |
@@ -3685,6 +3685,307 @@ class V8_EXPORT DataView : public ArrayBufferView { |
/** |
+ * TODO(binji): document |
+ * An instance of the built-in SharedArrayBuffer constructor (ES6 draft |
+ * 15.13.5). |
+ * This API is experimental and may change significantly. |
+ */ |
+class V8_EXPORT SharedArrayBuffer : public Object { |
+ public: |
+ /** |
+ * Allocator that V8 uses to allocate |SharedArrayBuffer|'s memory. The |
+ * allocator is a global V8 setting. It should be set with |
+ * V8::SetSharedArrayBufferAllocator prior to creation of a first |
+ * SharedArrayBuffer. |
+ * |
+ * This API is experimental and may change significantly. |
+ */ |
+ class V8_EXPORT Allocator { // NOLINT |
+ public: |
+ virtual ~Allocator() {} |
+ |
+ /** |
+ * Allocate |length| bytes. Return NULL if allocation is not successful. |
+ * Memory should be initialized to zeroes. |
+ */ |
+ virtual void* Allocate(size_t length) = 0; |
+ |
+ /** |
+ * Allocate |length| bytes. Return NULL if allocation is not successful. |
+ * Memory does not have to be initialized. |
+ */ |
+ virtual void* AllocateUninitialized(size_t length) = 0; |
+ /** |
+ * Free the memory block of size |length|, pointed to by |data|. |
+ * That memory is guaranteed to be previously allocated by |Allocate|. |
+ */ |
+ virtual void Free(void* data, size_t length) = 0; |
+ }; |
+ |
+ /** |
+ * The contents of an |SharedArrayBuffer|. Externalization of |
+ * |SharedArrayBuffer| returns an instance of this class, populated, with a |
+ * pointer to data and byte length. |
+ * |
+ * The Data pointer of SharedArrayBuffer::Contents is always allocated with |
+ * Allocator::Allocate that is set with V8::SetSharedArrayBufferAllocator. |
+ * |
+ * This API is experimental and may change significantly. |
+ */ |
+ class V8_EXPORT Contents { // NOLINT |
+ public: |
+ Contents() : data_(NULL), byte_length_(0) {} |
+ |
+ void* Data() const { return data_; } |
+ size_t ByteLength() const { return byte_length_; } |
+ |
+ private: |
+ void* data_; |
+ size_t byte_length_; |
+ |
+ friend class SharedArrayBuffer; |
+ }; |
+ |
+ |
+ /** |
+ * Data length in bytes. |
+ */ |
+ size_t ByteLength() const; |
+ |
+ /** |
+ * Create a new SharedArrayBuffer. Allocate |byte_length| bytes. |
+ * Allocated memory will be owned by a created SharedArrayBuffer and |
+ * will be deallocated when it is garbage-collected, |
+ * unless the object is externalized. |
+ */ |
+ static Local<SharedArrayBuffer> New(Isolate* isolate, size_t byte_length); |
+ |
+ /** |
+ * Create a new SharedArrayBuffer over an existing memory block. |
+ * The created array buffer is immediately in externalized state. |
+ * The memory block will not be reclaimed when a created SharedArrayBuffer |
+ * is garbage-collected. |
+ */ |
+ static Local<SharedArrayBuffer> New(Isolate* isolate, void* data, |
+ size_t byte_length); |
+ |
+ /** |
+ * Returns true if SharedArrayBuffer is extrenalized, that is, does not |
+ * own its memory block. |
+ */ |
+ bool IsExternal() const; |
+ |
+ /** |
+ * Make this SharedArrayBuffer external. The pointer to underlying memory |
+ * block and byte length are returned as |Contents| structure. After |
+ * SharedArrayBuffer had been etxrenalized, it does no longer owns the memory |
+ * block. The caller should take steps to free memory when it is no longer |
+ * needed. |
+ * |
+ * The memory block is guaranteed to be allocated with |Allocator::Allocate| |
+ * that has been set with V8::SetSharedArrayBufferAllocator. |
+ */ |
+ Contents Externalize(); |
+ |
+ V8_INLINE static SharedArrayBuffer* Cast(Value* obj); |
+ |
+ static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT; |
+ |
+ private: |
+ SharedArrayBuffer(); |
+ static void CheckCast(Value* obj); |
+}; |
+ |
+ |
+/** |
+ * TODO(binji): document |
+ * A base class for an instance of TypedArray series of constructors |
+ * (ES6 draft 15.13.6). |
+ * This API is experimental and may change significantly. |
+ */ |
+class V8_EXPORT SharedTypedArray : public Object { |
+ public: |
+ /** |
+ * Returns underlying SharedArrayBuffer. |
+ */ |
+ Local<SharedArrayBuffer> Buffer(); |
+ /** |
+ * Byte offset in |Buffer|. |
+ */ |
+ size_t ByteOffset(); |
+ /** |
+ * Size of a view in bytes. |
+ */ |
+ size_t ByteLength(); |
+ |
+ /** |
+ * Number of elements in this typed array |
+ * (e.g. for SharedInt16Array, |ByteLength|/2). |
+ */ |
+ size_t Length(); |
+ |
+ V8_INLINE static SharedTypedArray* Cast(Value* obj); |
+ |
+ private: |
+ SharedTypedArray(); |
+ static void CheckCast(Value* obj); |
+}; |
+ |
+ |
+/** |
+ * TODO(binji): document |
+ * An instance of Uint8Array constructor (ES6 draft 15.13.6). |
+ * This API is experimental and may change significantly. |
+ */ |
+class V8_EXPORT SharedUint8Array : public SharedTypedArray { |
+ public: |
+ static Local<SharedUint8Array> New(Handle<SharedArrayBuffer> array_buffer, |
+ size_t byte_offset, size_t length); |
+ V8_INLINE static SharedUint8Array* Cast(Value* obj); |
+ |
+ private: |
+ SharedUint8Array(); |
+ static void CheckCast(Value* obj); |
+}; |
+ |
+ |
+/** |
+ * TODO(binji): document |
+ * An instance of Uint8ClampedArray constructor (ES6 draft 15.13.6). |
+ * This API is experimental and may change significantly. |
+ */ |
+class V8_EXPORT SharedUint8ClampedArray : public SharedTypedArray { |
+ public: |
+ static Local<SharedUint8ClampedArray> New( |
+ Handle<SharedArrayBuffer> array_buffer, size_t byte_offset, |
+ size_t length); |
+ V8_INLINE static SharedUint8ClampedArray* Cast(Value* obj); |
+ |
+ private: |
+ SharedUint8ClampedArray(); |
+ static void CheckCast(Value* obj); |
+}; |
+ |
+/** |
+ * TODO(binji): document |
+ * An instance of Int8Array constructor (ES6 draft 15.13.6). |
+ * This API is experimental and may change significantly. |
+ */ |
+class V8_EXPORT SharedInt8Array : public SharedTypedArray { |
+ public: |
+ static Local<SharedInt8Array> New(Handle<SharedArrayBuffer> array_buffer, |
+ size_t byte_offset, size_t length); |
+ V8_INLINE static SharedInt8Array* Cast(Value* obj); |
+ |
+ private: |
+ SharedInt8Array(); |
+ static void CheckCast(Value* obj); |
+}; |
+ |
+ |
+/** |
+ * TODO(binji): document |
+ * An instance of Uint16Array constructor (ES6 draft 15.13.6). |
+ * This API is experimental and may change significantly. |
+ */ |
+class V8_EXPORT SharedUint16Array : public SharedTypedArray { |
+ public: |
+ static Local<SharedUint16Array> New(Handle<SharedArrayBuffer> array_buffer, |
+ size_t byte_offset, size_t length); |
+ V8_INLINE static SharedUint16Array* Cast(Value* obj); |
+ |
+ private: |
+ SharedUint16Array(); |
+ static void CheckCast(Value* obj); |
+}; |
+ |
+ |
+/** |
+ * TODO(binji): document |
+ * An instance of Int16Array constructor (ES6 draft 15.13.6). |
+ * This API is experimental and may change significantly. |
+ */ |
+class V8_EXPORT SharedInt16Array : public SharedTypedArray { |
+ public: |
+ static Local<SharedInt16Array> New(Handle<SharedArrayBuffer> array_buffer, |
+ size_t byte_offset, size_t length); |
+ V8_INLINE static SharedInt16Array* Cast(Value* obj); |
+ |
+ private: |
+ SharedInt16Array(); |
+ static void CheckCast(Value* obj); |
+}; |
+ |
+ |
+/** |
+ * TODO(binji): document |
+ * An instance of Uint32Array constructor (ES6 draft 15.13.6). |
+ * This API is experimental and may change significantly. |
+ */ |
+class V8_EXPORT SharedUint32Array : public SharedTypedArray { |
+ public: |
+ static Local<SharedUint32Array> New(Handle<SharedArrayBuffer> array_buffer, |
+ size_t byte_offset, size_t length); |
+ V8_INLINE static SharedUint32Array* Cast(Value* obj); |
+ |
+ private: |
+ SharedUint32Array(); |
+ static void CheckCast(Value* obj); |
+}; |
+ |
+ |
+/** |
+ * TODO(binji): document |
+ * An instance of Int32Array constructor (ES6 draft 15.13.6). |
+ * This API is experimental and may change significantly. |
+ */ |
+class V8_EXPORT SharedInt32Array : public SharedTypedArray { |
+ public: |
+ static Local<SharedInt32Array> New(Handle<SharedArrayBuffer> array_buffer, |
+ size_t byte_offset, size_t length); |
+ V8_INLINE static SharedInt32Array* Cast(Value* obj); |
+ |
+ private: |
+ SharedInt32Array(); |
+ static void CheckCast(Value* obj); |
+}; |
+ |
+ |
+/** |
+ * TODO(binji): document |
+ * An instance of Float32Array constructor (ES6 draft 15.13.6). |
+ * This API is experimental and may change significantly. |
+ */ |
+class V8_EXPORT SharedFloat32Array : public SharedTypedArray { |
+ public: |
+ static Local<SharedFloat32Array> New(Handle<SharedArrayBuffer> array_buffer, |
+ size_t byte_offset, size_t length); |
+ V8_INLINE static SharedFloat32Array* Cast(Value* obj); |
+ |
+ private: |
+ SharedFloat32Array(); |
+ static void CheckCast(Value* obj); |
+}; |
+ |
+ |
+/** |
+ * TODO(binji): document |
+ * An instance of Float64Array constructor (ES6 draft 15.13.6). |
+ * This API is experimental and may change significantly. |
+ */ |
+class V8_EXPORT SharedFloat64Array : public SharedTypedArray { |
+ public: |
+ static Local<SharedFloat64Array> New(Handle<SharedArrayBuffer> array_buffer, |
+ size_t byte_offset, size_t length); |
+ V8_INLINE static SharedFloat64Array* Cast(Value* obj); |
+ |
+ private: |
+ SharedFloat64Array(); |
+ static void CheckCast(Value* obj); |
+}; |
+ |
+ |
+/** |
* An instance of the built-in Date constructor (ECMA-262, 15.9). |
*/ |
class V8_EXPORT Date : public Object { |
@@ -5749,6 +6050,15 @@ class V8_EXPORT V8 { |
static void SetArrayBufferAllocator(ArrayBuffer::Allocator* allocator); |
/** |
+ * Set allocator to use for SharedArrayBuffer memory. |
+ * The allocator should be set only once. The allocator should be set |
+ * before any code tha uses SharedArrayBuffers is executed. |
+ * This allocator is used in all isolates. |
+ */ |
+ static void SetSharedArrayBufferAllocator( |
+ SharedArrayBuffer::Allocator* allocator); |
+ |
+ /** |
* Check if V8 is dead and therefore unusable. This is the case after |
* fatal errors such as out-of-memory situations. |
*/ |
@@ -6705,7 +7015,7 @@ class Internals { |
static const int kJSObjectHeaderSize = 3 * kApiPointerSize; |
static const int kFixedArrayHeaderSize = 2 * kApiPointerSize; |
static const int kContextHeaderSize = 2 * kApiPointerSize; |
- static const int kContextEmbedderDataIndex = 76; |
+ static const int kContextEmbedderDataIndex = 95; |
static const int kFullStringRepresentationMask = 0x07; |
static const int kStringEncodingMask = 0x4; |
static const int kExternalTwoByteRepresentationTag = 0x02; |
@@ -7771,6 +8081,94 @@ DataView* DataView::Cast(v8::Value* value) { |
} |
+SharedArrayBuffer* SharedArrayBuffer::Cast(v8::Value* value) { |
+#ifdef V8_ENABLE_CHECKS |
+ CheckCast(value); |
+#endif |
+ return static_cast<SharedArrayBuffer*>(value); |
+} |
+ |
+ |
+SharedTypedArray* SharedTypedArray::Cast(v8::Value* value) { |
+#ifdef V8_ENABLE_CHECKS |
+ CheckCast(value); |
+#endif |
+ return static_cast<SharedTypedArray*>(value); |
+} |
+ |
+ |
+SharedUint8Array* SharedUint8Array::Cast(v8::Value* value) { |
+#ifdef V8_ENABLE_CHECKS |
+ CheckCast(value); |
+#endif |
+ return static_cast<SharedUint8Array*>(value); |
+} |
+ |
+ |
+SharedInt8Array* SharedInt8Array::Cast(v8::Value* value) { |
+#ifdef V8_ENABLE_CHECKS |
+ CheckCast(value); |
+#endif |
+ return static_cast<SharedInt8Array*>(value); |
+} |
+ |
+ |
+SharedUint16Array* SharedUint16Array::Cast(v8::Value* value) { |
+#ifdef V8_ENABLE_CHECKS |
+ CheckCast(value); |
+#endif |
+ return static_cast<SharedUint16Array*>(value); |
+} |
+ |
+ |
+SharedInt16Array* SharedInt16Array::Cast(v8::Value* value) { |
+#ifdef V8_ENABLE_CHECKS |
+ CheckCast(value); |
+#endif |
+ return static_cast<SharedInt16Array*>(value); |
+} |
+ |
+ |
+SharedUint32Array* SharedUint32Array::Cast(v8::Value* value) { |
+#ifdef V8_ENABLE_CHECKS |
+ CheckCast(value); |
+#endif |
+ return static_cast<SharedUint32Array*>(value); |
+} |
+ |
+ |
+SharedInt32Array* SharedInt32Array::Cast(v8::Value* value) { |
+#ifdef V8_ENABLE_CHECKS |
+ CheckCast(value); |
+#endif |
+ return static_cast<SharedInt32Array*>(value); |
+} |
+ |
+ |
+SharedFloat32Array* SharedFloat32Array::Cast(v8::Value* value) { |
+#ifdef V8_ENABLE_CHECKS |
+ CheckCast(value); |
+#endif |
+ return static_cast<SharedFloat32Array*>(value); |
+} |
+ |
+ |
+SharedFloat64Array* SharedFloat64Array::Cast(v8::Value* value) { |
+#ifdef V8_ENABLE_CHECKS |
+ CheckCast(value); |
+#endif |
+ return static_cast<SharedFloat64Array*>(value); |
+} |
+ |
+ |
+SharedUint8ClampedArray* SharedUint8ClampedArray::Cast(v8::Value* value) { |
+#ifdef V8_ENABLE_CHECKS |
+ CheckCast(value); |
+#endif |
+ return static_cast<SharedUint8ClampedArray*>(value); |
+} |
+ |
+ |
Function* Function::Cast(v8::Value* value) { |
#ifdef V8_ENABLE_CHECKS |
CheckCast(value); |