Skip to content

Commit 47ed9a8

Browse files
committed
Don't transcode function values when the type is an EmptyDataDecl (closes #354)
1 parent 9dde74a commit 47ed9a8

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

js/runtime.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,13 @@ function Fay$$fayToJs(type,fayObj){
237237
}
238238
else if(base == "ptr" || base == "unknown")
239239
return fayObj;
240+
else if(base == "automatic" && fayObj instanceof Function) {
241+
return Fay$$fayToJs(["function", "automatic_function"], fayObj);
242+
}
240243
else if(base == "automatic" || base == "user") {
241-
242244
fayObj = Fay$$_(fayObj);
243245

244-
if(fayObj instanceof Function) {
245-
return Fay$$fayToJs(["function", "automatic_function"], fayObj);
246-
} else if(fayObj instanceof Fay$$Cons || fayObj === null){
246+
if(fayObj instanceof Fay$$Cons || fayObj === null){
247247
// Serialize Fay list to JavaScript array.
248248
var arr = [];
249249
while(fayObj instanceof Fay$$Cons) {
@@ -388,6 +388,12 @@ function Fay$$jsToFay(type,jsObj){
388388
base == "unknown") {
389389
return jsObj;
390390
}
391+
else if(base == "automatic" && jsObj instanceof Function) {
392+
var type = [["automatic"]];
393+
for (var i = 0; i < jsObj.length; i++)
394+
type.push(["automatic"]);
395+
return Fay$$jsToFay(["function", type], jsObj);
396+
}
391397
else if(base == "automatic" || base == "user") {
392398
if (jsObj && jsObj['instance']) {
393399
var jsToFayFun = Fay$$jsToFayHash[jsObj["instance"]];
@@ -400,12 +406,6 @@ function Fay$$jsToFay(type,jsObj){
400406
}
401407
return list;
402408
}
403-
else if (jsObj instanceof Function) {
404-
var type = [["automatic"]];
405-
for (var i = 0; i < jsObj.length; i++)
406-
type.push(["automatic"]);
407-
return Fay$$jsToFay(["function", type], jsObj);
408-
}
409409
else
410410
return jsObj;
411411
}

tests/JsFunctionPassing.hs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{-# LANGUAGE EmptyDataDecls #-}
2+
3+
import FFI
4+
import Prelude
5+
6+
data Func
7+
8+
makeFunc0 :: Int -> Func
9+
makeFunc0 = ffi "function() {return %1;}"
10+
11+
callFunc0 :: Func -> Fay Int
12+
callFunc0 = ffi "%1()"
13+
14+
makeFunc1 :: Int -> Func
15+
makeFunc1 = ffi "function(x) {return %1;}"
16+
17+
callFunc1 :: Func -> Fay Int
18+
callFunc1 = ffi "%1(1)"
19+
20+
main = do
21+
callFunc0 (makeFunc0 1) >>= print
22+
callFunc1 (makeFunc1 2) >>= print

tests/JsFunctionPassing.res

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1
2+
2

0 commit comments

Comments
 (0)