OLD | NEW |
1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
4 // | 4 // |
5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
7 // met: | 7 // met: |
8 // | 8 // |
9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 'Only messages expected: ' + thing); | 87 'Only messages expected: ' + thing); |
88 var ctor = message.constructor; | 88 var ctor = message.constructor; |
89 var messageName = ctor.name || ctor.displayName; | 89 var messageName = ctor.name || ctor.displayName; |
90 var object = { | 90 var object = { |
91 '$name': messageName | 91 '$name': messageName |
92 }; | 92 }; |
93 for (var name in ctor.prototype) { | 93 for (var name in ctor.prototype) { |
94 var match = /^get([A-Z]\w*)/.exec(name); | 94 var match = /^get([A-Z]\w*)/.exec(name); |
95 if (match && name != 'getExtension' && | 95 if (match && name != 'getExtension' && |
96 name != 'getJsPbMessageId') { | 96 name != 'getJsPbMessageId') { |
97 var has = 'has' + match[1]; | 97 var val = thing[name](); |
98 if (!thing[has] || thing[has]()) { | 98 if (val != null) { |
99 var val = thing[name](); | |
100 object[jspb.debug.formatFieldName_(match[1])] = jspb.debug.dump_(val); | 99 object[jspb.debug.formatFieldName_(match[1])] = jspb.debug.dump_(val); |
101 } | 100 } |
102 } | 101 } |
103 } | 102 } |
104 if (COMPILED && thing['extensionObject_']) { | 103 if (COMPILED && thing['extensionObject_']) { |
105 object['$extensions'] = 'Recursive dumping of extensions not supported ' + | 104 object['$extensions'] = 'Recursive dumping of extensions not supported ' + |
106 'in compiled code. Switch to uncompiled or dump extension object ' + | 105 'in compiled code. Switch to uncompiled or dump extension object ' + |
107 'directly'; | 106 'directly'; |
108 return object; | 107 return object; |
109 } | 108 } |
(...skipping 22 matching lines...) Expand all Loading... |
132 * @param {string} name Name of the field. | 131 * @param {string} name Name of the field. |
133 * @return {string} | 132 * @return {string} |
134 * @private | 133 * @private |
135 */ | 134 */ |
136 jspb.debug.formatFieldName_ = function(name) { | 135 jspb.debug.formatFieldName_ = function(name) { |
137 // Name may be in TitleCase. | 136 // Name may be in TitleCase. |
138 return name.replace(/^[A-Z]/, function(c) { | 137 return name.replace(/^[A-Z]/, function(c) { |
139 return c.toLowerCase(); | 138 return c.toLowerCase(); |
140 }); | 139 }); |
141 }; | 140 }; |
OLD | NEW |