Add types of BufferSource

This commit is contained in:
Christoph Diehl 2017-09-13 20:57:21 +02:00
parent 69d537325b
commit f098ea3b00
1 changed files with 32 additions and 0 deletions

View File

@ -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]]
])
}
}