aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-10-09 07:49:20 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-11-09 12:56:17 +0100
commit97a52383d4194678b781e8826c6512fc6fe40288 (patch)
tree1ddc466da9adde4e2025cddd591ad85e0b3ff0ac /src
parenta5d5b5f695ad557e25911f08be2d132ab1be658c (diff)
downloadfengari-97a52383d4194678b781e8826c6512fc6fe40288.tar.gz
fengari-97a52383d4194678b781e8826c6512fc6fe40288.tar.bz2
fengari-97a52383d4194678b781e8826c6512fc6fe40288.zip
Removed incorrect use of llimits.MAX/MIN_INT
llimit.js is renamed to llimits.js
Diffstat (limited to 'src')
-rw-r--r--src/ldo.js38
-rw-r--r--src/llex.js6
-rw-r--r--src/llimits.js (renamed from src/llimit.js)4
-rw-r--r--src/lmathlib.js7
-rw-r--r--src/lobject.js8
-rw-r--r--src/loslib.js3
-rw-r--r--src/lparser.js10
-rw-r--r--src/lstrlib.js5
-rw-r--r--src/ltablib.js10
-rw-r--r--src/luaconf.js12
-rw-r--r--src/lutf8lib.js3
-rw-r--r--src/lvm.js8
12 files changed, 55 insertions, 59 deletions
diff --git a/src/ldo.js b/src/ldo.js
index 9a1de38..c471e7e 100644
--- a/src/ldo.js
+++ b/src/ldo.js
@@ -2,21 +2,21 @@
const assert = require('assert');
-const defs = require('./defs.js');
-const lapi = require('./lapi.js');
-const ldebug = require('./ldebug.js');
-const lfunc = require('./lfunc.js');
-const llimit = require('./llimit.js');
-const lobject = require('./lobject.js');
-const lopcodes= require('./lopcodes.js');
-const lparser = require('./lparser.js');
-const lstate = require('./lstate.js');
-const lstring = require('./lstring.js');
-const ltm = require('./ltm.js');
-const luaconf = require('./luaconf.js');
-const lundump = require('./lundump.js');
-const lvm = require('./lvm.js');
-const lzio = require('./lzio.js');
+const defs = require('./defs.js');
+const lapi = require('./lapi.js');
+const ldebug = require('./ldebug.js');
+const lfunc = require('./lfunc.js');
+const llimits = require('./llimits.js');
+const lobject = require('./lobject.js');
+const lopcodes = require('./lopcodes.js');
+const lparser = require('./lparser.js');
+const lstate = require('./lstate.js');
+const lstring = require('./lstring.js');
+const ltm = require('./ltm.js');
+const luaconf = require('./luaconf.js');
+const lundump = require('./lundump.js');
+const lvm = require('./lvm.js');
+const lzio = require('./lzio.js');
const CT = defs.constant_types;
const TS = defs.thread_status;
@@ -322,9 +322,9 @@ const tryfuncTM = function(L, off, func) {
** allow overflow handling to work)
*/
const stackerror = function(L) {
- if (L.nCcalls === llimit.LUAI_MAXCCALLS)
+ if (L.nCcalls === llimits.LUAI_MAXCCALLS)
ldebug.luaG_runerror(L, defs.to_luastring("JS stack overflow", true));
- else if (L.nCcalls >= llimit.LUAI_MAXCCALLS + (llimit.LUAI_MAXCCALLS >> 3))
+ else if (L.nCcalls >= llimits.LUAI_MAXCCALLS + (llimits.LUAI_MAXCCALLS >> 3))
luaD_throw(L, TS.LUA_ERRERR); /* error while handing stack error */
};
@@ -335,7 +335,7 @@ const stackerror = function(L) {
** function position.
*/
const luaD_call = function(L, off, nResults) {
- if (++L.nCcalls >= llimit.LUAI_MAXCCALLS)
+ if (++L.nCcalls >= llimits.LUAI_MAXCCALLS)
stackerror(L);
if (!luaD_precall(L, off, nResults))
lvm.luaV_execute(L);
@@ -562,7 +562,7 @@ const lua_resume = function(L, from, nargs) {
return resume_error(L, "cannot resume dead coroutine", nargs);
L.nCcalls = from ? from.nCcalls + 1 : 1;
- if (L.nCcalls >= llimit.LUAI_MAXCCALLS)
+ if (L.nCcalls >= llimits.LUAI_MAXCCALLS)
return resume_error(L, "JS stack overflow", nargs);
L.nny = 0; /* allow yields */
diff --git a/src/llex.js b/src/llex.js
index dc0b382..a20f308 100644
--- a/src/llex.js
+++ b/src/llex.js
@@ -9,7 +9,7 @@ const ljstype = require('./ljstype.js');
const lobject = require('./lobject.js');
const lstring = require('./lstring.js');
const ltable = require('./ltable.js');
-const llimit = require('./llimit.js');
+const llimits = require('./llimits.js');
const lzio = require('./lzio.js');
const TS = defs.thread_status;
const char = defs.char;
@@ -108,7 +108,7 @@ class LexState {
const save = function(ls, c) {
let b = ls.buff;
if (b.n + 1 > b.buffer.length) {
- if (b.buffer.length >= llimit.MAX_INT/2)
+ if (b.buffer.length >= llimits.MAX_INT/2)
lexerror(ls, defs.to_luastring("lexical element too long", true), 0);
}
b.buffer[b.n++] = c < 0 ? 255 + c + 1 : c;
@@ -169,7 +169,7 @@ const inclinenumber = function(ls) {
next(ls); /* skip '\n' or '\r' */
if (currIsNewline(ls) && ls.current !== old)
next(ls); /* skip '\n\r' or '\r\n' */
- if (++ls.linenumber >= llimit.MAX_INT)
+ if (++ls.linenumber >= llimits.MAX_INT)
lexerror(ls, defs.to_luastring("chunk has too many lines", true), 0);
};
diff --git a/src/llimit.js b/src/llimits.js
index 18824b2..21a09a0 100644
--- a/src/llimit.js
+++ b/src/llimits.js
@@ -2,10 +2,6 @@
const LUAI_MAXCCALLS = 200;
module.exports.LUAI_MAXCCALLS = LUAI_MAXCCALLS;
-const LUA_MAXINTEGER = 2147483647;
-module.exports.LUA_MAXINTEGER = LUA_MAXINTEGER;
-const LUA_MININTEGER = -2147483648;
-module.exports.LUA_MININTEGER = LUA_MININTEGER;
const luai_nummod = function(L, a, b) {
let m = a % b;
diff --git a/src/lmathlib.js b/src/lmathlib.js
index 16e2ad3..f2354ca 100644
--- a/src/lmathlib.js
+++ b/src/lmathlib.js
@@ -2,7 +2,6 @@
const lua = require('./lua.js');
const lauxlib = require('./lauxlib.js');
-const llimit = require('./llimit.js');
const luaconf = require('./luaconf.js');
const math_random = function(L) {
@@ -27,7 +26,7 @@ const math_random = function(L) {
/* random integer in the interval [low, up] */
lauxlib.luaL_argcheck(L, low <= up, 1, lua.to_luastring("interval is empty", true));
- lauxlib.luaL_argcheck(L, low >= 0 || up <= llimit.MAX_INT + low, 1,
+ lauxlib.luaL_argcheck(L, low >= 0 || up <= luaconf.LUA_MAXINTEGER + low, 1,
lua.to_luastring("interval too large", true));
r *= (up - low) + 1;
@@ -257,9 +256,9 @@ const luaopen_math = function(L) {
lua.lua_setfield(L, -2, lua.to_luastring("pi", true));
lua.lua_pushnumber(L, Infinity);
lua.lua_setfield(L, -2, lua.to_luastring("huge", true));
- lua.lua_pushinteger(L, llimit.MAX_INT);
+ lua.lua_pushinteger(L, luaconf.LUA_MAXINTEGER);
lua.lua_setfield(L, -2, lua.to_luastring("maxinteger", true));
- lua.lua_pushinteger(L, llimit.MIN_INT);
+ lua.lua_pushinteger(L, luaconf.LUA_MININTEGER);
lua.lua_setfield(L, -2, lua.to_luastring("mininteger", true));
return 1;
};
diff --git a/src/lobject.js b/src/lobject.js
index 895e310..9263cb1 100644
--- a/src/lobject.js
+++ b/src/lobject.js
@@ -12,7 +12,7 @@ const lstring = require('./lstring.js');
const ltable = require('./ltable.js');
const luaconf = require('./luaconf.js');
const lvm = require('./lvm.js');
-const llimit = require('./llimit.js');
+const llimits = require('./llimits.js');
const ltm = require('./ltm.js');
const CT = defs.constant_types;
const char = defs.char;
@@ -437,8 +437,8 @@ const l_str2d = function(s) {
return end;
};
-const MAXBY10 = Math.floor(llimit.MAX_INT / 10);
-const MAXLASTD = llimit.MAX_INT % 10;
+const MAXBY10 = Math.floor(llimits.MAX_INT / 10);
+const MAXLASTD = llimits.MAX_INT % 10;
const l_str2int = function(s) {
let i = 0;
@@ -648,7 +648,7 @@ const numarith = function(L, op, v1, v2) {
case defs.LUA_OPPOW: return Math.pow(v1, v2);
case defs.LUA_OPIDIV: return Math.floor(v1 / v2);
case defs.LUA_OPUNM: return -v1;
- case defs.LUA_OPMOD: return llimit.luai_nummod(L, v1, v2);
+ case defs.LUA_OPMOD: return llimits.luai_nummod(L, v1, v2);
default: assert(0);
}
};
diff --git a/src/loslib.js b/src/loslib.js
index aecb647..e5e08d9 100644
--- a/src/loslib.js
+++ b/src/loslib.js
@@ -2,7 +2,6 @@
const lua = require('./lua.js');
const lauxlib = require('./lauxlib.js');
-const llimit = require('./llimit.js');
const strftime = require('strftime');
@@ -37,7 +36,7 @@ const setallfields = function(L, time, utc) {
// setboolfield(L, "isdst", time.get);
};
-const L_MAXDATEFIELD = (llimit.MAX_INT / 2);
+const L_MAXDATEFIELD = (Number.MAX_SAFE_INTEGER / 2);
const getfield = function(L, key, d, delta) {
let t = lua.lua_getfield(L, -1, lua.to_luastring(key, true)); /* get field and its type */
diff --git a/src/lparser.js b/src/lparser.js
index 7fc1458..ddd514e 100644
--- a/src/lparser.js
+++ b/src/lparser.js
@@ -7,7 +7,7 @@ const lcode = require('./lcode.js');
const ldo = require('./ldo.js');
const lfunc = require('./lfunc.js');
const llex = require('./llex.js');
-const llimit = require('./llimit.js');
+const llimits = require('./llimits.js');
const lobject = require('./lobject.js');
const lopcodes = require('./lopcodes.js');
const lstring = require('./lstring.js');
@@ -383,7 +383,7 @@ const adjust_assign = function(ls, nvars, nexps, e) {
const enterlevel = function(ls) {
let L = ls.L;
++L.nCcalls;
- checklimit(ls.fs, L.nCcalls, llimit.LUAI_MAXCCALLS, defs.to_luastring("JS levels", true));
+ checklimit(ls.fs, L.nCcalls, llimits.LUAI_MAXCCALLS, defs.to_luastring("JS levels", true));
};
const leavelevel = function(ls) {
@@ -652,7 +652,7 @@ const recfield = function(ls, cc) {
let val = new expdesc();
if (ls.t.token === R.TK_NAME) {
- checklimit(fs, cc.nh, llimit.MAX_INT, defs.to_luastring("items in a constructor", true));
+ checklimit(fs, cc.nh, llimits.MAX_INT, defs.to_luastring("items in a constructor", true));
checkname(ls, key);
} else /* ls->t.token === '[' */
yindex(ls, key);
@@ -690,7 +690,7 @@ const lastlistfield = function(fs, cc) {
const listfield = function(ls, cc) {
/* listfield -> exp */
expr(ls, cc.v);
- checklimit(ls.fs, cc.na, llimit.MAX_INT, defs.to_luastring("items in a constructor", true));
+ checklimit(ls.fs, cc.na, llimits.MAX_INT, defs.to_luastring("items in a constructor", true));
cc.na++;
cc.tostore++;
};
@@ -1122,7 +1122,7 @@ const assignment = function(ls, lh, nvars) {
suffixedexp(ls, nv.v);
if (nv.v.k !== expkind.VINDEXED)
check_conflict(ls, lh, nv.v);
- checklimit(ls.fs, nvars + ls.L.nCcalls, llimit.LUAI_MAXCCALLS, defs.to_luastring("JS levels", true));
+ checklimit(ls.fs, nvars + ls.L.nCcalls, llimits.LUAI_MAXCCALLS, defs.to_luastring("JS levels", true));
assignment(ls, nv, nvars + 1);
} else { /* assignment -> '=' explist */
checknext(ls, char['=']);
diff --git a/src/lstrlib.js b/src/lstrlib.js
index 7a2283c..17ee999 100644
--- a/src/lstrlib.js
+++ b/src/lstrlib.js
@@ -6,7 +6,6 @@ const sprintf = require('sprintf-js').sprintf;
const lauxlib = require('./lauxlib.js');
const lua = require('./lua.js');
const luaconf = require('./luaconf.js');
-const llimit = require('./llimit.js');
const sL_ESC = '%';
const L_ESC = sL_ESC.charCodeAt(0);
@@ -224,7 +223,7 @@ const addliteral = function(L, b, arg) {
checkdp(b); /* ensure it uses a dot */
} else { /* integers */
let n = lua.lua_tointeger(L, arg);
- let format = (n === llimit.LUA_MININTEGER) /* corner case? */
+ let format = (n === luaconf.LUA_MININTEGER) /* corner case? */
? "0x%" + luaconf.LUA_INTEGER_FRMLEN + "x" /* use hexa */
: luaconf.LUA_INTEGER_FMT; /* else use default format */
concat(b, lua.to_luastring(sprintf(format, n)));
@@ -678,7 +677,7 @@ const str_byte = function(L) {
if (posi < 1) posi = 1;
if (pose > l) pose = l;
if (posi > pose) return 0; /* empty interval; return no values */
- if (pose - posi >= llimit.MAX_INT) /* arithmetic overflow? */
+ if (pose - posi >= Number.MAX_SAFE_INTEGER) /* arithmetic overflow? */
return lauxlib.luaL_error(L, lua.to_luastring("string slice too long", true));
let n = (pose - posi) + 1;
diff --git a/src/ltablib.js b/src/ltablib.js
index aaadfd7..6d89acd 100644
--- a/src/ltablib.js
+++ b/src/ltablib.js
@@ -4,7 +4,7 @@ const assert = require('assert');
const lua = require('./lua.js');
const lauxlib = require('./lauxlib.js');
-const llimit = require('./llimit.js');
+const luaconf = require('./luaconf.js');
/*
@@ -107,9 +107,9 @@ const tmove = function(L) {
checktab(L, 1, TAB_R);
checktab(L, tt, TAB_W);
if (e >= f) { /* otherwise, nothing to move */
- lauxlib.luaL_argcheck(L, f > 0 || e < llimit.LUA_MAXINTEGER + f, 3, lua.to_luastring("too many elements to move", true));
+ lauxlib.luaL_argcheck(L, f > 0 || e < luaconf.LUA_MAXINTEGER + f, 3, lua.to_luastring("too many elements to move", true));
let n = e - f + 1; /* number of elements to move */
- lauxlib.luaL_argcheck(L, t <= llimit.LUA_MAXINTEGER - n + 1, 4, lua.to_luastring("destination wrap around", true));
+ lauxlib.luaL_argcheck(L, t <= luaconf.LUA_MAXINTEGER - n + 1, 4, lua.to_luastring("destination wrap around", true));
if (t > e || t <= f || (tt !== 1 && lua.lua_compare(L, 1, tt, lua.LUA_OPEQ) !== 1)) {
for (let i = 0; i < n; i++) {
@@ -166,7 +166,7 @@ const unpack = function(L) {
let e = lauxlib.luaL_opt(L, lauxlib.luaL_checkinteger, 3, lauxlib.luaL_len(L, 1));
if (i > e) return 0; /* empty range */
let n = e - i; /* number of elements minus 1 (avoid overflows) */
- if (n >= llimit.MAX_INT || !lua.lua_checkstack(L, ++n))
+ if (n >= Number.MAX_SAFE_INTEGER || !lua.lua_checkstack(L, ++n))
return lauxlib.luaL_error(L, lua.to_luastring("too many results to unpack", true));
for (; i < e; i++) /* push arg[i..e - 1] (to avoid overflows) */
lua.lua_geti(L, 1, i);
@@ -291,7 +291,7 @@ const auxsort = function(L, lo, up, rnd) {
const sort = function(L) {
let n = aux_getn(L, 1, TAB_RW);
if (n > 1) { /* non-trivial interval? */
- lauxlib.luaL_argcheck(L, n < llimit.MAX_INT, 1, lua.to_luastring("array too big", true));
+ lauxlib.luaL_argcheck(L, n < Number.MAX_SAFE_INTEGER, 1, lua.to_luastring("array too big", true));
if (!lua.lua_isnoneornil(L, 2)) /* is there a 2nd argument? */
lauxlib.luaL_checktype(L, 2, lua.LUA_TFUNCTION); /* must be a function */
lua.lua_settop(L, 2); /* make sure there are two arguments */
diff --git a/src/luaconf.js b/src/luaconf.js
index 8e7885c..00663a6 100644
--- a/src/luaconf.js
+++ b/src/luaconf.js
@@ -1,8 +1,10 @@
"use strict";
-const llimit = require('./llimit.js');
const sprintf = require('sprintf-js').sprintf;
+const LUA_MAXINTEGER = 2147483647;
+const LUA_MININTEGER = -2147483648;
+
/*
@@ LUAI_MAXSTACK limits the size of the Lua stack.
** CHANGE it if you need a different limit. This limit is arbitrary;
@@ -28,7 +30,7 @@ const lua_number2str = function(n) {
};
const lua_numbertointeger = function(n) {
- return n >= llimit.MIN_INT && n < -llimit.MIN_INT ? n : false;
+ return n >= LUA_MININTEGER && n < -LUA_MININTEGER ? n : false;
};
const LUA_INTEGER_FRMLEN = "";
@@ -64,14 +66,16 @@ const ldexp = function(mantissa, exponent) {
return result;
};
-module.exports.frexp = frexp;
-module.exports.ldexp = ldexp;
module.exports.LUAI_MAXSTACK = LUAI_MAXSTACK;
module.exports.LUA_IDSIZE = LUA_IDSIZE;
module.exports.LUA_INTEGER_FMT = LUA_INTEGER_FMT;
module.exports.LUA_INTEGER_FRMLEN = LUA_INTEGER_FRMLEN;
+module.exports.LUA_MAXINTEGER = LUA_MAXINTEGER;
+module.exports.LUA_MININTEGER = LUA_MININTEGER;
module.exports.LUA_NUMBER_FMT = LUA_NUMBER_FMT;
module.exports.LUA_NUMBER_FRMLEN = LUA_NUMBER_FRMLEN;
+module.exports.frexp = frexp;
+module.exports.ldexp = ldexp;
module.exports.lua_getlocaledecpoint = lua_getlocaledecpoint;
module.exports.lua_integer2str = lua_integer2str;
module.exports.lua_number2str = lua_number2str;
diff --git a/src/lutf8lib.js b/src/lutf8lib.js
index b69abb0..3baeeef 100644
--- a/src/lutf8lib.js
+++ b/src/lutf8lib.js
@@ -2,7 +2,6 @@
const lua = require('./lua.js');
const lauxlib = require('./lauxlib.js');
-const llimit = require('./llimit.js');
const MAXUNICODE = 0x10FFFF;
@@ -160,7 +159,7 @@ const codepoint = function(L) {
lauxlib.luaL_argcheck(L, pose <= s.length, 3, lua.to_luastring("out of range", true));
if (posi > pose) return 0; /* empty interval; return no values */
- if (pose - posi >= llimit.MAX_INT)
+ if (pose - posi >= Number.MAX_SAFE_INTEGER)
return lauxlib.luaL_error(L, lua.to_luastring("string slice too long", true));
let n = (pose - posi) + 1;
lauxlib.luaL_checkstack(L, n, lua.to_luastring("string slice too long", true));
diff --git a/src/lvm.js b/src/lvm.js
index 1adea8d..ffc1d74 100644
--- a/src/lvm.js
+++ b/src/lvm.js
@@ -9,7 +9,7 @@ const lobject = require('./lobject.js');
const lfunc = require('./lfunc.js');
const lstate = require('./lstate.js');
const lstring = require('./lstring.js');
-const llimit = require('./llimit.js');
+const llimits = require('./llimits.js');
const ldo = require('./ldo.js');
const ltm = require('./ltm.js');
const ltable = require('./ltable.js');
@@ -245,7 +245,7 @@ const luaV_execute = function(L) {
if (op1.ttisinteger() && op2.ttisinteger()) {
L.stack[ra].setivalue(luaV_mod(L, op1.value, op2.value));
} else if ((numberop1 = tonumber(op1)) !== false && (numberop2 = tonumber(op2)) !== false) {
- L.stack[ra].setfltvalue(llimit.luai_nummod(L, numberop1, numberop2));
+ L.stack[ra].setfltvalue(llimits.luai_nummod(L, numberop1, numberop2));
} else {
ltm.luaT_trybinTM(L, op1, op2, L.stack[ra], ltm.TMS.TM_MOD);
}
@@ -726,10 +726,10 @@ const forlimit = function(obj, step) {
return false;
if (0 < n) {
- ilimit = llimit.LUA_MAXINTEGER;
+ ilimit = luaconf.LUA_MAXINTEGER;
if (step < 0) stopnow = true;
} else {
- ilimit = llimit.LUA_MININTEGER;
+ ilimit = luaconf.LUA_MININTEGER;
if (step >= 0) stopnow = true;
}
}