OLD | NEW |
---|---|
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 #ifndef GIN_ARRAY_BUFFER_H_ | 5 #ifndef GIN_ARRAY_BUFFER_H_ |
6 #define GIN_ARRAY_BUFFER_H_ | 6 #define GIN_ARRAY_BUFFER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "gin/converter.h" | 11 #include "gin/converter.h" |
12 #include "gin/gin_export.h" | |
12 #include "v8/include/v8.h" | 13 #include "v8/include/v8.h" |
13 | 14 |
14 namespace gin { | 15 namespace gin { |
15 | 16 |
16 class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { | 17 class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { |
17 public: | 18 public: |
18 virtual void* Allocate(size_t length) OVERRIDE; | 19 virtual void* Allocate(size_t length) OVERRIDE; |
19 virtual void* AllocateUninitialized(size_t length) OVERRIDE; | 20 virtual void* AllocateUninitialized(size_t length) OVERRIDE; |
20 virtual void Free(void* data, size_t length) OVERRIDE; | 21 virtual void Free(void* data, size_t length) OVERRIDE; |
21 | 22 |
22 static ArrayBufferAllocator* SharedInstance(); | 23 static ArrayBufferAllocator* SharedInstance(); |
23 }; | 24 }; |
24 | 25 |
25 class ArrayBuffer { | 26 class GIN_EXPORT ArrayBuffer { |
26 public: | 27 public: |
27 ArrayBuffer(); | 28 ArrayBuffer(); |
28 explicit ArrayBuffer(v8::Isolate* isolate); | 29 explicit ArrayBuffer(v8::Isolate* isolate); |
29 ArrayBuffer(v8::Isolate* isolate, v8::Handle<v8::ArrayBuffer> buffer); | 30 ArrayBuffer(v8::Isolate* isolate, v8::Handle<v8::ArrayBuffer> buffer); |
30 ~ArrayBuffer(); | 31 ~ArrayBuffer(); |
32 ArrayBuffer& operator=(const ArrayBuffer& other); | |
abarth-chromium
2013/12/12 16:41:45
We need to write this operator explicitly?
| |
31 | 33 |
32 void* bytes() const { return bytes_; } | 34 void* bytes() const { return bytes_; } |
33 size_t num_bytes() const { return num_bytes_; } | 35 size_t num_bytes() const { return num_bytes_; } |
34 | 36 |
35 private: | 37 private: |
36 class Private; | 38 class Private; |
37 | 39 |
38 scoped_refptr<Private> private_; | 40 scoped_refptr<Private> private_; |
39 void* bytes_; | 41 void* bytes_; |
40 size_t num_bytes_; | 42 size_t num_bytes_; |
41 | 43 |
42 DISALLOW_COPY(ArrayBuffer); | 44 DISALLOW_COPY(ArrayBuffer); |
43 }; | 45 }; |
44 | 46 |
45 template<> | 47 template<> |
46 struct Converter<ArrayBuffer> { | 48 struct GIN_EXPORT Converter<ArrayBuffer> { |
47 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, | 49 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, |
48 ArrayBuffer* out); | 50 ArrayBuffer* out); |
49 }; | 51 }; |
50 | 52 |
51 class ArrayBufferView { | 53 class GIN_EXPORT ArrayBufferView { |
52 public: | 54 public: |
53 ArrayBufferView(); | 55 ArrayBufferView(); |
54 ArrayBufferView(v8::Isolate* isolate, v8::Handle<v8::ArrayBufferView> view); | 56 ArrayBufferView(v8::Isolate* isolate, v8::Handle<v8::ArrayBufferView> view); |
55 ~ArrayBufferView(); | 57 ~ArrayBufferView(); |
56 | 58 |
57 void* bytes() const { | 59 void* bytes() const { |
58 return static_cast<uint8_t*>(array_buffer_.bytes()) + offset_; | 60 return static_cast<uint8_t*>(array_buffer_.bytes()) + offset_; |
59 } | 61 } |
60 size_t num_bytes() const { return num_bytes_; } | 62 size_t num_bytes() const { return num_bytes_; } |
61 | 63 |
62 private: | 64 private: |
63 ArrayBuffer array_buffer_; | 65 ArrayBuffer array_buffer_; |
64 size_t offset_; | 66 size_t offset_; |
65 size_t num_bytes_; | 67 size_t num_bytes_; |
66 | 68 |
67 DISALLOW_COPY(ArrayBufferView); | 69 DISALLOW_COPY(ArrayBufferView); |
68 }; | 70 }; |
69 | 71 |
70 template<> | 72 template<> |
71 struct Converter<ArrayBufferView> { | 73 struct GIN_EXPORT Converter<ArrayBufferView> { |
72 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, | 74 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, |
73 ArrayBufferView* out); | 75 ArrayBufferView* out); |
74 }; | 76 }; |
75 | 77 |
76 } // namespace gin | 78 } // namespace gin |
77 | 79 |
78 #endif // GIN_ARRAY_BUFFER_H_ | 80 #endif // GIN_ARRAY_BUFFER_H_ |
OLD | NEW |