Skip to content

Commit c5267f4

Browse files
authored
Merge pull request #135 from feross/style
style: Move prototype setup to right after Buffer constructor
2 parents 7a38669 + bd05765 commit c5267f4

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

index.js

+12-13
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ function Buffer (arg, encodingOrOffset, length) {
113113
return from(this, arg, encodingOrOffset, length)
114114
}
115115

116+
if (Buffer.TYPED_ARRAY_SUPPORT) {
117+
Buffer.prototype.__proto__ = Uint8Array.prototype
118+
Buffer.__proto__ = Uint8Array
119+
if (typeof Symbol !== 'undefined' && Symbol.species &&
120+
Buffer[Symbol.species] === Buffer) {
121+
// Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
122+
Object.defineProperty(Buffer, Symbol.species, {
123+
value: null,
124+
configurable: true
125+
})
126+
}
127+
}
116128
Buffer.poolSize = 8192 // not used by this implementation
117129

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

152-
if (Buffer.TYPED_ARRAY_SUPPORT) {
153-
Buffer.prototype.__proto__ = Uint8Array.prototype
154-
Buffer.__proto__ = Uint8Array
155-
if (typeof Symbol !== 'undefined' && Symbol.species &&
156-
Buffer[Symbol.species] === Buffer) {
157-
// Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
158-
Object.defineProperty(Buffer, Symbol.species, {
159-
value: null,
160-
configurable: true
161-
})
162-
}
163-
}
164-
165164
function assertSize (size) {
166165
if (typeof size !== 'number') {
167166
throw new TypeError('"size" argument must be a number')

0 commit comments

Comments
 (0)