Chromium Code Reviews| Index: mojo/public/js/new_bindings/connector.js |
| diff --git a/mojo/public/js/new_bindings/connector.js b/mojo/public/js/new_bindings/connector.js |
| index 4d0627865337f19e231d69306e088054fe9ea36b..7a95d593690be549ad82856a52bb27000a8a9c6f 100644 |
| --- a/mojo/public/js/new_bindings/connector.js |
| +++ b/mojo/public/js/new_bindings/connector.js |
| @@ -2,15 +2,11 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -define("mojo/public/js/connector", [ |
| - "mojo/public/js/buffer", |
| - "mojo/public/js/codec", |
| - "mojo/public/js/core", |
| - "mojo/public/js/support", |
| -], function(buffer, codec, core, support) { |
| +(function() { |
| + var internal = mojoBindings.internal; |
| function Connector(handle) { |
| - if (!core.isHandle(handle)) |
| + if (!handle instanceof MojoHandle) |
|
Ken Rockot(use gerrit already)
2017/03/20 15:27:20
Unfortunately ! has higher precedence than instanc
yzshen1
2017/03/20 17:45:02
Oops. :P Now you know how little I know about JS.
|
| throw new Error("Connector: not a handle " + handle); |
| this.handle_ = handle; |
| this.dropWrites_ = false; |
| @@ -20,19 +16,18 @@ define("mojo/public/js/connector", [ |
| this.errorHandler_ = null; |
| if (handle) { |
| - this.readWatcher_ = support.watch(handle, |
| - core.HANDLE_SIGNAL_READABLE, |
| - this.readMore_.bind(this)); |
| + this.readWatcher_ = handle.watch({readable: true}, |
| + this.readMore_.bind(this)); |
| } |
| } |
| Connector.prototype.close = function() { |
| if (this.readWatcher_) { |
| - support.cancelWatch(this.readWatcher_); |
| + this.readWatcher_.cancel(); |
| this.readWatcher_ = null; |
| } |
| if (this.handle_ != null) { |
| - core.close(this.handle_); |
| + this.handle_.close(); |
| this.handle_ = null; |
| } |
| }; |
| @@ -44,17 +39,15 @@ define("mojo/public/js/connector", [ |
| if (this.dropWrites_) |
| return true; |
| - var result = core.writeMessage(this.handle_, |
| - new Uint8Array(message.buffer.arrayBuffer), |
| - message.handles, |
| - core.WRITE_MESSAGE_FLAG_NONE); |
| + var result = this.handle_.writeMessage( |
| + new Uint8Array(message.buffer.arrayBuffer), message.handles); |
| switch (result) { |
| - case core.RESULT_OK: |
| + case Mojo.RESULT_OK: |
| // The handles were successfully transferred, so we don't own them |
| // anymore. |
| message.handles = []; |
| break; |
| - case core.RESULT_FAILED_PRECONDITION: |
| + case Mojo.RESULT_FAILED_PRECONDITION: |
| // There's no point in continuing to write to this pipe since the other |
| // end is gone. Avoid writing any future messages. Hide write failures |
| // from the caller since we'd like them to continue consuming any |
| @@ -83,32 +76,29 @@ define("mojo/public/js/connector", [ |
| }; |
| Connector.prototype.waitForNextMessageForTesting = function() { |
| - var wait = core.wait(this.handle_, core.HANDLE_SIGNAL_READABLE); |
| - this.readMore_(wait.result); |
| + // TODO(yzshen): Change the tests that use this method. |
| + throw new Error("Not supported!"); |
|
Ken Rockot(use gerrit already)
2017/03/20 15:27:20
Just curious - are you planning to not implement w
yzshen1
2017/03/20 17:45:02
I am planning to make the tests that rely on this
|
| }; |
| Connector.prototype.readMore_ = function(result) { |
| for (;;) { |
| - var read = core.readMessage(this.handle_, |
| - core.READ_MESSAGE_FLAG_NONE); |
| + var read = this.handle_.readMessage(); |
| if (this.handle_ == null) // The connector has been closed. |
| return; |
| - if (read.result == core.RESULT_SHOULD_WAIT) |
| + if (read.result == Mojo.RESULT_SHOULD_WAIT) |
| return; |
| - if (read.result != core.RESULT_OK) { |
| + if (read.result != Mojo.RESULT_OK) { |
| this.error_ = true; |
| if (this.errorHandler_) |
| this.errorHandler_.onError(read.result); |
| return; |
| } |
| - var messageBuffer = new buffer.Buffer(read.buffer); |
| - var message = new codec.Message(messageBuffer, read.handles); |
| + var messageBuffer = new internal.Buffer(read.buffer); |
| + var message = new internal.Message(messageBuffer, read.handles); |
| if (this.incomingReceiver_) |
| this.incomingReceiver_.accept(message); |
| } |
| }; |
| - var exports = {}; |
| - exports.Connector = Connector; |
| - return exports; |
| -}); |
| + internal.Connector = Connector; |
| +})(); |