crossrealm.gno
1.01 Kb · 38 lines
1package crossrealm_d
2
3// Simple stateful realm for cross-realm consistency tests.
4// Separated from crossrealm_b to avoid perturbing its object IDs.
5//
6// Contains both crossing and non-crossing setters so tests can
7// demonstrate that non-crossing calls from another realm cannot
8// silently mutate state via assign+recover.
9
10var counter int
11
12func init() {
13 counter = 100
14}
15
16// SetCounter: non-crossing. Calling this cross-realm triggers
17// the readonly check because it directly assigns a package var.
18func SetCounter(n int) {
19 counter = n
20}
21
22// SetCounterCrossing: crossing version. This works correctly
23// cross-realm because the caller enters this realm's context.
24func SetCounterCrossing(cur realm, n int) {
25 counter = n
26}
27
28func GetCounter(cur realm) int {
29 return counter
30}
31
32// DoubleCounter reads counter and doubles it. Used to show that
33// if counter were silently corrupted in memory, subsequent crossing
34// calls would act on the wrong value.
35func DoubleCounter(cur realm) int {
36 counter = counter * 2
37 return counter
38}