Index: include/v8.h |
diff --git a/include/v8.h b/include/v8.h |
index 696892beed42ce6e5bc2acddeb359760cdf4d64d..54402c35e88d0e014b2becba54d2280b49952400 100644 |
--- a/include/v8.h |
+++ b/include/v8.h |
@@ -2325,6 +2325,36 @@ class V8EXPORT Function : public Object { |
static void CheckCast(Value* obj); |
}; |
+/** |
+ * The contents of an |ArrayBuffer|. Externalization of |ArrayBuffer| |
+ * populates an instance of this class with a pointer to data and byte length. |
+ * |
+ * |ArrayBufferContents| is the owner of its data. When an instance of |
+ * this class is destructed, the |Data| is freed. |
+ * |
+ * This API is experimental and may change significantly. |
+ */ |
+class V8EXPORT ArrayBufferContents { |
+ public: |
+ ArrayBufferContents() : data_(NULL), byte_length_(0) {} |
+ ~ArrayBufferContents(); |
+ |
+ void* Data() const { return data_; } |
+ size_t ByteLength() const { return byte_length_; } |
+ |
+ private: |
+ ArrayBufferContents(void* data, size_t byte_length) |
Sven Panne
2013/05/23 09:08:41
No callers, remove it.
|
+ : data_(data), byte_length_(byte_length) { } |
+ |
+ void* data_; |
+ size_t byte_length_; |
+ |
+ friend class ArrayBuffer; |
+}; |
+ |
+#ifndef V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT |
+#define V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT 2 |
+#endif |
/** |
* An instance of the built-in ArrayBuffer constructor (ES6 draft 15.13.5). |
@@ -2336,27 +2366,40 @@ class V8EXPORT ArrayBuffer : public Object { |
* Data length in bytes. |
*/ |
size_t ByteLength() const; |
- /** |
- * Raw pointer to the array buffer data |
- */ |
- void* Data() const; |
/** |
* Create a new ArrayBuffer. Allocate |byte_length| bytes. |
* Allocated memory will be owned by a created ArrayBuffer and |
- * will be deallocated when it is garbage-collected. |
+ * will be deallocated when it is garbage-collected, |
+ * unless the object is externalized. |
*/ |
static Local<ArrayBuffer> New(size_t byte_length); |
/** |
* Create a new ArrayBuffer over an existing memory block. |
+ * The created array buffer is immediately in externalized state. |
* The memory block will not be reclaimed when a created ArrayBuffer |
* is garbage-collected. |
*/ |
static Local<ArrayBuffer> New(void* data, size_t byte_length); |
+ /** |
+ * Returns true if ArrayBuffer is extrenalized, that is, does not |
+ * own its memory block. |
+ */ |
+ bool IsExternal() const; |
+ |
+ /** |
+ * Pass the ownership of this ArrayBuffer's backing store to |
+ * a given ArrayBufferContents. |
+ */ |
+ void Externalize(ArrayBufferContents* contents); |
+ |
V8_INLINE(static ArrayBuffer* Cast(Value* obj)); |
+ |
+ static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT; |
+ |
private: |
ArrayBuffer(); |
static void CheckCast(Value* obj); |