|  | 
| 3 | 3 | require('../common'); | 
| 4 | 4 | var assert = require('assert'); | 
| 5 | 5 | var Buffer = require('buffer').Buffer; | 
|  | 6 | +var SlowBuffer = require('buffer').SlowBuffer; | 
| 6 | 7 | 
 | 
| 7 | 8 | // coerce values to string | 
| 8 | 9 | assert.equal(Buffer.byteLength(32, 'binary'), 2); | 
| 9 | 10 | assert.equal(Buffer.byteLength(NaN, 'utf8'), 3); | 
| 10 | 11 | assert.equal(Buffer.byteLength({}, 'binary'), 15); | 
| 11 | 12 | assert.equal(Buffer.byteLength(), 9); | 
| 12 | 13 | 
 | 
|  | 14 | +var buff = new Buffer(10); | 
|  | 15 | +assert(ArrayBuffer.isView(buff)); | 
|  | 16 | +var slowbuff = new SlowBuffer(10); | 
|  | 17 | +assert(ArrayBuffer.isView(slowbuff)); | 
|  | 18 | + | 
| 13 | 19 | // buffer | 
| 14 | 20 | var incomplete = new Buffer([0xe4, 0xb8, 0xad, 0xe6, 0x96]); | 
| 15 | 21 | assert.equal(Buffer.byteLength(incomplete), 5); | 
| 16 | 22 | var ascii = new Buffer('abc'); | 
| 17 | 23 | assert.equal(Buffer.byteLength(ascii), 3); | 
| 18 | 24 | 
 | 
|  | 25 | +// ArrayBuffer | 
|  | 26 | +var buffer = new ArrayBuffer(8); | 
|  | 27 | +assert.equal(Buffer.byteLength(buffer), 8); | 
|  | 28 | + | 
|  | 29 | +// TypedArray | 
|  | 30 | +var int8 = new Int8Array(8); | 
|  | 31 | +assert.equal(Buffer.byteLength(int8), 8); | 
|  | 32 | +var uint8 = new Uint8Array(8); | 
|  | 33 | +assert.equal(Buffer.byteLength(uint8), 8); | 
|  | 34 | +var uintc8 = new Uint8ClampedArray(2); | 
|  | 35 | +assert.equal(Buffer.byteLength(uintc8), 2); | 
|  | 36 | +var int16 = new Int16Array(8); | 
|  | 37 | +assert.equal(Buffer.byteLength(int16), 16); | 
|  | 38 | +var uint16 = new Uint16Array(8); | 
|  | 39 | +assert.equal(Buffer.byteLength(uint16), 16); | 
|  | 40 | +var int32 = new Int32Array(8); | 
|  | 41 | +assert.equal(Buffer.byteLength(int32), 32); | 
|  | 42 | +var uint32 = new Uint32Array(8); | 
|  | 43 | +assert.equal(Buffer.byteLength(uint32), 32); | 
|  | 44 | +var float32 = new Float32Array(8); | 
|  | 45 | +assert.equal(Buffer.byteLength(float32), 32); | 
|  | 46 | +var float64 = new Float64Array(8); | 
|  | 47 | +assert.equal(Buffer.byteLength(float64), 64); | 
|  | 48 | + | 
|  | 49 | +// DataView | 
|  | 50 | +var dv = new DataView(new ArrayBuffer(2)); | 
|  | 51 | +assert.equal(Buffer.byteLength(dv), 2); | 
|  | 52 | + | 
| 19 | 53 | // special case: zero length string | 
| 20 | 54 | assert.equal(Buffer.byteLength('', 'ascii'), 0); | 
| 21 | 55 | assert.equal(Buffer.byteLength('', 'HeX'), 0); | 
|  | 
0 commit comments