Add types of BufferSource

This commit is contained in:
Christoph Diehl 2017-09-13 21:04:58 +02:00
parent 81ec8a9891
commit 6303c66f51

View file

@ -79,21 +79,21 @@ make.typed = {
]) ])
return random.chance(10) ? -value : value return random.chance(10) ? -value : value
}, },
arrayBuffer: function(byteLength = null) { arrayBuffer: function (byteLength = null) {
let length = (byteLength !== null) ? byteLength : this.unsignedShort() let length = (byteLength !== null) ? byteLength : this.unsignedShort()
return 'new ArrayBuffer(' + length + ')' return 'new ArrayBuffer(' + length + ')'
}, },
dataView: function(byteLength = null) { dataView: function (byteLength = null) {
let length = (byteLength !== null) ? byteLength : this.unsignedShort() let length = (byteLength !== null) ? byteLength : this.unsignedShort()
return 'new DataView(' + this.arrayBuffer(length) + ')' return 'new DataView(' + this.arrayBuffer(length) + ')'
}, },
typedArray: function(byteLength = null) { typedArray: function (byteLength = null) {
let length = (byteLength !== null) ? byteLength : this.unsignedShort() let length = (byteLength !== null) ? byteLength : this.unsignedShort()
let arrType = random.item([ let arrType = random.item([
'Int8', 'Uint8', 'Uint8Clamped', 'Int8', 'Uint8', 'Uint8Clamped',
'Int16', 'Uint16', 'Int16', 'Uint16',
'Int32', 'Uint32', 'Int32', 'Uint32',
'Float32', 'Float64', 'Float32', 'Float64'
]) ])
let method = 'new ' + arrType + 'Array' let method = 'new ' + arrType + 'Array'
switch (random.number(16)) { switch (random.number(16)) {
@ -105,7 +105,7 @@ make.typed = {
return method + '(' + length + ')' return method + '(' + length + ')'
} }
}, },
bufferSource: function() { bufferSource: function () {
return random.choose([ return random.choose([
[1, [this.arrayBuffer, this.dataView]], [1, [this.arrayBuffer, this.dataView]],
[1, [this.typedArray]] [1, [this.typedArray]]