Chromium Code Reviews| 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/validator", [ | 5 define("mojo/public/js/validator", [ |
| 6 "mojo/public/js/codec", | 6 "mojo/public/js/codec", |
| 7 ], function(codec) { | 7 ], function(codec) { |
| 8 | 8 |
| 9 var validationError = { | 9 var validationError = { |
| 10 NONE: 'VALIDATION_ERROR_NONE', | 10 NONE: 'VALIDATION_ERROR_NONE', |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 | 203 |
| 204 if (version == 0 && (expectsResponse || isResponse)) | 204 if (version == 0 && (expectsResponse || isResponse)) |
| 205 return validationError.MESSAGE_HEADER_MISSING_REQUEST_ID; | 205 return validationError.MESSAGE_HEADER_MISSING_REQUEST_ID; |
| 206 | 206 |
| 207 if (isResponse && expectsResponse) | 207 if (isResponse && expectsResponse) |
| 208 return validationError.MESSAGE_HEADER_INVALID_FLAGS; | 208 return validationError.MESSAGE_HEADER_INVALID_FLAGS; |
| 209 | 209 |
| 210 return validationError.NONE; | 210 return validationError.NONE; |
| 211 }; | 211 }; |
| 212 | 212 |
| 213 Validator.prototype.validateMessageIsRequestWithoutResponse = function() { | |
| 214 if (this.message.isResponse() || this.message.expectsResponse()) { | |
| 215 return validationError.MESSAGE_HEADER_INVALID_FLAGS; | |
| 216 } | |
| 217 return validationError.NONE; | |
| 218 }; | |
| 219 | |
| 220 Validator.prototype.validateMessageIsRequestExpectingResponse = function() { | |
| 221 if (this.message.isResponse() || !this.message.expectsResponse()) { | |
| 222 return validationError.MESSAGE_HEADER_INVALID_FLAGS; | |
| 223 } | |
| 224 return validationError.NONE; | |
| 225 }; | |
| 226 | |
| 227 Validator.prototype.validateMessageIsResponse = function() { | |
| 228 if (this.message.expectsResponse() || !this.message.isResponse()) { | |
| 229 return validationError.MESSAGE_HEADER_INVALID_FLAGS; | |
| 230 } | |
| 231 return validationError.NONE; | |
| 232 }; | |
| 233 | |
| 234 Validator.prototype.validateMessageIsRequestWithoutResponse = function() { | |
|
yzshen1
2017/02/13 23:44:23
Please remove redundant ones.
wangjimmy
2017/02/14 00:06:06
Done.
| |
| 235 if (this.message.isResponse() || this.message.expectsResponse()) { | |
| 236 return validationError.MESSAGE_HEADER_INVALID_FLAGS; | |
| 237 } | |
| 238 return validationError.NONE; | |
| 239 }; | |
| 240 | |
| 241 Validator.prototype.validateMessageIsRequestExpectingResponse = function() { | |
| 242 if (this.message.isResponse() || !this.message.expectsResponse()) { | |
| 243 return validationError.MESSAGE_HEADER_INVALID_FLAGS; | |
| 244 } | |
| 245 return validationError.NONE; | |
| 246 }; | |
| 247 | |
| 248 Validator.prototype.validateMessageIsResponse = function() { | |
| 249 if (this.message.expectsResponse() || !this.message.isResponse()) { | |
| 250 return validationError.MESSAGE_HEADER_INVALID_FLAGS; | |
| 251 } | |
| 252 return validationError.NONE; | |
| 253 }; | |
| 254 | |
| 213 // Returns the message.buffer relative offset this pointer "points to", | 255 // Returns the message.buffer relative offset this pointer "points to", |
| 214 // NULL_MOJO_POINTER if the pointer represents a null, or JS null if the | 256 // NULL_MOJO_POINTER if the pointer represents a null, or JS null if the |
| 215 // pointer's value is not valid. | 257 // pointer's value is not valid. |
| 216 Validator.prototype.decodePointer = function(offset) { | 258 Validator.prototype.decodePointer = function(offset) { |
| 217 var pointerValue = this.message.buffer.getUint64(offset); | 259 var pointerValue = this.message.buffer.getUint64(offset); |
| 218 if (pointerValue === 0) | 260 if (pointerValue === 0) |
| 219 return NULL_MOJO_POINTER; | 261 return NULL_MOJO_POINTER; |
| 220 var bufferOffset = offset + pointerValue; | 262 var bufferOffset = offset + pointerValue; |
| 221 return Number.isSafeInteger(bufferOffset) ? bufferOffset : null; | 263 return Number.isSafeInteger(bufferOffset) ? bufferOffset : null; |
| 222 }; | 264 }; |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 482 return err; | 524 return err; |
| 483 } | 525 } |
| 484 return validationError.NONE; | 526 return validationError.NONE; |
| 485 }; | 527 }; |
| 486 | 528 |
| 487 var exports = {}; | 529 var exports = {}; |
| 488 exports.validationError = validationError; | 530 exports.validationError = validationError; |
| 489 exports.Validator = Validator; | 531 exports.Validator = Validator; |
| 490 return exports; | 532 return exports; |
| 491 }); | 533 }); |
| OLD | NEW |