Version 3.19.13
Performance and stability improvements on all platforms.
git-svn-id: http://v8.googlecode.com/svn/trunk@15068 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
diff --git a/include/v8.h b/include/v8.h
index e99c6d9..c0bec79 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -2370,30 +2370,6 @@
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:
- 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
@@ -2405,6 +2381,53 @@
class V8EXPORT ArrayBuffer : public Object {
public:
/**
+ * Allocator that V8 uses to allocate |ArrayBuffer|'s memory.
+ * The allocator is a global V8 setting. It should be set with
+ * V8::SetArrayBufferAllocator prior to creation of a first ArrayBuffer.
+ *
+ * This API is experimental and may change significantly.
+ */
+ class V8EXPORT Allocator { // NOLINT
+ public:
+ virtual ~Allocator() {}
+
+ /**
+ * Allocate |length| bytes. Return NULL if allocation is not successful.
+ */
+ virtual void* Allocate(size_t length) = 0;
+ /**
+ * Free the memory pointed to |data|. That memory is guaranteed to be
+ * previously allocated by |Allocate|.
+ */
+ virtual void Free(void* data) = 0;
+ };
+
+ /**
+ * The contents of an |ArrayBuffer|. Externalization of |ArrayBuffer|
+ * returns an instance of this class, populated, with a pointer to data
+ * and byte length.
+ *
+ * The Data pointer of ArrayBuffer::Contents is always allocated with
+ * Allocator::Allocate that is set with V8::SetArrayBufferAllocator.
+ *
+ * This API is experimental and may change significantly.
+ */
+ class V8EXPORT 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 ArrayBuffer;
+ };
+
+
+ /**
* Data length in bytes.
*/
size_t ByteLength() const;
@@ -2440,14 +2463,18 @@
void Neuter();
/**
- * Pass the ownership of this ArrayBuffer's backing store to
- * a given ArrayBufferContents.
+ * Make this ArrayBuffer external. The pointer to underlying memory block
+ * and byte length are returned as |Contents| structure. After ArrayBuffer
+ * 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::SetArrayBufferAllocator.
*/
- void Externalize(ArrayBufferContents* contents);
+ Contents Externalize();
V8_INLINE(static ArrayBuffer* Cast(Value* obj));
-
static const int kInternalFieldCount = V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT;
private:
@@ -2845,6 +2872,7 @@
// Fast JS primitive setters
V8_INLINE(void SetNull());
V8_INLINE(void SetUndefined());
+ V8_INLINE(void SetEmptyString());
// Convenience getter for Isolate
V8_INLINE(Isolate* GetIsolate());
@@ -4193,6 +4221,14 @@
AllowCodeGenerationFromStringsCallback that);
/**
+ * Set allocator to use for ArrayBuffer memory.
+ * The allocator should be set only once. The allocator should be set
+ * before any code tha uses ArrayBuffers is executed.
+ * This allocator is used in all isolates.
+ */
+ static void SetArrayBufferAllocator(ArrayBuffer::Allocator* allocator);
+
+ /**
* Ignore out-of-memory exceptions.
*
* V8 running out of memory is treated as a fatal error by default.
@@ -5730,6 +5766,12 @@
}
template<typename T>
+void ReturnValue<T>::SetEmptyString() {
+ typedef internal::Internals I;
+ *value_ = *I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex);
+}
+
+template<typename T>
Isolate* ReturnValue<T>::GetIsolate() {
// Isolate is always the pointer below the default value on the stack.
return *reinterpret_cast<Isolate**>(&value_[-2]);