Index: include/v8.h |
diff --git a/include/v8.h b/include/v8.h |
index 5ce6dd5064fa30763ebd031fc30de117495d9814..bc0abd381207bb517867262c575ba8e58afb967e 100644 |
--- a/include/v8.h |
+++ b/include/v8.h |
@@ -1893,6 +1893,73 @@ class V8_EXPORT Value : public Data { |
*/ |
bool IsDataView() const; |
+ /** |
+ * Returns true if this value is a SharedArrayBuffer. |
+ * This is an experimental feature. |
+ */ |
+ bool IsSharedArrayBuffer() const; |
+ |
+ /** |
+ * Returns true if this value is one of SharedTypedArrays. |
+ * This is an experimental feature. |
+ */ |
+ bool IsSharedTypedArray() const; |
+ |
+ /** |
+ * Returns true if this value is a SharedUint8Array. |
+ * This is an experimental feature. |
+ */ |
+ bool IsSharedUint8Array() const; |
+ |
+ /** |
+ * Returns true if this value is a SharedUint8ClampedArray. |
+ * This is an experimental feature. |
+ */ |
+ bool IsSharedUint8ClampedArray() const; |
+ |
+ /** |
+ * Returns true if this value is a SharedInt8Array. |
+ * This is an experimental feature. |
+ */ |
+ bool IsSharedInt8Array() const; |
+ |
+ /** |
+ * Returns true if this value is a SharedUint16Array. |
+ * This is an experimental feature. |
+ */ |
+ bool IsSharedUint16Array() const; |
+ |
+ /** |
+ * Returns true if this value is a SharedInt16Array. |
+ * This is an experimental feature. |
+ */ |
+ bool IsSharedInt16Array() const; |
+ |
+ /** |
+ * Returns true if this value is a SharedUint32Array. |
+ * This is an experimental feature. |
+ */ |
+ bool IsSharedUint32Array() const; |
+ |
+ /** |
+ * Returns true if this value is a SharedInt32Array. |
+ * This is an experimental feature. |
+ */ |
+ bool IsSharedInt32Array() const; |
+ |
+ /** |
+ * Returns true if this value is a SharedFloat32Array. |
+ * This is an experimental feature. |
+ */ |
+ bool IsSharedFloat32Array() const; |
+ |
+ /** |
+ * Returns true if this value is a SharedFloat64Array. |
+ * This is an experimental feature. |
+ */ |
+ bool IsSharedFloat64Array() const; |
+ |
+ |
V8_WARN_UNUSED_RESULT MaybeLocal<Boolean> ToBoolean( |
Local<Context> context) const; |
V8_WARN_UNUSED_RESULT MaybeLocal<Number> ToNumber( |
@@ -3312,7 +3379,7 @@ class V8_EXPORT ArrayBuffer : public Object { |
ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized); |
/** |
- * Returns true if ArrayBuffer is extrenalized, that is, does not |
+ * Returns true if ArrayBuffer is externalized, that is, does not |
* own its memory block. |
*/ |
bool IsExternal() const; |
@@ -3599,6 +3666,295 @@ 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: |
+ /** |
+ * 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 |
+ * |ArrayBuffer::Allocator::Allocate| by the allocator specified in |
+ * v8::Isolate::CreateParams::shared_array_buffer_allocator. |
+ * |
+ * 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 unless otherwise |
+ * specified. 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, |
+ ArrayBufferCreationMode mode = ArrayBufferCreationMode::kExternalized); |
+ |
+ /** |
+ * Returns true if SharedArrayBuffer is externalized, 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| |
+ * by the allocator specified in |
+ * v8::Isolate::CreateParams::shared_array_buffer_allocator. |
+ * |
+ */ |
+ Contents Externalize(); |
+ |
+ /** |
+ * Get a pointer to the ArrayBuffer's underlying memory block without |
+ * externalizing it. If the ArrayBuffer is not externalized, this pointer |
+ * will become invalid as soon as the ArrayBuffer became garbage collected. |
+ * |
+ * The embedder should make sure to hold a strong reference to the |
+ * ArrayBuffer while accessing this pointer. |
+ * |
+ * The memory block is guaranteed to be allocated with |Allocator::Allocate| |
+ * by the allocator specified in |
+ * v8::Isolate::CreateParams::shared_array_buffer_allocator. |
+ */ |
+ Contents GetContents(); |
+ |
+ 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 { |
@@ -4956,7 +5312,8 @@ class V8_EXPORT Isolate { |
counter_lookup_callback(NULL), |
create_histogram_callback(NULL), |
add_histogram_sample_callback(NULL), |
- array_buffer_allocator(NULL) {} |
+ array_buffer_allocator(NULL), |
+ shared_array_buffer_allocator(NULL) {} |
/** |
* The optional entry_hook allows the host application to provide the |
@@ -5004,6 +5361,12 @@ class V8_EXPORT Isolate { |
* store of ArrayBuffers. |
*/ |
ArrayBuffer::Allocator* array_buffer_allocator; |
+ |
+ /** |
+ * The ArrayBuffer::Allocator to use for allocating and freeing the backing |
+ * store of SharedArrayBuffers. |
+ */ |
+ ArrayBuffer::Allocator* shared_array_buffer_allocator; |
}; |
@@ -6673,7 +7036,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 = 77; |
+ static const int kContextEmbedderDataIndex = 96; |
static const int kFullStringRepresentationMask = 0x07; |
static const int kStringEncodingMask = 0x4; |
static const int kExternalTwoByteRepresentationTag = 0x02; |
@@ -7724,6 +8087,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); |