kig / DataStream.js

DataStream.js is a library for reading data from ArrayBuffers
173 stars 39 forks source link

DataStream.js buggy in Opera 12 #7

Closed sukovec closed 10 years ago

sukovec commented 10 years ago

Hi,

Opera 12 is little buggy with typed arrays, BYTES_PER_ELEMENT is not defined in prototypes, so some functions in ds.js are not working. Simplest workaround (possibly the only and most simple bugfix) is to define it in prototypes like this:

if (Uint8Array.prototype.BYTES_PER_ELEMENT == undefined) {
    Uint8Array.prototype.BYTES_PER_ELEMENT = Uint8Array.BYTES_PER_ELEMENT; 
    Int8Array.prototype.BYTES_PER_ELEMENT = Int8Array.BYTES_PER_ELEMENT; 
    Uint8ClampedArray.prototype.BYTES_PER_ELEMENT = Uint8ClampedArray.BYTES_PER_ELEMENT; 
    Uint16Array.prototype.BYTES_PER_ELEMENT = Uint16Array.BYTES_PER_ELEMENT; 
    Int16Array.prototype.BYTES_PER_ELEMENT = Int16Array.BYTES_PER_ELEMENT; 
    Uint32Array.prototype.BYTES_PER_ELEMENT = Uint32Array.BYTES_PER_ELEMENT; 
    Int32Array.prototype.BYTES_PER_ELEMENT = Int32Array.BYTES_PER_ELEMENT; 
    Float64Array.prototype.BYTES_PER_ELEMENT = Float64Array.BYTES_PER_ELEMENT; 
}
kig commented 10 years ago

Good catch, thanks! Maybe we could also use arr.constructor.BYTES_PER_ELEMENT in the library, if that's more cross-browser.

If you've got this snippet in a branch, send me a PR and I'll merge.