Chromium Code Reviews| Index: mojo/public/js/validator.js |
| diff --git a/mojo/public/js/validator.js b/mojo/public/js/validator.js |
| index fee742d0c1b1c2761f99bd4494e587e5237965fd..6a9ed5065c4f07d07a0e66e9f4c614e31c0e94b7 100644 |
| --- a/mojo/public/js/validator.js |
| +++ b/mojo/public/js/validator.js |
| @@ -28,6 +28,53 @@ define("mojo/public/js/validator", [ |
| }; |
| var NULL_MOJO_POINTER = "NULL_MOJO_POINTER"; |
| + var gValidationErrorObserver = null; |
| + |
| + function reportValidationError(error) { |
| + if (gValidationErrorObserver) { |
| + gValidationErrorObserver.setLastError(error); |
| + } |
| + } |
| + |
| + var ValidationErrorObserverForTesting = (function() { |
| + function Observer() { |
| + this.lastError = validationError.NONE; |
| + gValidationErrorObserver = this; |
|
yzshen1
2017/03/24 21:20:13
This line is redundant (please see line 61).
wangjimmy
2017/03/27 16:51:28
Done.
|
| + this.callback = undefined; |
| + } |
| + |
| + Observer.prototype.setLastError = function(error) { |
| + this.lastError = error; |
| + if (this.callback) { |
| + this.callback(error); |
| + } |
| + }; |
| + |
| + Observer.prototype.reset = function(error) { |
| + this.lastError = validationError.NONE; |
| + this.callback = undefined; |
| + }; |
| + |
| + return { |
| + getInstance: function() { |
| + if (!gValidationErrorObserver) { |
| + gValidationErrorObserver = new Observer(); |
| + } |
| + return gValidationErrorObserver; |
| + } |
| + }; |
| + })(); |
| + |
| + function isTestingMode() { |
| + if (gValidationErrorObserver) { |
|
yzshen1
2017/03/24 21:20:13
Could we do "return !!gValidationErrorObserver"?
wangjimmy
2017/03/27 16:51:28
Done. I decided to do "return Boolean(gValidationE
|
| + return true; |
| + } |
| + return false; |
| + } |
| + |
| + function clearTestingMode() { |
| + gValidationErrorObserver = null; |
| + } |
| function isEnumClass(cls) { |
| return cls instanceof codec.Enum; |
| @@ -180,6 +227,7 @@ define("mojo/public/js/validator", [ |
| return fieldVersion <= structVersion; |
| }; |
| + // TODO(wangjimmy): Add support for v2 messages. |
| Validator.prototype.validateMessageHeader = function() { |
| var err = this.validateStructHeader(0, codec.kMessageHeaderSize); |
| @@ -508,5 +556,9 @@ define("mojo/public/js/validator", [ |
| var exports = {}; |
| exports.validationError = validationError; |
| exports.Validator = Validator; |
| + exports.ValidationErrorObserverForTesting = ValidationErrorObserverForTesting; |
| + exports.reportValidationError = reportValidationError; |
| + exports.isTestingMode = isTestingMode; |
| + exports.clearTestingMode = clearTestingMode; |
| return exports; |
| }); |