• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3// Fix for https://github.com/nodejs/node/issues/8266
4//
5// Zero length Buffer objects should expose the `buffer` property of the
6// TypedArrays, via the `parent` property.
7require('../common');
8const assert = require('assert');
9
10// If the length of the buffer object is zero
11assert((new Buffer(0)).parent instanceof ArrayBuffer);
12
13// If the length of the buffer object is equal to the underlying ArrayBuffer
14assert((new Buffer(Buffer.poolSize)).parent instanceof ArrayBuffer);
15
16// Same as the previous test, but with user created buffer
17const arrayBuffer = new ArrayBuffer(0);
18assert.strictEqual(new Buffer(arrayBuffer).parent, arrayBuffer);
19assert.strictEqual(new Buffer(arrayBuffer).buffer, arrayBuffer);
20assert.strictEqual(Buffer.from(arrayBuffer).parent, arrayBuffer);
21assert.strictEqual(Buffer.from(arrayBuffer).buffer, arrayBuffer);
22