| 1 |
/* Copyright 2021 Mozilla Foundation |
| 2 |
* |
| 3 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
* you may not use this file except in compliance with the License. |
| 5 |
* You may obtain a copy of the License at |
| 6 |
* |
| 7 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
* |
| 9 |
* Unless required by applicable law or agreed to in writing, software |
| 10 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
* See the License for the specific language governing permissions and |
| 13 |
* limitations under the License. |
| 14 |
*/ |
| 15 |
|
| 16 |
// ./test/core/gc/array_new_data.wast |
| 17 |
|
| 18 |
// ./test/core/gc/array_new_data.wast:1 |
| 19 |
let $0 = instantiate(`(module |
| 20 |
(type $$arr (array (mut i8))) |
| 21 |
|
| 22 |
(data $$d "abcd") |
| 23 |
|
| 24 |
(func (export "array-new-data") (param i32 i32) (result (ref $$arr)) |
| 25 |
(array.new_data $$arr $$d (local.get 0) (local.get 1)) |
| 26 |
) |
| 27 |
)`); |
| 28 |
|
| 29 |
// ./test/core/gc/array_new_data.wast:12 |
| 30 |
assert_return(() => invoke($0, `array-new-data`, [0, 0]), [new RefWithType('arrayref')]); |
| 31 |
|
| 32 |
// ./test/core/gc/array_new_data.wast:13 |
| 33 |
assert_return(() => invoke($0, `array-new-data`, [0, 4]), [new RefWithType('arrayref')]); |
| 34 |
|
| 35 |
// ./test/core/gc/array_new_data.wast:14 |
| 36 |
assert_return(() => invoke($0, `array-new-data`, [1, 2]), [new RefWithType('arrayref')]); |
| 37 |
|
| 38 |
// ./test/core/gc/array_new_data.wast:15 |
| 39 |
assert_return(() => invoke($0, `array-new-data`, [4, 0]), [new RefWithType('arrayref')]); |
| 40 |
|
| 41 |
// ./test/core/gc/array_new_data.wast:18 |
| 42 |
assert_trap(() => invoke($0, `array-new-data`, [0, 5]), `out of bounds memory access`); |
| 43 |
|
| 44 |
// ./test/core/gc/array_new_data.wast:19 |
| 45 |
assert_trap(() => invoke($0, `array-new-data`, [5, 0]), `out of bounds memory access`); |
| 46 |
|
| 47 |
// ./test/core/gc/array_new_data.wast:20 |
| 48 |
assert_trap(() => invoke($0, `array-new-data`, [1, 4]), `out of bounds memory access`); |
| 49 |
|
| 50 |
// ./test/core/gc/array_new_data.wast:21 |
| 51 |
assert_trap(() => invoke($0, `array-new-data`, [4, 1]), `out of bounds memory access`); |
| 52 |
|
| 53 |
// ./test/core/gc/array_new_data.wast:24 |
| 54 |
let $1 = instantiate(`(module |
| 55 |
(type $$arr (array (mut i8))) |
| 56 |
|
| 57 |
(data $$d "\\aa\\bb\\cc\\dd") |
| 58 |
|
| 59 |
(func (export "array-new-data-contents") (result i32 i32) |
| 60 |
(local (ref $$arr)) |
| 61 |
(local.set 0 (array.new_data $$arr $$d (i32.const 1) (i32.const 2))) |
| 62 |
(array.get_u $$arr (local.get 0) (i32.const 0)) |
| 63 |
(array.get_u $$arr (local.get 0) (i32.const 1)) |
| 64 |
) |
| 65 |
)`); |
| 66 |
|
| 67 |
// ./test/core/gc/array_new_data.wast:38 |
| 68 |
assert_return(() => invoke($1, `array-new-data-contents`, []), [value("i32", 187), value("i32", 204)]); |
| 69 |
|
| 70 |
// ./test/core/gc/array_new_data.wast:40 |
| 71 |
let $2 = instantiate(`(module |
| 72 |
(type $$arr (array (mut i32))) |
| 73 |
|
| 74 |
(data $$d "\\aa\\bb\\cc\\dd") |
| 75 |
|
| 76 |
(func (export "array-new-data-little-endian") (result i32) |
| 77 |
(array.get $$arr |
| 78 |
(array.new_data $$arr $$d (i32.const 0) (i32.const 1)) |
| 79 |
(i32.const 0)) |
| 80 |
) |
| 81 |
)`); |
| 82 |
|
| 83 |
// ./test/core/gc/array_new_data.wast:53 |
| 84 |
assert_return(() => invoke($2, `array-new-data-little-endian`, []), [value("i32", -573785174)]); |
| 85 |
|
| 86 |
// ./test/core/gc/array_new_data.wast:55 |
| 87 |
let $3 = instantiate(`(module |
| 88 |
(type $$arr (array (mut i16))) |
| 89 |
|
| 90 |
(data $$d "\\00\\11\\22") |
| 91 |
|
| 92 |
(func (export "array-new-data-unaligned") (result i32) |
| 93 |
(array.get_u $$arr |
| 94 |
(array.new_data $$arr $$d (i32.const 1) (i32.const 1)) |
| 95 |
(i32.const 0)) |
| 96 |
) |
| 97 |
)`); |
| 98 |
|
| 99 |
// ./test/core/gc/array_new_data.wast:68 |
| 100 |
assert_return(() => invoke($3, `array-new-data-unaligned`, []), [value("i32", 8721)]); |