summaryrefslogtreecommitdiffstats
path: root/gin/array_buffer.h
diff options
context:
space:
mode:
authorabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-12 00:41:27 +0000
committerabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-12 00:41:27 +0000
commite87f312c1a96c95046034585561932bfa4aae2d4 (patch)
tree4b73e5ff782b9103ac9d282d8eda720c6f14adce /gin/array_buffer.h
parent23cd38f16a09b542cb40f9d69f5ba86aca868c8b (diff)
downloadchromium_src-e87f312c1a96c95046034585561932bfa4aae2d4.zip
chromium_src-e87f312c1a96c95046034585561932bfa4aae2d4.tar.gz
chromium_src-e87f312c1a96c95046034585561932bfa4aae2d4.tar.bz2
Begin implementing V8 bindings for Mojo
This CL contains the beginnings of JavaScript bindings for the core Mojo system. The approach in this CL is to bind as close to the "metal" as possible so as to self-host as much as possiblem in the VM. I've tried to avoid retaining any state on the C++ side of the bindings, but I didn't quite succeed because V8 requires embedders to retain state in order to access the memory that backs ArrayBuffers. In this CL, I've added some basic bindings for the symbols exported by core.h. Specifically, I've created bindings for CreateMessagePipe, Close, Wait, WaitMany, WriteMessage, and ReadMessage. R=aa@chromium.org, darin@chromium.org BUG=317398 Review URL: https://codereview.chromium.org/59153005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@234347 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gin/array_buffer.h')
-rw-r--r--gin/array_buffer.h45
1 files changed, 39 insertions, 6 deletions
diff --git a/gin/array_buffer.h b/gin/array_buffer.h
index b48a687..a645431 100644
--- a/gin/array_buffer.h
+++ b/gin/array_buffer.h
@@ -8,6 +8,7 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h" // For scoped_refptr only!
+#include "gin/converter.h"
#include "v8/include/v8.h"
namespace gin {
@@ -21,25 +22,57 @@ class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
static ArrayBufferAllocator* SharedInstance();
};
-class BufferView {
+class ArrayBuffer {
public:
- BufferView(v8::Isolate* isolate, v8::Handle<v8::ArrayBufferView> view);
- BufferView(v8::Isolate* isolate, v8::Handle<v8::ArrayBuffer> buffer);
- ~BufferView();
+ explicit ArrayBuffer(v8::Isolate* isolate);
+ ArrayBuffer(v8::Isolate* isolate, v8::Handle<v8::ArrayBuffer> buffer);
+ ~ArrayBuffer();
void* bytes() const { return bytes_; }
size_t num_bytes() const { return num_bytes_; }
+ v8::Isolate* isolate() const { return isolate_; }
+
private:
class Private;
- void Initialize(v8::Isolate* isolate, v8::Handle<v8::ArrayBuffer> buffer);
-
+ v8::Isolate* isolate_;
scoped_refptr<Private> private_;
void* bytes_;
size_t num_bytes_;
};
+template<>
+struct Converter<ArrayBuffer> {
+ static bool FromV8(v8::Handle<v8::Value> val,
+ ArrayBuffer* out);
+};
+
+class ArrayBufferView {
+ public:
+ explicit ArrayBufferView(v8::Isolate* isolate);
+ ArrayBufferView(v8::Isolate* isolate, v8::Handle<v8::ArrayBufferView> view);
+ ~ArrayBufferView();
+
+ void* bytes() const {
+ return static_cast<uint8_t*>(array_buffer_.bytes()) + offset_;
+ }
+ size_t num_bytes() const { return num_bytes_; }
+
+ v8::Isolate* isolate() const { return array_buffer_.isolate(); }
+
+ private:
+ ArrayBuffer array_buffer_;
+ size_t offset_;
+ size_t num_bytes_;
+};
+
+template<>
+struct Converter<ArrayBufferView> {
+ static bool FromV8(v8::Handle<v8::Value> val,
+ ArrayBufferView* out);
+};
+
} // namespace gin
#endif // GIN_ARRAY_BUFFER_H_