1;;! gc = true 2 3(module 4 (type $arr (array i31ref)) 5 6 (elem $e i31ref 7 (ref.i31 (i32.const 0xaa)) 8 (ref.i31 (i32.const 0xbb)) 9 (ref.i31 (i32.const 0xcc)) 10 (ref.i31 (i32.const 0xdd))) 11 12 (func (export "array-new-elem") (param i32 i32) (result (ref $arr)) 13 (array.new_elem $arr $e (local.get 0) (local.get 1)) 14 ) 15) 16 17;; In-bounds element segment accesses. 18(assert_return (invoke "array-new-elem" (i32.const 0) (i32.const 0)) (ref.array)) 19(assert_return (invoke "array-new-elem" (i32.const 0) (i32.const 4)) (ref.array)) 20(assert_return (invoke "array-new-elem" (i32.const 1) (i32.const 2)) (ref.array)) 21(assert_return (invoke "array-new-elem" (i32.const 4) (i32.const 0)) (ref.array)) 22 23;; Out-of-bounds element segment accesses. 24(assert_trap (invoke "array-new-elem" (i32.const 0) (i32.const 5)) "out of bounds table access") 25(assert_trap (invoke "array-new-elem" (i32.const 5) (i32.const 0)) "out of bounds table access") 26(assert_trap (invoke "array-new-elem" (i32.const 1) (i32.const 4)) "out of bounds table access") 27(assert_trap (invoke "array-new-elem" (i32.const 4) (i32.const 1)) "out of bounds table access") 28 29(module 30 (type $arr (array i31ref)) 31 32 (elem $e i31ref 33 (ref.i31 (i32.const 0xaa)) 34 (ref.i31 (i32.const 0xbb)) 35 (ref.i31 (i32.const 0xcc)) 36 (ref.i31 (i32.const 0xdd))) 37 38 (func (export "array-new-elem-contents") (result i32 i32) 39 (local (ref $arr)) 40 (local.set 0 (array.new_elem $arr $e (i32.const 1) (i32.const 2))) 41 (i31.get_u (array.get $arr (local.get 0) (i32.const 0))) 42 (i31.get_u (array.get $arr (local.get 0) (i32.const 1))) 43 ) 44) 45 46;; Array is initialized with the correct contents. 47(assert_return (invoke "array-new-elem-contents") (i32.const 0xbb) (i32.const 0xcc)) 48