Skip to content

Commit 8ea0122

Browse files
committed
Don't deserialize Arrays into lists for empty data decls
1 parent ee64b24 commit 8ea0122

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

js/runtime.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -394,18 +394,18 @@ function Fay$$jsToFay(type,jsObj){
394394
type.push(["automatic"]);
395395
return Fay$$jsToFay(["function", type], jsObj);
396396
}
397+
else if(base == "automatic" && jsObj instanceof Array) {
398+
var list = null;
399+
for (var i = jsObj.length - 1; i >= 0; i--) {
400+
list = new Fay$$Cons(Fay$$jsToFay([base], jsObj[i]), list);
401+
}
402+
return list;
403+
}
397404
else if(base == "automatic" || base == "user") {
398405
if (jsObj && jsObj['instance']) {
399406
var jsToFayFun = Fay$$jsToFayHash[jsObj["instance"]];
400407
return jsToFayFun ? jsToFayFun(type,type[2],jsObj) : jsObj;
401408
}
402-
else if (jsObj instanceof Array) {
403-
var list = null;
404-
for (var i = jsObj.length - 1; i >= 0; i--) {
405-
list = new Fay$$Cons(Fay$$jsToFay([base], jsObj[i]), list);
406-
}
407-
return list;
408-
}
409409
else
410410
return jsObj;
411411
}

tests/EmptyDataDeclArray.hs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import FFI
2+
3+
data Array a
4+
5+
empty :: Fay (Array a)
6+
empty = ffi "[]"
7+
8+
push:: a -> Array a -> Fay ()
9+
push = ffi "%2.push(%1)"
10+
11+
len :: Array a -> Fay Int
12+
len = ffi "%1['length']"
13+
14+
main :: Fay ()
15+
main = do
16+
arr <- empty
17+
print arr
18+
push (5::Int) arr
19+
print =<< len arr
20+
print arr

tests/EmptyDataDeclArray.res

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

0 commit comments

Comments
 (0)