throw.wast.js (3223B)
1 /* Copyright 2021 Mozilla Foundation 2 * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 // ./test/core/exceptions/throw.wast 17 18 // ./test/core/exceptions/throw.wast:3 19 let $0 = instantiate(`(module 20 (tag \$e0) 21 (tag \$e-i32 (param i32)) 22 (tag \$e-f32 (param f32)) 23 (tag \$e-i64 (param i64)) 24 (tag \$e-f64 (param f64)) 25 (tag \$e-i32-i32 (param i32 i32)) 26 27 (func \$throw-if (export "throw-if") (param i32) (result i32) 28 (local.get 0) 29 (i32.const 0) (if (i32.ne) (then (throw \$e0))) 30 (i32.const 0) 31 ) 32 33 (func (export "throw-param-f32") (param f32) (local.get 0) (throw \$e-f32)) 34 35 (func (export "throw-param-i64") (param i64) (local.get 0) (throw \$e-i64)) 36 37 (func (export "throw-param-f64") (param f64) (local.get 0) (throw \$e-f64)) 38 39 (func (export "throw-polymorphic") (throw \$e0) (throw \$e-i32)) 40 41 (func (export "throw-polymorphic-block") (block (result i32) (throw \$e0)) (throw \$e-i32)) 42 43 (func \$throw-1-2 (i32.const 1) (i32.const 2) (throw \$e-i32-i32)) 44 (func (export "test-throw-1-2") 45 (block \$h (result i32 i32) 46 (try_table (catch \$e-i32-i32 \$h) (call \$throw-1-2)) 47 (return) 48 ) 49 (if (i32.ne (i32.const 2)) (then (unreachable))) 50 (if (i32.ne (i32.const 1)) (then (unreachable))) 51 ) 52 )`); 53 54 // ./test/core/exceptions/throw.wast:38 55 assert_return(() => invoke($0, `throw-if`, [0]), [value("i32", 0)]); 56 57 // ./test/core/exceptions/throw.wast:39 58 assert_exception(() => invoke($0, `throw-if`, [10])); 59 60 // ./test/core/exceptions/throw.wast:40 61 assert_exception(() => invoke($0, `throw-if`, [-1])); 62 63 // ./test/core/exceptions/throw.wast:42 64 assert_exception(() => invoke($0, `throw-param-f32`, [value("f32", 5)])); 65 66 // ./test/core/exceptions/throw.wast:43 67 assert_exception(() => invoke($0, `throw-param-i64`, [5n])); 68 69 // ./test/core/exceptions/throw.wast:44 70 assert_exception(() => invoke($0, `throw-param-f64`, [value("f64", 5)])); 71 72 // ./test/core/exceptions/throw.wast:46 73 assert_exception(() => invoke($0, `throw-polymorphic`, [])); 74 75 // ./test/core/exceptions/throw.wast:47 76 assert_exception(() => invoke($0, `throw-polymorphic-block`, [])); 77 78 // ./test/core/exceptions/throw.wast:49 79 assert_return(() => invoke($0, `test-throw-1-2`, []), []); 80 81 // ./test/core/exceptions/throw.wast:51 82 assert_invalid(() => instantiate(`(module (func (throw 0)))`), `unknown tag 0`); 83 84 // ./test/core/exceptions/throw.wast:52 85 assert_invalid( 86 () => instantiate(`(module (tag (param i32)) (func (throw 0)))`), 87 `type mismatch: instruction requires [i32] but stack has []`, 88 ); 89 90 // ./test/core/exceptions/throw.wast:54 91 assert_invalid( 92 () => instantiate(`(module (tag (param i32)) (func (i64.const 5) (throw 0)))`), 93 `type mismatch: instruction requires [i32] but stack has [i64]`, 94 );