summaryrefslogtreecommitdiffstats
path: root/mojo/apps
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-07 23:48:32 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-07 23:48:32 +0000
commitf8c8cc19338029b45a60bed95d85b7f44c7167be (patch)
tree9f469a4cb0141e17c8a985f09d3c23770f3756ac /mojo/apps
parent41bccff905b2e119360bf15c3a840fa931a16fd0 (diff)
downloadchromium_src-f8c8cc19338029b45a60bed95d85b7f44c7167be.zip
chromium_src-f8c8cc19338029b45a60bed95d85b7f44c7167be.tar.gz
chromium_src-f8c8cc19338029b45a60bed95d85b7f44c7167be.tar.bz2
Moves around js bindings related classes
The js files ended up in mojo/public/bindings/js The C++ code in mojo/bindings/js Adds a new target with the c++, mojo_js_bindings_lib I'm leaving the unit tests where they are for now, which is not ideal. Will move them in a followup patch. BUG=none TEST=none R=vtl@chromium.org TBR=jochen@chromium.org Review URL: https://codereview.chromium.org/189453003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255716 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/apps')
-rw-r--r--mojo/apps/js/bindings/codec.js459
-rw-r--r--mojo/apps/js/bindings/codec_unittests.js2
-rw-r--r--mojo/apps/js/bindings/connector.js97
-rw-r--r--mojo/apps/js/bindings/connector_unittests.js8
-rw-r--r--mojo/apps/js/bindings/core.cc150
-rw-r--r--mojo/apps/js/bindings/core.h22
-rw-r--r--mojo/apps/js/bindings/core_unittests.js2
-rw-r--r--mojo/apps/js/bindings/gl/context.h2
-rw-r--r--mojo/apps/js/bindings/gl/module.cc2
-rw-r--r--mojo/apps/js/bindings/handle.cc20
-rw-r--r--mojo/apps/js/bindings/handle.h23
-rw-r--r--mojo/apps/js/bindings/support.cc78
-rw-r--r--mojo/apps/js/bindings/support.h22
-rw-r--r--mojo/apps/js/bindings/threading.cc2
-rw-r--r--mojo/apps/js/bindings/waiting_callback.cc63
-rw-r--r--mojo/apps/js/bindings/waiting_callback.h49
-rw-r--r--mojo/apps/js/main.js4
-rw-r--r--mojo/apps/js/mojo_runner_delegate.cc4
-rw-r--r--mojo/apps/js/test/run_js_tests.cc2
19 files changed, 14 insertions, 997 deletions
diff --git a/mojo/apps/js/bindings/codec.js b/mojo/apps/js/bindings/codec.js
deleted file mode 100644
index 6160fea..0000000
--- a/mojo/apps/js/bindings/codec.js
+++ /dev/null
@@ -1,459 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-define("mojo/apps/js/bindings/codec", function() {
-
- // Memory -------------------------------------------------------------------
-
- function store8(memory, pointer, val) {
- memory[pointer] = val;
- }
-
- function store16(memory, pointer, val) {
- memory[pointer + 0] = val >> 0;
- memory[pointer + 1] = val >> 8;
- }
-
- function store32(memory, pointer, val) {
- memory[pointer + 0] = val >> 0;
- memory[pointer + 1] = val >> 8;
- memory[pointer + 2] = val >> 16;
- memory[pointer + 3] = val >> 24;
- }
-
- function store64(memory, pointer, val) {
- store32(memory, pointer, val);
- var high = (val / 0x10000) | 0;
- store32(memory, pointer + 4, high);
- }
-
- function load8(memory, pointer) {
- return memory[pointer];
- }
-
- function load16(memory, pointer) {
- return (memory[pointer + 0] << 0) +
- (memory[pointer + 1] << 8);
- }
-
- function load32(memory, pointer) {
- return (memory[pointer + 0] << 0) +
- (memory[pointer + 1] << 8) +
- (memory[pointer + 2] << 16) +
- (memory[pointer + 3] << 24);
- }
-
- var kAlignment = 8;
-
- function align(size) {
- return size + (kAlignment - (size % kAlignment)) % kAlignment;
- }
-
- // Buffer -------------------------------------------------------------------
-
- function Buffer(size) {
- this.memory = new Uint8Array(size);
- this.next = 0;
- }
-
- Buffer.prototype.alloc = function(size) {
- var pointer = this.next;
- this.next += size;
- if (this.next > this.memory.length) {
- var newSize = (1.5 * (this.memory.length + size)) | 0;
- this.grow(newSize);
- }
- return pointer;
- };
-
- Buffer.prototype.grow = function(size) {
- var newMemory = new Uint8Array(size);
- var oldMemory = this.memory;
- for (var i = 0; i < oldMemory.length; ++i)
- newMemory[i] = oldMemory[i];
- this.memory = newMemory;
- };
-
- Buffer.prototype.createViewOfAllocatedMemory = function() {
- return new Uint8Array(this.memory.buffer, 0, this.next);
- };
-
- // Constants ----------------------------------------------------------------
-
- var kArrayHeaderSize = 8;
- var kStructHeaderSize = 8;
- var kMessageHeaderSize = 8;
-
- // Decoder ------------------------------------------------------------------
-
- function Decoder(memory, handles, base) {
- this.memory = memory;
- this.handles = handles;
- this.base = base;
- this.next = base;
- this.viewU32 = new Uint32Array(
- this.memory.buffer, 0,
- Math.floor(this.memory.length / Uint32Array.BYTES_PER_ELEMENT));
- this.viewFloat = new Float32Array(
- this.memory.buffer, 0,
- Math.floor(this.memory.length / Float32Array.BYTES_PER_ELEMENT));
- }
-
- Decoder.prototype.skip = function(offset) {
- this.next += offset;
- };
-
- Decoder.prototype.read8 = function() {
- var result = load8(this.memory, this.next);
- this.next += 1;
- return result;
- };
-
- Decoder.prototype.read32 = function() {
- var result = this.viewU32[this.next / this.viewU32.BYTES_PER_ELEMENT];
- this.next += this.viewU32.BYTES_PER_ELEMENT;
- return result;
- };
-
- Decoder.prototype.read64 = function() {
- var low = this.read32();
- var high = this.read32();
- return low + high * 0x100000000;
- };
-
- Decoder.prototype.decodeFloat = function() {
- var result = this.viewFloat[this.next / this.viewFloat.BYTES_PER_ELEMENT];
- this.next += this.viewFloat.BYTES_PER_ELEMENT;
- return result;
- };
-
- Decoder.prototype.decodePointer = function() {
- // TODO(abarth): To correctly decode a pointer, we need to know the real
- // base address of the array buffer.
- var offsetPointer = this.next;
- var offset = this.read64();
- if (!offset)
- return 0;
- return offsetPointer + offset;
- };
-
- Decoder.prototype.decodeAndCreateDecoder = function() {
- return new Decoder(this.memory, this.handles, this.decodePointer());
- };
-
- Decoder.prototype.decodeHandle = function() {
- return this.handles[this.read32()];
- };
-
- Decoder.prototype.decodeString = function() {
- // TODO(abarth): We should really support UTF-8. We might want to
- // jump out of the VM to decode the string directly from the array
- // buffer using v8::String::NewFromUtf8.
- var numberOfBytes = this.read32();
- var numberOfElements = this.read32();
- var val = new Array(numberOfElements);
- var memory = this.memory;
- var base = this.next;
- for (var i = 0; i < numberOfElements; ++i) {
- val[i] = String.fromCharCode(memory[base + i] & 0x7F);
- }
- this.next += numberOfElements;
- return val.join('');
- };
-
- Decoder.prototype.decodeArray = function(cls) {
- var numberOfBytes = this.read32();
- var numberOfElements = this.read32();
- var val = new Array(numberOfElements);
- for (var i = 0; i < numberOfElements; ++i) {
- val[i] = cls.decode(this);
- }
- return val;
- };
-
- Decoder.prototype.decodeStructPointer = function(cls) {
- return cls.decode(this.decodeAndCreateDecoder());
- };
-
- Decoder.prototype.decodeArrayPointer = function(cls) {
- return this.decodeAndCreateDecoder().decodeArray(cls);
- };
-
- Decoder.prototype.decodeStringPointer = function() {
- return this.decodeAndCreateDecoder().decodeString();
- };
-
- // Encoder ------------------------------------------------------------------
-
- function Encoder(buffer, handles, base) {
- this.buffer = buffer;
- this.handles = handles;
- this.base = base;
- this.next = base;
- }
-
- Encoder.prototype.skip = function(offset) {
- this.next += offset;
- };
-
- Encoder.prototype.write8 = function(val) {
- store8(this.buffer.memory, this.next, val);
- this.next += 1;
- };
-
- Encoder.prototype.write32 = function(val) {
- store32(this.buffer.memory, this.next, val);
- this.next += 4;
- };
-
- Encoder.prototype.write64 = function(val) {
- store64(this.buffer.memory, this.next, val);
- this.next += 8;
- };
-
- Encoder.prototype.encodeFloat = function(val) {
- var floatBuffer = new Float32Array(1);
- floatBuffer[0] = val;
- var buffer = new Uint8Array(floatBuffer.buffer, 0);
- for (var i = 0; i < buffer.length; ++i)
- this.buffer.memory[this.next++] = buffer[i];
- };
-
- Encoder.prototype.encodePointer = function(pointer) {
- if (!pointer)
- return this.write64(0);
- // TODO(abarth): To correctly encode a pointer, we need to know the real
- // base address of the array buffer.
- var offset = pointer - this.next;
- this.write64(offset);
- };
-
- Encoder.prototype.createAndEncodeEncoder = function(size) {
- var pointer = this.buffer.alloc(align(size));
- this.encodePointer(pointer);
- return new Encoder(this.buffer, this.handles, pointer);
- };
-
- Encoder.prototype.encodeHandle = function(handle) {
- this.handles.push(handle);
- this.write32(this.handles.length - 1);
- };
-
- Encoder.prototype.encodeString = function(val) {
- var numberOfElements = val.length;
- var numberOfBytes = kArrayHeaderSize + numberOfElements;
- this.write32(numberOfBytes);
- this.write32(numberOfElements);
- // TODO(abarth): We should really support UTF-8. We might want to
- // jump out of the VM to encode the string directly from the array
- // buffer using v8::String::WriteUtf8.
- var memory = this.buffer.memory;
- var base = this.next;
- var len = val.length;
- for (var i = 0; i < len; ++i) {
- memory[base + i] = val.charCodeAt(i) & 0x7F;
- }
- this.next += len;
- };
-
- Encoder.prototype.encodeArray = function(cls, val) {
- var numberOfElements = val.length;
- var numberOfBytes = kArrayHeaderSize + cls.encodedSize * numberOfElements;
- this.write32(numberOfBytes);
- this.write32(numberOfElements);
- for (var i = 0; i < numberOfElements; ++i) {
- cls.encode(this, val[i]);
- }
- };
-
- Encoder.prototype.encodeStructPointer = function(cls, val) {
- var encoder = this.createAndEncodeEncoder(cls.encodedSize);
- cls.encode(encoder, val);
- };
-
- Encoder.prototype.encodeArrayPointer = function(cls, val) {
- var encodedSize = kArrayHeaderSize + cls.encodedSize * val.length;
- var encoder = this.createAndEncodeEncoder(encodedSize);
- encoder.encodeArray(cls, val);
- };
-
- Encoder.prototype.encodeStringPointer = function(val) {
- // TODO(abarth): This won't be right once we support UTF-8.
- var encodedSize = kArrayHeaderSize + val.length;
- var encoder = this.createAndEncodeEncoder(encodedSize);
- encoder.encodeString(val);
- };
-
- // Message ------------------------------------------------------------------
-
- function Message(memory, handles) {
- this.memory = memory;
- this.handles = handles;
- }
-
- // MessageBuilder -----------------------------------------------------------
-
- function MessageBuilder(messageName, payloadSize) {
- // Currently, we don't compute the payload size correctly ahead of time.
- // Instead, we overwrite this field at the end.
- var numberOfBytes = kMessageHeaderSize + payloadSize;
- this.buffer = new Buffer(numberOfBytes);
- this.handles = [];
- var encoder = this.createEncoder(kMessageHeaderSize);
- encoder.write32(numberOfBytes);
- encoder.write32(messageName);
- }
-
- MessageBuilder.prototype.createEncoder = function(size) {
- var pointer = this.buffer.alloc(size);
- return new Encoder(this.buffer, this.handles, pointer);
- }
-
- MessageBuilder.prototype.encodeStruct = function(cls, val) {
- cls.encode(this.createEncoder(cls.encodedSize), val);
- };
-
- MessageBuilder.prototype.finish = function() {
- // TODO(abarth): Rather than resizing the buffer at the end, we could
- // compute the size we need ahead of time, like we do in C++.
- var memory = this.buffer.createViewOfAllocatedMemory();
- store32(memory, 0, memory.length);
- var message = new Message(memory, this.handles);
- this.buffer = null;
- this.handles = null;
- this.encoder = null;
- return message;
- };
-
- // MessageReader ------------------------------------------------------------
-
- function MessageReader(message) {
- this.decoder = new Decoder(message.memory, message.handles, 0);
- this.payloadSize = this.decoder.read32() - kMessageHeaderSize;
- this.messageName = this.decoder.read32();
- }
-
- MessageReader.prototype.decodeStruct = function(cls) {
- return cls.decode(this.decoder);
- };
-
- // Built-in types -----------------------------------------------------------
-
- function Uint8() {
- }
-
- Uint8.encodedSize = 1;
-
- Uint8.decode = function(decoder) {
- return decoder.read8();
- };
-
- Uint8.encode = function(encoder, val) {
- encoder.write8(val);
- };
-
- function Uint16() {
- }
-
- Uint16.encodedSize = 2;
-
- Uint16.decode = function(decoder) {
- return decoder.read16();
- };
-
- Uint16.encode = function(encoder, val) {
- encoder.write16(val);
- };
-
- function Uint32() {
- }
-
- Uint32.encodedSize = 4;
-
- Uint32.decode = function(decoder) {
- return decoder.read32();
- };
-
- Uint32.encode = function(encoder, val) {
- encoder.write32(val);
- };
-
- function Uint64() {
- };
-
- Uint64.encodedSize = 8;
-
- Uint64.decode = function(decoder) {
- return decoder.read64();
- };
-
- Uint64.encode = function(encoder, val) {
- encoder.write64(val);
- };
-
- function PointerTo(cls) {
- this.cls = cls;
- };
-
- // TODO(abarth): Add missing types:
- // * String
- // * Float
- // * Double
- // * Signed integers
-
- PointerTo.prototype.encodedSize = 8;
-
- PointerTo.prototype.decode = function(decoder) {
- return this.cls.decode(decoder.decodeAndCreateDecoder());
- };
-
- PointerTo.prototype.encode = function(encoder, val) {
- var objectEncoder = encoder.createAndEncodeEncoder(this.cls.encodedSize);
- this.cls.encode(objectEncoder, val);
- };
-
- function ArrayOf(cls) {
- this.cls = cls;
- };
-
- ArrayOf.prototype.encodedSize = 8;
-
- ArrayOf.prototype.decode = function(decoder) {
- return decoder.decodeArrayPointer(self.cls);
- };
-
- ArrayOf.prototype.encode = function(encoder, val) {
- encoder.encodeArrayPointer(self.cls, val);
- };
-
- function Handle() {
- }
-
- Handle.encodedSize = 4;
-
- Handle.decode = function(decoder) {
- return decoder.decodeHandle();
- };
-
- Handle.encode = function(encoder, val) {
- encoder.encodeHandle(val);
- };
-
- var exports = {};
- exports.align = align;
- exports.Message = Message;
- exports.MessageBuilder = MessageBuilder;
- exports.MessageReader = MessageReader;
- exports.kArrayHeaderSize = kArrayHeaderSize;
- exports.kStructHeaderSize = kStructHeaderSize;
- exports.kMessageHeaderSize = kMessageHeaderSize;
- exports.Uint8 = Uint8;
- exports.Uint16 = Uint16;
- exports.Uint32 = Uint32;
- exports.Uint64 = Uint64;
- exports.PointerTo = PointerTo;
- exports.ArrayOf = ArrayOf;
- exports.Handle = Handle;
- return exports;
-});
diff --git a/mojo/apps/js/bindings/codec_unittests.js b/mojo/apps/js/bindings/codec_unittests.js
index 7fbea14..8e264d9 100644
--- a/mojo/apps/js/bindings/codec_unittests.js
+++ b/mojo/apps/js/bindings/codec_unittests.js
@@ -4,7 +4,7 @@
define([
"gin/test/expect",
- "mojo/apps/js/bindings/codec",
+ "mojo/public/bindings/js/codec",
"mojo/public/bindings/tests/sample_service.mojom",
], function(expect, codec, sample) {
testBar();
diff --git a/mojo/apps/js/bindings/connector.js b/mojo/apps/js/bindings/connector.js
deleted file mode 100644
index a9126c0..0000000
--- a/mojo/apps/js/bindings/connector.js
+++ /dev/null
@@ -1,97 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-define("mojo/apps/js/bindings/connector", [
- "mojo/apps/js/bindings/codec",
- "mojo/apps/js/bindings/core",
- "mojo/apps/js/bindings/support",
-], function(codec, core, support) {
-
- function Connector(handle) {
- this.handle_ = handle;
- this.error_ = false;
- this.incomingReceiver_ = null;
- this.readWaitCookie_ = null;
- }
-
- Connector.prototype.close = function() {
- if (this.readWaitCookie_) {
- support.cancelWait(this.readWaitCookie_);
- this.readWaitCookie_ = null;
- }
- if (this.handle_ != core.kInvalidHandle) {
- core.close(this.handle_);
- this.handle_ = core.kInvalidHandle;
- }
- };
-
- Connector.prototype.accept = function(message) {
- if (this.error_)
- return false;
- this.write_(message);
- return !this.error_;
- };
-
- Connector.prototype.setIncomingReceiver = function(receiver) {
- this.incomingReceiver_ = receiver;
- if (this.incomingReceiver_)
- this.waitToReadMore_();
- };
-
- Connector.prototype.write_ = function(message) {
- var result = core.writeMessage(this.handle_,
- message.memory,
- message.handles,
- core.WRITE_MESSAGE_FLAG_NONE);
- if (result != core.RESULT_OK) {
- this.error_ = true
- return;
- }
- // The handles were successfully transferred, so we don't own them anymore.
- message.handles = [];
- };
-
- Connector.prototype.waitToReadMore_ = function() {
- this.readWaitCookie_ = support.asyncWait(this.handle_,
- core.WAIT_FLAG_READABLE,
- this.readMore_.bind(this));
- };
-
- Connector.prototype.readMore_ = function(result) {
- for (;;) {
- var read = core.readMessage(this.handle_,
- core.READ_MESSAGE_FLAG_NONE);
- if (read.result == core.RESULT_SHOULD_WAIT) {
- this.waitToReadMore_();
- return;
- }
- if (read.result != core.RESULT_OK) {
- this.error_ = true;
- return;
- }
- // TODO(abarth): Should core.readMessage return a Uint8Array?
- var memory = new Uint8Array(read.buffer);
- var message = new codec.Message(memory, read.handles);
- this.incomingReceiver_.accept(message);
- }
- };
-
- function Connection(handle, localFactory, remoteFactory) {
- this.connector_ = new Connector(handle);
- this.remote = new remoteFactory(this.connector_);
- this.local = new localFactory(this.remote);
- this.connector_.setIncomingReceiver(this.local);
- }
-
- Connection.prototype.close = function() {
- this.connector_.close();
- this.connector_ = null;
- this.local = null;
- this.remote = null;
- };
-
- var exports = {};
- exports.Connection = Connection;
- return exports;
-});
diff --git a/mojo/apps/js/bindings/connector_unittests.js b/mojo/apps/js/bindings/connector_unittests.js
index c7c0c15..8777b6f 100644
--- a/mojo/apps/js/bindings/connector_unittests.js
+++ b/mojo/apps/js/bindings/connector_unittests.js
@@ -3,7 +3,7 @@
// found in the LICENSE file.
// Mock out the support module to avoid depending on the message loop.
-define("mojo/apps/js/bindings/support", function() {
+define("mojo/bindings/js/support", function() {
var waitingCallbacks = [];
function WaitCookie(id) {
@@ -46,9 +46,9 @@ define("mojo/apps/js/bindings/support", function() {
define([
"gin/test/expect",
- "mojo/apps/js/bindings/support",
- "mojo/apps/js/bindings/core",
- "mojo/apps/js/bindings/connector",
+ "mojo/bindings/js/support",
+ "mojo/bindings/js/core",
+ "mojo/public/bindings/js/connector",
"mojo/public/bindings/tests/sample_service.mojom",
], function(expect, mockSupport, core, connector, sample) {
diff --git a/mojo/apps/js/bindings/core.cc b/mojo/apps/js/bindings/core.cc
deleted file mode 100644
index fc7ac02..0000000
--- a/mojo/apps/js/bindings/core.cc
+++ /dev/null
@@ -1,150 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/apps/js/bindings/core.h"
-
-#include "base/bind.h"
-#include "base/logging.h"
-#include "gin/arguments.h"
-#include "gin/array_buffer.h"
-#include "gin/converter.h"
-#include "gin/dictionary.h"
-#include "gin/function_template.h"
-#include "gin/object_template_builder.h"
-#include "gin/per_isolate_data.h"
-#include "gin/public/wrapper_info.h"
-#include "mojo/apps/js/bindings/handle.h"
-
-namespace mojo {
-namespace js {
-
-namespace {
-
-gin::Dictionary CreateMessagePipe(const gin::Arguments& args) {
- MojoHandle handle0 = MOJO_HANDLE_INVALID;
- MojoHandle handle1 = MOJO_HANDLE_INVALID;
- MojoResult result = MojoCreateMessagePipe(&handle0, &handle1);
- CHECK(result == MOJO_RESULT_OK);
-
- gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate());
- dictionary.Set("handle0", handle0);
- dictionary.Set("handle1", handle1);
- return dictionary;
-}
-
-MojoResult WriteMessage(MojoHandle handle,
- const gin::ArrayBufferView& buffer,
- const std::vector<MojoHandle>& handles,
- MojoWriteMessageFlags flags) {
- return MojoWriteMessage(handle,
- buffer.bytes(),
- static_cast<uint32_t>(buffer.num_bytes()),
- handles.empty() ? NULL : handles.data(),
- static_cast<uint32_t>(handles.size()),
- flags);
-}
-
-gin::Dictionary ReadMessage(const gin::Arguments& args, MojoHandle handle,
- MojoReadMessageFlags flags) {
- uint32_t num_bytes = 0;
- uint32_t num_handles = 0;
- MojoResult result = MojoReadMessage(
- handle, NULL, &num_bytes, NULL, &num_handles, flags);
- if (result != MOJO_RESULT_RESOURCE_EXHAUSTED) {
- gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate());
- dictionary.Set("result", result);
- return dictionary;
- }
-
- v8::Handle<v8::ArrayBuffer> array_buffer =
- v8::ArrayBuffer::New(args.isolate(), num_bytes);
- std::vector<MojoHandle> handles(num_handles);
-
- gin::ArrayBuffer buffer;
- ConvertFromV8(args.isolate(), array_buffer, &buffer);
- CHECK(buffer.num_bytes() == num_bytes);
-
- result = MojoReadMessage(handle,
- buffer.bytes(),
- &num_bytes,
- handles.empty() ? NULL : handles.data(),
- &num_handles,
- flags);
-
- CHECK(buffer.num_bytes() == num_bytes);
- CHECK(handles.size() == num_handles);
-
- gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate());
- dictionary.Set("result", result);
- dictionary.Set("buffer", array_buffer);
- dictionary.Set("handles", handles);
- return dictionary;
-}
-
-gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin };
-
-} // namespace
-
-const char Core::kModuleName[] = "mojo/apps/js/bindings/core";
-
-v8::Local<v8::Value> Core::GetModule(v8::Isolate* isolate) {
- gin::PerIsolateData* data = gin::PerIsolateData::From(isolate);
- v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate(
- &g_wrapper_info);
-
- if (templ.IsEmpty()) {
- templ = gin::ObjectTemplateBuilder(isolate)
- .SetMethod("close", mojo::CloseRaw)
- .SetMethod("wait", mojo::Wait)
- .SetMethod("waitMany", mojo::WaitMany<std::vector<mojo::Handle>,
- std::vector<MojoWaitFlags> >)
- .SetMethod("createMessagePipe", CreateMessagePipe)
- .SetMethod("writeMessage", WriteMessage)
- .SetMethod("readMessage", ReadMessage)
-
- // TODO(vtl): Change name of "kInvalidHandle", now that there's no such
- // C++ constant?
- .SetValue("kInvalidHandle", mojo::Handle())
-
- .SetValue("RESULT_OK", MOJO_RESULT_OK)
- .SetValue("RESULT_CANCELLED", MOJO_RESULT_CANCELLED)
- .SetValue("RESULT_UNKNOWN", MOJO_RESULT_UNKNOWN)
- .SetValue("RESULT_INVALID_ARGUMENT", MOJO_RESULT_INVALID_ARGUMENT)
- .SetValue("RESULT_DEADLINE_EXCEEDED", MOJO_RESULT_DEADLINE_EXCEEDED)
- .SetValue("RESULT_NOT_FOUND", MOJO_RESULT_NOT_FOUND)
- .SetValue("RESULT_ALREADY_EXISTS", MOJO_RESULT_ALREADY_EXISTS)
- .SetValue("RESULT_PERMISSION_DENIED", MOJO_RESULT_PERMISSION_DENIED)
- .SetValue("RESULT_RESOURCE_EXHAUSTED", MOJO_RESULT_RESOURCE_EXHAUSTED)
- .SetValue("RESULT_FAILED_PRECONDITION", MOJO_RESULT_FAILED_PRECONDITION)
- .SetValue("RESULT_ABORTED", MOJO_RESULT_ABORTED)
- .SetValue("RESULT_OUT_OF_RANGE", MOJO_RESULT_OUT_OF_RANGE)
- .SetValue("RESULT_UNIMPLEMENTED", MOJO_RESULT_UNIMPLEMENTED)
- .SetValue("RESULT_INTERNAL", MOJO_RESULT_INTERNAL)
- .SetValue("RESULT_UNAVAILABLE", MOJO_RESULT_UNAVAILABLE)
- .SetValue("RESULT_DATA_LOSS", MOJO_RESULT_DATA_LOSS)
- .SetValue("RESULT_BUSY", MOJO_RESULT_BUSY)
- .SetValue("RESULT_SHOULD_WAIT", MOJO_RESULT_SHOULD_WAIT)
-
- .SetValue("DEADLINE_INDEFINITE", MOJO_DEADLINE_INDEFINITE)
-
- .SetValue("WAIT_FLAG_NONE", MOJO_WAIT_FLAG_NONE)
- .SetValue("WAIT_FLAG_READABLE", MOJO_WAIT_FLAG_READABLE)
- .SetValue("WAIT_FLAG_READABLE", MOJO_WAIT_FLAG_READABLE)
- .SetValue("WAIT_FLAG_EVERYTHING", MOJO_WAIT_FLAG_EVERYTHING)
-
- .SetValue("WRITE_MESSAGE_FLAG_NONE", MOJO_WRITE_MESSAGE_FLAG_NONE)
-
- .SetValue("READ_MESSAGE_FLAG_NONE", MOJO_READ_MESSAGE_FLAG_NONE)
- .SetValue("READ_MESSAGE_FLAG_MAY_DISCARD",
- MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)
- .Build();
-
- data->SetObjectTemplate(&g_wrapper_info, templ);
- }
-
- return templ->NewInstance();
-}
-
-} // namespace js
-} // namespace mojo
diff --git a/mojo/apps/js/bindings/core.h b/mojo/apps/js/bindings/core.h
deleted file mode 100644
index 3ff2828..0000000
--- a/mojo/apps/js/bindings/core.h
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MOJO_APPS_JS_BINDINGS_CORE_H_
-#define MOJO_APPS_JS_BINDINGS_CORE_H_
-
-#include "v8/include/v8.h"
-
-namespace mojo {
-namespace js {
-
-class Core {
- public:
- static const char kModuleName[];
- static v8::Local<v8::Value> GetModule(v8::Isolate* isolate);
-};
-
-} // namespace js
-} // namespace mojo
-
-#endif // MOJO_APPS_JS_BINDINGS_CORE_H_
diff --git a/mojo/apps/js/bindings/core_unittests.js b/mojo/apps/js/bindings/core_unittests.js
index 5b900a0..b085cd0 100644
--- a/mojo/apps/js/bindings/core_unittests.js
+++ b/mojo/apps/js/bindings/core_unittests.js
@@ -4,7 +4,7 @@
define([
"gin/test/expect",
- "mojo/apps/js/bindings/core",
+ "mojo/bindings/js/core",
], function(expect, core) {
runWithPipe(testNop);
runWithPipe(testReadAndWriteMessage);
diff --git a/mojo/apps/js/bindings/gl/context.h b/mojo/apps/js/bindings/gl/context.h
index d8daa82..7cf3979 100644
--- a/mojo/apps/js/bindings/gl/context.h
+++ b/mojo/apps/js/bindings/gl/context.h
@@ -12,7 +12,7 @@
#include "gin/public/wrapper_info.h"
#include "gin/runner.h"
#include "gin/wrappable.h"
-#include "mojo/apps/js/bindings/handle.h"
+#include "mojo/bindings/js/handle.h"
#include "mojo/public/gles2/gles2.h"
#include "v8/include/v8.h"
diff --git a/mojo/apps/js/bindings/gl/module.cc b/mojo/apps/js/bindings/gl/module.cc
index ef53e3d..413f22ed 100644
--- a/mojo/apps/js/bindings/gl/module.cc
+++ b/mojo/apps/js/bindings/gl/module.cc
@@ -10,7 +10,7 @@
#include "gin/per_isolate_data.h"
#include "gin/wrappable.h"
#include "mojo/apps/js/bindings/gl/context.h"
-#include "mojo/apps/js/bindings/handle.h"
+#include "mojo/bindings/js/handle.h"
namespace mojo {
namespace js {
diff --git a/mojo/apps/js/bindings/handle.cc b/mojo/apps/js/bindings/handle.cc
deleted file mode 100644
index 068be2d..0000000
--- a/mojo/apps/js/bindings/handle.cc
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/apps/js/bindings/handle.h"
-
-namespace gin {
-
-v8::Handle<v8::Value> Converter<mojo::Handle>::ToV8(v8::Isolate* isolate,
- const mojo::Handle& val) {
- return Converter<MojoHandle>::ToV8(isolate, val.value());
-}
-
-bool Converter<mojo::Handle>::FromV8(v8::Isolate* isolate,
- v8::Handle<v8::Value> val,
- mojo::Handle* out) {
- return Converter<MojoHandle>::FromV8(isolate, val, out->mutable_value());
-}
-
-} // namespace gin
diff --git a/mojo/apps/js/bindings/handle.h b/mojo/apps/js/bindings/handle.h
deleted file mode 100644
index 8bae517..0000000
--- a/mojo/apps/js/bindings/handle.h
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MOJO_APPS_JS_BINDINGS_HANDLE_H_
-#define MOJO_APPS_JS_BINDINGS_HANDLE_H_
-
-#include "gin/converter.h"
-#include "mojo/public/system/core_cpp.h"
-
-namespace gin {
-
-template<>
-struct Converter<mojo::Handle> {
- static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
- const mojo::Handle& val);
- static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
- mojo::Handle* out);
-};
-
-} // namespace gin
-
-#endif // MOJO_APPS_JS_BINDINGS_HANDLE_H_
diff --git a/mojo/apps/js/bindings/support.cc b/mojo/apps/js/bindings/support.cc
deleted file mode 100644
index bdb554b..0000000
--- a/mojo/apps/js/bindings/support.cc
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/apps/js/bindings/support.h"
-
-#include "base/bind.h"
-#include "gin/arguments.h"
-#include "gin/converter.h"
-#include "gin/function_template.h"
-#include "gin/object_template_builder.h"
-#include "gin/per_isolate_data.h"
-#include "gin/public/wrapper_info.h"
-#include "gin/wrappable.h"
-#include "mojo/apps/js/bindings/handle.h"
-#include "mojo/apps/js/bindings/waiting_callback.h"
-#include "mojo/public/environment/default_async_waiter.h"
-#include "mojo/public/system/core_cpp.h"
-
-namespace mojo {
-namespace js {
-
-namespace {
-
-WaitingCallback* AsyncWait(const gin::Arguments& args, mojo::Handle handle,
- MojoWaitFlags flags,
- v8::Handle<v8::Function> callback) {
- gin::Handle<WaitingCallback> waiting_callback =
- WaitingCallback::Create(args.isolate(), callback);
-
- MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter();
- MojoAsyncWaitID wait_id = waiter->AsyncWait(
- waiter,
- handle.value(),
- flags,
- MOJO_DEADLINE_INDEFINITE,
- &WaitingCallback::CallOnHandleReady,
- waiting_callback.get());
-
- waiting_callback->set_wait_id(wait_id);
-
- return waiting_callback.get();
-}
-
-void CancelWait(WaitingCallback* waiting_callback) {
- if (!waiting_callback->wait_id())
- return;
-
- MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter();
- waiter->CancelWait(waiter, waiting_callback->wait_id());
- waiting_callback->set_wait_id(0);
-}
-
-gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin };
-
-} // namespace
-
-const char Support::kModuleName[] = "mojo/apps/js/bindings/support";
-
-v8::Local<v8::Value> Support::GetModule(v8::Isolate* isolate) {
- gin::PerIsolateData* data = gin::PerIsolateData::From(isolate);
- v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate(
- &g_wrapper_info);
-
- if (templ.IsEmpty()) {
- templ = gin::ObjectTemplateBuilder(isolate)
- .SetMethod("asyncWait", AsyncWait)
- .SetMethod("cancelWait", CancelWait)
- .Build();
-
- data->SetObjectTemplate(&g_wrapper_info, templ);
- }
-
- return templ->NewInstance();
-}
-
-} // namespace js
-} // namespace mojo
diff --git a/mojo/apps/js/bindings/support.h b/mojo/apps/js/bindings/support.h
deleted file mode 100644
index 4f0a4ef..0000000
--- a/mojo/apps/js/bindings/support.h
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MOJO_APPS_JS_BINDINGS_SUPPORT_H_
-#define MOJO_APPS_JS_BINDINGS_SUPPORT_H_
-
-#include "v8/include/v8.h"
-
-namespace mojo {
-namespace js {
-
-class Support {
- public:
- static const char kModuleName[];
- static v8::Local<v8::Value> GetModule(v8::Isolate* isolate);
-};
-
-} // namespace js
-} // namespace mojo
-
-#endif // MOJO_APPS_JS_BINDINGS_SUPPORT_H_
diff --git a/mojo/apps/js/bindings/threading.cc b/mojo/apps/js/bindings/threading.cc
index 4b10bff..64e32fc 100644
--- a/mojo/apps/js/bindings/threading.cc
+++ b/mojo/apps/js/bindings/threading.cc
@@ -7,7 +7,7 @@
#include "base/message_loop/message_loop.h"
#include "gin/object_template_builder.h"
#include "gin/per_isolate_data.h"
-#include "mojo/apps/js/bindings/handle.h"
+#include "mojo/bindings/js/handle.h"
namespace mojo {
namespace apps {
diff --git a/mojo/apps/js/bindings/waiting_callback.cc b/mojo/apps/js/bindings/waiting_callback.cc
deleted file mode 100644
index 9234316..0000000
--- a/mojo/apps/js/bindings/waiting_callback.cc
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "mojo/apps/js/bindings/waiting_callback.h"
-
-#include "gin/per_context_data.h"
-
-namespace mojo {
-namespace js {
-
-namespace {
-
-v8::Handle<v8::String> GetHiddenPropertyName(v8::Isolate* isolate) {
- return gin::StringToSymbol(isolate, "::mojo::js::WaitingCallback");
-}
-
-} // namespace
-
-gin::WrapperInfo WaitingCallback::kWrapperInfo = { gin::kEmbedderNativeGin };
-
-WaitingCallback::WaitingCallback(v8::Isolate* isolate,
- v8::Handle<v8::Function> callback)
- : wait_id_() {
- v8::Handle<v8::Context> context = isolate->GetCurrentContext();
- runner_ = gin::PerContextData::From(context)->runner()->GetWeakPtr();
- GetWrapper(isolate)->SetHiddenValue(GetHiddenPropertyName(isolate), callback);
-}
-
-WaitingCallback::~WaitingCallback() {
- DCHECK(!wait_id_) << "Waiting callback was destroyed before being cancelled.";
-}
-
-gin::Handle<WaitingCallback> WaitingCallback::Create(
- v8::Isolate* isolate, v8::Handle<v8::Function> callback) {
- return gin::CreateHandle(isolate, new WaitingCallback(isolate, callback));
-}
-
-// static
-void WaitingCallback::CallOnHandleReady(void* closure, MojoResult result) {
- static_cast<WaitingCallback*>(closure)->OnHandleReady(result);
-}
-
-void WaitingCallback::OnHandleReady(MojoResult result) {
- wait_id_ = 0;
-
- if (!runner_)
- return;
-
- gin::Runner::Scope scope(runner_.get());
- v8::Isolate* isolate = runner_->GetContextHolder()->isolate();
-
- v8::Handle<v8::Value> hidden_value =
- GetWrapper(isolate)->GetHiddenValue(GetHiddenPropertyName(isolate));
- v8::Handle<v8::Function> callback;
- CHECK(gin::ConvertFromV8(isolate, hidden_value, &callback));
-
- v8::Handle<v8::Value> args[] = { gin::ConvertToV8(isolate, result) };
- runner_->Call(callback, runner_->global(), 1, args);
-}
-
-} // namespace js
-} // namespace mojo
diff --git a/mojo/apps/js/bindings/waiting_callback.h b/mojo/apps/js/bindings/waiting_callback.h
deleted file mode 100644
index c841028..0000000
--- a/mojo/apps/js/bindings/waiting_callback.h
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MOJO_APPS_JS_BINDINGS_WAITING_CALLBACK_H_
-#define MOJO_APPS_JS_BINDINGS_WAITING_CALLBACK_H_
-
-#include "gin/handle.h"
-#include "gin/runner.h"
-#include "gin/wrappable.h"
-#include "mojo/public/system/async_waiter.h"
-
-namespace mojo {
-namespace js {
-
-class WaitingCallback : public gin::Wrappable<WaitingCallback> {
- public:
- static gin::WrapperInfo kWrapperInfo;
-
- static gin::Handle<WaitingCallback> Create(
- v8::Isolate* isolate, v8::Handle<v8::Function> callback);
-
- MojoAsyncWaitID wait_id() const {
- return wait_id_;
- }
-
- void set_wait_id(MojoAsyncWaitID wait_id) {
- wait_id_ = wait_id;
- }
-
- // MojoAsyncWaitCallback
- static void CallOnHandleReady(void* closure, MojoResult result);
-
- private:
- WaitingCallback(v8::Isolate* isolate, v8::Handle<v8::Function> callback);
- virtual ~WaitingCallback();
-
- void OnHandleReady(MojoResult result);
-
- base::WeakPtr<gin::Runner> runner_;
- MojoAsyncWaitID wait_id_;
-
- DISALLOW_COPY_AND_ASSIGN(WaitingCallback);
-};
-
-} // namespace js
-} // namespace mojo
-
-#endif // MOJO_APPS_JS_BINDINGS_WAITING_CALLBACK_H_
diff --git a/mojo/apps/js/main.js b/mojo/apps/js/main.js
index 55bab29..355fb97 100644
--- a/mojo/apps/js/main.js
+++ b/mojo/apps/js/main.js
@@ -6,8 +6,8 @@ define([
'console',
'monotonic_clock',
'timer',
- 'mojo/apps/js/bindings/connector',
- 'mojo/apps/js/bindings/core',
+ 'mojo/public/bindings/js/connector',
+ 'mojo/bindings/js/core',
'mojo/apps/js/bindings/gl',
'mojo/apps/js/bindings/threading',
'mojo/services/native_viewport/native_viewport.mojom',
diff --git a/mojo/apps/js/mojo_runner_delegate.cc b/mojo/apps/js/mojo_runner_delegate.cc
index 58cb333..2a6c1bd 100644
--- a/mojo/apps/js/mojo_runner_delegate.cc
+++ b/mojo/apps/js/mojo_runner_delegate.cc
@@ -11,11 +11,11 @@
#include "gin/modules/module_registry.h"
#include "gin/modules/timer.h"
#include "gin/try_catch.h"
-#include "mojo/apps/js/bindings/core.h"
#include "mojo/apps/js/bindings/gl/module.h"
#include "mojo/apps/js/bindings/monotonic_clock.h"
-#include "mojo/apps/js/bindings/support.h"
#include "mojo/apps/js/bindings/threading.h"
+#include "mojo/bindings/js/core.h"
+#include "mojo/bindings/js/support.h"
namespace mojo {
namespace apps {
diff --git a/mojo/apps/js/test/run_js_tests.cc b/mojo/apps/js/test/run_js_tests.cc
index 30c2ea5..872e5e3 100644
--- a/mojo/apps/js/test/run_js_tests.cc
+++ b/mojo/apps/js/test/run_js_tests.cc
@@ -9,9 +9,9 @@
#include "gin/modules/timer.h"
#include "gin/test/file_runner.h"
#include "gin/test/gtest.h"
-#include "mojo/apps/js/bindings/core.h"
#include "mojo/apps/js/bindings/monotonic_clock.h"
#include "mojo/apps/js/bindings/threading.h"
+#include "mojo/bindings/js/core.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace mojo {