Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: gin/array_buffer.cc

Issue 172133002: gin: Make it possible to use gin array buffers when running on top of blink (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | gin/isolate_holder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdlib.h>
6
5 #include "gin/array_buffer.h" 7 #include "gin/array_buffer.h"
6 8 #include "gin/per_isolate_data.h"
7 #include <stdlib.h>
8 9
9 namespace gin { 10 namespace gin {
10 11
11 COMPILE_ASSERT(V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT == 2, 12 COMPILE_ASSERT(V8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT == 2,
12 array_buffers_must_have_two_internal_fields); 13 array_buffers_must_have_two_internal_fields);
13 14
14 static const int kBufferViewPrivateIndex = 0; 15 static const int kBufferViewPrivateIndex = 0;
15 16
16 // ArrayBufferAllocator ------------------------------------------------------- 17 // ArrayBufferAllocator -------------------------------------------------------
17 18
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 friend class base::RefCounted<Private>; 66 friend class base::RefCounted<Private>;
66 67
67 Private(v8::Isolate* isolate, v8::Handle<v8::ArrayBuffer> array); 68 Private(v8::Isolate* isolate, v8::Handle<v8::ArrayBuffer> array);
68 ~Private(); 69 ~Private();
69 70
70 static void WeakCallback( 71 static void WeakCallback(
71 const v8::WeakCallbackData<v8::ArrayBuffer, Private>& data); 72 const v8::WeakCallbackData<v8::ArrayBuffer, Private>& data);
72 73
73 v8::Persistent<v8::ArrayBuffer> array_buffer_; 74 v8::Persistent<v8::ArrayBuffer> array_buffer_;
74 scoped_refptr<Private> self_reference_; 75 scoped_refptr<Private> self_reference_;
76 v8::Isolate* isolate_;
75 void* buffer_; 77 void* buffer_;
76 size_t length_; 78 size_t length_;
77 }; 79 };
78 80
79 scoped_refptr<ArrayBuffer::Private> ArrayBuffer::Private::From( 81 scoped_refptr<ArrayBuffer::Private> ArrayBuffer::Private::From(
80 v8::Isolate* isolate, v8::Handle<v8::ArrayBuffer> array) { 82 v8::Isolate* isolate, v8::Handle<v8::ArrayBuffer> array) {
81 if (array->IsExternal()) { 83 if (array->IsExternal()) {
82 return make_scoped_refptr(static_cast<Private*>( 84 return make_scoped_refptr(static_cast<Private*>(
83 array->GetAlignedPointerFromInternalField(kBufferViewPrivateIndex))); 85 array->GetAlignedPointerFromInternalField(kBufferViewPrivateIndex)));
abarth-chromium 2014/02/19 15:52:55 This CL is a good step, but I think you still get
84 } 86 }
85 return make_scoped_refptr(new Private(isolate, array)); 87 return make_scoped_refptr(new Private(isolate, array));
86 } 88 }
87 89
88 ArrayBuffer::Private::Private(v8::Isolate* isolate, 90 ArrayBuffer::Private::Private(v8::Isolate* isolate,
89 v8::Handle<v8::ArrayBuffer> array) 91 v8::Handle<v8::ArrayBuffer> array)
90 : array_buffer_(isolate, array) { 92 : array_buffer_(isolate, array), isolate_(isolate) {
91 // Take ownership of the array buffer. 93 // Take ownership of the array buffer.
94 CHECK(!array->IsExternal());
92 v8::ArrayBuffer::Contents contents = array->Externalize(); 95 v8::ArrayBuffer::Contents contents = array->Externalize();
93 buffer_ = contents.Data(); 96 buffer_ = contents.Data();
94 length_ = contents.ByteLength(); 97 length_ = contents.ByteLength();
95 98
96 array->SetAlignedPointerInInternalField(kBufferViewPrivateIndex, this); 99 array->SetAlignedPointerInInternalField(kBufferViewPrivateIndex, this);
97 100
98 self_reference_ = this; // Cleared in WeakCallback. 101 self_reference_ = this; // Cleared in WeakCallback.
99 array_buffer_.SetWeak(this, WeakCallback); 102 array_buffer_.SetWeak(this, WeakCallback);
100 } 103 }
101 104
102 ArrayBuffer::Private::~Private() { 105 ArrayBuffer::Private::~Private() {
103 ArrayBufferAllocator::SharedInstance()->Free(buffer_, length_); 106 PerIsolateData::From(isolate_)->allocator()->Free(buffer_, length_);
104 } 107 }
105 108
106 void ArrayBuffer::Private::WeakCallback( 109 void ArrayBuffer::Private::WeakCallback(
107 const v8::WeakCallbackData<v8::ArrayBuffer, Private>& data) { 110 const v8::WeakCallbackData<v8::ArrayBuffer, Private>& data) {
108 Private* parameter = data.GetParameter(); 111 Private* parameter = data.GetParameter();
109 parameter->array_buffer_.Reset(); 112 parameter->array_buffer_.Reset();
110 parameter->self_reference_ = NULL; 113 parameter->self_reference_ = NULL;
111 } 114 }
112 115
113 // ArrayBuffer ---------------------------------------------------------------- 116 // ArrayBuffer ----------------------------------------------------------------
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 bool Converter<ArrayBufferView>::FromV8(v8::Isolate* isolate, 170 bool Converter<ArrayBufferView>::FromV8(v8::Isolate* isolate,
168 v8::Handle<v8::Value> val, 171 v8::Handle<v8::Value> val,
169 ArrayBufferView* out) { 172 ArrayBufferView* out) {
170 if (!val->IsArrayBufferView()) 173 if (!val->IsArrayBufferView())
171 return false; 174 return false;
172 *out = ArrayBufferView(isolate, v8::Handle<v8::ArrayBufferView>::Cast(val)); 175 *out = ArrayBufferView(isolate, v8::Handle<v8::ArrayBufferView>::Cast(val));
173 return true; 176 return true;
174 } 177 }
175 178
176 } // namespace gin 179 } // namespace gin
OLDNEW
« no previous file with comments | « no previous file | gin/isolate_holder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698