thanhlong203 / closure-library

Automatically exported from code.google.com/p/closure-library
0 stars 0 forks source link

proto2 getting unset field returns undefined (jsdoc only allows for null) #327

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The proto2 getField() accessors return undefined when called on an unset field. 
This behavior is expected by the unit tests:

http://code.google.com/p/closure-library/source/browse/trunk/closure/goog/proto2
/proto_test.html

 // Check non-set values.
 assertUndefined(message.getOptionalInt32());
 assertUndefined(message.getOptionalInt64());
 assertUndefined(message.getOptionalFloat());
 assertUndefined(message.getOptionalString());
 assertUndefined(message.getOptionalBytes());
 assertUndefined(message.getOptionalNestedMessage());
 assertUndefined(message.getOptionalNestedEnum());

However, the jsdoc type generated in the sample *.pb.js files, implies that 
null should be returned instead.

http://code.google.com/p/closure-library/source/browse/trunk/closure/goog/proto2
/test.pb.js

/**
 * Gets the value of the optional_int32 field.
 * @return {?number} The value.
 */
proto2.TestAllTypes.prototype.getOptionalInt32 = function() {
  return /** @type {?number} */ (this.get$Value(1));
};

I believe the best solution is return null (instead of undefined) when a field 
is unset.

Original issue reported on code.google.com by ahochhau...@gtempaccount.com on 16 May 2011 at 11:37

GoogleCodeExporter commented 8 years ago
This issue was closed by revision r1045.

Original comment by pall...@google.com on 16 Jun 2011 at 3:48

GoogleCodeExporter commented 8 years ago
Thanks!

Original comment by ahochhau...@gtempaccount.com on 16 Jun 2011 at 8:54