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

Side by Side Diff: gin/array_buffer.h

Issue 654653005: Rewrite gin/function_template.h to use C++11 variadic templates. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Re-add assignment operator. Created 6 years, 2 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
« no previous file with comments | « no previous file | gin/array_buffer.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 #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 "gin/gin_export.h"
13 #include "v8/include/v8.h" 13 #include "v8/include/v8.h"
14 14
15 namespace gin { 15 namespace gin {
16 16
17 class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { 17 class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
18 public: 18 public:
19 virtual void* Allocate(size_t length) override; 19 virtual void* Allocate(size_t length) override;
20 virtual void* AllocateUninitialized(size_t length) override; 20 virtual void* AllocateUninitialized(size_t length) override;
21 virtual void Free(void* data, size_t length) override; 21 virtual void Free(void* data, size_t length) override;
22 22
23 GIN_EXPORT static ArrayBufferAllocator* SharedInstance(); 23 GIN_EXPORT static ArrayBufferAllocator* SharedInstance();
24 }; 24 };
25 25
26 class GIN_EXPORT ArrayBuffer { 26 class GIN_EXPORT ArrayBuffer {
27 public: 27 public:
28 ArrayBuffer(); 28 ArrayBuffer();
29 ArrayBuffer(const ArrayBuffer& other);
29 ArrayBuffer(v8::Isolate* isolate, v8::Handle<v8::ArrayBuffer> buffer); 30 ArrayBuffer(v8::Isolate* isolate, v8::Handle<v8::ArrayBuffer> buffer);
30 ~ArrayBuffer(); 31 ~ArrayBuffer();
31 ArrayBuffer& operator=(const ArrayBuffer& other); 32 ArrayBuffer& operator=(const ArrayBuffer& other);
32 33
33 void* bytes() const { return bytes_; } 34 void* bytes() const { return bytes_; }
34 size_t num_bytes() const { return num_bytes_; } 35 size_t num_bytes() const { return num_bytes_; }
35 36
36 private: 37 private:
37 class Private; 38 class Private;
38 39
39 scoped_refptr<Private> private_; 40 scoped_refptr<Private> private_;
40 void* bytes_; 41 void* bytes_;
41 size_t num_bytes_; 42 size_t num_bytes_;
42
43 DISALLOW_COPY(ArrayBuffer);
44 }; 43 };
45 44
46 template<> 45 template<>
47 struct GIN_EXPORT Converter<ArrayBuffer> { 46 struct GIN_EXPORT Converter<ArrayBuffer> {
48 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, 47 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
49 ArrayBuffer* out); 48 ArrayBuffer* out);
50 }; 49 };
51 50
52 class GIN_EXPORT ArrayBufferView { 51 class GIN_EXPORT ArrayBufferView {
53 public: 52 public:
54 ArrayBufferView(); 53 ArrayBufferView();
54 ArrayBufferView(const ArrayBufferView& other);
55 ArrayBufferView(v8::Isolate* isolate, v8::Handle<v8::ArrayBufferView> view); 55 ArrayBufferView(v8::Isolate* isolate, v8::Handle<v8::ArrayBufferView> view);
56 ~ArrayBufferView(); 56 ~ArrayBufferView();
57 ArrayBufferView& operator=(const ArrayBufferView& other); 57 ArrayBufferView& operator=(const ArrayBufferView& other);
58 58
59 void* bytes() const { 59 void* bytes() const {
60 return static_cast<uint8_t*>(array_buffer_.bytes()) + offset_; 60 return static_cast<uint8_t*>(array_buffer_.bytes()) + offset_;
61 } 61 }
62 size_t num_bytes() const { return num_bytes_; } 62 size_t num_bytes() const { return num_bytes_; }
63 63
64 private: 64 private:
65 ArrayBuffer array_buffer_; 65 ArrayBuffer array_buffer_;
66 size_t offset_; 66 size_t offset_;
67 size_t num_bytes_; 67 size_t num_bytes_;
68
69 DISALLOW_COPY(ArrayBufferView);
70 }; 68 };
71 69
72 template<> 70 template<>
73 struct GIN_EXPORT Converter<ArrayBufferView> { 71 struct GIN_EXPORT Converter<ArrayBufferView> {
74 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, 72 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
75 ArrayBufferView* out); 73 ArrayBufferView* out);
76 }; 74 };
77 75
78 } // namespace gin 76 } // namespace gin
79 77
80 #endif // GIN_ARRAY_BUFFER_H_ 78 #endif // GIN_ARRAY_BUFFER_H_
OLDNEW
« no previous file with comments | « no previous file | gin/array_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698