Skip to content

Commit

Permalink
[interpreter] Fix ref asserts (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
rossberg authored Feb 3, 2020
1 parent 2719ec3 commit 22ce5e3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
35 changes: 15 additions & 20 deletions interpreter/script/js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,20 @@ function assert_return(action, expected) {
switch (expected) {
case "nan:canonical":
case "nan:arithmetic":
case "nan:any":
// Note that JS can't reliably distinguish different NaN values,
// so there's no good way to test that it's a canonical NaN.
if (!Number.isNaN(actual)) {
throw new Error("Wasm return value NaN expected, got " + actual);
throw new Error("Wasm NaN return value expected, got " + actual);
};
return;
case "ref.func":
if (typeof actual !== "function") {
throw new Error("Wasm function return value expected, got " + actual);
};
return;
case "ref.any":
if (actual === null) {
throw new Error("Wasm reference return value expected, got " + actual);
};
return;
default:
Expand All @@ -159,20 +168,6 @@ function assert_return(action, expected) {
};
}
}

function assert_return_ref(action) {
let actual = action();
if (actual === null || typeof actual !== "object" && typeof actual !== "function") {
throw new Error("Wasm reference return value expected, got " + actual);
};
}

function assert_return_func(action) {
let actual = action();
if (typeof actual !== "function") {
throw new Error("Wasm function return value expected, got " + actual);
};
}
|}


Expand Down Expand Up @@ -417,8 +412,8 @@ let of_value v =
| _ -> assert false

let of_nan = function
| CanonicalNan -> "nan:canonical"
| ArithmeticNan -> "nan:arithmetic"
| CanonicalNan -> "\"nan:canonical\""
| ArithmeticNan -> "\"nan:arithmetic\""

let of_result res =
match res.it with
Expand All @@ -428,8 +423,8 @@ let of_result res =
| Values.I32 _ | Values.I64 _ -> assert false
| Values.F32 n | Values.F64 n -> of_nan n
)
| RefResult -> "ref.any"
| FuncResult -> "ref.func"
| RefResult -> "\"ref.any\""
| FuncResult -> "\"ref.func\""

let rec of_definition def =
match def.it with
Expand Down
4 changes: 2 additions & 2 deletions test/core/select.wast
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
)

(func (export "join-nullref") (param i32) (result anyref)
(select (result anyref) (ref.null) (ref.null) (local.get 0))
(select (result nullref) (ref.null) (ref.null) (local.get 0))
)
(func (export "join-funcref") (param i32) (result anyref)
(select (result anyref)
(select (result funcref)
(table.get $tab (i32.const 0))
(ref.null)
(local.get 0)
Expand Down

0 comments on commit 22ce5e3

Please sign in to comment.