From 3813f2d43054708bab7221a5ca74a0183a2ebcaf Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Thu, 30 Mar 2017 11:58:09 +0200 Subject: 8-bit only in lstrlib --- src/llex.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'src/llex.js') diff --git a/src/llex.js b/src/llex.js index e043c17..3ed0e56 100644 --- a/src/llex.js +++ b/src/llex.js @@ -12,15 +12,10 @@ const lua = require('./lua.js'); const TValue = lobject.TValue; const CT = lua.constant_types; const TS = lua.thread_status; +const char = lua.char; const FIRST_RESERVED = 257; -// To avoid charCodeAt everywhere -const char = []; -for (let i = 0; i < 127; i++) - char[String.fromCharCode(i)] = i; -module.exports.char = char; - const RESERVED = { /* terminal symbols denoted by reserved words */ TK_AND: FIRST_RESERVED, @@ -87,7 +82,8 @@ class MBuffer { this.reader = reader ? reader : null; if (!this.reader) { - this.buffer = typeof data === "string" ? lua.to_luastring(data) : (data ? data : []); + assert(typeof data !== "string", "Should only load binary of array of bytes"); + this.buffer = data ? data : []; this.n = this.buffer instanceof DataView ? this.buffer.byteLength : this.buffer.length; this.off = 0; } @@ -103,7 +99,7 @@ class MBuffer { fill() { if (this.reader) { this.buffer = this.reader(this.L, this.data); - this.buffer = typeof this.buffer === "string" ? lua.to_luastring(this.buffer) : this.buffer; + assert(typeof this.buffer !== "string", "Should only load binary of array of bytes"); if (this.buffer === null) return -1; this.n = this.buffer instanceof DataView ? this.buffer.byteLength - 1 : this.buffer.length - 1; @@ -418,7 +414,7 @@ const readdecesc = function(ls) { let r = 0; /* result accumulator */ let i; for (i = 0; i < 3 && ljstype.lisdigit(ls.current); i++) { /* read up to 3 digits */ - r = 10 * r + parseInt(ls.current); + r = 10 * r + ls.current - char['0']; save_and_next(ls); } esccheck(ls, r <= 255, lua.to_luastring("decimal escape too large")); -- cgit v1.2.3-54-g00ecf