From: Feross Aboukhadijeh Date: Wed, 14 Sep 2016 16:49:58 +0000 (-0700) Subject: style: Move prototype setup to right after Buffer constructor X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=bd057655fef1fde15a3e64b08a1b48c27fce1309;p=buffer.git style: Move prototype setup to right after Buffer constructor --- diff --git a/index.js b/index.js index 0fcd80a..a51caae 100644 --- a/index.js +++ b/index.js @@ -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. @@ -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')