| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 define("mojo/public/js/connector", [ | 5 define("mojo/public/js/connector", [ |
| 6 "mojo/public/js/buffer", | 6 "mojo/public/js/buffer", |
| 7 "mojo/public/js/codec", | 7 "mojo/public/js/codec", |
| 8 "mojo/public/js/core", | 8 "mojo/public/js/core", |
| 9 "mojo/public/js/support", | 9 "mojo/public/js/support", |
| 10 ], function(buffer, codec, core, support) { | 10 ], function(buffer, codec, core, support) { |
| 11 | 11 |
| 12 function Connector(handle) { | 12 function Connector(handle) { |
| 13 if (!core.isHandle(handle)) | 13 if (!core.isHandle(handle)) |
| 14 throw new Error("Connector: not a handle " + handle); | 14 throw new Error("Connector: not a handle " + handle); |
| 15 this.handle_ = handle; | 15 this.handle_ = handle; |
| 16 this.dropWrites_ = false; | 16 this.dropWrites_ = false; |
| 17 this.error_ = false; | 17 this.error_ = false; |
| 18 this.incomingReceiver_ = null; | 18 this.incomingReceiver_ = null; |
| 19 this.readWaitCookie_ = null; | 19 this.readWaitCookie_ = null; |
| 20 this.errorHandler_ = null; | 20 this.errorHandler_ = null; |
| 21 | 21 |
| 22 this.waitToReadMore_(); | 22 if (handle) |
| 23 this.waitToReadMore_(); |
| 23 } | 24 } |
| 24 | 25 |
| 25 Connector.prototype.close = function() { | 26 Connector.prototype.close = function() { |
| 26 if (this.readWaitCookie_) { | 27 if (this.readWaitCookie_) { |
| 27 support.cancelWait(this.readWaitCookie_); | 28 support.cancelWait(this.readWaitCookie_); |
| 28 this.readWaitCookie_ = null; | 29 this.readWaitCookie_ = null; |
| 29 } | 30 } |
| 30 if (this.handle_ != null) { | 31 if (this.handle_ != null) { |
| 31 core.close(this.handle_); | 32 core.close(this.handle_); |
| 32 this.handle_ = null; | 33 this.handle_ = null; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 | 123 |
| 123 TestConnector.prototype.deliverMessage = function() { | 124 TestConnector.prototype.deliverMessage = function() { |
| 124 this.readMore_(core.RESULT_OK); | 125 this.readMore_(core.RESULT_OK); |
| 125 } | 126 } |
| 126 | 127 |
| 127 var exports = {}; | 128 var exports = {}; |
| 128 exports.Connector = Connector; | 129 exports.Connector = Connector; |
| 129 exports.TestConnector = TestConnector; | 130 exports.TestConnector = TestConnector; |
| 130 return exports; | 131 return exports; |
| 131 }); | 132 }); |
| OLD | NEW |