Index: include/v8.h |
diff --git a/include/v8.h b/include/v8.h |
index f52f8b8cfc6b8725748de27ae5896924d222aa07..b3c3e278635d0a91f056d4d72daed56b3c486032 100644 |
--- a/include/v8.h |
+++ b/include/v8.h |
@@ -1920,6 +1920,13 @@ 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; |
+ |
+ |
V8_WARN_UNUSED_RESULT MaybeLocal<Boolean> ToBoolean( |
Local<Context> context) const; |
V8_WARN_UNUSED_RESULT MaybeLocal<Number> ToNumber( |
@@ -3344,7 +3351,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; |
@@ -3631,6 +3638,107 @@ 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); |
+}; |
+ |
+ |
+/** |
* An instance of the built-in Date constructor (ECMA-262, 15.9). |
*/ |
class V8_EXPORT Date : public Object { |
@@ -5006,7 +5114,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 |
@@ -5054,6 +5163,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; |
jochen (gone - plz use gerrit)
2015/05/22 08:37:47
why do we need a separate allocator?
binji
2015/05/22 09:27:34
We probably don't. Removed.
|
}; |
@@ -6746,7 +6861,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 = 78; |
+ static const int kContextEmbedderDataIndex = 79; |
static const int kFullStringRepresentationMask = 0x07; |
static const int kStringEncodingMask = 0x4; |
static const int kExternalTwoByteRepresentationTag = 0x02; |
@@ -7817,6 +7932,14 @@ DataView* DataView::Cast(v8::Value* value) { |
} |
+SharedArrayBuffer* SharedArrayBuffer::Cast(v8::Value* value) { |
+#ifdef V8_ENABLE_CHECKS |
+ CheckCast(value); |
+#endif |
+ return static_cast<SharedArrayBuffer*>(value); |
+} |
+ |
+ |
Function* Function::Cast(v8::Value* value) { |
#ifdef V8_ENABLE_CHECKS |
CheckCast(value); |