1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770
pub use self::{
element::{ElementSegment, ElementSegmentEntity, ElementSegmentIdx},
error::TableError,
};
use super::{AsContext, AsContextMut, Stored};
use crate::{
collections::arena::ArenaIndex,
core::{TrapCode, UntypedVal, ValType},
error::EntityGrowError,
module::FuncIdx,
store::{Fuel, FuelError, ResourceLimiterRef},
value::WithType,
Func,
FuncRef,
Val,
};
use core::cmp::max;
use std::{vec, vec::Vec};
mod element;
mod error;
#[cfg(test)]
mod tests;
/// A raw index to a table entity.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct TableIdx(u32);
impl ArenaIndex for TableIdx {
fn into_usize(self) -> usize {
self.0 as usize
}
fn from_usize(value: usize) -> Self {
let value = value.try_into().unwrap_or_else(|error| {
panic!("index {value} is out of bounds as table index: {error}")
});
Self(value)
}
}
/// A descriptor for a [`Table`] instance.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct TableType {
/// The type of values stored in the [`Table`].
element: ValType,
/// The minimum number of elements the [`Table`] must have.
min: u32,
/// The optional maximum number of elements the [`Table`] can have.
///
/// If this is `None` then the [`Table`] is not limited in size.
max: Option<u32>,
}
impl TableType {
/// Creates a new [`TableType`].
///
/// # Panics
///
/// If `min` is greater than `max`.
pub fn new(element: ValType, min: u32, max: Option<u32>) -> Self {
if let Some(max) = max {
assert!(min <= max);
}
Self { element, min, max }
}
/// Returns the [`ValType`] of elements stored in the [`Table`].
pub fn element(&self) -> ValType {
self.element
}
/// Returns minimum number of elements the [`Table`] must have.
pub fn minimum(&self) -> u32 {
self.min
}
/// The optional maximum number of elements the [`Table`] can have.
///
/// If this returns `None` then the [`Table`] is not limited in size.
pub fn maximum(&self) -> Option<u32> {
self.max
}
/// Returns a [`TableError`] if `ty` does not match the [`Table`] element [`ValType`].
fn matches_element_type(&self, ty: ValType) -> Result<(), TableError> {
let expected = self.element();
let actual = ty;
if actual != expected {
return Err(TableError::ElementTypeMismatch { expected, actual });
}
Ok(())
}
/// Checks if `self` is a subtype of `other`.
///
/// # Note
///
/// This implements the [subtyping rules] according to the WebAssembly spec.
///
/// [import subtyping]:
/// https://webassembly.github.io/spec/core/valid/types.html#import-subtyping
///
/// # Errors
///
/// - If the `element` type of `self` does not match the `element` type of `other`.
/// - If the `minimum` size of `self` is less than or equal to the `minimum` size of `other`.
/// - If the `maximum` size of `self` is greater than the `maximum` size of `other`.
pub(crate) fn is_subtype_or_err(&self, other: &TableType) -> Result<(), TableError> {
match self.is_subtype_of(other) {
true => Ok(()),
false => Err(TableError::InvalidSubtype {
ty: *self,
other: *other,
}),
}
}
/// Returns `true` if the [`TableType`] is a subtype of the `other` [`TableType`].
///
/// # Note
///
/// This implements the [subtyping rules] according to the WebAssembly spec.
///
/// [import subtyping]:
/// https://webassembly.github.io/spec/core/valid/types.html#import-subtyping
pub(crate) fn is_subtype_of(&self, other: &Self) -> bool {
if self.matches_element_type(other.element()).is_err() {
return false;
}
if self.minimum() < other.minimum() {
return false;
}
match (self.maximum(), other.maximum()) {
(_, None) => true,
(Some(max), Some(other_max)) => max <= other_max,
_ => false,
}
}
}
/// A Wasm table entity.
#[derive(Debug)]
pub struct TableEntity {
ty: TableType,
elements: Vec<UntypedVal>,
}
impl TableEntity {
/// Creates a new table entity with the given resizable limits.
///
/// # Errors
///
/// If `init` does not match the [`TableType`] element type.
pub fn new(
ty: TableType,
init: Val,
limiter: &mut ResourceLimiterRef<'_>,
) -> Result<Self, TableError> {
ty.matches_element_type(init.ty())?;
if let Some(limiter) = limiter.as_resource_limiter() {
if !limiter.table_growing(0, ty.minimum(), ty.maximum())? {
// Here there's no meaningful way to map Ok(false) to
// INVALID_GROWTH_ERRCODE, so we just translate it to an
// appropriate Err(...)
return Err(TableError::GrowOutOfBounds {
maximum: ty.maximum().unwrap_or(u32::MAX),
current: 0,
delta: ty.minimum(),
});
}
}
let elements = vec![init.into(); ty.minimum() as usize];
Ok(Self { ty, elements })
}
/// Returns the resizable limits of the table.
pub fn ty(&self) -> TableType {
self.ty
}
/// Returns the dynamic [`TableType`] of the [`TableEntity`].
///
/// # Note
///
/// This respects the current size of the [`TableEntity`]
/// as its minimum size and is useful for import subtyping checks.
pub fn dynamic_ty(&self) -> TableType {
TableType::new(self.ty().element(), self.size(), self.ty().maximum())
}
/// Returns the current size of the [`Table`].
pub fn size(&self) -> u32 {
self.elements.len() as u32
}
/// Grows the table by the given amount of elements.
///
/// Returns the old size of the [`Table`] upon success.
///
/// # Note
///
/// The newly added elements are initialized to the `init` [`Val`].
///
/// # Errors
///
/// - If the table is grown beyond its maximum limits.
/// - If `value` does not match the [`Table`] element type.
pub fn grow(
&mut self,
delta: u32,
init: Val,
fuel: Option<&mut Fuel>,
limiter: &mut ResourceLimiterRef<'_>,
) -> Result<u32, EntityGrowError> {
self.ty()
.matches_element_type(init.ty())
.map_err(|_| EntityGrowError::InvalidGrow)?;
self.grow_untyped(delta, init.into(), fuel, limiter)
}
/// Grows the table by the given amount of elements.
///
/// Returns the old size of the [`Table`] upon success.
///
/// # Note
///
/// This is an internal API that exists for efficiency purposes.
///
/// The newly added elements are initialized to the `init` [`Val`].
///
/// # Errors
///
/// If the table is grown beyond its maximum limits.
pub fn grow_untyped(
&mut self,
delta: u32,
init: UntypedVal,
fuel: Option<&mut Fuel>,
limiter: &mut ResourceLimiterRef<'_>,
) -> Result<u32, EntityGrowError> {
// ResourceLimiter gets first look at the request.
let current = self.size();
let desired = current.checked_add(delta);
let maximum = self.ty.maximum();
if let Some(limiter) = limiter.as_resource_limiter() {
match limiter.table_growing(current, desired.unwrap_or(u32::MAX), maximum) {
Ok(true) => (),
Ok(false) => return Err(EntityGrowError::InvalidGrow),
Err(_) => return Err(EntityGrowError::TrapCode(TrapCode::GrowthOperationLimited)),
}
}
let maximum = maximum.unwrap_or(u32::MAX);
let notify_limiter =
|limiter: &mut ResourceLimiterRef<'_>| -> Result<u32, EntityGrowError> {
if let Some(limiter) = limiter.as_resource_limiter() {
limiter.table_grow_failed(&TableError::GrowOutOfBounds {
maximum,
current,
delta,
});
}
Err(EntityGrowError::InvalidGrow)
};
let Some(desired) = desired else {
return notify_limiter(limiter);
};
if desired > maximum {
return notify_limiter(limiter);
}
if let Some(fuel) = fuel {
match fuel.consume_fuel(|costs| costs.fuel_for_copies(u64::from(delta))) {
Ok(_) | Err(FuelError::FuelMeteringDisabled) => {}
Err(FuelError::OutOfFuel) => return notify_limiter(limiter),
}
}
self.elements.resize(desired as usize, init);
Ok(current)
}
/// Converts the internal [`UntypedVal`] into a [`Val`] for this [`Table`] element type.
fn make_typed(&self, untyped: UntypedVal) -> Val {
untyped.with_type(self.ty().element())
}
/// Returns the [`Table`] element value at `index`.
///
/// Returns `None` if `index` is out of bounds.
pub fn get(&self, index: u32) -> Option<Val> {
self.get_untyped(index)
.map(|untyped| self.make_typed(untyped))
}
/// Returns the untyped [`Table`] element value at `index`.
///
/// Returns `None` if `index` is out of bounds.
///
/// # Note
///
/// This is a more efficient version of [`Table::get`] for
/// internal use only.
pub fn get_untyped(&self, index: u32) -> Option<UntypedVal> {
self.elements.get(index as usize).copied()
}
/// Sets the [`Val`] of this [`Table`] at `index`.
///
/// # Errors
///
/// - If `index` is out of bounds.
/// - If `value` does not match the [`Table`] element type.
pub fn set(&mut self, index: u32, value: Val) -> Result<(), TableError> {
self.ty().matches_element_type(value.ty())?;
self.set_untyped(index, value.into())
}
/// Returns the [`UntypedVal`] of the [`Table`] at `index`.
///
/// # Errors
///
/// If `index` is out of bounds.
pub fn set_untyped(&mut self, index: u32, value: UntypedVal) -> Result<(), TableError> {
let current = self.size();
let untyped =
self.elements
.get_mut(index as usize)
.ok_or(TableError::AccessOutOfBounds {
current,
offset: index,
})?;
*untyped = value;
Ok(())
}
/// Initialize `len` elements from `src_element[src_index..]` into
/// `dst_table[dst_index..]`.
///
/// Uses the `instance` to resolve function indices of the element to [`Func`][`crate::Func`].
///
/// # Errors
///
/// Returns an error if the range is out of bounds
/// of either the source or destination tables.
///
/// # Panics
///
/// - Panics if the `instance` cannot resolve all the `element` func indices.
/// - If the [`ElementSegmentEntity`] element type does not match the [`Table`] element type.
/// Note: This is a panic instead of an error since it is asserted at Wasm validation time.
pub fn init(
&mut self,
dst_index: u32,
element: &ElementSegmentEntity,
src_index: u32,
len: u32,
fuel: Option<&mut Fuel>,
get_func: impl Fn(u32) -> Func,
) -> Result<(), TrapCode> {
let table_type = self.ty();
assert!(
table_type.element().is_ref(),
"table.init currently only works on reftypes"
);
table_type
.matches_element_type(element.ty())
.map_err(|_| TrapCode::BadSignature)?;
// Convert parameters to indices.
let dst_index = dst_index as usize;
let src_index = src_index as usize;
let len = len as usize;
// Perform bounds check before anything else.
let dst_items = self
.elements
.get_mut(dst_index..)
.and_then(|items| items.get_mut(..len))
.ok_or(TrapCode::TableOutOfBounds)?;
let src_items = element
.items()
.get(src_index..)
.and_then(|items| items.get(..len))
.ok_or(TrapCode::TableOutOfBounds)?;
if len == 0 {
// Bail out early if nothing needs to be initialized.
// The Wasm spec demands to still perform the bounds check
// so we cannot bail out earlier.
return Ok(());
}
if let Some(fuel) = fuel {
fuel.consume_fuel_if(|costs| costs.fuel_for_copies(len as u64))?;
}
// Perform the actual table initialization.
match table_type.element() {
ValType::FuncRef => {
// Initialize element interpreted as Wasm `funrefs`.
dst_items.iter_mut().zip(src_items).for_each(|(dst, src)| {
let func_or_null = src.funcref().map(FuncIdx::into_u32).map(&get_func);
*dst = FuncRef::new(func_or_null).into();
});
}
ValType::ExternRef => {
// Initialize element interpreted as Wasm `externrefs`.
dst_items.iter_mut().zip(src_items).for_each(|(dst, src)| {
*dst = src.eval_const().expect("must evaluate to some value");
});
}
_ => panic!("table.init currently only works on reftypes"),
};
Ok(())
}
/// Copy `len` elements from `src_table[src_index..]` into
/// `dst_table[dst_index..]`.
///
/// # Errors
///
/// Returns an error if the range is out of bounds of either the source or
/// destination tables.
pub fn copy(
dst_table: &mut Self,
dst_index: u32,
src_table: &Self,
src_index: u32,
len: u32,
fuel: Option<&mut Fuel>,
) -> Result<(), TrapCode> {
// Turn parameters into proper slice indices.
let src_index = src_index as usize;
let dst_index = dst_index as usize;
let len = len as usize;
// Perform bounds check before anything else.
let dst_items = dst_table
.elements
.get_mut(dst_index..)
.and_then(|items| items.get_mut(..len))
.ok_or(TrapCode::TableOutOfBounds)?;
let src_items = src_table
.elements
.get(src_index..)
.and_then(|items| items.get(..len))
.ok_or(TrapCode::TableOutOfBounds)?;
if let Some(fuel) = fuel {
fuel.consume_fuel_if(|costs| costs.fuel_for_copies(len as u64))?;
}
// Finally, copy elements in-place for the table.
dst_items.copy_from_slice(src_items);
Ok(())
}
/// Copy `len` elements from `self[src_index..]` into `self[dst_index..]`.
///
/// # Errors
///
/// Returns an error if the range is out of bounds of the table.
pub fn copy_within(
&mut self,
dst_index: u32,
src_index: u32,
len: u32,
fuel: Option<&mut Fuel>,
) -> Result<(), TrapCode> {
// These accesses just perform the bounds checks required by the Wasm spec.
let max_offset = max(dst_index, src_index);
max_offset
.checked_add(len)
.filter(|&offset| offset <= self.size())
.ok_or(TrapCode::TableOutOfBounds)?;
// Turn parameters into proper indices.
let src_index = src_index as usize;
let dst_index = dst_index as usize;
let len = len as usize;
if let Some(fuel) = fuel {
fuel.consume_fuel_if(|costs| costs.fuel_for_copies(len as u64))?;
}
// Finally, copy elements in-place for the table.
self.elements
.copy_within(src_index..src_index.wrapping_add(len), dst_index);
Ok(())
}
/// Fill `table[dst..(dst + len)]` with the given value.
///
/// # Errors
///
/// - If `val` has a type mismatch with the element type of the [`Table`].
/// - If the region to be filled is out of bounds for the [`Table`].
/// - If `val` originates from a different [`Store`] than the [`Table`].
///
/// # Panics
///
/// If `ctx` does not own `dst_table` or `src_table`.
///
/// [`Store`]: [`crate::Store`]
pub fn fill(
&mut self,
dst: u32,
val: Val,
len: u32,
fuel: Option<&mut Fuel>,
) -> Result<(), TrapCode> {
self.ty()
.matches_element_type(val.ty())
.map_err(|_| TrapCode::BadSignature)?;
self.fill_untyped(dst, val.into(), len, fuel)
}
/// Fill `table[dst..(dst + len)]` with the given value.
///
/// # Note
///
/// This is an API for internal use only and exists for efficiency reasons.
///
/// # Errors
///
/// - If the region to be filled is out of bounds for the [`Table`].
///
/// # Panics
///
/// If `ctx` does not own `dst_table` or `src_table`.
///
/// [`Store`]: [`crate::Store`]
pub fn fill_untyped(
&mut self,
dst: u32,
val: UntypedVal,
len: u32,
fuel: Option<&mut Fuel>,
) -> Result<(), TrapCode> {
let dst_index = dst as usize;
let len = len as usize;
let dst = self
.elements
.get_mut(dst_index..)
.and_then(|elements| elements.get_mut(..len))
.ok_or(TrapCode::TableOutOfBounds)?;
if let Some(fuel) = fuel {
fuel.consume_fuel_if(|costs| costs.fuel_for_copies(len as u64))?;
}
dst.fill(val);
Ok(())
}
}
/// A Wasm table reference.
#[derive(Debug, Copy, Clone)]
#[repr(transparent)]
pub struct Table(Stored<TableIdx>);
impl Table {
/// Creates a new table reference.
pub(super) fn from_inner(stored: Stored<TableIdx>) -> Self {
Self(stored)
}
/// Returns the underlying stored representation.
pub(super) fn as_inner(&self) -> &Stored<TableIdx> {
&self.0
}
/// Creates a new table to the store.
///
/// # Errors
///
/// If `init` does not match the [`TableType`] element type.
pub fn new(mut ctx: impl AsContextMut, ty: TableType, init: Val) -> Result<Self, TableError> {
let (inner, mut resource_limiter) = ctx
.as_context_mut()
.store
.store_inner_and_resource_limiter_ref();
let entity = TableEntity::new(ty, init, &mut resource_limiter)?;
let table = inner.alloc_table(entity);
Ok(table)
}
/// Returns the type and limits of the table.
///
/// # Panics
///
/// Panics if `ctx` does not own this [`Table`].
pub fn ty(&self, ctx: impl AsContext) -> TableType {
ctx.as_context().store.inner.resolve_table(self).ty()
}
/// Returns the dynamic [`TableType`] of the [`Table`].
///
/// # Note
///
/// This respects the current size of the [`Table`] as
/// its minimum size and is useful for import subtyping checks.
///
/// # Panics
///
/// Panics if `ctx` does not own this [`Table`].
pub(crate) fn dynamic_ty(&self, ctx: impl AsContext) -> TableType {
ctx.as_context()
.store
.inner
.resolve_table(self)
.dynamic_ty()
}
/// Returns the current size of the [`Table`].
///
/// # Panics
///
/// If `ctx` does not own this [`Table`].
pub fn size(&self, ctx: impl AsContext) -> u32 {
ctx.as_context().store.inner.resolve_table(self).size()
}
/// Grows the table by the given amount of elements.
///
/// Returns the old size of the [`Table`] upon success.
///
/// # Note
///
/// The newly added elements are initialized to the `init` [`Val`].
///
/// # Errors
///
/// - If the table is grown beyond its maximum limits.
/// - If `value` does not match the [`Table`] element type.
///
/// # Panics
///
/// Panics if `ctx` does not own this [`Table`].
pub fn grow(
&self,
mut ctx: impl AsContextMut,
delta: u32,
init: Val,
) -> Result<u32, TableError> {
let (inner, mut limiter) = ctx
.as_context_mut()
.store
.store_inner_and_resource_limiter_ref();
let table = inner.resolve_table_mut(self);
let current = table.size();
let maximum = table.ty().maximum().unwrap_or(u32::MAX);
table
.grow(delta, init, None, &mut limiter)
.map_err(|_| TableError::GrowOutOfBounds {
maximum,
current,
delta,
})
}
/// Returns the [`Table`] element value at `index`.
///
/// Returns `None` if `index` is out of bounds.
///
/// # Panics
///
/// Panics if `ctx` does not own this [`Table`].
pub fn get(&self, ctx: impl AsContext, index: u32) -> Option<Val> {
ctx.as_context().store.inner.resolve_table(self).get(index)
}
/// Sets the [`Val`] of this [`Table`] at `index`.
///
/// # Errors
///
/// - If `index` is out of bounds.
/// - If `value` does not match the [`Table`] element type.
///
/// # Panics
///
/// Panics if `ctx` does not own this [`Table`].
pub fn set(
&self,
mut ctx: impl AsContextMut,
index: u32,
value: Val,
) -> Result<(), TableError> {
ctx.as_context_mut()
.store
.inner
.resolve_table_mut(self)
.set(index, value)
}
/// Returns `true` if `lhs` and `rhs` [`Table`] refer to the same entity.
///
/// # Note
///
/// We do not implement `Eq` and `PartialEq` and
/// intentionally keep this API hidden from users.
#[inline]
pub(crate) fn eq(lhs: &Self, rhs: &Self) -> bool {
lhs.as_inner() == rhs.as_inner()
}
/// Copy `len` elements from `src_table[src_index..]` into
/// `dst_table[dst_index..]`.
///
/// # Errors
///
/// Returns an error if the range is out of bounds of either the source or
/// destination tables.
///
/// # Panics
///
/// Panics if `store` does not own either `dst_table` or `src_table`.
pub fn copy(
mut store: impl AsContextMut,
dst_table: &Table,
dst_index: u32,
src_table: &Table,
src_index: u32,
len: u32,
) -> Result<(), TableError> {
if Self::eq(dst_table, src_table) {
// The `dst_table` and `src_table` are the same table
// therefore we have to copy within the same table.
let table = store
.as_context_mut()
.store
.inner
.resolve_table_mut(dst_table);
table
.copy_within(dst_index, src_index, len, None)
.map_err(|_| TableError::CopyOutOfBounds)
} else {
// The `dst_table` and `src_table` are different entities
// therefore we have to copy from one table to the other.
let dst_ty = dst_table.ty(&store);
let src_ty = src_table.ty(&store).element();
dst_ty.matches_element_type(src_ty)?;
let (dst_table, src_table, _fuel) = store
.as_context_mut()
.store
.inner
.resolve_table_pair_and_fuel(dst_table, src_table);
TableEntity::copy(dst_table, dst_index, src_table, src_index, len, None)
.map_err(|_| TableError::CopyOutOfBounds)
}
}
/// Fill `table[dst..(dst + len)]` with the given value.
///
/// # Errors
///
/// - If `val` has a type mismatch with the element type of the [`Table`].
/// - If the region to be filled is out of bounds for the [`Table`].
/// - If `val` originates from a different [`Store`] than the [`Table`].
///
/// # Panics
///
/// If `ctx` does not own `dst_table` or `src_table`.
///
/// [`Store`]: [`crate::Store`]
pub fn fill(
&self,
mut ctx: impl AsContextMut,
dst: u32,
val: Val,
len: u32,
) -> Result<(), TrapCode> {
ctx.as_context_mut()
.store
.inner
.resolve_table_mut(self)
.fill(dst, val, len, None)
}
}