aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/WebAssembly/Execution/Runtime.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/WebAssembly/Execution/Runtime.php')
-rw-r--r--src/WebAssembly/Execution/Runtime.php6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/WebAssembly/Execution/Runtime.php b/src/WebAssembly/Execution/Runtime.php
index d0f90b5..07dc0d0 100644
--- a/src/WebAssembly/Execution/Runtime.php
+++ b/src/WebAssembly/Execution/Runtime.php
@@ -20,6 +20,7 @@ use function abs;
use function array_map;
use function array_merge;
use function array_reverse;
+use function array_slice;
use function assert;
use function ceil;
use function count;
@@ -114,7 +115,7 @@ final class Runtime
$externVals,
$vals,
$refsList,
- $moduleInstInit->funcAddrs,
+ array_slice($moduleInstInit->funcAddrs, count(array_filter($externVals, fn ($e) => $e instanceof ExternVals\Func))),
);
$runtime = new self($store, $stack, $moduleInst);
@@ -203,6 +204,9 @@ final class Runtime
{
try {
$export = $this->getExport($name);
+ if ($export === null) {
+ throw new TrapException("invoke($name) not found", trapKind: TrapKind::UninitializedElement);
+ }
assert($export instanceof ExternVals\Func);
$funcAddr = $export->addr;