1;;! component_model_threading = true
2
3(component definition $Tester
4  (core module $Memory
5    (table (export "t") 1 funcref)
6  )
7  (core instance $memory (instantiate $Memory))
8
9  (core type $ft (func (param i32)))
10  (core func $thread.new-indirect (canon thread.new-indirect $ft (table $memory "t")))
11  (core func $thread.switch-to (canon thread.switch-to))
12  (core func $thread.suspend (canon thread.suspend))
13  (core func $thread.resume-later (canon thread.resume-later))
14  (core func $thread.yield-to (canon thread.yield-to))
15
16  (core module $DM
17    (import "" "thread.new-indirect" (func $thread.new-indirect (param i32 i32) (result i32)))
18    (import "" "thread.switch-to" (func $thread.switch-to (param i32) (result i32)))
19    (import "" "thread.suspend" (func $thread.suspend (result i32)))
20    (import "" "thread.resume-later" (func $thread.resume-later (param i32)))
21    (import "" "thread.yield-to" (func $thread.yield-to (param i32) (result i32)))
22
23    (func (export "noop"))
24    (func (export "trap-calling-thread-new-indirect") (call $thread.new-indirect (i32.const 0) (i32.const 0)) drop)
25    (func (export "trap-calling-thread-switch-to") (call $thread.switch-to (i32.const 0)) drop)
26    (func (export "trap-calling-thread-suspend") (call $thread.suspend) drop)
27    (func (export "trap-calling-thread-resume-later") (call $thread.resume-later (i32.const 0)))
28    (func (export "trap-calling-thread-yield-to") (call $thread.yield-to (i32.const 0)) drop)
29  )
30  (core instance $dm (instantiate $DM (with "" (instance
31    (export "thread.new-indirect" (func $thread.new-indirect))
32    (export "thread.switch-to" (func $thread.switch-to))
33    (export "thread.suspend" (func $thread.suspend))
34    (export "thread.resume-later" (func $thread.resume-later))
35    (export "thread.yield-to" (func $thread.yield-to))
36  ))))
37  (func (export "trap-calling-thread-new-indirect")
38    (canon lift (core func $dm "noop")
39      (post-return (func $dm "trap-calling-thread-new-indirect"))))
40  (func (export "trap-calling-thread-switch-to")
41    (canon lift (core func $dm "noop")
42      (post-return (func $dm "trap-calling-thread-switch-to"))))
43  (func (export "trap-calling-thread-suspend")
44    (canon lift (core func $dm "noop")
45      (post-return (func $dm "trap-calling-thread-suspend"))))
46  (func (export "trap-calling-thread-resume-later")
47    (canon lift (core func $dm "noop")
48      (post-return (func $dm "trap-calling-thread-resume-later"))))
49  (func (export "trap-calling-thread-yield-to")
50    (canon lift (core func $dm "noop")
51      (post-return (func $dm "trap-calling-thread-yield-to"))))
52)
53
54(component instance $i0 $Tester)
55(assert_trap (invoke "trap-calling-thread-new-indirect") "cannot leave component instance")
56(component instance $i1 $Tester)
57(assert_trap (invoke "trap-calling-thread-switch-to") "cannot leave component instance")
58(component instance $i2 $Tester)
59(assert_trap (invoke "trap-calling-thread-suspend") "cannot leave component instance")
60(component instance $i3 $Tester)
61(assert_trap (invoke "trap-calling-thread-resume-later") "cannot leave component instance")
62(component instance $i4 $Tester)
63(assert_trap (invoke "trap-calling-thread-yield-to") "cannot leave component instance")
64