Index: mojo/public/js/validator.js |
diff --git a/mojo/public/js/validator.js b/mojo/public/js/validator.js |
index cbf7521b5c3bfa4717a500ee53836342d4a6fc5b..48e36c61d224b2b8064af45b011014e6769a2865 100644 |
--- a/mojo/public/js/validator.js |
+++ b/mojo/public/js/validator.js |
@@ -24,10 +24,15 @@ define("mojo/public/js/validator", [ |
'VALIDATION_ERROR_DIFFERENT_SIZED_ARRAYS_IN_MAP', |
INVALID_UNION_SIZE: 'VALIDATION_ERROR_INVALID_UNION_SIZE', |
UNEXPECTED_NULL_UNION: 'VALIDATION_ERROR_UNEXPECTED_NULL_UNION', |
+ UNKNOWN_ENUM_VALUE: 'VALIDATION_ERROR_UNKNOWN_ENUM_VALUE', |
}; |
var NULL_MOJO_POINTER = "NULL_MOJO_POINTER"; |
+ function isEnumClass(cls) { |
+ return cls instanceof codec.Enum; |
+ } |
+ |
function isStringClass(cls) { |
return cls === codec.String || cls === codec.NullableString; |
} |
@@ -98,6 +103,13 @@ define("mojo/public/js/validator", [ |
return true; |
} |
+ Validator.prototype.validateEnum = function(offset, enumClass, nullable) { |
+ // Note: Assumes that enums are always 32 bits! But this matches |
+ // mojom::generate::pack::PackedField::GetSizeForKind, so it should be okay. |
+ var value = this.message.buffer.getInt32(offset); |
+ return enumClass.validate(value); |
+ } |
+ |
Validator.prototype.validateHandle = function(offset, nullable) { |
var index = this.message.buffer.getUint32(offset); |
@@ -347,6 +359,8 @@ define("mojo/public/js/validator", [ |
return this.validateArrayElements( |
elementsOffset, numElements, elementType.cls, nullable, |
expectedDimensionSizes, currentDimension + 1); |
+ if (isEnumClass(elementType)) |
+ return this.validateEnum(elementsOffset, elementType.cls, nullable); |
return validationError.NONE; |
} |