fix: preserve stack until operation completes

This commit is contained in:
2026-04-25 03:41:01 +02:00
parent eaedcb6b74
commit 69c4bfbfab
+5 -1
View File
@@ -369,9 +369,13 @@ class RpnCalculator {
throw new Error('Stack underflow');
}
const operands = argCount > 0 ? this.stack.splice(0, argCount).reverse() : [];
const operands = argCount > 0 ? this.stack.slice(0, argCount).reverse() : [];
const result = operation.execute(this, ...operands, ...args);
if (argCount > 0) {
this.stack.splice(0, argCount);
}
if (Array.isArray(result)) {
for (let i = result.length - 1; i >= 0; i -= 1) {
this.push(result[i]);