sirikata / protojs

Protobuf implementation in javascript

Home Page:http://sirikata.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

default value issue

SteveBaker opened this issue · comments

With this proto file:

 package Test;

 message MyTest {
        enum MyTestEnum {
                ZERO = 0 ;
                ONE  = 1 ;
        }
        optional MyTestEnum value = 2 [default = ZERO];
 }

...I get this JS output:

 "use strict";
 /** @suppress {duplicate}*/var Test;
 if (typeof(Test)=="undefined") {Test = {};}

 Test.MyTest = PROTO.Message("Test.MyTest",{
        MyTestEnum: PROTO.Enum("Test.MyTest.MyTestEnum",{
                ZERO :0,
                ONE :1  }),
        value: {
                options: {default_value:Test.MyTest.MyTestEnum.ZERO},
                multiplicity: PROTO.optional,
                type: function(){return Test.MyTest.MyTestEnum;},
                id: 2
        }});

...which produces (in Firefox):

 TypeError: Test.MyTest is undefined

...and in Chrome:

 Uncaught TypeError: Cannot read property 'MyTestEnum' of undefined 

...in both cases, the offending line is:

                  options: {default_value:Test.MyTest.MyTestEnum.ZERO},

...changing the default value from the enum "ZERO" to a literal value of "0" fixes the problem.

This .proto file works fine in at least three other protobuf systems - so I presume that it's legal.