diff options
author | Torne (Richard Coles) <torne@google.com> | 2014-03-18 10:20:56 +0000 |
---|---|---|
committer | Torne (Richard Coles) <torne@google.com> | 2014-03-18 10:20:56 +0000 |
commit | a1401311d1ab56c4ed0a474bd38c108f75cb0cd9 (patch) | |
tree | 3437151d9ae1ce20a1e53a0d98c19ca01c786394 /gin/array_buffer.cc | |
parent | af5066f1e36c6579e74752647e6c584438f80f94 (diff) | |
download | chromium_org-a1401311d1ab56c4ed0a474bd38c108f75cb0cd9.tar.gz |
Merge from Chromium at DEPS revision 257591
This commit was generated by merge_to_master.py.
Change-Id: I0010df2ec3fbb5d4947cd026de2feb150ce7a6b5
Diffstat (limited to 'gin/array_buffer.cc')
-rw-r--r-- | gin/array_buffer.cc | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/gin/array_buffer.cc b/gin/array_buffer.cc index ee9f2a5867..68237bcbf8 100644 --- a/gin/array_buffer.cc +++ b/gin/array_buffer.cc @@ -2,17 +2,23 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "gin/array_buffer.h" - #include <stdlib.h> +#include "base/logging.h" +#include "gin/array_buffer.h" +#include "gin/per_isolate_data.h" + namespace gin { +namespace { + +gin::WrapperInfo g_array_buffer_wrapper_info = {gin::kEmbedderNativeGin}; + +} // namespace + COMPILE_ASSERT(V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT == 2, array_buffers_must_have_two_internal_fields); -static const int kBufferViewPrivateIndex = 0; - // ArrayBufferAllocator ------------------------------------------------------- void* ArrayBufferAllocator::Allocate(size_t length) { @@ -72,6 +78,7 @@ class ArrayBuffer::Private : public base::RefCounted<ArrayBuffer::Private> { v8::Persistent<v8::ArrayBuffer> array_buffer_; scoped_refptr<Private> self_reference_; + v8::Isolate* isolate_; void* buffer_; size_t length_; }; @@ -79,28 +86,34 @@ class ArrayBuffer::Private : public base::RefCounted<ArrayBuffer::Private> { scoped_refptr<ArrayBuffer::Private> ArrayBuffer::Private::From( v8::Isolate* isolate, v8::Handle<v8::ArrayBuffer> array) { if (array->IsExternal()) { + CHECK_EQ(WrapperInfo::From(v8::Handle<v8::Object>::Cast(array)), + &g_array_buffer_wrapper_info) + << "Cannot mix blink and gin ArrayBuffers"; return make_scoped_refptr(static_cast<Private*>( - array->GetAlignedPointerFromInternalField(kBufferViewPrivateIndex))); + array->GetAlignedPointerFromInternalField(kEncodedValueIndex))); } return make_scoped_refptr(new Private(isolate, array)); } ArrayBuffer::Private::Private(v8::Isolate* isolate, v8::Handle<v8::ArrayBuffer> array) - : array_buffer_(isolate, array) { + : array_buffer_(isolate, array), isolate_(isolate) { // Take ownership of the array buffer. + CHECK(!array->IsExternal()); v8::ArrayBuffer::Contents contents = array->Externalize(); buffer_ = contents.Data(); length_ = contents.ByteLength(); - array->SetAlignedPointerInInternalField(kBufferViewPrivateIndex, this); + array->SetAlignedPointerInInternalField(kWrapperInfoIndex, + &g_array_buffer_wrapper_info); + array->SetAlignedPointerInInternalField(kEncodedValueIndex, this); self_reference_ = this; // Cleared in WeakCallback. array_buffer_.SetWeak(this, WeakCallback); } ArrayBuffer::Private::~Private() { - ArrayBufferAllocator::SharedInstance()->Free(buffer_, length_); + PerIsolateData::From(isolate_)->allocator()->Free(buffer_, length_); } void ArrayBuffer::Private::WeakCallback( |