Skip to content

Commit e22f88e

Browse files
author
Minggang Wang
committed
Fix the error when providing an empty array to assign the property
When assigning a value to an property of the message, whose type is array, we should use the fill() method instead of copy(), because the copy() method is designed to copy value from another wrapper, not an array. Fix #235
1 parent 99bd8dc commit e22f88e

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

lib/message_translator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function copyMsgObject(msg, obj) {
4444
// 3. Assign
4545
msg[i].fill(msgArray);
4646
} else {
47-
// It's an array of primitive-type elements
47+
// It's an array of primitive-type elements or an empty array
4848
msg[i] = obj[i];
4949
}
5050
} else {

rosidl_gen/templates/message.dot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ class {{=objectWrapper}} {
393393
{{?? field.type.isArray && field.type.isPrimitiveType}}
394394
this._{{=field.name}}Array = value;
395395
{{?? field.type.isArray && !field.type.isPrimitiveType}}
396-
this._wrapperFields.{{=field.name}}.copy(value);
396+
this._wrapperFields.{{=field.name}}.fill(value);
397397
{{?? !field.type.isPrimitiveType && !field.type.isArray}}
398398
this._wrapperFields.{{=field.name}}.copy(value);
399399
{{?? !field.type.isArray && field.type.type === 'string' && it.spec.msgName !== 'String'}}
@@ -580,7 +580,7 @@ class {{=arrayWrapper}} {
580580
}
581581

582582
copy(other) {
583-
if (! other instanceof {{=arrayWrapper}}) {
583+
if (! (other instanceof {{=arrayWrapper}})) {
584584
throw new TypeError('Invalid argument: should provide "{{=arrayWrapper}}".');
585585
}
586586

test/test-array-data.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,13 @@ describe('rclnodejs message communication', function() {
192192
values: [
193193
{
194194
header: {stamp: {sec: 11223, nanosec: 44556}, frame_id: 'f001', },
195-
height: 240, width: 320, fields: [{}], is_bigendian: false, point_step: 16, row_step: 320*16,
195+
height: 240, width: 320, fields: [], is_bigendian: false, point_step: 16, row_step: 320*16,
196196
data: uint8Data,
197197
is_dense: false,
198198
},
199199
{
200200
header: {stamp: {sec: 11223, nanosec: 44556}, frame_id: 'f001', },
201-
height: 240, width: 320, fields: [{}], is_bigendian: false, point_step: 16, row_step: 320*16,
201+
height: 240, width: 320, fields: [], is_bigendian: false, point_step: 16, row_step: 320*16,
202202
data: Uint8Array.from(uint8Data),
203203
is_dense: false,
204204
},

0 commit comments

Comments
 (0)