Chromium Code Reviews| Index: include/v8.h |
| diff --git a/include/v8.h b/include/v8.h |
| index 37bd427df205ee77771445f5448c85612b8692f5..dc80602da22ea1c37fea40b18c453a4ca07d3fb6 100644 |
| --- a/include/v8.h |
| +++ b/include/v8.h |
| @@ -2325,6 +2325,37 @@ 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: |
| + void* Data() const { return data_; } |
| + size_t ByteLength() const { return byte_length_; } |
| + |
| + ArrayBufferContents() : data_(NULL), byte_length_(0) {} |
|
Sven Panne
2013/05/23 07:57:01
Nit: We usually put the constructor/destructor at
Dmitry Lomov (no reviews)
2013/05/23 08:42:15
Done.
|
| + ~ArrayBufferContents(); |
| + |
| + private: |
| + ArrayBufferContents(void* data, size_t byte_length) |
| + : data_(data), byte_length_(byte_length) |
| + { } |
|
Sven Panne
2013/05/23 07:57:01
Nit: Put this at the end of the initializer list.
Dmitry Lomov (no reviews)
2013/05/23 08:42:15
Done.
|
| + |
| + 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 +2367,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); |