Skip to content

Commit c5f537d

Browse files
committed
Add JavaScript.Web.Performance
1 parent c694b0f commit c5f537d

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

JavaScript/Web/Performance.hs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{-# LANGUAGE ForeignFunctionInterface, JavaScriptFFI, InterruptibleFFI,
2+
DeriveDataTypeable
3+
#-}
4+
5+
{- | The Performance interface represents timing-related performance information for the given page.
6+
-}
7+
8+
module JavaScript.Web.Performance
9+
( now
10+
) where
11+
12+
import GHCJS.Foreign.Callback
13+
import GHCJS.Marshal.Pure
14+
import GHCJS.Types
15+
16+
import Control.Exception (onException)
17+
import Data.Typeable
18+
19+
newtype AnimationFrameHandle = AnimationFrameHandle (JSRef ())
20+
deriving (Typeable)
21+
22+
{- | The 'now' computation returns a high resolution time stamp, measured in
23+
milliseconds, accurate to one thousandth of a millisecond.
24+
25+
The value represented by 0 varies according the context, but
26+
in dedicated workers created from a Window context, the epoch is the value
27+
of the @PerformanceTiming.navigationStart@ property.
28+
-}
29+
now :: IO Double
30+
now = js_performanceNow
31+
{-# INLINE now #-}
32+
33+
-- -----------------------------------------------------------------------------
34+
35+
foreign import javascript unsafe "performance.now()"
36+
js_performanceNow :: IO Double

ghcjs-base.cabal

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ library
4444
GeneralizedNewtypeDeriving
4545
ScopedTypeVariables
4646
TypeOperators
47-
47+
4848
ghc-options: -O
4949
exposed-modules: Data.JSString
5050
Data.JSString.Int
@@ -107,6 +107,7 @@ library
107107
JavaScript.Web.File
108108
JavaScript.Web.MessageEvent
109109
JavaScript.Web.MessageEvent.Internal
110+
JavaScript.Web.Performance
110111
JavaScript.Web.Storage
111112
JavaScript.Web.Storage.Internal
112113
JavaScript.Web.StorageEvent
@@ -168,5 +169,3 @@ test-suite tests
168169
test-framework >= 0.4,
169170
test-framework-hunit >= 0.2,
170171
test-framework-quickcheck2 >= 0.2
171-
172-

0 commit comments

Comments
 (0)