Skip to content

replace FFI functions with unsafeCoerce #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/Foreign.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
"use strict";

exports.unsafeToForeign = function (value) {
return value;
};

exports.unsafeFromForeign = function (value) {
return value;
};

exports.typeOf = function (value) {
return typeof value;
};
Expand Down
8 changes: 5 additions & 3 deletions src/Foreign.purs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ module Foreign
import Prelude

import Control.Monad.Except (Except, throwError, mapExcept)

import Data.Either (Either(..), either)
import Data.Int as Int
import Data.List.NonEmpty (NonEmptyList)
import Data.List.NonEmpty as NEL
import Data.Maybe (Maybe(..), maybe)
import Data.String.CodeUnits (toChar)
import Unsafe.Coerce (unsafeCoerce)

-- | A type for _foreign data_.
-- |
Expand Down Expand Up @@ -88,10 +88,12 @@ type F = Except MultipleErrors
-- | JavaScript types, rather than PureScript types. Exporting PureScript values
-- | via the FFI can be dangerous as they can be mutated by code outside the
-- | PureScript program, resulting in difficult to diagnose problems elsewhere.
foreign import unsafeToForeign :: forall a. a -> Foreign
unsafeToForeign :: forall a. a -> Foreign
unsafeToForeign = unsafeCoerce

-- | Unsafely coerce a `Foreign` value.
foreign import unsafeFromForeign :: forall a. Foreign -> a
unsafeFromForeign :: forall a. Foreign -> a
unsafeFromForeign = unsafeCoerce

-- | Read the Javascript _type_ of a value
foreign import typeOf :: Foreign -> String
Expand Down