aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-06-02 04:41:59 +0900
committernsfisis <nsfisis@gmail.com>2024-06-02 04:41:59 +0900
commit73d19c2f4bdae0aac4ebe8303ff88f42a9e59978 (patch)
tree896908710bddcb23c8fe3e5b6248cbd58b16f69d /src
parent3e402a951e455d22aa8a23293327bb4b791bf390 (diff)
downloadphp-waddiwasi-73d19c2f4bdae0aac4ebe8303ff88f42a9e59978.tar.gz
php-waddiwasi-73d19c2f4bdae0aac4ebe8303ff88f42a9e59978.tar.zst
php-waddiwasi-73d19c2f4bdae0aac4ebe8303ff88f42a9e59978.zip
test: add more trap kind
Diffstat (limited to 'src')
-rw-r--r--src/Execution/Runtime.php26
-rw-r--r--src/Execution/TrapKind.php1
2 files changed, 17 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;
}