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

Side by Side Diff: mojo/public/js/router.js

Issue 2618693004: Mojo JS bindings: make sure that console.log() could be used in the bindings. (Closed)
Patch Set: . Created 3 years, 11 months 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
« no previous file with comments | « ios/web/webui/resources/console.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/router", [ 5 define("mojo/public/js/router", [
6 "console",
6 "mojo/public/js/codec", 7 "mojo/public/js/codec",
7 "mojo/public/js/core", 8 "mojo/public/js/core",
8 "mojo/public/js/connector", 9 "mojo/public/js/connector",
9 "mojo/public/js/validator", 10 "mojo/public/js/validator",
10 ], function(codec, core, connector, validator) { 11 ], function(console, codec, core, connector, validator) {
11 12
12 var Connector = connector.Connector; 13 var Connector = connector.Connector;
13 var MessageReader = codec.MessageReader; 14 var MessageReader = codec.MessageReader;
14 var Validator = validator.Validator; 15 var Validator = validator.Validator;
15 16
16 function Router(handle, connectorFactory) { 17 function Router(handle, connectorFactory) {
17 if (!core.isHandle(handle)) 18 if (!core.isHandle(handle))
18 throw new Error("Router constructor: Not a handle"); 19 throw new Error("Router constructor: Not a handle");
19 if (connectorFactory === undefined) 20 if (connectorFactory === undefined)
20 connectorFactory = Connector; 21 connectorFactory = Connector;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 for (var i = 0; err === noError && i < this.payloadValidators_.length; ++i) 96 for (var i = 0; err === noError && i < this.payloadValidators_.length; ++i)
96 err = this.payloadValidators_[i](messageValidator); 97 err = this.payloadValidators_[i](messageValidator);
97 98
98 if (err == noError) 99 if (err == noError)
99 this.handleValidIncomingMessage_(message); 100 this.handleValidIncomingMessage_(message);
100 else 101 else
101 this.handleInvalidIncomingMessage_(message, err); 102 this.handleInvalidIncomingMessage_(message, err);
102 }; 103 };
103 104
104 Router.prototype.handleValidIncomingMessage_ = function(message) { 105 Router.prototype.handleValidIncomingMessage_ = function(message) {
106 console.log("heeeeeeeeeeeeeeeeeeeeeeeeeeeeeere");
105 if (this.testingController_) 107 if (this.testingController_)
106 return; 108 return;
107 109
108 if (message.expectsResponse()) { 110 if (message.expectsResponse()) {
109 if (this.incomingReceiver_) { 111 if (this.incomingReceiver_) {
110 this.incomingReceiver_.acceptWithResponder(message, this); 112 this.incomingReceiver_.acceptWithResponder(message, this);
111 } else { 113 } else {
112 // If we receive a request expecting a response when the client is not 114 // If we receive a request expecting a response when the client is not
113 // listening, then we have no choice but to tear down the pipe. 115 // listening, then we have no choice but to tear down the pipe.
114 this.close(); 116 this.close();
115 } 117 }
116 } else if (message.isResponse()) { 118 } else if (message.isResponse()) {
117 var reader = new MessageReader(message); 119 var reader = new MessageReader(message);
118 var requestID = reader.requestID; 120 var requestID = reader.requestID;
119 var completer = this.completers_.get(requestID); 121 var completer = this.completers_.get(requestID);
120 this.completers_.delete(requestID); 122 if (completer) {
121 completer.resolve(message); 123 this.completers_.delete(requestID);
124 completer.resolve(message);
125 } else {
126 console.log("Unexpected response with request ID: " + requestID);
127 }
122 } else { 128 } else {
123 if (this.incomingReceiver_) 129 if (this.incomingReceiver_)
124 this.incomingReceiver_.accept(message); 130 this.incomingReceiver_.accept(message);
125 } 131 }
126 }; 132 };
127 133
128 Router.prototype.handleInvalidIncomingMessage_ = function(message, error) { 134 Router.prototype.handleInvalidIncomingMessage_ = function(message, error) {
129 if (!this.testingController_) { 135 if (!this.testingController_) {
130 // TODO(yzshen): Consider logging and notifying the embedder. 136 // TODO(yzshen): Consider notifying the embedder.
131 // TODO(yzshen): This should also trigger connection error handler. 137 // TODO(yzshen): This should also trigger connection error handler.
132 // Consider making accept() return a boolean and let the connector deal 138 // Consider making accept() return a boolean and let the connector deal
133 // with this, as the C++ code does. 139 // with this, as the C++ code does.
140 console.log("Invalid message: " + validator.validationError[error]);
141
134 this.close(); 142 this.close();
135 return; 143 return;
136 } 144 }
137 145
138 this.testingController_.onInvalidIncomingMessage(error); 146 this.testingController_.onInvalidIncomingMessage(error);
139 }; 147 };
140 148
141 Router.prototype.handleConnectionError_ = function(result) { 149 Router.prototype.handleConnectionError_ = function(result) {
142 this.completers_.forEach(function(value) { 150 this.completers_.forEach(function(value) {
143 value.reject(result); 151 value.reject(result);
(...skipping 23 matching lines...) Expand all
167 RouterTestingController.prototype.onInvalidIncomingMessage = 175 RouterTestingController.prototype.onInvalidIncomingMessage =
168 function(error) { 176 function(error) {
169 if (this.invalidMessageHandler_) 177 if (this.invalidMessageHandler_)
170 this.invalidMessageHandler_(error); 178 this.invalidMessageHandler_(error);
171 }; 179 };
172 180
173 var exports = {}; 181 var exports = {};
174 exports.Router = Router; 182 exports.Router = Router;
175 return exports; 183 return exports;
176 }); 184 });
OLDNEW
« no previous file with comments | « ios/web/webui/resources/console.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698