| 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/linking.wast |
| 17 |
|
| 18 |
// ./test/core/linking.wast:3 |
| 19 |
let $0 = instantiate(`(module $$Mf |
| 20 |
(func (export "call") (result i32) (call $$g)) |
| 21 |
(func $$g (result i32) (i32.const 2)) |
| 22 |
)`); |
| 23 |
let $Mf = $0; |
| 24 |
|
| 25 |
// ./test/core/linking.wast:7 |
| 26 |
register($Mf, `Mf`); |
| 27 |
|
| 28 |
// ./test/core/linking.wast:9 |
| 29 |
let $1 = instantiate(`(module $$Nf |
| 30 |
(func $$f (import "Mf" "call") (result i32)) |
| 31 |
(export "Mf.call" (func $$f)) |
| 32 |
(func (export "call Mf.call") (result i32) (call $$f)) |
| 33 |
(func (export "call") (result i32) (call $$g)) |
| 34 |
(func $$g (result i32) (i32.const 3)) |
| 35 |
)`); |
| 36 |
let $Nf = $1; |
| 37 |
|
| 38 |
// ./test/core/linking.wast:17 |
| 39 |
assert_return(() => invoke($Mf, `call`, []), [value("i32", 2)]); |
| 40 |
|
| 41 |
// ./test/core/linking.wast:18 |
| 42 |
assert_return(() => invoke($Nf, `Mf.call`, []), [value("i32", 2)]); |
| 43 |
|
| 44 |
// ./test/core/linking.wast:19 |
| 45 |
assert_return(() => invoke($Nf, `call`, []), [value("i32", 3)]); |
| 46 |
|
| 47 |
// ./test/core/linking.wast:20 |
| 48 |
assert_return(() => invoke($Nf, `call Mf.call`, []), [value("i32", 2)]); |
| 49 |
|
| 50 |
// ./test/core/linking.wast:22 |
| 51 |
let $2 = instantiate(`(module |
| 52 |
(import "spectest" "print_i32" (func $$f (param i32))) |
| 53 |
(export "print" (func $$f)) |
| 54 |
)`); |
| 55 |
|
| 56 |
// ./test/core/linking.wast:26 |
| 57 |
register($2, `reexport_f`); |
| 58 |
|
| 59 |
// ./test/core/linking.wast:27 |
| 60 |
assert_unlinkable( |
| 61 |
() => instantiate(`(module (import "reexport_f" "print" (func (param i64))))`), |
| 62 |
`incompatible import type`, |
| 63 |
); |
| 64 |
|
| 65 |
// ./test/core/linking.wast:31 |
| 66 |
assert_unlinkable( |
| 67 |
() => instantiate(`(module (import "reexport_f" "print" (func (param i32) (result i32))))`), |
| 68 |
`incompatible import type`, |
| 69 |
); |
| 70 |
|
| 71 |
// ./test/core/linking.wast:39 |
| 72 |
let $3 = instantiate(`(module $$Mg |
| 73 |
(global $$glob (export "glob") i32 (i32.const 42)) |
| 74 |
(func (export "get") (result i32) (global.get $$glob)) |
| 75 |
|
| 76 |
;; export mutable globals |
| 77 |
(global $$mut_glob (export "mut_glob") (mut i32) (i32.const 142)) |
| 78 |
(func (export "get_mut") (result i32) (global.get $$mut_glob)) |
| 79 |
(func (export "set_mut") (param i32) (global.set $$mut_glob (local.get 0))) |
| 80 |
)`); |
| 81 |
let $Mg = $3; |
| 82 |
|
| 83 |
// ./test/core/linking.wast:48 |
| 84 |
register($Mg, `Mg`); |
| 85 |
|
| 86 |
// ./test/core/linking.wast:50 |
| 87 |
let $4 = instantiate(`(module $$Ng |
| 88 |
(global $$x (import "Mg" "glob") i32) |
| 89 |
(global $$mut_glob (import "Mg" "mut_glob") (mut i32)) |
| 90 |
(func $$f (import "Mg" "get") (result i32)) |
| 91 |
(func $$get_mut (import "Mg" "get_mut") (result i32)) |
| 92 |
(func $$set_mut (import "Mg" "set_mut") (param i32)) |
| 93 |
|
| 94 |
(export "Mg.glob" (global $$x)) |
| 95 |
(export "Mg.get" (func $$f)) |
| 96 |
(global $$glob (export "glob") i32 (i32.const 43)) |
| 97 |
(func (export "get") (result i32) (global.get $$glob)) |
| 98 |
|
| 99 |
(export "Mg.mut_glob" (global $$mut_glob)) |
| 100 |
(export "Mg.get_mut" (func $$get_mut)) |
| 101 |
(export "Mg.set_mut" (func $$set_mut)) |
| 102 |
)`); |
| 103 |
let $Ng = $4; |
| 104 |
|
| 105 |
// ./test/core/linking.wast:67 |
| 106 |
assert_return(() => get($Mg, `glob`), [value("i32", 42)]); |
| 107 |
|
| 108 |
// ./test/core/linking.wast:68 |
| 109 |
assert_return(() => get($Ng, `Mg.glob`), [value("i32", 42)]); |
| 110 |
|
| 111 |
// ./test/core/linking.wast:69 |
| 112 |
assert_return(() => get($Ng, `glob`), [value("i32", 43)]); |
| 113 |
|
| 114 |
// ./test/core/linking.wast:70 |
| 115 |
assert_return(() => invoke($Mg, `get`, []), [value("i32", 42)]); |
| 116 |
|
| 117 |
// ./test/core/linking.wast:71 |
| 118 |
assert_return(() => invoke($Ng, `Mg.get`, []), [value("i32", 42)]); |
| 119 |
|
| 120 |
// ./test/core/linking.wast:72 |
| 121 |
assert_return(() => invoke($Ng, `get`, []), [value("i32", 43)]); |
| 122 |
|
| 123 |
// ./test/core/linking.wast:74 |
| 124 |
assert_return(() => get($Mg, `mut_glob`), [value("i32", 142)]); |
| 125 |
|
| 126 |
// ./test/core/linking.wast:75 |
| 127 |
assert_return(() => get($Ng, `Mg.mut_glob`), [value("i32", 142)]); |
| 128 |
|
| 129 |
// ./test/core/linking.wast:76 |
| 130 |
assert_return(() => invoke($Mg, `get_mut`, []), [value("i32", 142)]); |
| 131 |
|
| 132 |
// ./test/core/linking.wast:77 |
| 133 |
assert_return(() => invoke($Ng, `Mg.get_mut`, []), [value("i32", 142)]); |
| 134 |
|
| 135 |
// ./test/core/linking.wast:79 |
| 136 |
assert_return(() => invoke($Mg, `set_mut`, [241]), []); |
| 137 |
|
| 138 |
// ./test/core/linking.wast:80 |
| 139 |
assert_return(() => get($Mg, `mut_glob`), [value("i32", 241)]); |
| 140 |
|
| 141 |
// ./test/core/linking.wast:81 |
| 142 |
assert_return(() => get($Ng, `Mg.mut_glob`), [value("i32", 241)]); |
| 143 |
|
| 144 |
// ./test/core/linking.wast:82 |
| 145 |
assert_return(() => invoke($Mg, `get_mut`, []), [value("i32", 241)]); |
| 146 |
|
| 147 |
// ./test/core/linking.wast:83 |
| 148 |
assert_return(() => invoke($Ng, `Mg.get_mut`, []), [value("i32", 241)]); |
| 149 |
|
| 150 |
// ./test/core/linking.wast:86 |
| 151 |
assert_unlinkable( |
| 152 |
() => instantiate(`(module (import "Mg" "mut_glob" (global i32)))`), |
| 153 |
`incompatible import type`, |
| 154 |
); |
| 155 |
|
| 156 |
// ./test/core/linking.wast:90 |
| 157 |
assert_unlinkable( |
| 158 |
() => instantiate(`(module (import "Mg" "glob" (global (mut i32))))`), |
| 159 |
`incompatible import type`, |
| 160 |
); |
| 161 |
|
| 162 |
// ./test/core/linking.wast:96 |
| 163 |
let $5 = instantiate(`(module $$Mref_ex |
| 164 |
(global (export "g-const-func") funcref (ref.null func)) |
| 165 |
(global (export "g-var-func") (mut funcref) (ref.null func)) |
| 166 |
(global (export "g-const-extern") externref (ref.null extern)) |
| 167 |
(global (export "g-var-extern") (mut externref) (ref.null extern)) |
| 168 |
)`); |
| 169 |
let $Mref_ex = $5; |
| 170 |
|
| 171 |
// ./test/core/linking.wast:102 |
| 172 |
register($Mref_ex, `Mref_ex`); |
| 173 |
|
| 174 |
// ./test/core/linking.wast:104 |
| 175 |
let $6 = instantiate(`(module $$Mref_im |
| 176 |
(global (import "Mref_ex" "g-const-func") funcref) |
| 177 |
(global (import "Mref_ex" "g-const-extern") externref) |
| 178 |
|
| 179 |
(global (import "Mref_ex" "g-var-func") (mut funcref)) |
| 180 |
(global (import "Mref_ex" "g-var-extern") (mut externref)) |
| 181 |
)`); |
| 182 |
let $Mref_im = $6; |
| 183 |
|
| 184 |
// ./test/core/linking.wast:112 |
| 185 |
assert_unlinkable( |
| 186 |
() => instantiate(`(module (global (import "Mref_ex" "g-const-extern") funcref))`), |
| 187 |
`incompatible import type`, |
| 188 |
); |
| 189 |
|
| 190 |
// ./test/core/linking.wast:116 |
| 191 |
assert_unlinkable( |
| 192 |
() => instantiate(`(module (global (import "Mref_ex" "g-const-func") externref))`), |
| 193 |
`incompatible import type`, |
| 194 |
); |
| 195 |
|
| 196 |
// ./test/core/linking.wast:122 |
| 197 |
assert_unlinkable( |
| 198 |
() => instantiate(`(module (global (import "Mref_ex" "g-var-func") (mut externref)))`), |
| 199 |
`incompatible import type`, |
| 200 |
); |
| 201 |
|
| 202 |
// ./test/core/linking.wast:126 |
| 203 |
assert_unlinkable( |
| 204 |
() => instantiate(`(module (global (import "Mref_ex" "g-var-extern") (mut funcref)))`), |
| 205 |
`incompatible import type`, |
| 206 |
); |
| 207 |
|
| 208 |
// ./test/core/linking.wast:134 |
| 209 |
let $7 = instantiate(`(module $$Mt |
| 210 |
(type (func (result i32))) |
| 211 |
(type (func)) |
| 212 |
|
| 213 |
(table (export "tab") 10 funcref) |
| 214 |
(elem (i32.const 2) $$g $$g $$g $$g) |
| 215 |
(func $$g (result i32) (i32.const 4)) |
| 216 |
(func (export "h") (result i32) (i32.const -4)) |
| 217 |
|
| 218 |
(func (export "call") (param i32) (result i32) |
| 219 |
(call_indirect (type 0) (local.get 0)) |
| 220 |
) |
| 221 |
)`); |
| 222 |
let $Mt = $7; |
| 223 |
|
| 224 |
// ./test/core/linking.wast:147 |
| 225 |
register($Mt, `Mt`); |
| 226 |
|
| 227 |
// ./test/core/linking.wast:149 |
| 228 |
let $8 = instantiate(`(module $$Nt |
| 229 |
(type (func)) |
| 230 |
(type (func (result i32))) |
| 231 |
|
| 232 |
(func $$f (import "Mt" "call") (param i32) (result i32)) |
| 233 |
(func $$h (import "Mt" "h") (result i32)) |
| 234 |
|
| 235 |
(table funcref (elem $$g $$g $$g $$h $$f)) |
| 236 |
(func $$g (result i32) (i32.const 5)) |
| 237 |
|
| 238 |
(export "Mt.call" (func $$f)) |
| 239 |
(func (export "call Mt.call") (param i32) (result i32) |
| 240 |
(call $$f (local.get 0)) |
| 241 |
) |
| 242 |
(func (export "call") (param i32) (result i32) |
| 243 |
(call_indirect (type 1) (local.get 0)) |
| 244 |
) |
| 245 |
)`); |
| 246 |
let $Nt = $8; |
| 247 |
|
| 248 |
// ./test/core/linking.wast:168 |
| 249 |
assert_return(() => invoke($Mt, `call`, [2]), [value("i32", 4)]); |
| 250 |
|
| 251 |
// ./test/core/linking.wast:169 |
| 252 |
assert_return(() => invoke($Nt, `Mt.call`, [2]), [value("i32", 4)]); |
| 253 |
|
| 254 |
// ./test/core/linking.wast:170 |
| 255 |
assert_return(() => invoke($Nt, `call`, [2]), [value("i32", 5)]); |
| 256 |
|
| 257 |
// ./test/core/linking.wast:171 |
| 258 |
assert_return(() => invoke($Nt, `call Mt.call`, [2]), [value("i32", 4)]); |
| 259 |
|
| 260 |
// ./test/core/linking.wast:173 |
| 261 |
assert_trap(() => invoke($Mt, `call`, [1]), `uninitialized element`); |
| 262 |
|
| 263 |
// ./test/core/linking.wast:174 |
| 264 |
assert_trap(() => invoke($Nt, `Mt.call`, [1]), `uninitialized element`); |
| 265 |
|
| 266 |
// ./test/core/linking.wast:175 |
| 267 |
assert_return(() => invoke($Nt, `call`, [1]), [value("i32", 5)]); |
| 268 |
|
| 269 |
// ./test/core/linking.wast:176 |
| 270 |
assert_trap(() => invoke($Nt, `call Mt.call`, [1]), `uninitialized element`); |
| 271 |
|
| 272 |
// ./test/core/linking.wast:178 |
| 273 |
assert_trap(() => invoke($Mt, `call`, [0]), `uninitialized element`); |
| 274 |
|
| 275 |
// ./test/core/linking.wast:179 |
| 276 |
assert_trap(() => invoke($Nt, `Mt.call`, [0]), `uninitialized element`); |
| 277 |
|
| 278 |
// ./test/core/linking.wast:180 |
| 279 |
assert_return(() => invoke($Nt, `call`, [0]), [value("i32", 5)]); |
| 280 |
|
| 281 |
// ./test/core/linking.wast:181 |
| 282 |
assert_trap(() => invoke($Nt, `call Mt.call`, [0]), `uninitialized element`); |
| 283 |
|
| 284 |
// ./test/core/linking.wast:183 |
| 285 |
assert_trap(() => invoke($Mt, `call`, [20]), `undefined element`); |
| 286 |
|
| 287 |
// ./test/core/linking.wast:184 |
| 288 |
assert_trap(() => invoke($Nt, `Mt.call`, [20]), `undefined element`); |
| 289 |
|
| 290 |
// ./test/core/linking.wast:185 |
| 291 |
assert_trap(() => invoke($Nt, `call`, [7]), `undefined element`); |
| 292 |
|
| 293 |
// ./test/core/linking.wast:186 |
| 294 |
assert_trap(() => invoke($Nt, `call Mt.call`, [20]), `undefined element`); |
| 295 |
|
| 296 |
// ./test/core/linking.wast:188 |
| 297 |
assert_return(() => invoke($Nt, `call`, [3]), [value("i32", -4)]); |
| 298 |
|
| 299 |
// ./test/core/linking.wast:189 |
| 300 |
assert_trap(() => invoke($Nt, `call`, [4]), `indirect call type mismatch`); |
| 301 |
|
| 302 |
// ./test/core/linking.wast:191 |
| 303 |
let $9 = instantiate(`(module $$Ot |
| 304 |
(type (func (result i32))) |
| 305 |
|
| 306 |
(func $$h (import "Mt" "h") (result i32)) |
| 307 |
(table (import "Mt" "tab") 5 funcref) |
| 308 |
(elem (i32.const 1) $$i $$h) |
| 309 |
(func $$i (result i32) (i32.const 6)) |
| 310 |
|
| 311 |
(func (export "call") (param i32) (result i32) |
| 312 |
(call_indirect (type 0) (local.get 0)) |
| 313 |
) |
| 314 |
)`); |
| 315 |
let $Ot = $9; |
| 316 |
|
| 317 |
// ./test/core/linking.wast:204 |
| 318 |
assert_return(() => invoke($Mt, `call`, [3]), [value("i32", 4)]); |
| 319 |
|
| 320 |
// ./test/core/linking.wast:205 |
| 321 |
assert_return(() => invoke($Nt, `Mt.call`, [3]), [value("i32", 4)]); |
| 322 |
|
| 323 |
// ./test/core/linking.wast:206 |
| 324 |
assert_return(() => invoke($Nt, `call Mt.call`, [3]), [value("i32", 4)]); |
| 325 |
|
| 326 |
// ./test/core/linking.wast:207 |
| 327 |
assert_return(() => invoke($Ot, `call`, [3]), [value("i32", 4)]); |
| 328 |
|
| 329 |
// ./test/core/linking.wast:209 |
| 330 |
assert_return(() => invoke($Mt, `call`, [2]), [value("i32", -4)]); |
| 331 |
|
| 332 |
// ./test/core/linking.wast:210 |
| 333 |
assert_return(() => invoke($Nt, `Mt.call`, [2]), [value("i32", -4)]); |
| 334 |
|
| 335 |
// ./test/core/linking.wast:211 |
| 336 |
assert_return(() => invoke($Nt, `call`, [2]), [value("i32", 5)]); |
| 337 |
|
| 338 |
// ./test/core/linking.wast:212 |
| 339 |
assert_return(() => invoke($Nt, `call Mt.call`, [2]), [value("i32", -4)]); |
| 340 |
|
| 341 |
// ./test/core/linking.wast:213 |
| 342 |
assert_return(() => invoke($Ot, `call`, [2]), [value("i32", -4)]); |
| 343 |
|
| 344 |
// ./test/core/linking.wast:215 |
| 345 |
assert_return(() => invoke($Mt, `call`, [1]), [value("i32", 6)]); |
| 346 |
|
| 347 |
// ./test/core/linking.wast:216 |
| 348 |
assert_return(() => invoke($Nt, `Mt.call`, [1]), [value("i32", 6)]); |
| 349 |
|
| 350 |
// ./test/core/linking.wast:217 |
| 351 |
assert_return(() => invoke($Nt, `call`, [1]), [value("i32", 5)]); |
| 352 |
|
| 353 |
// ./test/core/linking.wast:218 |
| 354 |
assert_return(() => invoke($Nt, `call Mt.call`, [1]), [value("i32", 6)]); |
| 355 |
|
| 356 |
// ./test/core/linking.wast:219 |
| 357 |
assert_return(() => invoke($Ot, `call`, [1]), [value("i32", 6)]); |
| 358 |
|
| 359 |
// ./test/core/linking.wast:221 |
| 360 |
assert_trap(() => invoke($Mt, `call`, [0]), `uninitialized element`); |
| 361 |
|
| 362 |
// ./test/core/linking.wast:222 |
| 363 |
assert_trap(() => invoke($Nt, `Mt.call`, [0]), `uninitialized element`); |
| 364 |
|
| 365 |
// ./test/core/linking.wast:223 |
| 366 |
assert_return(() => invoke($Nt, `call`, [0]), [value("i32", 5)]); |
| 367 |
|
| 368 |
// ./test/core/linking.wast:224 |
| 369 |
assert_trap(() => invoke($Nt, `call Mt.call`, [0]), `uninitialized element`); |
| 370 |
|
| 371 |
// ./test/core/linking.wast:225 |
| 372 |
assert_trap(() => invoke($Ot, `call`, [0]), `uninitialized element`); |
| 373 |
|
| 374 |
// ./test/core/linking.wast:227 |
| 375 |
assert_trap(() => invoke($Ot, `call`, [20]), `undefined element`); |
| 376 |
|
| 377 |
// ./test/core/linking.wast:229 |
| 378 |
let $10 = instantiate(`(module |
| 379 |
(table (import "Mt" "tab") 0 funcref) |
| 380 |
(elem (i32.const 9) $$f) |
| 381 |
(func $$f) |
| 382 |
)`); |
| 383 |
|
| 384 |
// ./test/core/linking.wast:235 |
| 385 |
let $11 = instantiate(`(module $$G1 (global (export "g") i32 (i32.const 5)))`); |
| 386 |
let $G1 = $11; |
| 387 |
|
| 388 |
// ./test/core/linking.wast:236 |
| 389 |
register($G1, `G1`); |
| 390 |
|
| 391 |
// ./test/core/linking.wast:237 |
| 392 |
let $12 = instantiate(`(module $$G2 |
| 393 |
(global (import "G1" "g") i32) |
| 394 |
(global (export "g") i32 (global.get 0)) |
| 395 |
)`); |
| 396 |
let $G2 = $12; |
| 397 |
|
| 398 |
// ./test/core/linking.wast:241 |
| 399 |
assert_return(() => get($G2, `g`), [value("i32", 5)]); |
| 400 |
|
| 401 |
// ./test/core/linking.wast:243 |
| 402 |
assert_trap( |
| 403 |
() => instantiate(`(module |
| 404 |
(table (import "Mt" "tab") 0 funcref) |
| 405 |
(elem (i32.const 10) $$f) |
| 406 |
(func $$f) |
| 407 |
)`), |
| 408 |
`out of bounds table access`, |
| 409 |
); |
| 410 |
|
| 411 |
// ./test/core/linking.wast:252 |
| 412 |
assert_unlinkable( |
| 413 |
() => instantiate(`(module |
| 414 |
(table (import "Mt" "tab") 10 funcref) |
| 415 |
(memory (import "Mt" "mem") 1) ;; does not exist |
| 416 |
(func $$f (result i32) (i32.const 0)) |
| 417 |
(elem (i32.const 7) $$f) |
| 418 |
(elem (i32.const 9) $$f) |
| 419 |
)`), |
| 420 |
`unknown import`, |
| 421 |
); |
| 422 |
|
| 423 |
// ./test/core/linking.wast:262 |
| 424 |
assert_trap(() => invoke($Mt, `call`, [7]), `uninitialized element`); |
| 425 |
|
| 426 |
// ./test/core/linking.wast:266 |
| 427 |
assert_trap( |
| 428 |
() => instantiate(`(module |
| 429 |
(table (import "Mt" "tab") 10 funcref) |
| 430 |
(func $$f (result i32) (i32.const 0)) |
| 431 |
(elem (i32.const 7) $$f) |
| 432 |
(elem (i32.const 8) $$f $$f $$f $$f $$f) ;; (partially) out of bounds |
| 433 |
)`), |
| 434 |
`out of bounds table access`, |
| 435 |
); |
| 436 |
|
| 437 |
// ./test/core/linking.wast:275 |
| 438 |
assert_return(() => invoke($Mt, `call`, [7]), [value("i32", 0)]); |
| 439 |
|
| 440 |
// ./test/core/linking.wast:276 |
| 441 |
assert_trap(() => invoke($Mt, `call`, [8]), `uninitialized element`); |
| 442 |
|
| 443 |
// ./test/core/linking.wast:278 |
| 444 |
assert_trap( |
| 445 |
() => instantiate(`(module |
| 446 |
(table (import "Mt" "tab") 10 funcref) |
| 447 |
(func $$f (result i32) (i32.const 0)) |
| 448 |
(elem (i32.const 7) $$f) |
| 449 |
(memory 1) |
| 450 |
(data (i32.const 0x10000) "d") ;; out of bounds |
| 451 |
)`), |
| 452 |
`out of bounds memory access`, |
| 453 |
); |
| 454 |
|
| 455 |
// ./test/core/linking.wast:288 |
| 456 |
assert_return(() => invoke($Mt, `call`, [7]), [value("i32", 0)]); |
| 457 |
|
| 458 |
// ./test/core/linking.wast:291 |
| 459 |
let $13 = instantiate(`(module $$Mtable_ex |
| 460 |
(table $$t1 (export "t-func") 1 funcref) |
| 461 |
(table $$t2 (export "t-extern") 1 externref) |
| 462 |
)`); |
| 463 |
let $Mtable_ex = $13; |
| 464 |
|
| 465 |
// ./test/core/linking.wast:295 |
| 466 |
register($Mtable_ex, `Mtable_ex`); |
| 467 |
|
| 468 |
// ./test/core/linking.wast:297 |
| 469 |
let $14 = instantiate(`(module |
| 470 |
(table (import "Mtable_ex" "t-func") 1 funcref) |
| 471 |
(table (import "Mtable_ex" "t-extern") 1 externref) |
| 472 |
)`); |
| 473 |
|
| 474 |
// ./test/core/linking.wast:302 |
| 475 |
assert_unlinkable( |
| 476 |
() => instantiate(`(module (table (import "Mtable_ex" "t-func") 1 externref))`), |
| 477 |
`incompatible import type`, |
| 478 |
); |
| 479 |
|
| 480 |
// ./test/core/linking.wast:306 |
| 481 |
assert_unlinkable( |
| 482 |
() => instantiate(`(module (table (import "Mtable_ex" "t-extern") 1 funcref))`), |
| 483 |
`incompatible import type`, |
| 484 |
); |
| 485 |
|
| 486 |
// ./test/core/linking.wast:314 |
| 487 |
let $15 = instantiate(`(module $$Mm |
| 488 |
(memory (export "mem") 1 5) |
| 489 |
(data (i32.const 10) "\\00\\01\\02\\03\\04\\05\\06\\07\\08\\09") |
| 490 |
|
| 491 |
(func (export "load") (param $$a i32) (result i32) |
| 492 |
(i32.load8_u (local.get 0)) |
| 493 |
) |
| 494 |
)`); |
| 495 |
let $Mm = $15; |
| 496 |
|
| 497 |
// ./test/core/linking.wast:322 |
| 498 |
register($Mm, `Mm`); |
| 499 |
|
| 500 |
// ./test/core/linking.wast:324 |
| 501 |
let $16 = instantiate(`(module $$Nm |
| 502 |
(func $$loadM (import "Mm" "load") (param i32) (result i32)) |
| 503 |
|
| 504 |
(memory 1) |
| 505 |
(data (i32.const 10) "\\f0\\f1\\f2\\f3\\f4\\f5") |
| 506 |
|
| 507 |
(export "Mm.load" (func $$loadM)) |
| 508 |
(func (export "load") (param $$a i32) (result i32) |
| 509 |
(i32.load8_u (local.get 0)) |
| 510 |
) |
| 511 |
)`); |
| 512 |
let $Nm = $16; |
| 513 |
|
| 514 |
// ./test/core/linking.wast:336 |
| 515 |
assert_return(() => invoke($Mm, `load`, [12]), [value("i32", 2)]); |
| 516 |
|
| 517 |
// ./test/core/linking.wast:337 |
| 518 |
assert_return(() => invoke($Nm, `Mm.load`, [12]), [value("i32", 2)]); |
| 519 |
|
| 520 |
// ./test/core/linking.wast:338 |
| 521 |
assert_return(() => invoke($Nm, `load`, [12]), [value("i32", 242)]); |
| 522 |
|
| 523 |
// ./test/core/linking.wast:340 |
| 524 |
let $17 = instantiate(`(module $$Om |
| 525 |
(memory (import "Mm" "mem") 1) |
| 526 |
(data (i32.const 5) "\\a0\\a1\\a2\\a3\\a4\\a5\\a6\\a7") |
| 527 |
|
| 528 |
(func (export "load") (param $$a i32) (result i32) |
| 529 |
(i32.load8_u (local.get 0)) |
| 530 |
) |
| 531 |
)`); |
| 532 |
let $Om = $17; |
| 533 |
|
| 534 |
// ./test/core/linking.wast:349 |
| 535 |
assert_return(() => invoke($Mm, `load`, [12]), [value("i32", 167)]); |
| 536 |
|
| 537 |
// ./test/core/linking.wast:350 |
| 538 |
assert_return(() => invoke($Nm, `Mm.load`, [12]), [value("i32", 167)]); |
| 539 |
|
| 540 |
// ./test/core/linking.wast:351 |
| 541 |
assert_return(() => invoke($Nm, `load`, [12]), [value("i32", 242)]); |
| 542 |
|
| 543 |
// ./test/core/linking.wast:352 |
| 544 |
assert_return(() => invoke($Om, `load`, [12]), [value("i32", 167)]); |
| 545 |
|
| 546 |
// ./test/core/linking.wast:354 |
| 547 |
let $18 = instantiate(`(module |
| 548 |
(memory (import "Mm" "mem") 0) |
| 549 |
(data (i32.const 0xffff) "a") |
| 550 |
)`); |
| 551 |
|
| 552 |
// ./test/core/linking.wast:359 |
| 553 |
assert_trap( |
| 554 |
() => instantiate(`(module |
| 555 |
(memory (import "Mm" "mem") 0) |
| 556 |
(data (i32.const 0x10000) "a") |
| 557 |
)`), |
| 558 |
`out of bounds memory access`, |
| 559 |
); |
| 560 |
|
| 561 |
// ./test/core/linking.wast:367 |
| 562 |
let $19 = instantiate(`(module $$Pm |
| 563 |
(memory (import "Mm" "mem") 1 8) |
| 564 |
|
| 565 |
(func (export "grow") (param $$a i32) (result i32) |
| 566 |
(memory.grow (local.get 0)) |
| 567 |
) |
| 568 |
)`); |
| 569 |
let $Pm = $19; |
| 570 |
|
| 571 |
// ./test/core/linking.wast:375 |
| 572 |
assert_return(() => invoke($Pm, `grow`, [0]), [value("i32", 1)]); |
| 573 |
|
| 574 |
// ./test/core/linking.wast:376 |
| 575 |
assert_return(() => invoke($Pm, `grow`, [2]), [value("i32", 1)]); |
| 576 |
|
| 577 |
// ./test/core/linking.wast:377 |
| 578 |
assert_return(() => invoke($Pm, `grow`, [0]), [value("i32", 3)]); |
| 579 |
|
| 580 |
// ./test/core/linking.wast:378 |
| 581 |
assert_return(() => invoke($Pm, `grow`, [1]), [value("i32", 3)]); |
| 582 |
|
| 583 |
// ./test/core/linking.wast:379 |
| 584 |
assert_return(() => invoke($Pm, `grow`, [1]), [value("i32", 4)]); |
| 585 |
|
| 586 |
// ./test/core/linking.wast:380 |
| 587 |
assert_return(() => invoke($Pm, `grow`, [0]), [value("i32", 5)]); |
| 588 |
|
| 589 |
// ./test/core/linking.wast:381 |
| 590 |
assert_return(() => invoke($Pm, `grow`, [1]), [value("i32", -1)]); |
| 591 |
|
| 592 |
// ./test/core/linking.wast:382 |
| 593 |
assert_return(() => invoke($Pm, `grow`, [0]), [value("i32", 5)]); |
| 594 |
|
| 595 |
// ./test/core/linking.wast:384 |
| 596 |
assert_unlinkable( |
| 597 |
() => instantiate(`(module |
| 598 |
(func $$host (import "spectest" "print")) |
| 599 |
(memory (import "Mm" "mem") 1) |
| 600 |
(table (import "Mm" "tab") 0 funcref) ;; does not exist |
| 601 |
(data (i32.const 0) "abc") |
| 602 |
)`), |
| 603 |
`unknown import`, |
| 604 |
); |
| 605 |
|
| 606 |
// ./test/core/linking.wast:393 |
| 607 |
assert_return(() => invoke($Mm, `load`, [0]), [value("i32", 0)]); |
| 608 |
|
| 609 |
// ./test/core/linking.wast:397 |
| 610 |
assert_trap( |
| 611 |
() => instantiate(`(module |
| 612 |
;; Note: the memory is 5 pages large by the time we get here. |
| 613 |
(memory (import "Mm" "mem") 1) |
| 614 |
(data (i32.const 0) "abc") |
| 615 |
(data (i32.const 327670) "zzzzzzzzzzzzzzzzzz") ;; (partially) out of bounds |
| 616 |
)`), |
| 617 |
`out of bounds memory access`, |
| 618 |
); |
| 619 |
|
| 620 |
// ./test/core/linking.wast:406 |
| 621 |
assert_return(() => invoke($Mm, `load`, [0]), [value("i32", 97)]); |
| 622 |
|
| 623 |
// ./test/core/linking.wast:407 |
| 624 |
assert_return(() => invoke($Mm, `load`, [327670]), [value("i32", 0)]); |
| 625 |
|
| 626 |
// ./test/core/linking.wast:409 |
| 627 |
assert_trap( |
| 628 |
() => instantiate(`(module |
| 629 |
(memory (import "Mm" "mem") 1) |
| 630 |
(data (i32.const 0) "abc") |
| 631 |
(table 0 funcref) |
| 632 |
(func) |
| 633 |
(elem (i32.const 0) 0) ;; out of bounds |
| 634 |
)`), |
| 635 |
`out of bounds table access`, |
| 636 |
); |
| 637 |
|
| 638 |
// ./test/core/linking.wast:419 |
| 639 |
assert_return(() => invoke($Mm, `load`, [0]), [value("i32", 97)]); |
| 640 |
|
| 641 |
// ./test/core/linking.wast:422 |
| 642 |
let $20 = instantiate(`(module $$Ms |
| 643 |
(type $$t (func (result i32))) |
| 644 |
(memory (export "memory") 1) |
| 645 |
(table (export "table") 1 funcref) |
| 646 |
(func (export "get memory[0]") (type $$t) |
| 647 |
(i32.load8_u (i32.const 0)) |
| 648 |
) |
| 649 |
(func (export "get table[0]") (type $$t) |
| 650 |
(call_indirect (type $$t) (i32.const 0)) |
| 651 |
) |
| 652 |
)`); |
| 653 |
let $Ms = $20; |
| 654 |
|
| 655 |
// ./test/core/linking.wast:433 |
| 656 |
register($Ms, `Ms`); |
| 657 |
|
| 658 |
// ./test/core/linking.wast:435 |
| 659 |
assert_trap( |
| 660 |
() => instantiate(`(module |
| 661 |
(import "Ms" "memory" (memory 1)) |
| 662 |
(import "Ms" "table" (table 1 funcref)) |
| 663 |
(data (i32.const 0) "hello") |
| 664 |
(elem (i32.const 0) $$f) |
| 665 |
(func $$f (result i32) |
| 666 |
(i32.const 0xdead) |
| 667 |
) |
| 668 |
(func $$main |
| 669 |
(unreachable) |
| 670 |
) |
| 671 |
(start $$main) |
| 672 |
)`), |
| 673 |
`unreachable`, |
| 674 |
); |
| 675 |
|
| 676 |
// ./test/core/linking.wast:452 |
| 677 |
assert_return(() => invoke($Ms, `get memory[0]`, []), [value("i32", 104)]); |
| 678 |
|
| 679 |
// ./test/core/linking.wast:453 |
| 680 |
assert_return(() => invoke($Ms, `get table[0]`, []), [value("i32", 57005)]); |