Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: mojo/public/js/validator.js

Issue 2744963002: Introduce InterfaceEndpointClient(IEC), InterfaceEndpointHandle and (Closed)
Patch Set: Resolve Merge with new changes from master. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 10 matching lines...) Expand all
21 MESSAGE_HEADER_MISSING_REQUEST_ID: 21 MESSAGE_HEADER_MISSING_REQUEST_ID:
22 'VALIDATION_ERROR_MESSAGE_HEADER_MISSING_REQUEST_ID', 22 'VALIDATION_ERROR_MESSAGE_HEADER_MISSING_REQUEST_ID',
23 DIFFERENT_SIZED_ARRAYS_IN_MAP: 23 DIFFERENT_SIZED_ARRAYS_IN_MAP:
24 'VALIDATION_ERROR_DIFFERENT_SIZED_ARRAYS_IN_MAP', 24 'VALIDATION_ERROR_DIFFERENT_SIZED_ARRAYS_IN_MAP',
25 INVALID_UNION_SIZE: 'VALIDATION_ERROR_INVALID_UNION_SIZE', 25 INVALID_UNION_SIZE: 'VALIDATION_ERROR_INVALID_UNION_SIZE',
26 UNEXPECTED_NULL_UNION: 'VALIDATION_ERROR_UNEXPECTED_NULL_UNION', 26 UNEXPECTED_NULL_UNION: 'VALIDATION_ERROR_UNEXPECTED_NULL_UNION',
27 UNKNOWN_ENUM_VALUE: 'VALIDATION_ERROR_UNKNOWN_ENUM_VALUE', 27 UNKNOWN_ENUM_VALUE: 'VALIDATION_ERROR_UNKNOWN_ENUM_VALUE',
28 }; 28 };
29 29
30 var NULL_MOJO_POINTER = "NULL_MOJO_POINTER"; 30 var NULL_MOJO_POINTER = "NULL_MOJO_POINTER";
31 var gValidationErrorObserver = null;
32
33 function reportValidationError(error) {
34 if (gValidationErrorObserver) {
35 gValidationErrorObserver.setLastError(error);
36 }
37 }
38
39 var ValidationErrorObserverForTesting = (function() {
40 function Observer() {
41 this.lastError = validationError.NONE;
42 gValidationErrorObserver = this;
43 this.callback = undefined;
44 }
45
46 Observer.prototype.setLastError = function(error) {
47 this.lastError = error;
48 if (this.callback) {
49 this.callback(error);
50 }
51 };
52
53 Observer.prototype.reset = function(error) {
54 this.lastError = validationError.NONE;
55 this.callback = undefined;
56 };
57
58 return {
59 getInstance: function() {
60 if (!gValidationErrorObserver) {
61 gValidationErrorObserver = new Observer();
62 }
63 return gValidationErrorObserver;
64 }
65 };
66 })();
67
68 function isTestingMode() {
69 if (gValidationErrorObserver) {
70 return true;
71 }
72 return false;
73 }
74
31 75
32 function isEnumClass(cls) { 76 function isEnumClass(cls) {
33 return cls instanceof codec.Enum; 77 return cls instanceof codec.Enum;
34 } 78 }
35 79
36 function isStringClass(cls) { 80 function isStringClass(cls) {
37 return cls === codec.String || cls === codec.NullableString; 81 return cls === codec.String || cls === codec.NullableString;
38 } 82 }
39 83
40 function isHandleClass(cls) { 84 function isHandleClass(cls) {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 } 217 }
174 218
175 return validationError.NONE; 219 return validationError.NONE;
176 }; 220 };
177 221
178 Validator.prototype.isFieldInStructVersion = function(offset, fieldVersion) { 222 Validator.prototype.isFieldInStructVersion = function(offset, fieldVersion) {
179 var structVersion = this.message.buffer.getUint32(offset + 4); 223 var structVersion = this.message.buffer.getUint32(offset + 4);
180 return fieldVersion <= structVersion; 224 return fieldVersion <= structVersion;
181 }; 225 };
182 226
227 // TODO(wangjimmy): Add support for v2 messages.
183 Validator.prototype.validateMessageHeader = function() { 228 Validator.prototype.validateMessageHeader = function() {
184 229
185 var err = this.validateStructHeader(0, codec.kMessageHeaderSize); 230 var err = this.validateStructHeader(0, codec.kMessageHeaderSize);
186 if (err != validationError.NONE) 231 if (err != validationError.NONE)
187 return err; 232 return err;
188 233
189 var numBytes = this.message.getHeaderNumBytes(); 234 var numBytes = this.message.getHeaderNumBytes();
190 var version = this.message.getHeaderVersion(); 235 var version = this.message.getHeaderVersion();
191 236
192 var validVersionAndNumBytes = 237 var validVersionAndNumBytes =
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 var err = this.validateEnum(elementOffset, enumClass); 546 var err = this.validateEnum(elementOffset, enumClass);
502 if (err != validationError.NONE) 547 if (err != validationError.NONE)
503 return err; 548 return err;
504 } 549 }
505 return validationError.NONE; 550 return validationError.NONE;
506 }; 551 };
507 552
508 var exports = {}; 553 var exports = {};
509 exports.validationError = validationError; 554 exports.validationError = validationError;
510 exports.Validator = Validator; 555 exports.Validator = Validator;
556 exports.ValidationErrorObserverForTesting = ValidationErrorObserverForTesting;
557 exports.reportValidationError = reportValidationError;
558 exports.isTestingMode = isTestingMode;
511 return exports; 559 return exports;
512 }); 560 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698