Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
lib: mark Buffer/SlowBuffer not supporting @@species
Browse files Browse the repository at this point in the history
Buffer/SlowBuffer not supporting @@species constructor. Mark them as such
to avoid failure with TypedArray @@species spec.

Reviewed-by: @kunalspathak
  • Loading branch information
Jianchun Xu committed Sep 21, 2015
1 parent 91b675a commit 3a55f98
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ function alignPool() {
}
}

// Mark a constructor not supporting @@species
function markNoSpeciesConstructor(constructor) {
if (Symbol.species) {
Object.defineProperty(constructor, Symbol.species, {
get: function() { return undefined; },
configurable: true,
});
}
}

function Buffer(arg) {
// Common case.
Expand All @@ -60,6 +69,7 @@ function Buffer(arg) {

Buffer.prototype.__proto__ = Uint8Array.prototype;
Buffer.__proto__ = Uint8Array;
markNoSpeciesConstructor(Buffer);


function SlowBuffer(length) {
Expand All @@ -74,6 +84,7 @@ function SlowBuffer(length) {

SlowBuffer.prototype.__proto__ = Buffer.prototype;
SlowBuffer.__proto__ = Buffer;
markNoSpeciesConstructor(SlowBuffer);


function allocate(size) {
Expand Down

0 comments on commit 3a55f98

Please sign in to comment.