Skip to content

Commit

Permalink
[pjs] Post inc/dec operators should always result in a value coerced …
Browse files Browse the repository at this point in the history
…to the type of number
  • Loading branch information
pajama-coder committed Aug 22, 2023
1 parent e6205dc commit b685917
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/pjs/expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1846,8 +1846,10 @@ bool PostIncrement::eval(Context &ctx, Value &result) {
if (result.is<Int>()) {
Value v(result.as<Int>()->inc());
return m_x->assign(ctx, v);
} else if (!result.is_number()) {
result.set(result.to_number());
}
Value v(result.to_number() + 1);
Value v(result.n() + 1);
return m_x->assign(ctx, v);
}

Expand All @@ -1869,8 +1871,10 @@ bool PostDecrement::eval(Context &ctx, Value &result) {
if (result.is<Int>()) {
Value v(result.as<Int>()->dec());
return m_x->assign(ctx, v);
} else if (!result.is_number()) {
result.set(result.to_number());
}
Value v(result.to_number() - 1);
Value v(result.n() - 1);
return m_x->assign(ctx, v);
}

Expand Down

0 comments on commit b685917

Please sign in to comment.