Commit 651a5b5
buffer: only check if instance is Uint8Array
Native Buffer method calls do not require anything from the prototype.
So it is unnecessary to check if the Object's prototype is equal to
Buffer.prototype.
This fixes an issue that prevents Buffer from being inherited the ES5
way. Now the following will work:
function A(n) {
const b = new Buffer(n);
Object.setPrototypeOf(b, A.prototype);
return b;
}
Object.setPrototypeOf(A.prototype, Buffer.prototype);
Object.setPrototypeOf(A, Buffer);
console.log(new A(4));
Fix: #2882
PR-URL: #3080
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>1 parent d5a1b1a commit 651a5b5Copy full SHA for 651a5b5
File tree
Expand file treeCollapse file tree
2 files changed
+47
-12
lines changedOpen diff view settings
Filter options
- src
- test/parallel
Expand file treeCollapse file tree
2 files changed
+47
-12
lines changedOpen diff view settings
Collapse file
+9-12Lines changed: 9 additions & 12 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
163 | 163 | |
164 | 164 | |
165 | 165 | |
166 | | - |
| 166 | + |
167 | 167 | |
168 | 168 | |
169 | 169 | |
170 | 170 | |
171 | | - |
172 | | - |
173 | | - |
174 | | - |
175 | | - |
| 171 | + |
176 | 172 | |
177 | 173 | |
178 | 174 | |
179 | 175 | |
180 | | - |
181 | | - |
182 | | - |
183 | | - |
| 176 | + |
| 177 | + |
| 178 | + |
| 179 | + |
184 | 180 | |
185 | 181 | |
186 | 182 | |
| ||
193 | 189 | |
194 | 190 | |
195 | 191 | |
196 | | - |
197 | | - |
| 192 | + |
| 193 | + |
| 194 | + |
198 | 195 | |
199 | 196 | |
200 | 197 | |
|
Collapse file
test/parallel/test-buffer-inheritance.js
Copy file name to clipboard+38Lines changed: 38 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | + |
0 commit comments