buffer: only check if instance is Uint8Array
authorTrevor Norris <trev.norris@gmail.com>
Sat, 26 Sep 2015 21:26:52 +0000 (15:26 -0600)
committerJames M Snell <jasnell@gmail.com>
Thu, 8 Oct 2015 03:39:16 +0000 (20:39 -0700)
commit651a5b51eb838e8e23a5b94ba34e8e06630a004a
treef09485d6768195c3a0727e00abbb2c8df7c34878
parentd5a1b1ad7c4456e3c5747dadf8b12e981fe47e7c
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: https://github.com/nodejs/node/issues/2882
PR-URL: https://github.com/nodejs/node/pull/3080
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
src/node_buffer.cc
test/parallel/test-buffer-inheritance.js [new file with mode: 0644]