Skip to content

Commit

Permalink
fix(buffer): allow setting falsy values through proxy (#11512)
Browse files Browse the repository at this point in the history
  • Loading branch information
janvennemann committed Mar 18, 2020
1 parent 83c85df commit a45a8d0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions common/Resources/ti.internal/extensions/node/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1615,7 +1615,8 @@ const arrayIndexHandler = {
if (typeof propKey === 'string') {
const num = Number(propKey);
if (Number.isSafeInteger(num)) {
return setAdjustedIndex(target, num, value);
setAdjustedIndex(target, num, value);
return true;
}
}
return Reflect.set(target, propKey, value, receiver);
Expand Down Expand Up @@ -1644,7 +1645,6 @@ function setAdjustedIndex(buf, index, value) {
if (index >= 0 || index < buf._tiBuffer.length) {
buf._tiBuffer[index + buf.byteOffset] = value;
}
return value;
}

/**
Expand Down
17 changes: 17 additions & 0 deletions tests/Resources/buffer.addontest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

const should = require('./utilities/assertions');

describe('buffer', () => {
it('supports array index access', () => {
const buf = Buffer.alloc(4);
should(buf.length).eql(4);
should(buf).eql(Buffer.from([ 0, 0, 0, 0 ]));
const values = [ 0, 1, 2, 3 ];
for (let i = 0; i < values.length; i++) {
buf[i] = values[i];
should(buf[i]).eql(values[i]);
}
should(buf).eql(Buffer.from(values));
});
});

0 comments on commit a45a8d0

Please sign in to comment.