diff options
author | daurnimator <quae@daurnimator.com> | 2017-06-09 16:30:45 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-06-09 16:32:06 +1000 |
commit | 2a95440f071782b829d0823103fd2d737dd42957 (patch) | |
tree | fe2b0acad12042838782bb5b23716415d73dee93 /src/llex.js | |
parent | 0ca60aeadcba9ac66063abd539966c91a55064bd (diff) | |
download | fengari-2a95440f071782b829d0823103fd2d737dd42957.tar.gz fengari-2a95440f071782b829d0823103fd2d737dd42957.tar.bz2 fengari-2a95440f071782b829d0823103fd2d737dd42957.zip |
src/llex.js: Fix isreserved (it is passed a TString, not a JS string)
Diffstat (limited to 'src/llex.js')
-rw-r--r-- | src/llex.js | 11 |
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; |