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 // Support for parsing binary sequences encoded as readable strings | 5 // Support for parsing binary sequences encoded as readable strings |
6 // or ".data" files. The input format is described here: | 6 // or ".data" files. The input format is described here: |
7 // mojo/public/cpp/bindings/tests/validation_test_input_parser.h | 7 // mojo/public/cpp/bindings/tests/validation_test_input_parser.h |
8 | 8 |
9 define("mojo/resources/validation_test_input_parser", [ | 9 (function() { |
10 "mojo/public/js/buffer" | |
11 ], function(buffer) { | |
12 | |
13 // Files and Lines represent the raw text from an input string | 10 // Files and Lines represent the raw text from an input string |
14 // or ".data" file. | 11 // or ".data" file. |
15 | 12 |
16 function InputError(message, line) { | 13 function InputError(message, line) { |
17 this.name = "InputError"; | 14 this.name = "InputError"; |
18 this.message = message; | 15 this.message = message; |
19 this.line = line; | 16 this.line = line; |
20 } | 17 } |
21 | 18 |
22 InputError.prototype.toString = function() { | 19 InputError.prototype.toString = function() { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 Item.prototype.isHandles = function() { | 128 Item.prototype.isHandles = function() { |
132 return this.type == 'handles'; | 129 return this.type == 'handles'; |
133 } | 130 } |
134 | 131 |
135 // A TestMessage represents the complete binary message loaded from an input | 132 // A TestMessage represents the complete binary message loaded from an input |
136 // string or ".data" file. The parseTestMessage() function below constructs | 133 // string or ".data" file. The parseTestMessage() function below constructs |
137 // a TestMessage from a File. | 134 // a TestMessage from a File. |
138 | 135 |
139 function TestMessage(byteLength) { | 136 function TestMessage(byteLength) { |
140 this.index = 0; | 137 this.index = 0; |
141 this.buffer = new buffer.Buffer(byteLength); | 138 this.buffer = new mojo.internal.Buffer(byteLength); |
142 this.distances = {}; | 139 this.distances = {}; |
143 this.handleCount = 0; | 140 this.handleCount = 0; |
144 } | 141 } |
145 | 142 |
146 function checkItemNumberValue(item, n, min, max) { | 143 function checkItemNumberValue(item, n, min, max) { |
147 if (n < min || n > max) | 144 if (n < min || n > max) |
148 throw new InputError('invalid item value', item.line); | 145 throw new InputError('invalid item value', item.line); |
149 } | 146 } |
150 | 147 |
151 TestMessage.prototype.addNumber = function(item) { | 148 TestMessage.prototype.addNumber = function(item) { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 | 283 |
287 if (messageLength != msg.index) | 284 if (messageLength != msg.index) |
288 throw new InputError('failed to compute message length'); | 285 throw new InputError('failed to compute message length'); |
289 var names = msg.unanchoredDistances(); | 286 var names = msg.unanchoredDistances(); |
290 if (names) | 287 if (names) |
291 throw new InputError('no anchors for ' + names, 0); | 288 throw new InputError('no anchors for ' + names, 0); |
292 | 289 |
293 return msg; | 290 return msg; |
294 } | 291 } |
295 | 292 |
296 var exports = {}; | 293 mojo.test = mojo.test || {}; |
297 exports.parseTestMessage = parseTestMessage; | 294 mojo.test.parseTestMessage = parseTestMessage; |
298 exports.InputError = InputError; | 295 mojo.test.InputError = InputError; |
299 return exports; | 296 })(); |
300 }); | |
OLD | NEW |