Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. var undefined = (void 0); // Paranoia
  2. // Beyond this value, index getters/setters (i.e. array[0], array[1]) are so slow to
  3. // create, and consume so much memory, that the browser appears frozen.
  4. var MAX_ARRAY_LENGTH = 1e5;
  5. // Approximations of internal ECMAScript conversion functions
  6. var ECMAScript = (function() {
  7. // Stash a copy in case other scripts modify these
  8. var opts = Object.prototype.toString,
  9. ophop = Object.prototype.hasOwnProperty;
  10. return {
  11. // Class returns internal [[Class]] property, used to avoid cross-frame instanceof issues:
  12. Class: function(v) { return opts.call(v).replace(/^\[object *|\]$/g, ''); },
  13. HasProperty: function(o, p) { return p in o; },
  14. HasOwnProperty: function(o, p) { return ophop.call(o, p); },
  15. IsCallable: function(o) { return typeof o === 'function'; },
  16. ToInt32: function(v) { return v >> 0; },
  17. ToUint32: function(v) { return v >>> 0; }
  18. };
  19. }());
  20. // Snapshot intrinsics
  21. var LN2 = Math.LN2,
  22. abs = Math.abs,
  23. floor = Math.floor,
  24. log = Math.log,
  25. min = Math.min,
  26. pow = Math.pow,
  27. round = Math.round;
  28. // ES5: lock down object properties
  29. function configureProperties(obj) {
  30. if (getOwnPropNames && defineProp) {
  31. var props = getOwnPropNames(obj), i;
  32. for (i = 0; i < props.length; i += 1) {
  33. defineProp(obj, props[i], {
  34. value: obj[props[i]],
  35. writable: false,
  36. enumerable: false,
  37. configurable: false
  38. });
  39. }
  40. }
  41. }
  42. // emulate ES5 getter/setter API using legacy APIs
  43. // http://blogs.msdn.com/b/ie/archive/2010/09/07/transitioning-existing-code-to-the-es5-getter-setter-apis.aspx
  44. // (second clause tests for Object.defineProperty() in IE<9 that only supports extending DOM prototypes, but
  45. // note that IE<9 does not support __defineGetter__ or __defineSetter__ so it just renders the method harmless)
  46. var defineProp
  47. if (Object.defineProperty && (function() {
  48. try {
  49. Object.defineProperty({}, 'x', {});
  50. return true;
  51. } catch (e) {
  52. return false;
  53. }
  54. })()) {
  55. defineProp = Object.defineProperty;
  56. } else {
  57. defineProp = function(o, p, desc) {
  58. if (!o === Object(o)) throw new TypeError("Object.defineProperty called on non-object");
  59. if (ECMAScript.HasProperty(desc, 'get') && Object.prototype.__defineGetter__) { Object.prototype.__defineGetter__.call(o, p, desc.get); }
  60. if (ECMAScript.HasProperty(desc, 'set') && Object.prototype.__defineSetter__) { Object.prototype.__defineSetter__.call(o, p, desc.set); }
  61. if (ECMAScript.HasProperty(desc, 'value')) { o[p] = desc.value; }
  62. return o;
  63. };
  64. }
  65. var getOwnPropNames = Object.getOwnPropertyNames || function (o) {
  66. if (o !== Object(o)) throw new TypeError("Object.getOwnPropertyNames called on non-object");
  67. var props = [], p;
  68. for (p in o) {
  69. if (ECMAScript.HasOwnProperty(o, p)) {
  70. props.push(p);
  71. }
  72. }
  73. return props;
  74. };
  75. // ES5: Make obj[index] an alias for obj._getter(index)/obj._setter(index, value)
  76. // for index in 0 ... obj.length
  77. function makeArrayAccessors(obj) {
  78. if (!defineProp) { return; }
  79. if (obj.length > MAX_ARRAY_LENGTH) throw new RangeError("Array too large for polyfill");
  80. function makeArrayAccessor(index) {
  81. defineProp(obj, index, {
  82. 'get': function() { return obj._getter(index); },
  83. 'set': function(v) { obj._setter(index, v); },
  84. enumerable: true,
  85. configurable: false
  86. });
  87. }
  88. var i;
  89. for (i = 0; i < obj.length; i += 1) {
  90. makeArrayAccessor(i);
  91. }
  92. }
  93. // Internal conversion functions:
  94. // pack<Type>() - take a number (interpreted as Type), output a byte array
  95. // unpack<Type>() - take a byte array, output a Type-like number
  96. function as_signed(value, bits) { var s = 32 - bits; return (value << s) >> s; }
  97. function as_unsigned(value, bits) { var s = 32 - bits; return (value << s) >>> s; }
  98. function packI8(n) { return [n & 0xff]; }
  99. function unpackI8(bytes) { return as_signed(bytes[0], 8); }
  100. function packU8(n) { return [n & 0xff]; }
  101. function unpackU8(bytes) { return as_unsigned(bytes[0], 8); }
  102. function packU8Clamped(n) { n = round(Number(n)); return [n < 0 ? 0 : n > 0xff ? 0xff : n & 0xff]; }
  103. function packI16(n) { return [(n >> 8) & 0xff, n & 0xff]; }
  104. function unpackI16(bytes) { return as_signed(bytes[0] << 8 | bytes[1], 16); }
  105. function packU16(n) { return [(n >> 8) & 0xff, n & 0xff]; }
  106. function unpackU16(bytes) { return as_unsigned(bytes[0] << 8 | bytes[1], 16); }
  107. function packI32(n) { return [(n >> 24) & 0xff, (n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff]; }
  108. function unpackI32(bytes) { return as_signed(bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3], 32); }
  109. function packU32(n) { return [(n >> 24) & 0xff, (n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff]; }
  110. function unpackU32(bytes) { return as_unsigned(bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3], 32); }
  111. function packIEEE754(v, ebits, fbits) {
  112. var bias = (1 << (ebits - 1)) - 1,
  113. s, e, f, ln,
  114. i, bits, str, bytes;
  115. function roundToEven(n) {
  116. var w = floor(n), f = n - w;
  117. if (f < 0.5)
  118. return w;
  119. if (f > 0.5)
  120. return w + 1;
  121. return w % 2 ? w + 1 : w;
  122. }
  123. // Compute sign, exponent, fraction
  124. if (v !== v) {
  125. // NaN
  126. // http://dev.w3.org/2006/webapi/WebIDL/#es-type-mapping
  127. e = (1 << ebits) - 1; f = pow(2, fbits - 1); s = 0;
  128. } else if (v === Infinity || v === -Infinity) {
  129. e = (1 << ebits) - 1; f = 0; s = (v < 0) ? 1 : 0;
  130. } else if (v === 0) {
  131. e = 0; f = 0; s = (1 / v === -Infinity) ? 1 : 0;
  132. } else {
  133. s = v < 0;
  134. v = abs(v);
  135. if (v >= pow(2, 1 - bias)) {
  136. e = min(floor(log(v) / LN2), 1023);
  137. f = roundToEven(v / pow(2, e) * pow(2, fbits));
  138. if (f / pow(2, fbits) >= 2) {
  139. e = e + 1;
  140. f = 1;
  141. }
  142. if (e > bias) {
  143. // Overflow
  144. e = (1 << ebits) - 1;
  145. f = 0;
  146. } else {
  147. // Normalized
  148. e = e + bias;
  149. f = f - pow(2, fbits);
  150. }
  151. } else {
  152. // Denormalized
  153. e = 0;
  154. f = roundToEven(v / pow(2, 1 - bias - fbits));
  155. }
  156. }
  157. // Pack sign, exponent, fraction
  158. bits = [];
  159. for (i = fbits; i; i -= 1) { bits.push(f % 2 ? 1 : 0); f = floor(f / 2); }
  160. for (i = ebits; i; i -= 1) { bits.push(e % 2 ? 1 : 0); e = floor(e / 2); }
  161. bits.push(s ? 1 : 0);
  162. bits.reverse();
  163. str = bits.join('');
  164. // Bits to bytes
  165. bytes = [];
  166. while (str.length) {
  167. bytes.push(parseInt(str.substring(0, 8), 2));
  168. str = str.substring(8);
  169. }
  170. return bytes;
  171. }
  172. function unpackIEEE754(bytes, ebits, fbits) {
  173. // Bytes to bits
  174. var bits = [], i, j, b, str,
  175. bias, s, e, f;
  176. for (i = bytes.length; i; i -= 1) {
  177. b = bytes[i - 1];
  178. for (j = 8; j; j -= 1) {
  179. bits.push(b % 2 ? 1 : 0); b = b >> 1;
  180. }
  181. }
  182. bits.reverse();
  183. str = bits.join('');
  184. // Unpack sign, exponent, fraction
  185. bias = (1 << (ebits - 1)) - 1;
  186. s = parseInt(str.substring(0, 1), 2) ? -1 : 1;
  187. e = parseInt(str.substring(1, 1 + ebits), 2);
  188. f = parseInt(str.substring(1 + ebits), 2);
  189. // Produce number
  190. if (e === (1 << ebits) - 1) {
  191. return f !== 0 ? NaN : s * Infinity;
  192. } else if (e > 0) {
  193. // Normalized
  194. return s * pow(2, e - bias) * (1 + f / pow(2, fbits));
  195. } else if (f !== 0) {
  196. // Denormalized
  197. return s * pow(2, -(bias - 1)) * (f / pow(2, fbits));
  198. } else {
  199. return s < 0 ? -0 : 0;
  200. }
  201. }
  202. function unpackF64(b) { return unpackIEEE754(b, 11, 52); }
  203. function packF64(v) { return packIEEE754(v, 11, 52); }
  204. function unpackF32(b) { return unpackIEEE754(b, 8, 23); }
  205. function packF32(v) { return packIEEE754(v, 8, 23); }
  206. //
  207. // 3 The ArrayBuffer Type
  208. //
  209. (function() {
  210. /** @constructor */
  211. var ArrayBuffer = function ArrayBuffer(length) {
  212. length = ECMAScript.ToInt32(length);
  213. if (length < 0) throw new RangeError('ArrayBuffer size is not a small enough positive integer');
  214. this.byteLength = length;
  215. this._bytes = [];
  216. this._bytes.length = length;
  217. var i;
  218. for (i = 0; i < this.byteLength; i += 1) {
  219. this._bytes[i] = 0;
  220. }
  221. configureProperties(this);
  222. };
  223. exports.ArrayBuffer = exports.ArrayBuffer || ArrayBuffer;
  224. //
  225. // 4 The ArrayBufferView Type
  226. //
  227. // NOTE: this constructor is not exported
  228. /** @constructor */
  229. var ArrayBufferView = function ArrayBufferView() {
  230. //this.buffer = null;
  231. //this.byteOffset = 0;
  232. //this.byteLength = 0;
  233. };
  234. //
  235. // 5 The Typed Array View Types
  236. //
  237. function makeConstructor(bytesPerElement, pack, unpack) {
  238. // Each TypedArray type requires a distinct constructor instance with
  239. // identical logic, which this produces.
  240. var ctor;
  241. ctor = function(buffer, byteOffset, length) {
  242. var array, sequence, i, s;
  243. if (!arguments.length || typeof arguments[0] === 'number') {
  244. // Constructor(unsigned long length)
  245. this.length = ECMAScript.ToInt32(arguments[0]);
  246. if (length < 0) throw new RangeError('ArrayBufferView size is not a small enough positive integer');
  247. this.byteLength = this.length * this.BYTES_PER_ELEMENT;
  248. this.buffer = new ArrayBuffer(this.byteLength);
  249. this.byteOffset = 0;
  250. } else if (typeof arguments[0] === 'object' && arguments[0].constructor === ctor) {
  251. // Constructor(TypedArray array)
  252. array = arguments[0];
  253. this.length = array.length;
  254. this.byteLength = this.length * this.BYTES_PER_ELEMENT;
  255. this.buffer = new ArrayBuffer(this.byteLength);
  256. this.byteOffset = 0;
  257. for (i = 0; i < this.length; i += 1) {
  258. this._setter(i, array._getter(i));
  259. }
  260. } else if (typeof arguments[0] === 'object' &&
  261. !(arguments[0] instanceof ArrayBuffer || ECMAScript.Class(arguments[0]) === 'ArrayBuffer')) {
  262. // Constructor(sequence<type> array)
  263. sequence = arguments[0];
  264. this.length = ECMAScript.ToUint32(sequence.length);
  265. this.byteLength = this.length * this.BYTES_PER_ELEMENT;
  266. this.buffer = new ArrayBuffer(this.byteLength);
  267. this.byteOffset = 0;
  268. for (i = 0; i < this.length; i += 1) {
  269. s = sequence[i];
  270. this._setter(i, Number(s));
  271. }
  272. } else if (typeof arguments[0] === 'object' &&
  273. (arguments[0] instanceof ArrayBuffer || ECMAScript.Class(arguments[0]) === 'ArrayBuffer')) {
  274. // Constructor(ArrayBuffer buffer,
  275. // optional unsigned long byteOffset, optional unsigned long length)
  276. this.buffer = buffer;
  277. this.byteOffset = ECMAScript.ToUint32(byteOffset);
  278. if (this.byteOffset > this.buffer.byteLength) {
  279. throw new RangeError("byteOffset out of range");
  280. }
  281. if (this.byteOffset % this.BYTES_PER_ELEMENT) {
  282. // The given byteOffset must be a multiple of the element
  283. // size of the specific type, otherwise an exception is raised.
  284. throw new RangeError("ArrayBuffer length minus the byteOffset is not a multiple of the element size.");
  285. }
  286. if (arguments.length < 3) {
  287. this.byteLength = this.buffer.byteLength - this.byteOffset;
  288. if (this.byteLength % this.BYTES_PER_ELEMENT) {
  289. throw new RangeError("length of buffer minus byteOffset not a multiple of the element size");
  290. }
  291. this.length = this.byteLength / this.BYTES_PER_ELEMENT;
  292. } else {
  293. this.length = ECMAScript.ToUint32(length);
  294. this.byteLength = this.length * this.BYTES_PER_ELEMENT;
  295. }
  296. if ((this.byteOffset + this.byteLength) > this.buffer.byteLength) {
  297. throw new RangeError("byteOffset and length reference an area beyond the end of the buffer");
  298. }
  299. } else {
  300. throw new TypeError("Unexpected argument type(s)");
  301. }
  302. this.constructor = ctor;
  303. configureProperties(this);
  304. makeArrayAccessors(this);
  305. };
  306. ctor.prototype = new ArrayBufferView();
  307. ctor.prototype.BYTES_PER_ELEMENT = bytesPerElement;
  308. ctor.prototype._pack = pack;
  309. ctor.prototype._unpack = unpack;
  310. ctor.BYTES_PER_ELEMENT = bytesPerElement;
  311. // getter type (unsigned long index);
  312. ctor.prototype._getter = function(index) {
  313. if (arguments.length < 1) throw new SyntaxError("Not enough arguments");
  314. index = ECMAScript.ToUint32(index);
  315. if (index >= this.length) {
  316. return undefined;
  317. }
  318. var bytes = [], i, o;
  319. for (i = 0, o = this.byteOffset + index * this.BYTES_PER_ELEMENT;
  320. i < this.BYTES_PER_ELEMENT;
  321. i += 1, o += 1) {
  322. bytes.push(this.buffer._bytes[o]);
  323. }
  324. return this._unpack(bytes);
  325. };
  326. // NONSTANDARD: convenience alias for getter: type get(unsigned long index);
  327. ctor.prototype.get = ctor.prototype._getter;
  328. // setter void (unsigned long index, type value);
  329. ctor.prototype._setter = function(index, value) {
  330. if (arguments.length < 2) throw new SyntaxError("Not enough arguments");
  331. index = ECMAScript.ToUint32(index);
  332. if (index >= this.length) {
  333. return undefined;
  334. }
  335. var bytes = this._pack(value), i, o;
  336. for (i = 0, o = this.byteOffset + index * this.BYTES_PER_ELEMENT;
  337. i < this.BYTES_PER_ELEMENT;
  338. i += 1, o += 1) {
  339. this.buffer._bytes[o] = bytes[i];
  340. }
  341. };
  342. // void set(TypedArray array, optional unsigned long offset);
  343. // void set(sequence<type> array, optional unsigned long offset);
  344. ctor.prototype.set = function(index, value) {
  345. if (arguments.length < 1) throw new SyntaxError("Not enough arguments");
  346. var array, sequence, offset, len,
  347. i, s, d,
  348. byteOffset, byteLength, tmp;
  349. if (typeof arguments[0] === 'object' && arguments[0].constructor === this.constructor) {
  350. // void set(TypedArray array, optional unsigned long offset);
  351. array = arguments[0];
  352. offset = ECMAScript.ToUint32(arguments[1]);
  353. if (offset + array.length > this.length) {
  354. throw new RangeError("Offset plus length of array is out of range");
  355. }
  356. byteOffset = this.byteOffset + offset * this.BYTES_PER_ELEMENT;
  357. byteLength = array.length * this.BYTES_PER_ELEMENT;
  358. if (array.buffer === this.buffer) {
  359. tmp = [];
  360. for (i = 0, s = array.byteOffset; i < byteLength; i += 1, s += 1) {
  361. tmp[i] = array.buffer._bytes[s];
  362. }
  363. for (i = 0, d = byteOffset; i < byteLength; i += 1, d += 1) {
  364. this.buffer._bytes[d] = tmp[i];
  365. }
  366. } else {
  367. for (i = 0, s = array.byteOffset, d = byteOffset;
  368. i < byteLength; i += 1, s += 1, d += 1) {
  369. this.buffer._bytes[d] = array.buffer._bytes[s];
  370. }
  371. }
  372. } else if (typeof arguments[0] === 'object' && typeof arguments[0].length !== 'undefined') {
  373. // void set(sequence<type> array, optional unsigned long offset);
  374. sequence = arguments[0];
  375. len = ECMAScript.ToUint32(sequence.length);
  376. offset = ECMAScript.ToUint32(arguments[1]);
  377. if (offset + len > this.length) {
  378. throw new RangeError("Offset plus length of array is out of range");
  379. }
  380. for (i = 0; i < len; i += 1) {
  381. s = sequence[i];
  382. this._setter(offset + i, Number(s));
  383. }
  384. } else {
  385. throw new TypeError("Unexpected argument type(s)");
  386. }
  387. };
  388. // TypedArray subarray(long begin, optional long end);
  389. ctor.prototype.subarray = function(start, end) {
  390. function clamp(v, min, max) { return v < min ? min : v > max ? max : v; }
  391. start = ECMAScript.ToInt32(start);
  392. end = ECMAScript.ToInt32(end);
  393. if (arguments.length < 1) { start = 0; }
  394. if (arguments.length < 2) { end = this.length; }
  395. if (start < 0) { start = this.length + start; }
  396. if (end < 0) { end = this.length + end; }
  397. start = clamp(start, 0, this.length);
  398. end = clamp(end, 0, this.length);
  399. var len = end - start;
  400. if (len < 0) {
  401. len = 0;
  402. }
  403. return new this.constructor(
  404. this.buffer, this.byteOffset + start * this.BYTES_PER_ELEMENT, len);
  405. };
  406. return ctor;
  407. }
  408. var Int8Array = makeConstructor(1, packI8, unpackI8);
  409. var Uint8Array = makeConstructor(1, packU8, unpackU8);
  410. var Uint8ClampedArray = makeConstructor(1, packU8Clamped, unpackU8);
  411. var Int16Array = makeConstructor(2, packI16, unpackI16);
  412. var Uint16Array = makeConstructor(2, packU16, unpackU16);
  413. var Int32Array = makeConstructor(4, packI32, unpackI32);
  414. var Uint32Array = makeConstructor(4, packU32, unpackU32);
  415. var Float32Array = makeConstructor(4, packF32, unpackF32);
  416. var Float64Array = makeConstructor(8, packF64, unpackF64);
  417. exports.Int8Array = exports.Int8Array || Int8Array;
  418. exports.Uint8Array = exports.Uint8Array || Uint8Array;
  419. exports.Uint8ClampedArray = exports.Uint8ClampedArray || Uint8ClampedArray;
  420. exports.Int16Array = exports.Int16Array || Int16Array;
  421. exports.Uint16Array = exports.Uint16Array || Uint16Array;
  422. exports.Int32Array = exports.Int32Array || Int32Array;
  423. exports.Uint32Array = exports.Uint32Array || Uint32Array;
  424. exports.Float32Array = exports.Float32Array || Float32Array;
  425. exports.Float64Array = exports.Float64Array || Float64Array;
  426. }());
  427. //
  428. // 6 The DataView View Type
  429. //
  430. (function() {
  431. function r(array, index) {
  432. return ECMAScript.IsCallable(array.get) ? array.get(index) : array[index];
  433. }
  434. var IS_BIG_ENDIAN = (function() {
  435. var u16array = new(exports.Uint16Array)([0x1234]),
  436. u8array = new(exports.Uint8Array)(u16array.buffer);
  437. return r(u8array, 0) === 0x12;
  438. }());
  439. // Constructor(ArrayBuffer buffer,
  440. // optional unsigned long byteOffset,
  441. // optional unsigned long byteLength)
  442. /** @constructor */
  443. var DataView = function DataView(buffer, byteOffset, byteLength) {
  444. if (arguments.length === 0) {
  445. buffer = new exports.ArrayBuffer(0);
  446. } else if (!(buffer instanceof exports.ArrayBuffer || ECMAScript.Class(buffer) === 'ArrayBuffer')) {
  447. throw new TypeError("TypeError");
  448. }
  449. this.buffer = buffer || new exports.ArrayBuffer(0);
  450. this.byteOffset = ECMAScript.ToUint32(byteOffset);
  451. if (this.byteOffset > this.buffer.byteLength) {
  452. throw new RangeError("byteOffset out of range");
  453. }
  454. if (arguments.length < 3) {
  455. this.byteLength = this.buffer.byteLength - this.byteOffset;
  456. } else {
  457. this.byteLength = ECMAScript.ToUint32(byteLength);
  458. }
  459. if ((this.byteOffset + this.byteLength) > this.buffer.byteLength) {
  460. throw new RangeError("byteOffset and length reference an area beyond the end of the buffer");
  461. }
  462. configureProperties(this);
  463. };
  464. function makeGetter(arrayType) {
  465. return function(byteOffset, littleEndian) {
  466. byteOffset = ECMAScript.ToUint32(byteOffset);
  467. if (byteOffset + arrayType.BYTES_PER_ELEMENT > this.byteLength) {
  468. throw new RangeError("Array index out of range");
  469. }
  470. byteOffset += this.byteOffset;
  471. var uint8Array = new exports.Uint8Array(this.buffer, byteOffset, arrayType.BYTES_PER_ELEMENT),
  472. bytes = [], i;
  473. for (i = 0; i < arrayType.BYTES_PER_ELEMENT; i += 1) {
  474. bytes.push(r(uint8Array, i));
  475. }
  476. if (Boolean(littleEndian) === Boolean(IS_BIG_ENDIAN)) {
  477. bytes.reverse();
  478. }
  479. return r(new arrayType(new exports.Uint8Array(bytes).buffer), 0);
  480. };
  481. }
  482. DataView.prototype.getUint8 = makeGetter(exports.Uint8Array);
  483. DataView.prototype.getInt8 = makeGetter(exports.Int8Array);
  484. DataView.prototype.getUint16 = makeGetter(exports.Uint16Array);
  485. DataView.prototype.getInt16 = makeGetter(exports.Int16Array);
  486. DataView.prototype.getUint32 = makeGetter(exports.Uint32Array);
  487. DataView.prototype.getInt32 = makeGetter(exports.Int32Array);
  488. DataView.prototype.getFloat32 = makeGetter(exports.Float32Array);
  489. DataView.prototype.getFloat64 = makeGetter(exports.Float64Array);
  490. function makeSetter(arrayType) {
  491. return function(byteOffset, value, littleEndian) {
  492. byteOffset = ECMAScript.ToUint32(byteOffset);
  493. if (byteOffset + arrayType.BYTES_PER_ELEMENT > this.byteLength) {
  494. throw new RangeError("Array index out of range");
  495. }
  496. // Get bytes
  497. var typeArray = new arrayType([value]),
  498. byteArray = new exports.Uint8Array(typeArray.buffer),
  499. bytes = [], i, byteView;
  500. for (i = 0; i < arrayType.BYTES_PER_ELEMENT; i += 1) {
  501. bytes.push(r(byteArray, i));
  502. }
  503. // Flip if necessary
  504. if (Boolean(littleEndian) === Boolean(IS_BIG_ENDIAN)) {
  505. bytes.reverse();
  506. }
  507. // Write them
  508. byteView = new exports.Uint8Array(this.buffer, byteOffset, arrayType.BYTES_PER_ELEMENT);
  509. byteView.set(bytes);
  510. };
  511. }
  512. DataView.prototype.setUint8 = makeSetter(exports.Uint8Array);
  513. DataView.prototype.setInt8 = makeSetter(exports.Int8Array);
  514. DataView.prototype.setUint16 = makeSetter(exports.Uint16Array);
  515. DataView.prototype.setInt16 = makeSetter(exports.Int16Array);
  516. DataView.prototype.setUint32 = makeSetter(exports.Uint32Array);
  517. DataView.prototype.setInt32 = makeSetter(exports.Int32Array);
  518. DataView.prototype.setFloat32 = makeSetter(exports.Float32Array);
  519. DataView.prototype.setFloat64 = makeSetter(exports.Float64Array);
  520. exports.DataView = exports.DataView || DataView;
  521. }());