Skip to content

Commit

Permalink
Merge pull request #135 from feross/style
Browse files Browse the repository at this point in the history
style: Move prototype setup to right after Buffer constructor
  • Loading branch information
feross authored Sep 14, 2016
2 parents 7a38669 + bd05765 commit c5267f4
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ function Buffer (arg, encodingOrOffset, length) {
return from(this, arg, encodingOrOffset, length)
}

if (Buffer.TYPED_ARRAY_SUPPORT) {
Buffer.prototype.__proto__ = Uint8Array.prototype
Buffer.__proto__ = Uint8Array
if (typeof Symbol !== 'undefined' && Symbol.species &&
Buffer[Symbol.species] === Buffer) {
// Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
Object.defineProperty(Buffer, Symbol.species, {
value: null,
configurable: true
})
}
}
Buffer.poolSize = 8192 // not used by this implementation

// TODO: Legacy, not needed anymore. Remove in next major version.
Expand Down Expand Up @@ -149,19 +161,6 @@ Buffer.from = function (value, encodingOrOffset, length) {
return from(null, value, encodingOrOffset, length)
}

if (Buffer.TYPED_ARRAY_SUPPORT) {
Buffer.prototype.__proto__ = Uint8Array.prototype
Buffer.__proto__ = Uint8Array
if (typeof Symbol !== 'undefined' && Symbol.species &&
Buffer[Symbol.species] === Buffer) {
// Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
Object.defineProperty(Buffer, Symbol.species, {
value: null,
configurable: true
})
}
}

function assertSize (size) {
if (typeof size !== 'number') {
throw new TypeError('"size" argument must be a number')
Expand Down

0 comments on commit c5267f4

Please sign in to comment.