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

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

Issue 2595563004: Mojo JS bindings: fix enum array validation. (Closed)
Patch Set: . Created 4 years 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 1328c33048b5d78a4a184073fb740437be47ab3e..9f2b7cf4db141f3eab218b4e79ce89e69e9c4fa2 100644
--- a/mojo/public/js/validator.js
+++ b/mojo/public/js/validator.js
@@ -109,7 +109,7 @@ define("mojo/public/js/validator", [
return true;
};
- Validator.prototype.validateEnum = function(offset, enumClass, nullable) {
+ Validator.prototype.validateEnum = function(offset, enumClass) {
// 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);
@@ -397,7 +397,8 @@ define("mojo/public/js/validator", [
elementsOffset, numElements, elementType.cls, nullable,
expectedDimensionSizes, currentDimension + 1);
if (isEnumClass(elementType))
- return this.validateEnum(elementsOffset, elementType.cls, nullable);
+ return this.validateEnumElements(elementsOffset, numElements,
+ elementType.cls);
return validationError.NONE;
};
@@ -471,6 +472,18 @@ define("mojo/public/js/validator", [
return validationError.NONE;
};
+ Validator.prototype.validateEnumElements =
+ function(offset, numElements, enumClass) {
+ var elementSize = codec.Enum.prototype.encodedSize;
+ for (var i = 0; i < numElements; i++) {
+ var elementOffset = offset + i * elementSize;
+ var err = this.validateEnum(elementOffset, enumClass);
+ if (err != validationError.NONE)
+ return err;
+ }
+ return validationError.NONE;
+ };
+
var exports = {};
exports.validationError = validationError;
exports.Validator = Validator;

Powered by Google App Engine
This is Rietveld 408576698