From 22ce5e36584e0116795244e928402dc0b5fd6f65 Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Mon, 3 Feb 2020 20:11:57 +0100 Subject: [PATCH] [interpreter] Fix ref asserts (#78) --- interpreter/script/js.ml | 35 +++++++++++++++-------------------- test/core/select.wast | 4 ++-- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/interpreter/script/js.ml b/interpreter/script/js.ml index 461c94dfe..f0eeb1144 100644 --- a/interpreter/script/js.ml +++ b/interpreter/script/js.ml @@ -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: @@ -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); - }; -} |} @@ -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 @@ -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 diff --git a/test/core/select.wast b/test/core/select.wast index 7d02a44da..267dd5738 100644 --- a/test/core/select.wast +++ b/test/core/select.wast @@ -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)