| 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.validateMessageIsResponse = function |
| 214 validateMessageIsResponse(message) { |
| 215 if (message.expectsResponse() || !message.isResponse()){ |
| 216 return validationError.MESSAGE_HEADER_INVALID_FLAGS; |
| 217 } |
| 218 return validationError.NONE; |
| 219 } |
| 220 |
| 213 // Returns the message.buffer relative offset this pointer "points to", | 221 // 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 | 222 // NULL_MOJO_POINTER if the pointer represents a null, or JS null if the |
| 215 // pointer's value is not valid. | 223 // pointer's value is not valid. |
| 216 Validator.prototype.decodePointer = function(offset) { | 224 Validator.prototype.decodePointer = function(offset) { |
| 217 var pointerValue = this.message.buffer.getUint64(offset); | 225 var pointerValue = this.message.buffer.getUint64(offset); |
| 218 if (pointerValue === 0) | 226 if (pointerValue === 0) |
| 219 return NULL_MOJO_POINTER; | 227 return NULL_MOJO_POINTER; |
| 220 var bufferOffset = offset + pointerValue; | 228 var bufferOffset = offset + pointerValue; |
| 221 return Number.isSafeInteger(bufferOffset) ? bufferOffset : null; | 229 return Number.isSafeInteger(bufferOffset) ? bufferOffset : null; |
| 222 }; | 230 }; |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 return err; | 490 return err; |
| 483 } | 491 } |
| 484 return validationError.NONE; | 492 return validationError.NONE; |
| 485 }; | 493 }; |
| 486 | 494 |
| 487 var exports = {}; | 495 var exports = {}; |
| 488 exports.validationError = validationError; | 496 exports.validationError = validationError; |
| 489 exports.Validator = Validator; | 497 exports.Validator = Validator; |
| 490 return exports; | 498 return exports; |
| 491 }); | 499 }); |
| OLD | NEW |