@@ -10,14 +10,14 @@ import Data.ArrayBuffer.Types
1010foreign import data ArrayView :: * -> *
1111
1212type Int8Array = ArrayView Int8
13+ type Int16Array = ArrayView Int16
14+ type Int32Array = ArrayView Int32
1315type Uint8Array = ArrayView Uint8
14- -- type Uint8ClampedArray = ArrayView Uint8Clamped
15- -- type Int16Array = ArrayView Int16
16- -- type Uint16Array = ArrayView Uint16
17- -- type Int32Array = ArrayView Int32
18- -- type Uint32Array = ArrayView Uint32
19- -- type Float32Array = ArrayView Float32
20- -- type Float64Array = ArrayView Float64
16+ type Uint16Array = ArrayView Uint16
17+ type Uint32Array = ArrayView Uint32
18+ type Uint8ClampedArray = ArrayView Uint8Clamped
19+ type Float32Array = ArrayView Float32
20+ type Float64Array = ArrayView Float64
2121
2222foreign import asInt8Array
2323"""
@@ -26,13 +26,62 @@ function asInt8Array(v) {
2626}
2727""" :: DataView -> Int8Array
2828
29+ foreign import asInt16Array
30+ """
31+ function asInt16Array(v) {
32+ return new Int16Array(v.buffer, v.byteOffset, v.byteLength >>> 1);
33+ }
34+ """ :: DataView -> Int16Array
35+
36+ foreign import asInt32Array
37+ """
38+ function asInt32Array(v) {
39+ return new Int32Array(v.buffer, v.byteOffset, v.byteLength >>> 2);
40+ }
41+ """ :: DataView -> Int32Array
42+
2943foreign import asUint8Array
3044"""
3145function asUint8Array(v) {
3246 return new Uint8Array(v.buffer, v.byteOffset, v.byteLength);
3347}
3448""" :: DataView -> Uint8Array
3549
50+ foreign import asUint16Array
51+ """
52+ function asUint16Array(v) {
53+ return new Uint16Array(v.buffer, v.byteOffset, v.byteLength >>> 1);
54+ }
55+ """ :: DataView -> Uint16Array
56+
57+ foreign import asUint32Array
58+ """
59+ function asUint32Array(v) {
60+ return new Uint32Array(v.buffer, v.byteOffset, v.byteLength >>> 2);
61+ }
62+ """ :: DataView -> Uint32Array
63+
64+ foreign import asUint8ClampedArray
65+ """
66+ function asUint8ClampedArray(v) {
67+ return new Uint8ClampedArray(v.buffer, v.byteOffset, v.byteLength);
68+ }
69+ """ :: DataView -> Uint8ClampedArray
70+
71+ foreign import asFloat32Array
72+ """
73+ function asFloat32Array(v) {
74+ return new Float32Array(v.buffer, v.byteOffset, v.byteLength >>> 2);
75+ }
76+ """ :: DataView -> Float32Array
77+
78+ foreign import asFloat64Array
79+ """
80+ function asFloat64Array(v) {
81+ return new Float64Array(v.buffer, v.byteOffset, v.byteLength >>> 3);
82+ }
83+ """ :: DataView -> Float64Array
84+
3685foreign import dataView
3786"""
3887function dataView(a) {
@@ -66,8 +115,9 @@ at a n = if a `hasIndex` n then
66115foreign import toArray
67116"""
68117function toArray(a) {
69- var ret = [];
70- for (var i = 0, l = a.length; i < l; i++)
118+ var l = a.length;
119+ var ret = new Array(l);
120+ for (var i = 0; i < l; i++)
71121 ret[i] = a[i];
72122 return ret;
73123}
0 commit comments