summaryrefslogtreecommitdiff
path: root/src/lobject.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-24 16:27:34 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-24 16:27:34 +1000
commitb5ed872df1a418c6437dad8a80bfab75447c7dfb (patch)
tree3a1aaafd2fb2232eed592adf7d2781c945d031ed /src/lobject.js
parent201d393d59645c96d8faf163e807378a63831821 (diff)
downloadfengari-b5ed872df1a418c6437dad8a80bfab75447c7dfb.tar.gz
fengari-b5ed872df1a418c6437dad8a80bfab75447c7dfb.tar.bz2
fengari-b5ed872df1a418c6437dad8a80bfab75447c7dfb.zip
src/lobject.js: don't convert operands to numbers if first branch fails
Diffstat (limited to 'src/lobject.js')
-rw-r--r--src/lobject.js15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/lobject.js b/src/lobject.js
index 5cbf2c3..b6fd581 100644
--- a/src/lobject.js
+++ b/src/lobject.js
@@ -610,9 +610,8 @@ const luaO_arith = function(L, op, p1, p2, res) {
case defs.LUA_OPBAND: case defs.LUA_OPBOR: case defs.LUA_OPBXOR:
case defs.LUA_OPSHL: case defs.LUA_OPSHR:
case defs.LUA_OPBNOT: { /* operate only on integers */
- let i1 = lvm.tointeger(p1);
- let i2 = lvm.tointeger(p2);
- if (i1 !== false && i2 !== false) {
+ let i1, i2;
+ if ((i1 = lvm.tointeger(p1)) !== false && (i2 = lvm.tointeger(p2)) !== false) {
res.type = CT.LUA_TNUMINT;
res.value = intarith(L, op, i1, i2);
return;
@@ -620,9 +619,8 @@ const luaO_arith = function(L, op, p1, p2, res) {
else break; /* go to the end */
}
case defs.LUA_OPDIV: case defs.LUA_OPPOW: { /* operate only on floats */
- let n1 = lvm.tonumber(p1);
- let n2 = lvm.tonumber(p2);
- if (n1 !== false && n2 !== false) {
+ let n1, n2;
+ if ((n1 = lvm.tonumber(p1)) !== false && (n2 = lvm.tonumber(p2)) !== false) {
res.type = CT.LUA_TNUMFLT;
res.value = numarith(L, op, n1, n2);
return;
@@ -630,14 +628,13 @@ const luaO_arith = function(L, op, p1, p2, res) {
else break; /* go to the end */
}
default: { /* other operations */
- let n1 = lvm.tonumber(p1);
- let n2 = lvm.tonumber(p2);
+ let n1, n2;
if (p1.ttisinteger() && p2.ttisinteger()) {
res.type = CT.LUA_TNUMINT;
res.value = intarith(L, op, p1.value, p2.value);
return;
}
- else if (n1 !== false && n2 !== false) {
+ else if ((n1 = lvm.tonumber(p1)) !== false && (n2 = lvm.tonumber(p2)) !== false) {
res.type = CT.LUA_TNUMFLT;
res.value = numarith(L, op, n1, n2);
return;