| 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 |
| 213 // Returns the message.buffer relative offset this pointer "points to", | 234 // 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 | 235 // NULL_MOJO_POINTER if the pointer represents a null, or JS null if the |
| 215 // pointer's value is not valid. | 236 // pointer's value is not valid. |
| 216 Validator.prototype.decodePointer = function(offset) { | 237 Validator.prototype.decodePointer = function(offset) { |
| 217 var pointerValue = this.message.buffer.getUint64(offset); | 238 var pointerValue = this.message.buffer.getUint64(offset); |
| 218 if (pointerValue === 0) | 239 if (pointerValue === 0) |
| 219 return NULL_MOJO_POINTER; | 240 return NULL_MOJO_POINTER; |
| 220 var bufferOffset = offset + pointerValue; | 241 var bufferOffset = offset + pointerValue; |
| 221 return Number.isSafeInteger(bufferOffset) ? bufferOffset : null; | 242 return Number.isSafeInteger(bufferOffset) ? bufferOffset : null; |
| 222 }; | 243 }; |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 return err; | 503 return err; |
| 483 } | 504 } |
| 484 return validationError.NONE; | 505 return validationError.NONE; |
| 485 }; | 506 }; |
| 486 | 507 |
| 487 var exports = {}; | 508 var exports = {}; |
| 488 exports.validationError = validationError; | 509 exports.validationError = validationError; |
| 489 exports.Validator = Validator; | 510 exports.Validator = Validator; |
| 490 return exports; | 511 return exports; |
| 491 }); | 512 }); |
| OLD | NEW |