Index: mojo/public/tools/bindings/generators/js_templates/enum_definition.tmpl |
diff --git a/mojo/public/tools/bindings/generators/js_templates/enum_definition.tmpl b/mojo/public/tools/bindings/generators/js_templates/enum_definition.tmpl |
index 4ae0a9b5cdb4d3b72e8aab6d64cfc9173211421d..018ca0555496601d6f5f5b6a896c8a097168d27d 100644 |
--- a/mojo/public/tools/bindings/generators/js_templates/enum_definition.tmpl |
+++ b/mojo/public/tools/bindings/generators/js_templates/enum_definition.tmpl |
@@ -1,5 +1,5 @@ |
{%- macro enum_def(enum_name, enum) -%} |
- {{enum_name}} = {}; |
+{{enum_name}} = {}; |
{%- set prev_enum = 0 %} |
{%- for field in enum.fields %} |
{%- if field.value %} |
@@ -10,4 +10,25 @@ |
{{enum_name}}.{{field.name}} = {{enum_name}}.{{enum.fields[loop.index0 - 1].name}} + 1; |
{%- endif %} |
{%- endfor %} |
+ |
+{{enum_name}}.isKnownEnumValue = function(value) { |
+{%- if enum.fields %} |
+ switch (value) { |
Ken Rockot(use gerrit already)
2016/09/30 21:51:54
nit: 2 space indentation, not 4. Note, the jinja i
|
+{%- for enum_field in enum.fields|groupby('numeric_value') %} |
+ case {{enum_field[0]}}: |
+{%- endfor %} |
+ return true; |
+ } |
+{%- endif %} |
+ return false; |
+ }; |
+ |
+{{enum_name}}.validate = function(enumValue) { |
+ var isExtensible = {% if enum.extensible %}true{% else %}false{% endif %}; |
+ if (isExtensible || this.isKnownEnumValue(enumValue)) |
+ return validator.validationError.NONE; |
+ |
+ return validator.validationError.UNKNOWN_ENUM_VALUE; |
+ }; |
+ |
{%- endmacro %} |