Skip to content

Commit cf5ea14

Browse files
committed
typed arrays redone
1 parent 29c1c4f commit cf5ea14

File tree

20 files changed

+1260
-1659
lines changed

20 files changed

+1260
-1659
lines changed

GHCJS/Buffer.hs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ import qualified Data.ByteString.Unsafe as BS
5252
import qualified Data.ByteString.Internal as BS
5353
import Data.Primitive.ByteArray
5454

55-
import qualified JavaScript.TypedArray.Internal.Types as I
56-
import JavaScript.TypedArray.ArrayBuffer.Internal (SomeArrayBuffer)
57-
import JavaScript.TypedArray.DataView.Internal (SomeDataView)
58-
import qualified JavaScript.TypedArray.Internal as I
55+
import JavaScript.TypedArray
56+
hiding (fromByteArrayPrim, toByteArrayPrim, fromMutableByteArrayPrim, toMutableByteArrayPrim
57+
, toByteArray, fromByteArray)
5958

6059
import GHC.ForeignPtr
6160

@@ -72,23 +71,23 @@ getArrayBuffer :: SomeBuffer any -> SomeArrayBuffer any
7271
getArrayBuffer buf = js_getArrayBuffer buf
7372
{-# INLINE getArrayBuffer #-}
7473

75-
getInt32Array :: SomeBuffer any -> I.SomeInt32Array any
74+
getInt32Array :: SomeBuffer any -> SomeTypedArray any Int32
7675
getInt32Array buf = js_getInt32Array buf
7776
{-# INLINE getInt32Array #-}
7877

79-
getUint8Array :: SomeBuffer any -> I.SomeUint8Array any
78+
getUint8Array :: SomeBuffer any -> SomeTypedArray any Word8
8079
getUint8Array buf = js_getUint8Array buf
8180
{-# INLINE getUint8Array #-}
8281

83-
getUint16Array :: SomeBuffer any -> I.SomeUint16Array any
82+
getUint16Array :: SomeBuffer any -> SomeTypedArray any Word16
8483
getUint16Array buf = js_getUint16Array buf
8584
{-# INLINE getUint16Array #-}
8685

87-
getFloat32Array :: SomeBuffer any -> I.SomeFloat32Array any
86+
getFloat32Array :: SomeBuffer any -> SomeTypedArray any Float
8887
getFloat32Array buf = js_getFloat32Array buf
8988
{-# INLINE getFloat32Array #-}
9089

91-
getFloat64Array :: SomeBuffer any -> I.SomeFloat64Array any
90+
getFloat64Array :: SomeBuffer any -> SomeTypedArray any Double
9291
getFloat64Array buf = js_getFloat64Array buf
9392
{-# INLINE getFloat64Array #-}
9493

@@ -180,9 +179,11 @@ unsafeToPtr :: Buffer -> Ptr a
180179
unsafeToPtr buf = Ptr (js_toAddr buf)
181180
{-# INLINE unsafeToPtr #-}
182181

183-
byteLength :: SomeBuffer any -> Int
184-
byteLength buf = js_byteLength buf
185-
{-# INLINE byteLength #-}
182+
instance ArrayBufferData (SomeBuffer m) where
183+
{-# INLINE byteLength #-}
184+
byteLength = js_byteLength
185+
{-# INLINE sliceImmutable #-}
186+
sliceImmutable = undefined
186187

187188
-- ----------------------------------------------------------------------------
188189

@@ -198,25 +199,25 @@ foreign import javascript unsafe
198199
foreign import javascript unsafe
199200
"$1.buf" js_getArrayBuffer :: SomeBuffer any -> SomeArrayBuffer any
200201
foreign import javascript unsafe
201-
"$1.i3" js_getInt32Array :: SomeBuffer any -> I.SomeInt32Array any
202+
"$1.i3" js_getInt32Array :: SomeBuffer any -> SomeTypedArray any Int32
202203
foreign import javascript unsafe
203-
"$1.u8" js_getUint8Array :: SomeBuffer any -> I.SomeUint8Array any
204+
"$1.u8" js_getUint8Array :: SomeBuffer any -> SomeTypedArray any Word8
204205
foreign import javascript unsafe
205-
"$1.u1" js_getUint16Array :: SomeBuffer any -> I.SomeUint16Array any
206+
"$1.u1" js_getUint16Array :: SomeBuffer any -> SomeTypedArray any Word16
206207
foreign import javascript unsafe
207-
"$1.f3" js_getFloat32Array :: SomeBuffer any -> I.SomeFloat32Array any
208+
"$1.f3" js_getFloat32Array :: SomeBuffer any -> SomeTypedArray any Float
208209
foreign import javascript unsafe
209-
"$1.f6" js_getFloat64Array :: SomeBuffer any -> I.SomeFloat64Array any
210+
"$1.f6" js_getFloat64Array :: SomeBuffer any -> SomeTypedArray any Double
210211
foreign import javascript unsafe
211212
"$1.dv" js_getDataView :: SomeBuffer any -> SomeDataView any
212213

213214
-- ----------------------------------------------------------------------------
214215
-- these things have the same representation (modulo boxing),
215216
-- conversion is free
216217

217-
foreign import javascript unsafe
218+
foreign import javascript unsafe
218219
"$r = $1;" js_toByteArray :: SomeBuffer any -> ByteArray#
219-
foreign import javascript unsafe
220+
foreign import javascript unsafe
220221
"$r = $1;" js_fromByteArray :: ByteArray# -> JSVal
221222
foreign import javascript unsafe
222223
"$r = $1;" js_fromMutableByteArray :: MutableByteArray# s -> JSVal

0 commit comments

Comments
 (0)