diff --git a/lib/make/typed.js b/lib/make/typed.js index 78a2a23..b74f4e3 100644 --- a/lib/make/typed.js +++ b/lib/make/typed.js @@ -78,5 +78,37 @@ make.typed = { [1, [this.range, make.number.tiny]] ]) return random.chance(10) ? -value : value + }, + arrayBuffer: function(byteLength = null) { + let length = (byteLength !== null) ? byteLength : this.unsignedShort() + return 'new ArrayBuffer(' + length + ')' + }, + dataView: function(byteLength = null) { + let length = (byteLength !== null) ? byteLength : this.unsignedShort() + return 'new DataView(' + this.arrayBuffer(length) + ')' + }, + typedArray: function(byteLength = null) { + let length = (byteLength !== null) ? byteLength : this.unsignedShort() + let arrType = random.item([ + 'Int8', 'Uint8', 'Uint8Clamped', + 'Int16', 'Uint16', + 'Int32', 'Uint32', + 'Float32', 'Float64', + ]) + let method = 'new ' + arrType + 'Array' + switch (random.number(16)) { + case 0: + return method + '()' + case 1: + return method + '(' + this.typedArray() + ')' + default: + return method + '(' + length + ')' + } + }, + bufferSource: function() { + return random.choose([ + [1, [this.arrayBuffer, this.dataView]], + [1, [this.typedArray]] + ]) } }