diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/binaryen.js/expressions.js | 48 | ||||
-rw-r--r-- | test/binaryen.js/expressions.js.txt | 5 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.c | 7 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.txt | 35 |
4 files changed, 95 insertions, 0 deletions
diff --git a/test/binaryen.js/expressions.js b/test/binaryen.js/expressions.js index 69081f0e6..d6256cec1 100644 --- a/test/binaryen.js/expressions.js +++ b/test/binaryen.js/expressions.js @@ -1403,6 +1403,54 @@ console.log("# RefIs"); module.dispose(); })(); +console.log("# RefAs"); +(function testRefAs() { + const module = new binaryen.Module(); + + var op = binaryen.Operations.RefAsNonNull; + var value = module.local.get(1, binaryen.anyref); + const theRefAs = binaryen.RefAs(module.ref.as_non_null(value)); + assert(theRefAs instanceof binaryen.RefAs); + assert(theRefAs instanceof binaryen.Expression); + assert(theRefAs.op === op); + assert(theRefAs.value === value); + assert(theRefAs.type !== binaryen.i32); // TODO: === (ref any) + + theRefAs.op = op = binaryen.Operations.RefAsFunc; + assert(theRefAs.op === op); + theRefAs.op = op = binaryen.Operations.RefAsNull; + theRefAs.value = value = module.local.get(2, binaryen.anyref); + assert(theRefAs.value === value); + theRefAs.type = binaryen.f64; + theRefAs.finalize(); + assert(theRefAs.type !== binaryen.f64); // TODO: === (ref any) + + console.log(theRefAs.toText()); + assert( + theRefAs.toText() + == + "(ref.as_non_null\n (local.get $2)\n)\n" + ); + + assert( + binaryen.RefAs(module.ref.as_func(value)).toText() + == + "(ref.as_func\n (local.get $2)\n)\n" + ); + assert( + binaryen.RefAs(module.ref.as_data(value)).toText() + == + "(ref.as_data\n (local.get $2)\n)\n" + ); + assert( + binaryen.RefAs(module.ref.as_i31(value)).toText() + == + "(ref.as_i31\n (local.get $2)\n)\n" + ); + + module.dispose(); +})(); + console.log("# RefFunc"); (function testRefFunc() { const module = new binaryen.Module(); diff --git a/test/binaryen.js/expressions.js.txt b/test/binaryen.js/expressions.js.txt index 1efbd9e13..0467e9332 100644 --- a/test/binaryen.js/expressions.js.txt +++ b/test/binaryen.js/expressions.js.txt @@ -207,6 +207,11 @@ (local.get $2) ) +# RefAs +(ref.as_non_null + (local.get $2) +) + # RefFunc (ref.func $b) diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c index cbf795e5c..4faf7aa5e 100644 --- a/test/example/c-api-kitchen-sink.c +++ b/test/example/c-api-kitchen-sink.c @@ -731,6 +731,13 @@ void test_core() { BinaryenRefEq(module, BinaryenRefNull(module, BinaryenTypeEqref()), BinaryenRefNull(module, BinaryenTypeEqref())), + BinaryenRefIs(module, BinaryenRefIsFunc(), BinaryenRefNull(module, BinaryenTypeAnyref())), + BinaryenRefIs(module, BinaryenRefIsData(), BinaryenRefNull(module, BinaryenTypeAnyref())), + BinaryenRefIs(module, BinaryenRefIsI31(), BinaryenRefNull(module, BinaryenTypeAnyref())), + BinaryenRefAs(module, BinaryenRefAsNonNull(), BinaryenRefNull(module, BinaryenTypeAnyref())), + BinaryenRefAs(module, BinaryenRefAsFunc(), BinaryenRefNull(module, BinaryenTypeAnyref())), + BinaryenRefAs(module, BinaryenRefAsData(), BinaryenRefNull(module, BinaryenTypeAnyref())), + BinaryenRefAs(module, BinaryenRefAsI31(), BinaryenRefNull(module, BinaryenTypeAnyref())), // Exception handling BinaryenTry(module, NULL, tryBody, catchEvents, 1, catchBodies, 2, NULL), // (try $try_outer diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt index 66b9ab507..40b7da26e 100644 --- a/test/example/c-api-kitchen-sink.txt +++ b/test/example/c-api-kitchen-sink.txt @@ -1761,6 +1761,41 @@ BinaryenFeatureAll: 8191 (ref.null eq) ) ) + (drop + (ref.is_func + (ref.null any) + ) + ) + (drop + (ref.is_data + (ref.null any) + ) + ) + (drop + (ref.is_i31 + (ref.null any) + ) + ) + (drop + (ref.as_non_null + (ref.null any) + ) + ) + (drop + (ref.as_func + (ref.null any) + ) + ) + (drop + (ref.as_data + (ref.null any) + ) + ) + (drop + (ref.as_i31 + (ref.null any) + ) + ) (try (do (throw $a-event |