Skip to content

Commit 5200641

Browse files
committed
polyfill
1 parent addf664 commit 5200641

File tree

2 files changed

+32
-21
lines changed

2 files changed

+32
-21
lines changed

Diff for: src/Data/ArrayBuffer/Typed.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
"use strict";
22

33

4-
// Lightweight polyfill for ie - see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#Methods_Polyfill
5-
var typedArrayTypes = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array,
6-
Uint16Array, ​​​Int32Array, Uint32Array, ​​​Float32Array, Float64Array];
7-
8-
for (var k in typedArrayTypes)
9-
for (var v in Array.prototype)
10-
if (Array.prototype.hasOwnProperty(v) &&
11-
!typedArrayTypes[k].prototype.hasOwnProperty(v))
12-
typedArrayTypes[k].prototype[v] = Array.prototype[v];
4+
exports.polyFill = function () {
5+
var typedArrayTypes =
6+
[ Int8Array, Uint8Array, Uint8ClampedArray, Int16Array
7+
, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array
8+
];
9+
10+
for (var k in typedArrayTypes) {
11+
for (var v in Array.prototype) {
12+
if (Array.prototype.hasOwnProperty(v) && !typedArrayTypes[k].prototype.hasOwnProperty(v))
13+
typedArrayTypes[k].prototype[v] = Array.prototype[v];
14+
}
15+
}
16+
};
1317

1418

1519
// module Data.ArrayBuffer.Typed

Diff for: src/Data/ArrayBuffer/Typed.purs

+19-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
module Data.ArrayBuffer.Typed
2-
( buffer
2+
( polyFill
3+
, buffer
34
, byteOffset
45
, byteLength
6+
, AProxy (..)
57
, class Bytes
68
, bytesPer
79
, length
@@ -15,17 +17,20 @@ module Data.ArrayBuffer.Typed
1517

1618
import Prelude
1719
import Effect (Effect)
20+
import Effect.Uncurried (EffectFn2, runEffectFn2)
1821
import Data.ArrayBuffer.Types
19-
( ArrayView, ByteOffset
22+
( ArrayView, kind ArrayViewType, ArrayBuffer, ByteOffset, ByteLength
2023
, Float64Array, Float32Array
2124
, Uint8ClampedArray, Uint32Array, Uint16Array, Uint8Array, Int32Array, Int16Array, Int8Array
2225
, Float64, Float32
2326
, Uint8Clamped, Uint32, Uint16, Uint8, Int32, Int16, Int8)
2427
import Data.Function.Uncurried (Fn2, Fn3, runFn2, runFn3)
2528
import Data.Maybe (Maybe(..))
26-
import Type.Proxy (Proxy(..))
2729

2830

31+
-- | Lightweight polyfill for ie - see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#Methods_Polyfill
32+
foreign import polyFill :: Effect Unit
33+
2934
-- | `ArrayBuffer` being mapped by the typed array.
3035
foreign import buffer :: forall a. ArrayView a -> ArrayBuffer
3136

@@ -37,23 +42,25 @@ foreign import byteLength :: forall a. ArrayView a -> ByteLength
3742

3843
foreign import lengthImpl :: forall a. ArrayView a -> Int
3944

40-
class Bytes a where
41-
bytesPer :: Proxy a -> Int
45+
data AProxy (a :: ArrayViewType) = AProxy
46+
47+
class Bytes (a :: ArrayViewType) where
48+
bytesPer :: AProxy a -> Int
4249

4350
instance bytesUint8Clamped :: Bytes Uint8Clamped where
44-
bytesPer Proxy = 1
51+
bytesPer AProxy = 1
4552
instance bytesUint32 :: Bytes Uint32 where
46-
bytesPer Proxy = 4
53+
bytesPer AProxy = 4
4754
instance bytesUint16 :: Bytes Uint16 where
48-
bytesPer Proxy = 2
55+
bytesPer AProxy = 2
4956
instance bytesUint8 :: Bytes Uint8 where
50-
bytesPer Proxy = 1
57+
bytesPer AProxy = 1
5158
instance bytesInt32 :: Bytes Int32 where
52-
bytesPer Proxy = 4
59+
bytesPer AProxy = 4
5360
instance bytesInt16 :: Bytes Int16 where
54-
bytesPer Proxy = 2
61+
bytesPer AProxy = 2
5562
instance bytesInt8 :: Bytes Int8 where
56-
bytesPer Proxy = 1
63+
bytesPer AProxy = 1
5764

5865
length :: forall a. Bytes a => ArrayView a -> Int
5966
length = lengthImpl

0 commit comments

Comments
 (0)