From: dslomov@chromium.org Date: Fri, 2 Aug 2013 13:03:06 +0000 (+0000) Subject: Add size_t length argument to v8::ArrayBuffer::Allocator::Free. X-Git-Tag: upstream/4.7.83~13068 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5230c19d8bcd0d220c399a83be4971eda0efa674;p=platform%2Fupstream%2Fv8.git Add size_t length argument to v8::ArrayBuffer::Allocator::Free. The previous implementation of Free is a deprecated overload now. R=mstarzinger@chromium.org Committed: https://code.google.com/p/v8/source/detail?r=16031 Review URL: https://codereview.chromium.org/21803002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16033 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/include/v8.h b/include/v8.h index 11fccdf..311ad43 100644 --- a/include/v8.h +++ b/include/v8.h @@ -2425,10 +2425,20 @@ class V8EXPORT ArrayBuffer : public Object { } /** - * Free the memory pointed to |data|. That memory is guaranteed to be - * previously allocated by |Allocate|. + * Free the memory block of size |length|, pointed to by |data|. + * That memory is guaranteed to be previously allocated by |Allocate|. */ - virtual void Free(void* data) = 0; + virtual void Free(void* data, size_t length) { + // Override with call to |Free(void*)| for compatibility + // with legacy version. + Free(data); + } + + /** + * Deprecated. Never called directly by V8. + * For compatibility with legacy version of this interface. + */ + virtual void Free(void* data); }; /** diff --git a/src/api.cc b/src/api.cc index 1ae81b1..d442126 100644 --- a/src/api.cc +++ b/src/api.cc @@ -3071,6 +3071,12 @@ void v8::ArrayBuffer::CheckCast(Value* that) { } +void v8::ArrayBuffer::Allocator::Free(void* data) { + API_Fatal("v8::ArrayBuffer::Allocator::Free", + "Override Allocator::Free(void*, size_t)"); +} + + void v8::ArrayBufferView::CheckCast(Value* that) { i::Handle obj = Utils::OpenHandle(that); ApiCheck(obj->IsJSArrayBufferView(), diff --git a/src/d8.cc b/src/d8.cc index e66a2ec..9471aa4 100644 --- a/src/d8.cc +++ b/src/d8.cc @@ -1635,7 +1635,13 @@ class ShellArrayBufferAllocator : public v8::ArrayBuffer::Allocator { virtual void* AllocateUninitialized(size_t length) { return malloc(length); } - virtual void Free(void* data) { free(data); } + virtual void Free(void* data, size_t) { free(data); } + // TODO(dslomov): Remove when v8:2823 is fixed. + virtual void Free(void* data) { +#ifndef V8_SHARED + UNREACHABLE(); +#endif + } }; diff --git a/src/runtime.cc b/src/runtime.cc index df31e70..9775147 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -689,7 +689,9 @@ void Runtime::FreeArrayBuffer(Isolate* isolate, isolate->heap()->AdjustAmountOfExternalAllocatedMemory( -static_cast(allocated_length)); CHECK(V8::ArrayBufferAllocator() != NULL); - V8::ArrayBufferAllocator()->Free(phantom_array_buffer->backing_store()); + V8::ArrayBufferAllocator()->Free( + phantom_array_buffer->backing_store(), + allocated_length); } diff --git a/test/cctest/cctest.cc b/test/cctest/cctest.cc index 94dcce1..a2caf0f 100644 --- a/test/cctest/cctest.cc +++ b/test/cctest/cctest.cc @@ -99,9 +99,10 @@ v8::Isolate* CcTest::default_isolate_; class CcTestArrayBufferAllocator : public v8::ArrayBuffer::Allocator { - public: virtual void* Allocate(size_t length) { return malloc(length); } - virtual void Free(void* data) { free(data); } + virtual void Free(void* data, size_t length) { free(data); } + // TODO(dslomov): Remove when v8:2823 is fixed. + virtual void Free(void* data) { UNREACHABLE(); } };