Skip to content

Commit

Permalink
fix(common): copy sliced buffer doesn't extend beyond view now
Browse files Browse the repository at this point in the history
Alos support ArrayBuffer.isView and BYTES_PER_ELEMENT sniffing pixelmatch does
  • Loading branch information
sgtcoolguy committed Jul 6, 2020
1 parent 704fb8f commit 035c579
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions common/Resources/ti.internal/extensions/node/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const uint8FloatArray = new Uint8Array(floatArray.buffer);

let INSPECT_MAX_BYTES = 50;

class Buffer {
class Buffer { // FIXME: Extend Uint8Array
/**
* Constructs a new buffer.
*
Expand Down Expand Up @@ -207,8 +207,8 @@ class Buffer {
}

// TODO: handle overlap when target === this!
// TODO: Do we need to take target or this.byteOffset into account here?
target._tiBuffer.copy(this._tiBuffer, targetStart, sourceStart, length);
// TODO: Do we need to take target byteOffset into account here?
target._tiBuffer.copy(this._tiBuffer, targetStart, sourceStart + this.byteOffset, length);
return length;
}

Expand Down Expand Up @@ -1473,6 +1473,13 @@ Buffer.prototype.inspect = Buffer.prototype[customInspectSymbol];

Buffer.poolSize = 8192;

// HACK: ArrayBuffer.isView returns true for Node Buffer, but false for us. Until we can extend Uint8Array, we need to hack this sniffing method
const ArrayBufferIsView = ArrayBuffer.isView;
ArrayBuffer.isView = function (thing) {
return ArrayBufferIsView(thing) || thing instanceof Buffer;
};
Object.setPrototypeOf(Buffer, Uint8Array);

export default {
Buffer,
// TODO: Implement transcode()!
Expand Down

0 comments on commit 035c579

Please sign in to comment.