MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / TEST

Function TEST

crates/c-api/tests/exception.cc:12–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10}
11
12TEST(Exception, ConstructAndExamine) {
13 auto engine = make_engine();
14 Store store(engine);
15 auto cx = store.context();
16
17 // Create a tag type with (i32, i64) payload.
18 FuncType ft({ValType::i32(), ValType::i64()}, {});
19 TagType tt(ft);
20
21 // Create a tag instance.
22 auto tag = Tag::create(cx, tt).unwrap();
23
24 // Create an exception with payload (42, 100).
25 std::vector<Val> fields = {Val(int32_t(42)), Val(int64_t(100))};
26 auto exn = ExnRef::create(cx, tag, fields).unwrap();
27
28 // Read back the tag and verify identity.
29 auto exn_tag = exn.tag(cx).unwrap();
30 EXPECT_TRUE(tag.eq(cx, exn_tag));
31
32 // Read field count.
33 EXPECT_EQ(exn.field_count(cx), 2u);
34
35 // Read fields.
36 auto f0 = exn.field(cx, 0).unwrap();
37 EXPECT_EQ(f0.kind(), ValKind::I32);
38 EXPECT_EQ(f0.i32(), 42);
39
40 auto f1 = exn.field(cx, 1).unwrap();
41 EXPECT_EQ(f1.kind(), ValKind::I64);
42 EXPECT_EQ(f1.i64(), 100);
43
44 auto fty = exn.ty(cx).tag_type()->functype();
45 EXPECT_EQ(fty->params().size(), 2);
46 EXPECT_EQ(*fty->params().begin(), ValType::i32());
47 EXPECT_EQ(*(fty->params().begin() + 1), ValType::i64());
48 EXPECT_EQ(fty->results().size(), 0);
49}
50
51TEST(Exception, TagFromModule) {
52 auto engine = make_engine();

Callers

nothing calls this directly

Calls 15

i64Function · 0.85
functypeMethod · 0.80
throw_exceptionMethod · 0.80
has_exceptionMethod · 0.80
take_exceptionMethod · 0.80
make_engineFunction · 0.70
createFunction · 0.50
ValClass · 0.50
compileFunction · 0.50
contextMethod · 0.45
unwrapMethod · 0.45
tagMethod · 0.45

Tested by

no test coverage detected