aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Execution/Runtime.php26
-rw-r--r--src/Execution/TrapKind.php1
-rw-r--r--tests/src/SpecTestsuites/SpecTestsuiteBase.php1
3 files changed, 18 insertions, 10 deletions
diff --git a/src/Execution/Runtime.php b/src/Execution/Runtime.php
index ade7cf1..5b97be3 100644
--- a/src/Execution/Runtime.php
+++ b/src/Execution/Runtime.php
@@ -955,8 +955,11 @@ final class Runtime
{
$c2 = $this->stack->popInt();
$c1 = $this->stack->popInt();
- if ($c2 === 0 || ($c1 === PHP_INT_MIN && $c2 === -1)) {
- throw new TrapException("i32.div_s: divide by zero or overflow");
+ if ($c2 === 0) {
+ throw new TrapException("i32.div_s: divide by zero", trapKind: TrapKind::DivideByZero);
+ }
+ if ($c1 === PHP_INT_MIN && $c2 === -1) {
+ throw new TrapException("i32.div_s: overflow");
}
$this->stack->pushValue(intdiv($c1, $c2));
}
@@ -966,7 +969,7 @@ final class Runtime
$c2 = $this->stack->popInt();
$c1 = $this->stack->popInt();
if ($c2 === 0) {
- throw new TrapException("i32.div_u: divide by zero");
+ throw new TrapException("i32.div_u: divide by zero", trapKind: TrapKind::DivideByZero);
}
$this->stack->pushValue(intdiv($c1, $c2));
}
@@ -1107,8 +1110,11 @@ final class Runtime
{
$c2 = $this->stack->popInt();
$c1 = $this->stack->popInt();
- if ($c2 === 0 || ($c1 === PHP_INT_MIN && $c2 === -1)) {
- throw new TrapException("i32.rem_s: divide by zero or overflow");
+ if ($c2 === 0) {
+ throw new TrapException("i32.rem_s: divide by zero or overflow", trapKind: TrapKind::DivideByZero);
+ }
+ if ($c1 === PHP_INT_MIN && $c2 === -1) {
+ throw new TrapException("i32.rem_s: divide by zero or overflow", trapKind: TrapKind::DivideByZero);
}
$this->stack->pushValue($c1 % $c2);
}
@@ -1118,7 +1124,7 @@ final class Runtime
$c2 = $this->stack->popInt();
$c1 = $this->stack->popInt();
if ($c2 === 0) {
- throw new TrapException("i32.rem_u: divide by zero");
+ throw new TrapException("i32.rem_u: divide by zero", trapKind: TrapKind::DivideByZero);
}
$this->stack->pushValue($c1 % $c2);
}
@@ -1327,7 +1333,7 @@ final class Runtime
$c2 = $this->stack->popInt();
$c1 = $this->stack->popInt();
if ($c2 === 0) {
- throw new TrapException("i64.div_s: divide by zero");
+ throw new TrapException("i64.div_s: divide by zero", trapKind: TrapKind::DivideByZero);
}
$this->stack->pushValue(intdiv($c1, $c2));
}
@@ -1337,7 +1343,7 @@ final class Runtime
$c2 = $this->stack->popInt();
$c1 = $this->stack->popInt();
if ($c2 === 0) {
- throw new TrapException("i64.div_u: divide by zero");
+ throw new TrapException("i64.div_u: divide by zero", trapKind: TrapKind::DivideByZero);
}
$this->stack->pushValue(intdiv($c1, $c2));
}
@@ -1510,7 +1516,7 @@ final class Runtime
$c2 = $this->stack->popInt();
$c1 = $this->stack->popInt();
if ($c2 === 0) {
- throw new TrapException("i64.rem_s: divide by zero");
+ throw new TrapException("i64.rem_s: divide by zero", trapKind: TrapKind::DivideByZero);
}
$this->stack->pushValue($c1 % $c2);
}
@@ -1520,7 +1526,7 @@ final class Runtime
$c2 = $this->stack->popInt();
$c1 = $this->stack->popInt();
if ($c2 === 0) {
- throw new TrapException("i64.rem_u: divide by zero");
+ throw new TrapException("i64.rem_u: divide by zero", trapKind: TrapKind::DivideByZero);
}
$this->stack->pushValue($c1 % $c2);
}
diff --git a/src/Execution/TrapKind.php b/src/Execution/TrapKind.php
index c44747d..5cdc480 100644
--- a/src/Execution/TrapKind.php
+++ b/src/Execution/TrapKind.php
@@ -13,4 +13,5 @@ enum TrapKind
case UninitializedElement;
case IndirectCallTypeMismatch;
case UndefinedElement;
+ case DivideByZero;
}
diff --git a/tests/src/SpecTestsuites/SpecTestsuiteBase.php b/tests/src/SpecTestsuites/SpecTestsuiteBase.php
index 36eedec..06a911e 100644
--- a/tests/src/SpecTestsuites/SpecTestsuiteBase.php
+++ b/tests/src/SpecTestsuites/SpecTestsuiteBase.php
@@ -269,6 +269,7 @@ abstract class SpecTestsuiteBase extends TestCase
TrapKind::UninitializedElement => 'uninitialized element',
TrapKind::IndirectCallTypeMismatch => 'indirect call type mismatch',
TrapKind::UndefinedElement => 'undefined element',
+ TrapKind::DivideByZero => 'integer divide by zero',
};
$this->assertStringContainsString(
$actualErrorMessage,