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 "v8/include/v8.h" | 12 #include "v8/include/v8.h" |
13 | 13 |
14 namespace gin { | 14 namespace gin { |
15 | 15 |
16 class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { | 16 class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { |
17 public: | 17 public: |
18 virtual void* Allocate(size_t length) OVERRIDE; | 18 virtual void* Allocate(size_t length) OVERRIDE; |
19 virtual void* AllocateUninitialized(size_t length) OVERRIDE; | 19 virtual void* AllocateUninitialized(size_t length) OVERRIDE; |
20 virtual void Free(void* data, size_t length) OVERRIDE; | 20 virtual void Free(void* data, size_t length) OVERRIDE; |
21 | 21 |
22 static ArrayBufferAllocator* SharedInstance(); | 22 static ArrayBufferAllocator* SharedInstance(); |
23 }; | 23 }; |
24 | 24 |
25 class ArrayBuffer { | 25 class ArrayBuffer { |
26 public: | 26 public: |
27 ArrayBuffer(); | |
27 explicit ArrayBuffer(v8::Isolate* isolate); | 28 explicit ArrayBuffer(v8::Isolate* isolate); |
28 ArrayBuffer(v8::Isolate* isolate, v8::Handle<v8::ArrayBuffer> buffer); | 29 ArrayBuffer(v8::Isolate* isolate, v8::Handle<v8::ArrayBuffer> buffer); |
29 ~ArrayBuffer(); | 30 ~ArrayBuffer(); |
30 | 31 |
31 void* bytes() const { return bytes_; } | 32 void* bytes() const { return bytes_; } |
32 size_t num_bytes() const { return num_bytes_; } | 33 size_t num_bytes() const { return num_bytes_; } |
33 | 34 |
34 v8::Isolate* isolate() const { return isolate_; } | |
35 | |
36 private: | 35 private: |
37 class Private; | 36 class Private; |
abarth-chromium
2013/11/27 00:20:10
If you're not going to move this into the header,
Aaron Boodman
2013/11/27 00:34:43
Good idea, but we need assign because Arguments::G
| |
38 | 37 |
39 v8::Isolate* isolate_; | |
40 scoped_refptr<Private> private_; | 38 scoped_refptr<Private> private_; |
41 void* bytes_; | 39 void* bytes_; |
42 size_t num_bytes_; | 40 size_t num_bytes_; |
43 }; | 41 }; |
44 | 42 |
45 template<> | 43 template<> |
46 struct Converter<ArrayBuffer> { | 44 struct Converter<ArrayBuffer> { |
47 static bool FromV8(v8::Handle<v8::Value> val, | 45 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, |
48 ArrayBuffer* out); | 46 ArrayBuffer* out); |
49 }; | 47 }; |
50 | 48 |
51 class ArrayBufferView { | 49 class ArrayBufferView { |
52 public: | 50 public: |
53 explicit ArrayBufferView(v8::Isolate* isolate); | 51 ArrayBufferView(); |
54 ArrayBufferView(v8::Isolate* isolate, v8::Handle<v8::ArrayBufferView> view); | 52 ArrayBufferView(v8::Isolate* isolate, v8::Handle<v8::ArrayBufferView> view); |
55 ~ArrayBufferView(); | 53 ~ArrayBufferView(); |
56 | 54 |
57 void* bytes() const { | 55 void* bytes() const { |
58 return static_cast<uint8_t*>(array_buffer_.bytes()) + offset_; | 56 return static_cast<uint8_t*>(array_buffer_.bytes()) + offset_; |
59 } | 57 } |
60 size_t num_bytes() const { return num_bytes_; } | 58 size_t num_bytes() const { return num_bytes_; } |
61 | 59 |
62 v8::Isolate* isolate() const { return array_buffer_.isolate(); } | |
63 | |
64 private: | 60 private: |
65 ArrayBuffer array_buffer_; | 61 ArrayBuffer array_buffer_; |
66 size_t offset_; | 62 size_t offset_; |
67 size_t num_bytes_; | 63 size_t num_bytes_; |
68 }; | 64 }; |
69 | 65 |
70 template<> | 66 template<> |
71 struct Converter<ArrayBufferView> { | 67 struct Converter<ArrayBufferView> { |
72 static bool FromV8(v8::Handle<v8::Value> val, | 68 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, |
73 ArrayBufferView* out); | 69 ArrayBufferView* out); |
74 }; | 70 }; |
75 | 71 |
76 } // namespace gin | 72 } // namespace gin |
77 | 73 |
78 #endif // GIN_ARRAY_BUFFER_H_ | 74 #endif // GIN_ARRAY_BUFFER_H_ |
OLD | NEW |