1'use strict'; 2 3require('../common'); 4const assert = require('assert'); 5 6 7function T(n) { 8 const ui8 = new Uint8Array(n); 9 Object.setPrototypeOf(ui8, T.prototype); 10 return ui8; 11} 12Object.setPrototypeOf(T.prototype, Buffer.prototype); 13Object.setPrototypeOf(T, Buffer); 14 15T.prototype.sum = function sum() { 16 let cntr = 0; 17 for (let i = 0; i < this.length; i++) 18 cntr += this[i]; 19 return cntr; 20}; 21 22 23const vals = [new T(4), T(4)]; 24 25vals.forEach(function(t) { 26 assert.strictEqual(t.constructor, T); 27 assert.strictEqual(Object.getPrototypeOf(t), T.prototype); 28 assert.strictEqual(Object.getPrototypeOf(Object.getPrototypeOf(t)), 29 Buffer.prototype); 30 31 t.fill(5); 32 let cntr = 0; 33 for (let i = 0; i < t.length; i++) 34 cntr += t[i]; 35 assert.strictEqual(cntr, t.length * 5); 36 37 // Check this does not throw 38 t.toString(); 39}); 40