linkdata_push_panics.mx raw

   1  //:expect-panic linkdata slice: cap is foreign (copy it first)
   2  //:wasmtest skip
   3  /*
   4  A //:linkdata binding has foreign storage. push on it must die with a message
   5  that names the cause - a foreign capacity - rather than an "invalid capacity"
   6  or a bounds trap in the runtime, which reads like memory corruption to whoever
   7  sees it in a parser.
   8  
   9  This fixture exists so the guard cannot be dropped quietly: the harness runs it,
  10  requires a non-zero exit, and requires that exact text. The existing
  11  linkdata_fixed_length fixture pins the header (cap reports len, subslicing
  12  yields normal storage); this one pins the refusal.
  13  */
  14  package main
  15  
  16  //:linkdata 16 fixturesymbol
  17  var local []byte
  18  
  19  func main() {
  20  	select {
  21  	case <-shutdown:
  22  		return
  23  	default:
  24  	}
  25  	// push on the package global is a compile error (a global is immutable
  26  	// outside init), so take a local header copy: it keeps the foreign
  27  	// capacity and reaches the runtime guard.
  28  	l := local
  29  	push(l, 1)
  30  	println("push on a linkdata slice did not panic")
  31  }
  32