aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-06-09 16:30:45 +1000
committerdaurnimator <quae@daurnimator.com>2017-06-09 16:32:06 +1000
commit2a95440f071782b829d0823103fd2d737dd42957 (patch)
treefe2b0acad12042838782bb5b23716415d73dee93
parent0ca60aeadcba9ac66063abd539966c91a55064bd (diff)
downloadfengari-2a95440f071782b829d0823103fd2d737dd42957.tar.gz
fengari-2a95440f071782b829d0823103fd2d737dd42957.tar.bz2
fengari-2a95440f071782b829d0823103fd2d737dd42957.zip
src/llex.js: Fix isreserved (it is passed a TString, not a JS string)
-rw-r--r--src/llex.js11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/llex.js b/src/llex.js
index 0be6ea8..4fd061e 100644
--- a/src/llex.js
+++ b/src/llex.js
@@ -459,9 +459,12 @@ const read_string = function(ls, del, seminfo) {
seminfo.ts = luaX_newstring(ls, ls.buff.buffer.slice(1, ls.buff.n-1));
};
+const token_to_index = Object.create(null); /* don't want to return true for e.g. 'hasOwnProperty' */
+luaX_tokens.forEach((e, i)=>token_to_index[lstring.luaS_hash(defs.to_luastring(e))] = i);
+
const isreserved = function(w) {
- let kidx = luaX_tokens.indexOf(w);
- return kidx >= 0 && kidx <= 22;
+ let kidx = token_to_index[lstring.luaS_hashlongstr(w)];
+ return kidx !== void 0 && kidx <= 22;
};
const llex = function(ls, seminfo) {
@@ -567,8 +570,8 @@ const llex = function(ls, seminfo) {
let ts = luaX_newstring(ls, ls.buff.buffer);
seminfo.ts = ts;
- let kidx = luaX_tokens.indexOf(defs.to_jsstring(ts.getstr()));
- if (kidx >= 0 && kidx <= 22) /* reserved word? */
+ let kidx = token_to_index[lstring.luaS_hashlongstr(ts)];
+ if (kidx !== void 0 && kidx <= 22) /* reserved word? */
return kidx + FIRST_RESERVED;
else
return R.TK_NAME;