From f83115f90039666b9dc19c3ee9972a3aa98d28e7 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 22 May 2017 23:34:25 +1000 Subject: src/lapi.js: Throw errors when attempting to use pseudo-index with index2addr_ --- src/lapi.js | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/lapi.js b/src/lapi.js index efc59aa..8e0c491 100644 --- a/src/lapi.js +++ b/src/lapi.js @@ -66,7 +66,7 @@ const index2addr = function(L, idx) { } }; -// Like index2addr but returns the index on stack +// Like index2addr but returns the index on stack; doesn't allow pseudo indices const index2addr_ = function(L, idx) { let ci = L.ci; if (idx > 0) { @@ -77,16 +77,8 @@ const index2addr_ = function(L, idx) { } else if (idx > defs.LUA_REGISTRYINDEX) { assert(idx !== 0 && -idx <= L.top, "invalid index"); return L.top + idx; - } else if (idx === defs.LUA_REGISTRYINDEX) { - return null; - } else { /* upvalues */ - idx = defs.LUA_REGISTRYINDEX - idx; - assert(idx <= MAXUPVAL + 1, "upvalue index too large"); - if (ci.func.ttislcf()) /* light C function? */ - return null; /* it has no upvalues */ - else { - return idx <= ci.func.nupvalues ? idx - 1 : null; - } + } else { /* registry or upvalue */ + throw Error("attempt to use pseudo-index"); } }; -- cgit v1.2.3-70-g09d2