main.mx raw

   1  // Regression: map keys kept their bytes across a cross-package return on wasm.
   2  //
   3  // The map fixup paths wrote a string/[]byte header's length at the hardcoded
   4  // offset 8 (and cap at 16) - correct only where a pointer is 8 bytes. On wasm
   5  // the length landed in the cap slot and the length field stayed 0, so every
   6  // map key decoded empty: the relay proxy re-serialized a tag filter
   7  // {"#p":[pubkey]} as {"":[pubkey]} and matched nothing.
   8  //
   9  // Fixed in: src/runtime/codec.mx (codecDecodeMapValue, fixKey/fixStrVal/fixIface
  10  // use codecPtrSize() offsets) and src/runtime/relocate.mx
  11  // (relocFixupInterfaceValue).
  12  
  13  package main
  14  
  15  import (
  16  	"os"
  17  	"tests/regressions/should_compile/map_string_key_wasm/lib"
  18  )
  19  
  20  const want = `{"#p":["abc123"]}`
  21  
  22  func check(label, got string) {
  23  	if got == want {
  24  		println(label, "ok")
  25  		return
  26  	}
  27  	println(label, "FAIL got", got, "want", want)
  28  	os.Exit(1)
  29  }
  30  
  31  func main() {
  32  	check("lit   ", lib.Serialize(lib.BuildLit("abc123")))
  33  	check("concat", lib.Serialize(lib.BuildConcat("p", "abc123")))
  34  	check("sub   ", lib.Serialize(lib.BuildSub("x#py", "abc123")))
  35  }
  36