on c12cb3f help sign in
27 files changed+290−201
since splitsnapshots
unifiedsplit
.travis.yml+40−37 README.md+6−6 cabal.project+35−3 default.nix+8 jsaddle-clib/default.nix+9 jsaddle-clib/jsaddle-clib.cabal+3−4 jsaddle-clib/src-ghc/Language/Javascript/JSaddle/CLib.hs+1−3 jsaddle-warp/default.nix+31 jsaddle-warp/jsaddle-warp.cabal+7−7 jsaddle-warp/src/Language/Javascript/JSaddle/WebSockets.hs+1−1 jsaddle-webkit2gtk/default.nix+16 jsaddle-webkit2gtk/jsaddle-webkit2gtk.cabal+4−4 jsaddle-webkit2gtk/src/Language/Javascript/JSaddle/WebKitGTK.hs+36−15 jsaddle-webkitgtk/default.nix+16 jsaddle-wkwebview/cbits-cocoa/AppDelegate.m+1−10 jsaddle-wkwebview/cbits-uikit/AppDelegate.m−12 jsaddle-wkwebview/default.nix+30−14 jsaddle-wkwebview/jsaddle-wkwebview.cabal+3−5 jsaddle-wkwebview/src-ghc/Language/Javascript/JSaddle/WKWebView.hs+1−40 jsaddle-wkwebview/src/Language/Javascript/JSaddle/WKWebView/Internal.hs−13 jsaddle/default.nix+23 jsaddle/jsaddle.cabal+9−10 jsaddle/src-ghc/JavaScript/Array.hs+2−2 jsaddle/src/Language/Javascript/JSaddle/Evaluate.hs+1−1 jsaddle/src/Language/Javascript/JSaddle/Object.hs+6−5 jsaddle/src/Language/Javascript/JSaddle/Run/Files.hs+1−1 nix/hix.nix−8
.travis.yml+40−37
@@ -1,47 +1,50 @@
1−language: nix
2−nix: 2.2.2
1+language: c
32
4−jobs:
3+#ghc:
4+# - "8.4.4"
5+
6+sudo: false
7+
8+dist: xenial
9+#addons:
10+# apt:
11+# sources:
12+# - ppa:hvr/ghc
13+# packages:
14+# - libgirepository1.0-dev
15+# - libwebkit2gtk-4.0-dev,phantomjs
16+
17+cache:
18+ directories:
19+ - $HOME/.cabal
20+ - $HOME/.ghc
21+
22+matrix:
523 include:
6− - stage: Build
7− env: OS=linux GHCVER=ghc865
8− - stage: Build
9− env: OS=linux GHCVER=ghc881
10− - env: OS=macos GHCVER=ghc865
11− os: osx
12− # Fix OSX, see https://travis-ci.community/t/cannot-use-nix-support-on-osx/2927
13− language: generic
14− before_install:
15− - curl https://nixos.org/nix/install | sh
16− - source /Users/travis/.nix-profile/etc/profile.d/nix.sh
17− - env: OS=macos GHCVER=ghc881
18− os: osx
19− # Fix OSX, see https://travis-ci.community/t/cannot-use-nix-support-on-osx/2927
20− language: generic
21− before_install:
22− - curl https://nixos.org/nix/install | sh
23− - source /Users/travis/.nix-profile/etc/profile.d/nix.sh
24+# - env: CABALVER=2.0 GHCVER=8.2.2
25+# addons: {apt: {packages: [cabal-install-2.0,ghc-8.2.2,happy-1.19.5,alex-3.1.7,libgirepository1.0-dev,libwebkit2gtk-4.0-dev,phantomjs], sources: [hvr-ghc]}}
26+ - env: CABALVER=2.2 GHCVER=8.4.4
27+ addons: {apt: {packages: [cabal-install-2.2,ghc-8.4.4,happy-1.19.5,alex-3.1.7,libgirepository1.0-dev,libwebkit2gtk-4.0-dev,phantomjs], sources: [hvr-ghc]}}
28+# - env: CABALVER=2.4 GHCVER=8.6.3
29+# addons: {apt: {packages: [cabal-install-2.4,ghc-8.6.3,happy-1.19.5,alex-3.1.7,libgirepository1.0-dev,libwebkit2gtk-4.0-dev,phantomjs], sources: [hvr-ghc]}}
30+# - env: CABALVER=head GHCVER=head
31+# addons: {apt: {packages: [cabal-install-head,ghc-head,happy-1.19.5,alex-3.1.7,libgirepository1.0-dev,libwebkit2gtk-4.0-dev,phantomjs], sources: [hvr-ghc]}}
32+ allow_failures:
33+ - env: CABALVER=head GHCVER=head
34+
35+before_install:
36+ - export PATH=$HOME/.cabal/bin:/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:/opt/alex/3.1.7/bin:/opt/happy/1.19.5/bin:$PATH
2437
2538install:
26−- sudo mkdir -p /etc/nix
27−- echo "substituters = https://cache.nixos.org https://hydra.iohk.io" | sudo tee -a /etc/nix/nix.conf > /dev/null
28−- echo "trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=" | sudo tee -a /etc/nix/nix.conf > /dev/null
39+ - cabal --version
40+ - echo "$(ghc --version) [$(ghc --print-project-git-commit-id 2> /dev/null || echo '?')]"
41+ - cabal update
2942
3043script:
31−- nix-build --argstr haskellCompiler $GHCVER -A hsPkgs.jsaddle.components.library
32−- nix-build --argstr haskellCompiler $GHCVER -A hsPkgs.jsaddle-warp.components.library
33−- nix-build --argstr haskellCompiler $GHCVER -A hsPkgs.jsaddle-clib.components.library
34−- |
35− if [ "$OS" == "macos" ]; then
36− nix-build --argstr haskellCompiler $GHCVER -A hsPkgs.jsaddle-wkwebview.components.library
37− fi
38−# TODO try to find how to get working webkitgtk with nix on macOS
39−- |
40− if [ "$OS" != "macos" ]; then
41− nix-build --argstr haskellCompiler $GHCVER -A hsPkgs.jsaddle-webkit2gtk.components.library
42− fi
44+ ./travis/build.sh
4345
4446notifications:
4547 irc:
4648 channels: "irc.freenode.net#ghcjs"
47− email: true
49+ skip_join: true
50+ email: true
README.md+6−6
@@ -80,7 +80,7 @@ main = run 3708 $ do
8080 appendChild newParagraph text
8181 appendChild body (Just newParagraph)
8282 return ()
83−
83+
8484 -- Make an exit button
8585 exitMVar <- liftIO newEmptyMVar
8686 Just exit <- createElement doc (Just "span")
@@ -111,8 +111,8 @@ There are a number of different JSaddle runners to choose from
111111* [jsaddle-clib](https://hackage.haskell.org/package/jsaddle-clib) - C interface used to run JSaddle on Android using JNI.
112112
113113In all of these cases a web control or browser of some sort is used. An
114−[HTML file](./jsaddle/src/Language/Javascript/JSaddle/Run/Files.hs#L24)
115−and a [small JavaScript command interpreter](./jsaddle/src/Language/Javascript/JSaddle/Run/Files.hs#L340)
114+[HTML file](https://github.com/ghcjs/jsaddle/blob/master/data/index.html)
115+and a [small JavaScript command interpreter](https://github.com/ghcjs/jsaddle/blob/master/data/jsaddle.js)
116116are loaded into it. Then the native GHC compiled JSaddle code runs. In order to interact with the browser
117117it sends commands to the JavaScript command interpreter. The mechanism for sending the commands differs
118118for the different runners, but they are always combined into batches and encoded in JSON.
@@ -137,7 +137,7 @@ The first five keys `[0..4]` are
137137these values. Both the Haskell code and `jsaddle.js` can allocate new `JSVal` keys. The Haskell code allocates negative
138138keys and `jsaddle.js` allocates positive keys to avoid clashing.
139139
140−The haskell code will not know the value to go with the key, but it will include it in commands to the server
140+The haskell code will not know the value of the to go with the key, but it will include it in commands to the server
141141that are sort of "hey call this function and put the result in the map with this key"). This allows for the
142142lazy execution of the JSaddle code.
143143
@@ -146,7 +146,7 @@ when the JSVal is no longer reachable. The `jsaddle.js` code then deletes the k
146146
147147### JSStrings
148148
149−These are haskell `Text` type and so reside on the native side of the WebSocket. If you want to avoid transferring large string values over the WebSocket use `toJSVal` to convert it to a `JSVal`.
149+These are haskell `Text` type and so reside on the native side of the WebSocket. If you want to make avoid transferring large string values over the WebSocket use `toJSVal` to convert it to a `JSVal`.
150150
151151### Lazy Execution
152152
@@ -213,7 +213,7 @@ JSaddle does not support exceptions well. When compiled with GHCJS an exception
213213at the point the exception is thrown.
214214
215215When using GHC the Haskell executions will probably continue for a while before the exception is received at all by the Haskell code
216−(because the lazy execution of the JS code). The exception will be thrown when the next synchronous command is executed.
216+(because the lazy execution of the JS code). The exception will be thrown when the the next synchronous command is executed.
217217When it reaches the synchronous command a haskell type JSException will be thrown (this may not be the thread that initiated the
218218command that caused the exception). You can use `syncPoint` and `syncAfter` to force the exception to be thrown.
219219There are `JSM` versions of `catch` and `bracket` that also include a `syncPoint` call.
cabal.project+35−3
@@ -1,10 +1,42 @@
1+flags: -overloaded-methods -overloaded-signals -overloaded-properties
2+
13packages:
24 jsaddle/
35 jsaddle-warp/
46 jsaddle-wkwebview/
7+-- jsaddle-webkitgtk/
58 jsaddle-webkit2gtk/
69 jsaddle-clib/
710
8−constraints: haskell-gi-overloading == 0.0
9−
10−allow-newer: websockets:random, splitmix:time, *:time, *:unix, *:process, stm:base
11+package gi-atk
12+ flags: -overloaded-methods -overloaded-signals -overloaded-properties
13+package gi-cairo
14+ flags: -overloaded-methods -overloaded-signals -overloaded-properties
15+package gi-gdk
16+ flags: -overloaded-methods -overloaded-signals -overloaded-properties
17+package gi-gdkpixbuf
18+ flags: -overloaded-methods -overloaded-signals -overloaded-properties
19+package gi-gio
20+ flags: -overloaded-methods -overloaded-signals -overloaded-properties
21+package gi-glib
22+ flags: -overloaded-methods -overloaded-signals -overloaded-properties
23+package gi-gobject
24+ flags: -overloaded-methods -overloaded-signals -overloaded-properties
25+package gi-gtk
26+ flags: -overloaded-methods -overloaded-signals -overloaded-properties
27+package gi-gtk-hs
28+ flags: -overloaded-methods -overloaded-signals -overloaded-properties
29+package gi-gtkosxapplication
30+ flags: -overloaded-methods -overloaded-signals -overloaded-properties
31+package gi-gtksource
32+ flags: -overloaded-methods -overloaded-signals -overloaded-properties
33+package gi-javascriptcore
34+ flags: -overloaded-methods -overloaded-signals -overloaded-properties
35+package gi-pango
36+ flags: -overloaded-methods -overloaded-signals -overloaded-properties
37+package gi-soup
38+ flags: -overloaded-methods -overloaded-signals -overloaded-properties
39+package gi-webkit
40+ flags: -overloaded-methods -overloaded-signals -overloaded-properties
41+package gi-webkit2
42+ flags: -overloaded-methods -overloaded-signals -overloaded-properties
default.nixnew file+8
@@ -0,0 +1,8 @@
1+haskellPackages: {
2+ jsaddle = haskellPackages.callPackage ./jsaddle {};
3+ jsaddle-warp = haskellPackages.callPackage ./jsaddle-warp {};
4+ jsaddle-wkwebview = haskellPackages.callPackage ./jsaddle-wkwebview {};
5+ jsaddle-webkit2gtk = haskellPackages.callPackage ./jsaddle-webkit2gtk {};
6+ jsaddle-webkitgtk = haskellPackages.callPackage ./jsaddle-webkitgtk {};
7+ jsaddle-clib = haskellPackages.callPackage ./jsaddle-clib {};
8+}
jsaddle-clib/default.nixnew file+9
@@ -0,0 +1,9 @@
1+{ mkDerivation, aeson, base, bytestring, data-default, jsaddle, stdenv, text }:
2+mkDerivation {
3+ pname = "jsaddle-clib";
4+ version = "0.9.0.0";
5+ src = builtins.filterSource (path: type: !(builtins.elem (baseNameOf path) [ ".git" "dist" ])) ./.;
6+ libraryHaskellDepends = [ aeson base bytestring data-default jsaddle text ];
7+ description = "Interface for JavaScript that works with GHCJS and GHC";
8+ license = stdenv.lib.licenses.mit;
9+}
jsaddle-clib/jsaddle-clib.cabal+3−4
@@ -1,5 +1,5 @@
11name: jsaddle-clib
2−version: 0.9.8.0
2+version: 0.9.6.0
33cabal-version: >=1.10
44build-type: Simple
55license: MIT
@@ -21,9 +21,8 @@ library
2121 Language.Javascript.JSaddle.CLib
2222 Language.Javascript.JSaddle.CLib.Internal
2323 build-depends:
24− aeson >=0.8.0.2 && <1.6,
24+ aeson >=0.8.0.2 && <1.5,
2525 base <5,
26− base-compat >=0.9.0 && <0.12,
2726 bytestring >=0.10.6.0 && <0.11,
2827 jsaddle >= 0.9.0.0 && <0.10,
2928 data-default,
@@ -33,7 +32,7 @@ library
3332 Include-dirs: cbits/include
3433 Includes: jsaddle.h
3534 Install-includes: jsaddle.h
36− ghc-options: -ferror-spans -Wall
35+ ghc-options: -ferror-spans -Wall -Werror
3736 if impl(ghcjs)
3837 hs-source-dirs: src-ghcjs
3938 else
jsaddle-clib/src-ghc/Language/Javascript/JSaddle/CLib.hs+1−3
@@ -8,9 +8,6 @@ module Language.Javascript.JSaddle.CLib
88 , appConfigToAppCallbacks
99 ) where
1010
11−import Prelude ()
12−import Prelude.Compat
13−
1411import Control.Monad (void)
1512import Control.Concurrent (forkIO)
1613
@@ -19,6 +16,7 @@ import Data.ByteString (useAsCString, packCString)
1916import Data.ByteString.Char8 (unpack)
2017import Data.ByteString.Lazy (ByteString, toStrict, fromStrict)
2118import Data.Default (def, Default)
19+import Data.Monoid ((<>))
2220import Data.Text (Text)
2321import qualified Data.Text.Encoding as T
2422
jsaddle-warp/default.nixnew file+31
@@ -0,0 +1,31 @@
1+{ mkDerivation, aeson, base, bytestring, containers, deepseq
2+, doctest, filepath, foreign-store, ghc-prim, http-types, jsaddle
3+, lens, network, primitive, process, QuickCheck, ref-tf, stdenv
4+, stm, text, time, transformers, uuid, uuid-types, wai
5+, wai-websockets, warp, webdriver, websockets, ghc
6+}:
7+mkDerivation {
8+ pname = "jsaddle-warp";
9+ version = "0.9.6.0";
10+ src = builtins.filterSource (path: type: !(builtins.elem (baseNameOf path) [ ".git" "dist" ])) ./.;
11+ libraryHaskellDepends = [
12+ base
13+ ] ++ (if ghc.isGhcjs or false
14+ then []
15+ else [
16+ aeson bytestring containers foreign-store http-types jsaddle
17+ stm text time transformers uuid uuid-types wai wai-websockets warp
18+ websockets
19+ ]);
20+ testHaskellDepends = if ghc.isGhcjs or false
21+ then []
22+ else [
23+ aeson base bytestring containers deepseq doctest filepath ghc-prim
24+ http-types jsaddle lens network primitive process QuickCheck ref-tf
25+ stm text time transformers wai wai-websockets warp webdriver
26+ websockets
27+ ];
28+ testTarget = "--test-option=${jsaddle.src}";
29+ description = "Interface for JavaScript that works with GHCJS and GHC";
30+ license = stdenv.lib.licenses.mit;
31+}
jsaddle-warp/jsaddle-warp.cabal+7−7
@@ -1,5 +1,5 @@
11name: jsaddle-warp
2−version: 0.9.8.0
2+version: 0.9.6.0
33cabal-version: >=1.10
44build-type: Simple
55license: MIT
@@ -10,7 +10,7 @@ description:
1010 This package provides an EDSL for calling JavaScript that
1111 can be used both from GHCJS and GHC. When using GHC
1212 the application is run using Warp and WebSockets to
13− drive a small JavaScript helper.
13+ drive a small JavaScipt helper.
1414category: Web, Javascript
1515author: Hamish Mackenzie
1616
@@ -27,7 +27,7 @@ library
2727 other-modules:
2828 Language.Javascript.JSaddle.WebSockets.Compat
2929 build-depends:
30− aeson >=0.8.0.2 && <1.6,
30+ aeson >=0.8.0.2 && <1.5,
3131 bytestring >=0.10.6.0 && <0.11,
3232 containers >=0.5.6.2 && <0.7,
3333 foreign-store >=0.2 && <0.3,
@@ -35,11 +35,11 @@ library
3535 jsaddle >=0.9.4.0 && <0.10,
3636 stm >=2.4.4 && <2.6,
3737 text >=1.2.1.3 && <1.3,
38− time >=1.5.0.1 && <1.11,
38+ time >=1.5.0.1 && <1.9,
3939 transformers >=0.4.2.0 && <0.6,
4040 wai >=3.0.3.0 && <3.3,
4141 wai-websockets >=3.0.0.6 && <3.1,
42− warp >=3.1.2 && <3.4,
42+ warp >=3.1.2 && <3.3,
4343 websockets >=0.9.5.0 && <0.13
4444 exposed-modules:
4545 Language.Javascript.JSaddle.Warp
@@ -59,7 +59,7 @@ test-suite test-tool
5959 bytestring -any,
6060 containers -any,
6161 deepseq -any,
62− doctest >=0.10.1 && <0.19,
62+ doctest >=0.10.1 && <0.17,
6363 exceptions -any,
6464 filepath >=1.4.0.0 && <1.5,
6565 foreign-store -any,
@@ -81,7 +81,7 @@ test-suite test-tool
8181 wai -any,
8282 wai-websockets -any,
8383 warp -any,
84− webdriver >=0.8.4 && <0.10,
84+ webdriver >=0.8.4 && <0.9,
8585 websockets -any
8686 type: exitcode-stdio-1.0
8787 main-is: DocTest.hs
jsaddle-warp/src/Language/Javascript/JSaddle/WebSockets.hs+1−1
@@ -176,7 +176,7 @@ jsaddleJs = jsaddleJs' Nothing
176176-- sed -e 's|\\|\\\\|g' -e 's|^| \\|' -e 's|$|\\n\\|' -e 's|"|\\"|g' data/jsaddle.js | pbcopy
177177jsaddleJs' :: Maybe ByteString -> Bool -> ByteString
178178jsaddleJs' jsaddleUri refreshOnLoad = "\
179− \if(typeof global !== \"undefined\" && typeof require === \"function\") {\n\
179+ \if(typeof global !== \"undefined\") {\n\
180180 \ global.window = global;\n\
181181 \ global.WebSocket = require('ws');\n\
182182 \}\n\
jsaddle-webkit2gtk/default.nixnew file+16
@@ -0,0 +1,16 @@
1+{ mkDerivation, aeson, base, bytestring, directory, gi-gio, gi-glib
2+, gi-gtk, gi-javascriptcore, gi-webkit2, haskell-gi-base, jsaddle
3+, stdenv, text, unix, webkit2gtk3-javascriptcore
4+}:
5+mkDerivation {
6+ pname = "jsaddle-webkit2gtk";
7+ version = "0.9.6.0";
8+ src = builtins.filterSource (path: type: !(builtins.elem (baseNameOf path) [ ".git" "dist" ])) ./.;
9+ libraryHaskellDepends = [
10+ aeson base bytestring directory gi-gio gi-glib gi-gtk
11+ gi-javascriptcore gi-webkit2 haskell-gi-base jsaddle text unix
12+ webkit2gtk3-javascriptcore
13+ ];
14+ description = "Interface for JavaScript that works with GHCJS and GHC";
15+ license = stdenv.lib.licenses.mit;
16+}
jsaddle-webkit2gtk/jsaddle-webkit2gtk.cabal+4−4
@@ -1,5 +1,5 @@
11name: jsaddle-webkit2gtk
2−version: 0.9.8.0
2+version: 0.9.6.0
33cabal-version: >=1.10
44build-type: Simple
55license: MIT
@@ -26,7 +26,7 @@ library
2626 base <5
2727 if !impl(ghcjs -any)
2828 build-depends:
29− aeson >=0.8.0.2 && <1.6,
29+ aeson >=0.8.0.2 && <1.5,
3030 base <5,
3131 bytestring >=0.10.6.0 && <0.11,
3232 directory >=1.0.0.2 && <1.4,
@@ -35,8 +35,8 @@ library
3535 gi-gtk >=3.0.17 && <3.1,
3636 gi-webkit2 >=4.0.14 && <4.1,
3737 gi-javascriptcore >=4.0.14 && <4.1,
38− haskell-gi-base >=0.20 && <0.26,
39− haskell-gi-overloading >=0.0 && < 2.0,
38+ haskell-gi-base >=0.20 && <0.22,
39+ haskell-gi-overloading ==0.0.*,
4040 jsaddle >=0.9.4.0 && <0.10,
4141 text >=1.2.1.3 && <1.3,
4242 webkit2gtk3-javascriptcore >=0.14.0.0 && <0.15
jsaddle-webkit2gtk/src/Language/Javascript/JSaddle/WebKitGTK.hs+36−15
@@ -43,24 +43,29 @@ import Data.Monoid ((<>))
4343import Data.ByteString.Lazy (toStrict, fromStrict)
4444import qualified Data.ByteString.Lazy as LB (ByteString)
4545import Data.Aeson (encode, decode)
46+import Data.Text (Text)
4647import qualified Data.Text as T (pack)
48+import Data.Text.Foreign (fromPtr)
4749import Data.Text.Encoding (decodeUtf8, encodeUtf8)
4850
51+import Foreign.Ptr (castPtr, nullPtr)
52+
4953import Data.GI.Base.BasicTypes (GObject)
5054import Data.GI.Base.Signals
5155 (connectSignalFunPtr, SignalConnectMode(..), SignalConnectMode,
5256 SignalHandlerId)
57+import Data.GI.Base.ManagedPtr (withManagedPtr)
5358
5459import GI.GLib (timeoutAdd, idleAdd, pattern PRIORITY_HIGH, pattern PRIORITY_DEFAULT)
5560import qualified GI.Gtk as Gtk (main, init)
5661import GI.Gtk
5762 (windowSetPosition, windowSetDefaultSize, windowNew,
58− scrolledWindowNew, Adjustment, containerAdd,
63+ scrolledWindowNew, noAdjustment, containerAdd,
5964 WindowType(..), WindowPosition(..), widgetDestroy,
6065 widgetGetToplevel, widgetShowAll, onWidgetDestroy,
6166 mainQuit)
62−import GI.Gio (Cancellable)
63−import GI.JavaScriptCore (valueToString)
67+import GI.Gio (noCancellable)
68+import GI.JavaScriptCore (Value(..), GlobalContext(..))
6469import GI.WebKit2
6570 (scriptDialogPromptSetText, scriptDialogPromptGetDefaultText,
6671 scriptDialogGetMessage, scriptDialogGetDialogType,
@@ -69,7 +74,7 @@ import GI.WebKit2
6974 setSettingsEnableJavascript, webViewNewWithUserContentManager,
7075 userContentManagerNew,
7176 userContentManagerRegisterScriptMessageHandler,
72− javascriptResultGetJsValue,
77+ javascriptResultGetValue, javascriptResultGetGlobalContext,
7378 webViewGetUserContentManager,
7479 mk_UserContentManagerScriptMessageReceivedCallback,
7580 wrap_UserContentManagerScriptMessageReceivedCallback,
@@ -78,16 +83,17 @@ import GI.WebKit2
7883 onWebViewLoadChanged, setSettingsEnableDeveloperExtras,
7984 webViewSetSettings, webViewGetSettings, ScriptDialogType(..))
8085
86+import Graphics.UI.Gtk.WebKit.JavaScriptCore.JSBase
87+ (JSValueRef, JSContextRef)
88+import Graphics.UI.Gtk.WebKit.JavaScriptCore.JSStringRef
89+ (jsstringgetcharactersptr, jsstringgetlength, jsstringrelease)
90+import Graphics.UI.Gtk.WebKit.JavaScriptCore.JSValueRef
91+ (jsvaluetostringcopy)
92+
8193import Language.Javascript.JSaddle (JSM, Results, Batch)
8294import Language.Javascript.JSaddle.Run (runJavaScript)
8395import Language.Javascript.JSaddle.Run.Files (initState, runBatch, ghcjsHelpers)
8496
85−noAdjustment :: Maybe Adjustment
86−noAdjustment = Nothing
87−
88−noCancellable :: Maybe Cancellable
89−noCancellable = Nothing
90−
9197quitWebView :: WebView -> IO ()
9298quitWebView wv = postGUIAsync $ do w <- widgetGetToplevel wv --TODO: Shouldn't this be postGUISync?
9399 widgetDestroy w
@@ -103,6 +109,21 @@ postGUIAsync :: IO () -> IO ()
103109postGUIAsync action =
104110 void . idleAdd PRIORITY_DEFAULT $ action >> return False
105111
112+withJSContextRef :: GlobalContext -> (JSContextRef -> IO a) -> IO a
113+withJSContextRef (GlobalContext ctx) f = withManagedPtr ctx (f . castPtr)
114+
115+withJSValueRef :: Value -> (JSValueRef -> IO a) -> IO a
116+withJSValueRef (Value ptr) f = withManagedPtr ptr (f . castPtr)
117+
118+valueToText :: JSContextRef -> JSValueRef -> IO Text
119+valueToText ctxRef s = do
120+ jsstring <- jsvaluetostringcopy ctxRef s nullPtr
121+ l <- jsstringgetlength jsstring
122+ p <- jsstringgetcharactersptr jsstring
123+ result <- fromPtr (castPtr p) (fromIntegral l)
124+ jsstringrelease jsstring
125+ return result
126+
106127run :: JSM () -> IO ()
107128run main = do
108129 _ <- Gtk.init Nothing
@@ -151,16 +172,16 @@ connectUserContentManagerScriptMessageReceived obj cb after = liftIO $ do
151172 let cb' = wrap_UserContentManagerScriptMessageReceivedCallback cb
152173 cb'' <- mk_UserContentManagerScriptMessageReceivedCallback cb'
153174 connectSignalFunPtr obj "script-message-received::jsaddle" cb'' after
154−#if MIN_VERSION_haskell_gi_base(0,23,0)
155− Nothing
156−#endif
157175
158176addJSaddleHandler :: WebView -> (Results -> IO ()) -> (Results -> IO Batch) -> IO ()
159177addJSaddleHandler webView processResult syncResults = do
160178 manager <- webViewGetUserContentManager webView
161179 _ <- onUserContentManagerScriptMessageReceived manager $ \result -> do
162− arg <- javascriptResultGetJsValue result
163− bs <- encodeUtf8 <$> valueToString arg
180+ ctx <- javascriptResultGetGlobalContext result
181+ arg <- javascriptResultGetValue result
182+ bs <- withJSContextRef ctx $ \ctxRef ->
183+ withJSValueRef arg $ \argRef ->
184+ encodeUtf8 <$> valueToText ctxRef argRef
164185 mapM_ processResult (decode (fromStrict bs))
165186 _ <- onWebViewScriptDialog webView $ \dialog ->
166187 scriptDialogGetDialogType dialog >>= \case
jsaddle-webkitgtk/default.nixnew file+16
@@ -0,0 +1,16 @@
1+{ mkDerivation, aeson, base, bytestring, directory, gi-glib, gi-gtk
2+, gi-javascriptcore, gi-webkit, haskell-gi-base, jsaddle, stdenv
3+, text, unix, webkitgtk3-javascriptcore
4+}:
5+mkDerivation {
6+ pname = "jsaddle-webkitgtk";
7+ version = "0.9.0.0";
8+ src = builtins.filterSource (path: type: !(builtins.elem (baseNameOf path) [ ".git" "dist" ])) ./.;
9+ libraryHaskellDepends = [
10+ aeson base bytestring directory gi-glib gi-gtk gi-javascriptcore
11+ gi-webkit haskell-gi-base jsaddle text unix
12+ webkitgtk3-javascriptcore
13+ ];
14+ description = "Interface for JavaScript that works with GHCJS and GHC";
15+ license = stdenv.lib.licenses.mit;
16+}
jsaddle-wkwebview/cbits-cocoa/AppDelegate.m+1−10
@@ -3,7 +3,6 @@
33#import <WebKit/WebKit.h>
44
55extern void callIO(HsStablePtr);
6−extern bool callWithCStringReturningBool(const char * _Nonnull, HsStablePtr);
76extern void callWithCString(const char * _Nonnull, HsStablePtr);
87extern void callWithWebView(WKWebView *, HsStablePtr);
98
@@ -17,7 +16,6 @@ extern void callWithWebView(WKWebView *, HsStablePtr);
1716HsStablePtr global_willFinishLaunchingWithOptions = 0;
1817HsStablePtr global_didFinishLaunchingWithOptions = 0;
1918HsStablePtr global_applicationUniversalLink = 0;
20−HsStablePtr global_applicationOpenFile = 0;
2119uint64_t global_developerExtrasEnabled = 1;
2220
2321@implementation AppDelegate
@@ -40,11 +38,6 @@ uint64_t global_developerExtrasEnabled = 1;
4038 return self;
4139}
4240
43−-(BOOL)application:(NSApplication *)sender openFile:(NSString *)filename {
44− bool b = callWithCStringReturningBool([filename UTF8String], global_applicationOpenFile);
45− return b ? YES : NO;
46−}
47−
4841-(void)applicationWillFinishLaunching:(NSNotification *)notification {
4942 WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
5043 if (global_developerExtrasEnabled) {
@@ -100,13 +93,11 @@ void runInWKWebView(HsStablePtr handler,
10093 const uint64_t hs_registerForRemoteNotifications,
10194 HsStablePtr hs_didRegisterForRemoteNotificationsWithDeviceToken,
10295 HsStablePtr hs_didFailToRegisterForRemoteNotificationsWithError,
103− const uint64_t hs_developerExtrasEnabled,
104− HsStablePtr hs_applicationOpenFile) {
96+ const uint64_t hs_developerExtrasEnabled) {
10597 @autoreleasepool {
10698 global_willFinishLaunchingWithOptions = hs_willFinishLaunchingWithOptions;
10799 global_didFinishLaunchingWithOptions = hs_didFinishLaunchingWithOptions;
108100 global_applicationUniversalLink = hs_applicationUniversalLink;
109− global_applicationOpenFile = hs_applicationOpenFile;
110101 global_developerExtrasEnabled = hs_developerExtrasEnabled;
111102 NSApplication *application = [NSApplication sharedApplication];
112103 AppDelegate *appDelegate = [[AppDelegate alloc] initApp:handler progName:[NSString stringWithCString:progName encoding:NSUTF8StringEncoding]];
jsaddle-wkwebview/cbits-uikit/AppDelegate.m−12
@@ -5,7 +5,6 @@
55
66extern void callIO(HsStablePtr);
77extern void callWithCString(const char * _Nonnull, HsStablePtr);
8−extern void callWithCIntCString(int n, const char * _Nonnull, HsStablePtr);
98
109@interface AppDelegate ()
1110
@@ -21,7 +20,6 @@ HsStablePtr global_applicationWillEnterForeground = 0;
2120HsStablePtr global_applicationWillTerminate = 0;
2221HsStablePtr global_applicationSignificantTimeChange = 0;
2322HsStablePtr global_applicationUniversalLink = 0;
24−HsStablePtr global_applicationDidReceiveRemoteNotification = 0;
2523uint64_t global_requestAuthorizationWithOptions = 0;
2624uint64_t global_requestAuthorizationOptionBadge = 0;
2725uint64_t global_requestAuthorizationOptionSound = 0;
@@ -117,14 +115,6 @@ HsStablePtr global_didFailToRegisterForRemoteNotificationsWithError = 0;
117115 if ([userInfo valueForKeyPath:@"aps.badge"] != nil) {
118116 [UIApplication sharedApplication].applicationIconBadgeNumber=[[[userInfo objectForKey:@"aps"] objectForKey:@"badge"] intValue];
119117 }
120− NSError *error;
121− NSData *jsonData = [NSJSONSerialization dataWithJSONObject:userInfo options:0 error:&error];
122− if (jsonData) {
123− NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
124− callWithCIntCString((int) application.applicationState, [jsonString UTF8String], global_applicationDidReceiveRemoteNotification);
125− } else {
126− NSLog(@"jsaddle-wkwebview didReceiveRemoteNotification handler: error while serialising push notification as JSON");
127− }
128118 completionHandler(UIBackgroundFetchResultNewData);
129119}
130120
@@ -162,7 +152,6 @@ void runInWKWebView(HsStablePtr handler,
162152 HsStablePtr hs_applicationWillTerminate,
163153 HsStablePtr hs_applicationSignificantTimeChange,
164154 HsStablePtr hs_applicationUniversalLink,
165− HsStablePtr hs_applicationDidReceiveRemoteNotification,
166155 const uint64_t hs_requestAuthorizationWithOptions,
167156 const uint64_t hs_requestAuthorizationOptionBadge,
168157 const uint64_t hs_requestAuthorizationOptionSound,
@@ -183,7 +172,6 @@ void runInWKWebView(HsStablePtr handler,
183172 global_applicationWillTerminate = hs_applicationWillTerminate;
184173 global_applicationSignificantTimeChange = hs_applicationSignificantTimeChange;
185174 global_applicationUniversalLink = hs_applicationUniversalLink;
186− global_applicationDidReceiveRemoteNotification = hs_applicationDidReceiveRemoteNotification;
187175 global_requestAuthorizationWithOptions = hs_requestAuthorizationWithOptions;
188176 global_requestAuthorizationOptionBadge = hs_requestAuthorizationOptionBadge;
189177 global_requestAuthorizationOptionSound = hs_requestAuthorizationOptionSound;
jsaddle-wkwebview/default.nix+30−14
@@ -1,14 +1,30 @@
1−{ filterSource ? (x: x) }:
2−self: super:
3−let
4− pkgs = self.callPackage ({pkgs}: pkgs) {};
5− inherit (pkgs) lib;
6−in
7−with pkgs.haskell.lib;
8−overrideCabal (self.callCabal2nix "jsaddle-wkwebview" (filterSource ./.) {}) (drv: {
9− libraryFrameworkDepends = (drv.libraryFrameworkDepends or []) ++
10− (if pkgs.stdenv.hostPlatform.useiOSPrebuilt then [
11− "${pkgs.buildPackages.darwin.xcode}/Contents/Developer/Platforms/${pkgs.stdenv.hostPlatform.xcodePlatform}.platform/Developer/SDKs/${pkgs.stdenv.hostPlatform.xcodePlatform}.sdk/System"
12− ] else (with pkgs.buildPackages.darwin.apple_sdk.frameworks; [ Cocoa WebKit ]));
13− buildDepends = lib.optional (!pkgs.stdenv.hostPlatform.useiOSPrebuilt) [ pkgs.buildPackages.darwin.cf-private ];
14−})
1+{ mkDerivation, stdenv, aeson, base, bytestring, jsaddle, data-default
2+, buildPackages, hostPlatform
3+}:
4+
5+mkDerivation {
6+ pname = "jsaddle-wkwebview";
7+ version = "0.9.6.0";
8+ src = ./.;
9+ libraryHaskellDepends = [ aeson base bytestring jsaddle data-default ];
10+
11+ # HACK(matthewbauer): Can’t figure out why cf-private framework is
12+ # not getting pulled in correctly. Has something
13+ # to with how headers are looked up in xcode.
14+ preBuild = stdenv.lib.optionalString (!hostPlatform.useiOSPrebuilt) ''
15+ mkdir include
16+ ln -s ${buildPackages.darwin.cf-private}/Library/Frameworks/CoreFoundation.framework/Headers include/CoreFoundation
17+ export NIX_CFLAGS_COMPILE="-I$PWD/include $NIX_CFLAGS_COMPILE"
18+ '';
19+
20+ libraryFrameworkDepends =
21+ stdenv.lib.optional (hostPlatform.useiOSPrebuilt)
22+ "${buildPackages.darwin.xcode}/Contents/Developer/Platforms/${hostPlatform.xcodePlatform}.platform/Developer/SDKs/${hostPlatform.xcodePlatform}.sdk/System"
23+ ++ stdenv.lib.optional (!hostPlatform.useiOSPrebuilt)
24+ (with buildPackages.darwin; with apple_sdk.frameworks; [
25+ Cocoa
26+ WebKit
27+ ]);
28+ description = "Interface for JavaScript that works with GHCJS and GHC";
29+ license = stdenv.lib.licenses.mit;
30+}
jsaddle-wkwebview/jsaddle-wkwebview.cabal+3−5
@@ -1,5 +1,5 @@
11name: jsaddle-wkwebview
2−version: 0.9.8.0
2+version: 0.9.6.0
33cabal-version: >=1.10
44build-type: Simple
55license: MIT
@@ -29,15 +29,13 @@ library
2929 base <5
3030 default-language: Haskell2010
3131 hs-source-dirs: src
32+ frameworks: Foundation, WebKit
3233 ghc-options: -ferror-spans -Wall
33− if os(linux)
34− buildable: False
3534 if impl(ghcjs)
3635 hs-source-dirs: src-ghcjs
3736 else
38− frameworks: Foundation, WebKit
3937 build-depends:
40− aeson >=0.8.0.2 && <1.6,
38+ aeson >=0.8.0.2 && <1.5,
4139 bytestring >=0.10.6.0 && <0.11,
4240 directory,
4341 jsaddle >= 0.9.4.0 && <0.10,
jsaddle-wkwebview/src-ghc/Language/Javascript/JSaddle/WKWebView.hs+1−40
@@ -9,7 +9,6 @@ module Language.Javascript.JSaddle.WKWebView
99 , runHTMLWithBaseURL
1010 , runFile
1111 , mainBundleResourcePath
12− , ApplicationState (..)
1312 , AppDelegateConfig (..)
1413 , AppDelegateNotificationConfig (..)
1514 , AuthorizationOption (..)
@@ -25,7 +24,6 @@ import Language.Javascript.JSaddle.WKWebView.Internal
2524 (jsaddleMain, jsaddleMainHTMLWithBaseURL, jsaddleMainFile, WKWebView(..), mainBundleResourcePath)
2625import System.Environment (getProgName)
2726import Foreign.C.String (CString, withCString)
28−import Foreign.C.Types (CBool, CInt)
2927import Foreign.StablePtr (StablePtr, newStablePtr)
3028import Language.Javascript.JSaddle (JSM)
3129
@@ -41,7 +39,6 @@ foreign import ccall runInWKWebView
4139 -> StablePtr (IO ()) -- applicationWillTerminate
4240 -> StablePtr (IO ()) -- applicationSignificantTimeChange
4341 -> StablePtr (CString -> IO ()) -- applicationUniversalLink
44− -> StablePtr (CInt -> CString -> IO ()) -- applicationDidReceiveRemoteNotification
4542 -> Word64 -- whether to run requestAuthorizationWithOptions
4643 -> Word64 -- Ask for Badge authorization
4744 -> Word64 -- Ask for Sound authorization
@@ -50,8 +47,7 @@ foreign import ccall runInWKWebView
5047 -> Word64 -- registerForRemoteNotifications
5148 -> StablePtr (CString -> IO ()) -- didRegisterForRemoteNotificationsWithDeviceToken
5249 -> StablePtr (CString -> IO ()) -- didFailToRegisterForRemoteNotificationsWithError
53− -> Word64 -- developerExtrasEnabled
54− -> StablePtr (CString -> IO CBool) -- applicationOpenFile
50+ -> Word64 -- Allow developer tools
5551 -> IO ()
5652
5753data AppDelegateConfig = AppDelegateConfig
@@ -64,25 +60,8 @@ data AppDelegateConfig = AppDelegateConfig
6460 , _appDelegateConfig_applicationWillTerminate :: IO ()
6561 , _appDelegateConfig_applicationSignificantTimeChange :: IO ()
6662 , _appDelegateConfig_applicationUniversalLink :: CString -> IO ()
67− -- ^ Called when the app is launched from a URL. 'CString' contains the URL.
68− --
69− -- The Core Foundation plist key CFBundleURLTypes controls which URL schemes
70− -- the app should respond to.
71− , _appDelegateConfig_applicationDidReceiveRemoteNotification :: ApplicationState -> CString -> IO ()
72− -- ^ Called when the application receives a remote notification.
73− -- 'ApplicationState' is the current state of the app.
74− -- The 'CString' JSON-encoded user info contained in the notification.
75− -- For more information see https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623117-application?language=objc
7663 , _appDelegateConfig_appDelegateNotificationConfig :: AppDelegateNotificationConfig
7764 , _appDelegateConfig_developerExtrasEnabled :: Bool
78− -- ^ Allow devtools in the app. Defaults to 'True'
79− , _appDelegateConfig_applicationOpenFile :: CString -> IO Bool
80− -- ^ Called when the app is launched by opening a file. 'CString' contains
81− -- the file path. Return value is 'True' if the file was successfully
82− -- opened. Defaults to ignoring the file and returning 'False'.
83− --
84− -- The Core Foundation plist key CFBundleDocumentTypes controls which file
85− -- types should be associated with the app.
8665 }
8766
8867instance Default AppDelegateConfig where
@@ -96,10 +75,8 @@ instance Default AppDelegateConfig where
9675 , _appDelegateConfig_applicationWillTerminate = return ()
9776 , _appDelegateConfig_applicationSignificantTimeChange = return ()
9877 , _appDelegateConfig_applicationUniversalLink = \_ -> return ()
99− , _appDelegateConfig_applicationDidReceiveRemoteNotification = \_ _ -> return ()
10078 , _appDelegateConfig_appDelegateNotificationConfig = def
10179 , _appDelegateConfig_developerExtrasEnabled = True
102− , _appDelegateConfig_applicationOpenFile = \_ -> return False
10380 }
10481
10582data AuthorizationOption = AuthorizationOption_Badge
@@ -108,12 +85,6 @@ data AuthorizationOption = AuthorizationOption_Badge
10885 | AuthorizationOption_CarPlay
10986 deriving (Show, Read, Eq, Ord)
11087
111−data ApplicationState = ApplicationState_Active
112− | ApplicationState_Inactive
113− | ApplicationState_Background
114− | ApplicationState_Unknown CInt
115− deriving (Show, Read, Eq, Ord)
116−
11788data AppDelegateNotificationConfig = AppDelegateNotificationConfig
11889 { _appDelegateNotificationConfig_requestAuthorizationWithOptions :: Maybe (Set AuthorizationOption)
11990 , _appDelegateNotificationConfig_registerForRemoteNotifications :: Bool
@@ -176,14 +147,6 @@ run' cfg main = do
176147 applicationWillTerminate <- newStablePtr $ _appDelegateConfig_applicationWillTerminate cfg
177148 applicationSignificantTimeChange <- newStablePtr $ _appDelegateConfig_applicationSignificantTimeChange cfg
178149 applicationUniversalLink <- newStablePtr $ _appDelegateConfig_applicationUniversalLink cfg
179− applicationDidReceiveRemoteNotification <- newStablePtr $ \n s -> do
180− let appState = case n of
181− 0 -> ApplicationState_Active
182− 1 -> ApplicationState_Inactive
183− 2 -> ApplicationState_Background
184− _ -> ApplicationState_Unknown n
185− _appDelegateConfig_applicationDidReceiveRemoteNotification cfg appState s
186− applicationOpenFile <- newStablePtr $ fmap fromBool . _appDelegateConfig_applicationOpenFile cfg
187150
188151 -- AppDelegate notification configuration
189152 let ncfg = _appDelegateConfig_appDelegateNotificationConfig cfg
@@ -206,7 +169,6 @@ run' cfg main = do
206169 applicationWillTerminate
207170 applicationSignificantTimeChange
208171 applicationUniversalLink
209− applicationDidReceiveRemoteNotification
210172 (fromBool requestAuthorizationWithOptions)
211173 (fromBool $ Set.member AuthorizationOption_Badge authorizationOptions)
212174 (fromBool $ Set.member AuthorizationOption_Sound authorizationOptions)
@@ -216,4 +178,3 @@ run' cfg main = do
216178 didRegisterForRemoteNotificationsWithDeviceToken
217179 didFailToRegisterForRemoteNotificationsWithError
218180 (fromBool $ _appDelegateConfig_developerExtrasEnabled cfg)
219− applicationOpenFile
jsaddle-wkwebview/src/Language/Javascript/JSaddle/WKWebView/Internal.hs−13
@@ -20,7 +20,6 @@ import qualified Data.Text as T (pack)
2020import Data.Text.Encoding (encodeUtf8)
2121
2222import Foreign.C.String (CString)
23−import Foreign.C.Types (CBool(..), CInt(..))
2423import Foreign.Ptr (Ptr, nullPtr)
2524import Foreign.StablePtr (StablePtr, newStablePtr, deRefStablePtr)
2625
@@ -37,9 +36,7 @@ foreign export ccall jsaddleStart :: StablePtr (IO ()) -> IO ()
3736foreign export ccall jsaddleResult :: StablePtr (Results -> IO ()) -> CString -> IO ()
3837foreign export ccall jsaddleSyncResult :: StablePtr (Results -> IO Batch) -> JSaddleHandler -> CString -> IO ()
3938foreign export ccall callWithWebView :: WKWebView -> StablePtr (WKWebView -> IO ()) -> IO ()
40−foreign export ccall callWithCIntCString :: CInt -> CString -> StablePtr (CInt -> CString -> IO ()) -> IO ()
4139foreign export ccall callWithCString :: CString -> StablePtr (CString -> IO ()) -> IO ()
42−foreign export ccall callWithCStringReturningBool :: CString -> StablePtr (CString -> IO CBool) -> IO CBool
4340foreign export ccall callIO :: StablePtr (IO ()) -> IO ()
4441foreign import ccall addJSaddleHandler :: WKWebView -> StablePtr (IO ()) -> StablePtr (Results -> IO ()) -> StablePtr (Results -> IO Batch) -> IO ()
4542foreign import ccall loadHTMLStringWithBaseURL :: WKWebView -> CString -> CString -> IO ()
@@ -129,16 +126,6 @@ callWithCString c fptr = do
129126 f <- deRefStablePtr fptr
130127 f c
131128
132−callWithCIntCString :: CInt -> CString -> StablePtr (CInt -> CString -> IO ()) -> IO ()
133−callWithCIntCString n s fptr = do
134− f <- deRefStablePtr fptr
135− f n s
136−
137−callWithCStringReturningBool :: CString -> StablePtr (CString -> IO CBool) -> IO CBool
138−callWithCStringReturningBool c fptr = do
139− f <- deRefStablePtr fptr
140− f c
141−
142129callIO :: StablePtr (IO ()) -> IO ()
143130callIO ptr = do
144131 f <- deRefStablePtr ptr
jsaddle/default.nixnew file+23
@@ -0,0 +1,23 @@
1+{ mkDerivation, aeson, attoparsec, base, base64-bytestring
2+, bytestring, containers, deepseq, filepath, ghc-prim, http-types
3+, lens, primitive, process, random, ref-tf, scientific, stdenv, stm
4+, text, time, transformers, unordered-containers, unliftio-core
5+, vector, exceptions, ghcjs-base, ghcjs-prim, ghc
6+}:
7+mkDerivation {
8+ pname = "jsaddle";
9+ version = "0.9.6.0";
10+ src = builtins.filterSource (path: type: !(builtins.elem (baseNameOf path) [ ".git" "dist" ])) ./.;
11+ libraryHaskellDepends = [
12+ aeson base base64-bytestring bytestring exceptions lens primitive
13+ text transformers
14+ ] ++ (if ghc.isGhcjs or false then [
15+ ghcjs-base ghcjs-prim
16+ ] else [
17+ attoparsec containers deepseq filepath ghc-prim http-types process
18+ random ref-tf scientific stm time unordered-containers vector
19+ unliftio-core
20+ ]);
21+ description = "Interface for JavaScript that works with GHCJS and GHC";
22+ license = stdenv.lib.licenses.mit;
23+}
jsaddle/jsaddle.cabal+9−10
@@ -1,5 +1,5 @@
11name: jsaddle
2−version: 0.9.8.0
2+version: 0.9.6.0
33cabal-version: >=1.10
44build-type: Simple
55license: MIT
@@ -10,7 +10,7 @@ description:
1010 This package provides an EDSL for calling JavaScript that
1111 can be used both from GHCJS and GHC. When using GHC
1212 the application is run using Warp and WebSockets to
13− drive a small JavaScript helper.
13+ drive a small JavaScipt helper.
1414category: Web, Javascript
1515author: Hamish Mackenzie
1616
@@ -42,14 +42,14 @@ library
4242 ghc-prim,
4343 http-types >=0.8.6 && <0.13,
4444 process >=1.2.3.0 && <1.7,
45− random >= 1.1 && < 1.3,
45+ random >= 1.1 && < 1.2,
4646 ref-tf >=0.4.0.1 && <0.5,
4747 scientific >=0.3 && <0.4,
4848 stm >=2.4.4 && <2.6,
49− time >=1.5.0.1 && <1.11,
49+ time >=1.5.0.1 && <1.9,
5050 unordered-containers >=0.2 && <0.3,
5151 vector >=0.10 && <0.13,
52− unliftio-core >=0.1 && < 0.3
52+ unliftio-core >=0.1 && < 0.2
5353 exposed-modules:
5454 Data.JSString
5555 Data.JSString.Internal
@@ -107,14 +107,13 @@ library
107107 Language.Javascript.JSaddle.Value
108108 Language.Javascript.JSaddle.Types
109109 build-depends:
110− aeson >=0.11.3.0 && <1.6,
110+ aeson >=0.8.0.2 && <1.5,
111111 base >=4.9 && <5,
112− base-compat >=0.9.0 && <0.12,
113− base64-bytestring >=1.0.0.1 && <1.2,
112+ base64-bytestring >=1.0.0.1 && <1.1,
114113 bytestring >=0.10.6.0 && <0.11,
115114 exceptions >=0.8 && <0.11,
116− lens >=3.8.5 && <5.1,
117− primitive >=0.6.1.0 && <0.8,
115+ lens >=3.8.5 && <4.18,
116+ primitive >=0.6.1.0 && <0.7,
118117 text >=1.2.1.3 && <1.3,
119118 transformers >=0.4.2.0 && <0.6
120119 default-language: Haskell2010
jsaddle/src-ghc/JavaScript/Array.hs+2−2
@@ -48,7 +48,7 @@ import Language.Javascript.JSaddle.Types
4848 (JSM, JSVal, SomeJSArray(..), JSArray,
4949 MutableJSArray, GHCJSPure(..))
5050import Control.Lens.Operators ((^.))
51−import Language.Javascript.JSaddle.Object (js2, js0, (<##), js1, js)
51+import Language.Javascript.JSaddle.Object (js2, js0, (##), js1, js)
5252import Language.Javascript.JSaddle.Value (valToNumber)
5353import JavaScript.Array.Internal (create, fromList, fromListIO, toList, toListIO, index, read, push)
5454
@@ -69,7 +69,7 @@ append (SomeJSArray x) (SomeJSArray y) = SomeJSArray <$> x ^. js1 "concat" y
6969{-# INLINE append #-}
7070
7171write :: Int -> JSVal -> MutableJSArray -> JSM ()
72−write n e (SomeJSArray x) = void $ (x <## n) e
72+write n e (SomeJSArray x) = void $ (x ## n) e
7373{-# INLINE write #-}
7474
7575pop :: MutableJSArray -> JSM JSVal
jsaddle/src/Language/Javascript/JSaddle/Evaluate.hs+1−1
@@ -50,7 +50,7 @@ eval :: (ToJSString script)
5050 -> JSM JSVal
5151#ifdef ghcjs_HOST_OS
5252eval script = liftIO $ js_eval (toJSString script)
53−foreign import javascript safe "$r = eval($1);"
53+foreign import javascript unsafe "$r = eval($1);"
5454 js_eval :: JSString -> IO JSVal
5555#else
5656eval = evaluateScript . toJSString
jsaddle/src/Language/Javascript/JSaddle/Object.hs+6−5
@@ -526,11 +526,12 @@ array args = do
526526 Object . coerce <$> fromListIO rargs
527527
528528-- | JavaScript's global object
529+global :: Object
529530#ifdef ghcjs_HOST_OS
530−foreign import javascript unsafe "$r = globalThis"
531− global :: Object
531+global = js_window
532+foreign import javascript unsafe "$r = window"
533+ js_window :: Object
532534#else
533−global :: Object
534535global = Object . JSVal . unsafePerformIO $ newIORef 4
535536#endif
536537
@@ -556,7 +557,7 @@ objCallAsFunction :: MakeArgs args
556557objCallAsFunction f this args = do
557558 rargs <- makeArgs args >>= liftIO . Array.fromListIO
558559 liftIO $ js_apply f this rargs
559−foreign import javascript safe "$r = $1.apply($2, $3)"
560+foreign import javascript unsafe "$r = $1.apply($2, $3)"
560561 js_apply :: Object -> Object -> MutableJSArray -> IO JSVal
561562#else
562563objCallAsFunction f this args = do
@@ -576,7 +577,7 @@ objCallAsConstructor :: MakeArgs args
576577objCallAsConstructor f args = do
577578 rargs <- makeArgs args >>= liftIO . Array.fromListIO
578579 liftIO $ js_new f rargs
579−foreign import javascript safe "\
580+foreign import javascript unsafe "\
580581 switch($2.length) {\
581582 case 0 : $r = new $1(); break;\
582583 case 1 : $r = new $1($2[0]); break;\
jsaddle/src/Language/Javascript/JSaddle/Run/Files.hs+1−1
@@ -41,7 +41,7 @@ initState = "\
4141 \ jsaddle_values.set(1, undefined);\n\
4242 \ jsaddle_values.set(2, false);\n\
4343 \ jsaddle_values.set(3, true);\n\
44− \ jsaddle_values.set(4, globalThis);\n\
44+ \ jsaddle_values.set(4, window);\n\
4545 \ var jsaddle_index = 100;\n\
4646 \ var expectedBatch = 1;\n\
4747 \ var lastResults = [0, {\"tag\": \"Success\", \"contents\": [[], []]}];\n\
nix/hix.nixdeleted−8
@@ -1,8 +0,0 @@
1−{pkgs, ...}:
2−{ modules = [({pkgs, ...}: {
3− packages.webkit2gtk3-javascriptcore.components.library.doHaddock = false;
4− })];
5− shell.buildInputs = [ pkgs.nodejs ];
6− shell.tools.cabal = {};
7− shell.crossPlatforms = p: [ p.ghcjs ];
8−}