aliyun / aliyun-tablestore-nodejs-sdk

Aliyun TableStore(原OTS) SDK for Node.js
Apache License 2.0
88 stars 33 forks source link

for..in used on Arrays in encoder.js issue #43

Open alextekartik opened 4 years ago

alextekartik commented 4 years ago

I'm currently developing a dart interop wrapper (using https://pub.dev/packages/node_interop). While I was able to handle most nodejs API from tablestore, some issue remain in how some arrays are handled. For example in encode.js, we have currently

for (var pk in params.tables[i].primaryKey) {
  item.primaryKey.push(TableStore.PlainBufferBuilder.serializePrimaryKey(params.tables[i].primaryKey[pk]));
}

This is not the recommended way to iterate over an array. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...inhttps://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Instructions/for...in. This is also causing an issue with dart adding hidden properties.

Something like this is preferable:

for (var k = 0; k < params.tables[i].primaryKey.length; k++) {
  item.primaryKey.push(TableStore.PlainBufferBuilder.serializePrimaryKey(params.tables[i].primaryKey[k]));
}

This seems to be done (at least) in 3 places in encoder.js:

Would you consider changing this? Thanks!