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

Unified Diff: mojo/public/js/validator.js

Issue 2744963002: Introduce InterfaceEndpointClient(IEC), InterfaceEndpointHandle and (Closed)
Patch Set: Throw the error with the string being the stack trace needed to debug layouts which don't output an… 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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/js/validator.js
diff --git a/mojo/public/js/validator.js b/mojo/public/js/validator.js
index fee742d0c1b1c2761f99bd4494e587e5237965fd..283546d4f18803fc7fd75cb4c165ce4f2886c0d4 100644
--- a/mojo/public/js/validator.js
+++ b/mojo/public/js/validator.js
@@ -28,6 +28,49 @@ 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;
+ this.callback = null;
+ }
+
+ 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 = null;
+ };
+
+ return {
+ getInstance: function() {
+ if (!gValidationErrorObserver) {
+ gValidationErrorObserver = new Observer();
+ }
+ return gValidationErrorObserver;
+ }
+ };
+ })();
+
+ function isTestingMode() {
+ return Boolean(gValidationErrorObserver);
+ }
+
+ function clearTestingMode() {
+ gValidationErrorObserver = null;
+ }
function isEnumClass(cls) {
return cls instanceof codec.Enum;
@@ -180,6 +223,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 +552,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;
});

Powered by Google App Engine
This is Rietveld 408576698