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

Side by Side Diff: gin/array_buffer.h

Issue 59153005: Begin implementing V8 bindings for Mojo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix skipped comment Created 7 years, 1 month 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
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" // For scoped_refptr only! 10 #include "base/memory/ref_counted.h" // For scoped_refptr only!
11 #include "gin/converter.h"
11 #include "v8/include/v8.h" 12 #include "v8/include/v8.h"
12 13
13 namespace gin { 14 namespace gin {
14 15
15 class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { 16 class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
16 public: 17 public:
17 virtual void* Allocate(size_t length) OVERRIDE; 18 virtual void* Allocate(size_t length) OVERRIDE;
18 virtual void* AllocateUninitialized(size_t length) OVERRIDE; 19 virtual void* AllocateUninitialized(size_t length) OVERRIDE;
19 virtual void Free(void* data, size_t length) OVERRIDE; 20 virtual void Free(void* data, size_t length) OVERRIDE;
20 21
21 static ArrayBufferAllocator* SharedInstance(); 22 static ArrayBufferAllocator* SharedInstance();
22 }; 23 };
23 24
24 class BufferView { 25 class ArrayBuffer {
25 public: 26 public:
26 BufferView(v8::Isolate* isolate, v8::Handle<v8::ArrayBufferView> view); 27 explicit ArrayBuffer(v8::Isolate* isolate);
27 BufferView(v8::Isolate* isolate, v8::Handle<v8::ArrayBuffer> buffer); 28 ArrayBuffer(v8::Isolate* isolate, v8::Handle<v8::ArrayBuffer> buffer);
28 ~BufferView(); 29 ~ArrayBuffer();
29 30
30 void* bytes() const { return bytes_; } 31 void* bytes() const { return bytes_; }
31 size_t num_bytes() const { return num_bytes_; } 32 size_t num_bytes() const { return num_bytes_; }
32 33
34 v8::Isolate* isolate() const { return isolate_; }
35
33 private: 36 private:
34 class Private; 37 class Private;
35 38
36 void Initialize(v8::Isolate* isolate, v8::Handle<v8::ArrayBuffer> buffer); 39 v8::Isolate* isolate_;
37
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 44
45 template<>
46 struct Converter<ArrayBuffer> {
47 static bool FromV8(v8::Handle<v8::Value> val,
48 ArrayBuffer* out);
49 };
50
51 class ArrayBufferView {
52 public:
53 explicit ArrayBufferView(v8::Isolate* isolate);
54 ArrayBufferView(v8::Isolate* isolate, v8::Handle<v8::ArrayBufferView> view);
55 ~ArrayBufferView();
56
57 void* bytes() const {
58 return static_cast<uint8_t*>(array_buffer_.bytes()) + offset_;
59 }
60 size_t num_bytes() const { return num_bytes_; }
61
62 v8::Isolate* isolate() const { return array_buffer_.isolate(); }
63
64 private:
65 ArrayBuffer array_buffer_;
66 size_t offset_;
67 size_t num_bytes_;
68 };
69
70 template<>
71 struct Converter<ArrayBufferView> {
72 static bool FromV8(v8::Handle<v8::Value> val,
73 ArrayBufferView* out);
74 };
75
43 } // namespace gin 76 } // namespace gin
44 77
45 #endif // GIN_ARRAY_BUFFER_H_ 78 #endif // GIN_ARRAY_BUFFER_H_
OLDNEW
« gin/arguments.cc ('K') | « gin/arguments.cc ('k') | gin/array_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698