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/bindings/validator", [ | 5 define("mojo/public/js/bindings/validator", [ |
| 6 "mojo/public/js/bindings/codec", | 6 "mojo/public/js/bindings/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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 | 169 |
| 170 if (arrayOffset === NULL_MOJO_POINTER) | 170 if (arrayOffset === NULL_MOJO_POINTER) |
| 171 return nullable ? | 171 return nullable ? |
| 172 validationError.NONE : validationError.UNEXPECTED_NULL_POINTER; | 172 validationError.NONE : validationError.UNEXPECTED_NULL_POINTER; |
| 173 | 173 |
| 174 return this.validateArray( | 174 return this.validateArray( |
| 175 arrayOffset, elementSize, expectedElementCount, elementType); | 175 arrayOffset, elementSize, expectedElementCount, elementType); |
| 176 } | 176 } |
| 177 | 177 |
| 178 Validator.prototype.validateStructPointer = function( | 178 Validator.prototype.validateStructPointer = function( |
| 179 offset, structClass, nullable) { | 179 offset, structClass, nullable) { |
| 180 var structOffset = this.decodePointer(offset); | 180 var structOffset = this.decodePointer(offset); |
| 181 if (structOffset === null) | 181 if (structOffset === null) |
| 182 return validationError.ILLEGAL_POINTER; | 182 return validationError.ILLEGAL_POINTER; |
| 183 | 183 |
| 184 if (structOffset === NULL_MOJO_POINTER) | 184 if (structOffset === NULL_MOJO_POINTER) |
| 185 return nullable ? | 185 return nullable ? |
| 186 validationError.NONE : validationError.UNEXPECTED_NULL_POINTER; | 186 validationError.NONE : validationError.UNEXPECTED_NULL_POINTER; |
| 187 | 187 |
| 188 return structClass.validate(this, structOffset); | 188 return structClass.validate(this, structOffset); |
| 189 } | 189 } |
| 190 | 190 |
| 191 Validator.prototype.validateMapPointer = function( | |
|
yzshen1
2014/10/15 22:22:13
This probably misses fixed-size array dimensions,
hansmuller
2014/10/16 20:11:04
I've integrated the patch with the fixed-size arra
| |
| 192 offset, mapIsNullable, keyClass, valueClass, valueIsNullable) { | |
| 193 var structOffset = this.decodePointer(offset); | |
| 194 if (structOffset === null) | |
| 195 return validationError.ILLEGAL_POINTER; | |
| 196 | |
| 197 if (structOffset === NULL_MOJO_POINTER) | |
| 198 return mapIsNullable ? | |
| 199 validationError.NONE : validationError.UNEXPECTED_NULL_POINTER; | |
| 200 | |
| 201 var mapEncodedSize = codec.kStructHeaderSize + codec.kMapStructPayloadSize; | |
| 202 var err = this.validateStructHeader(structOffset, mapEncodedSize, 2); | |
| 203 if (err !== validationError.NONE) | |
| 204 return err; | |
| 205 | |
| 206 var keysArrayPointerOffset = structOffset + codec.kStructHeaderSize; | |
| 207 err = this.validateArrayPointer( | |
| 208 keysArrayPointerOffset, keyClass.encodedSize, 0, keyClass, false); | |
| 209 if (err !== validationError.NONE) | |
| 210 return err; | |
| 211 | |
| 212 var keysArrayOffset = this.decodePointer(keysArrayPointerOffset); | |
| 213 var keysArrayLength = this.message.buffer.getUint32(keysArrayOffset + 4); | |
| 214 | |
| 215 var valuesArrayPointerOffset = keysArrayPointerOffset + 8; | |
| 216 return this.validateArrayPointer(valuesArrayPointerOffset, | |
| 217 valueClass.encodedSize, | |
| 218 keysArrayLength, | |
|
yzshen1
2014/10/15 22:22:13
This will detect the validation failure, but with
hansmuller
2014/10/16 20:11:04
I've changed this to first validate the keys and v
| |
| 219 valueClass, | |
| 220 valueIsNullable); | |
| 221 } | |
| 222 | |
| 191 Validator.prototype.validateStringPointer = function(offset, nullable) { | 223 Validator.prototype.validateStringPointer = function(offset, nullable) { |
| 192 return this.validateArrayPointer( | 224 return this.validateArrayPointer( |
| 193 offset, codec.Uint8.encodedSize, 0, codec.Uint8, nullable); | 225 offset, codec.Uint8.encodedSize, 0, codec.Uint8, nullable); |
| 194 } | 226 } |
| 195 | 227 |
| 196 // Similar to Array_Data<T>::Validate() | 228 // Similar to Array_Data<T>::Validate() |
| 197 // mojo/public/cpp/bindings/lib/array_internal.h | 229 // mojo/public/cpp/bindings/lib/array_internal.h |
| 198 | 230 |
| 199 Validator.prototype.validateArray = | 231 Validator.prototype.validateArray = |
| 200 function (offset, elementSize, expectedElementCount, elementType) { | 232 function (offset, elementSize, expectedElementCount, elementType) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 return err; | 314 return err; |
| 283 } | 315 } |
| 284 return validationError.NONE; | 316 return validationError.NONE; |
| 285 } | 317 } |
| 286 | 318 |
| 287 var exports = {}; | 319 var exports = {}; |
| 288 exports.validationError = validationError; | 320 exports.validationError = validationError; |
| 289 exports.Validator = Validator; | 321 exports.Validator = Validator; |
| 290 return exports; | 322 return exports; |
| 291 }); | 323 }); |
| OLD | NEW |