From 74dd47160960b3f0faa13dd1b61b64af69fde02e Mon Sep 17 00:00:00 2001 From: daurnimator Date: Fri, 9 Jun 2017 13:01:21 +1000 Subject: Add is_luastring function instead of using Array.isArray directly --- src/defs.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/defs.js') diff --git a/src/defs.js b/src/defs.js index 9e0fa5c..a125c34 100644 --- a/src/defs.js +++ b/src/defs.js @@ -132,8 +132,12 @@ class lua_Debug { } +const is_luastring = function(s) { + return Array.isArray(s); +}; + const to_jsstring = function(value, from, to) { - assert(Array.isArray(value), "jsstring expect a array of bytes"); + assert(is_luastring(value), "jsstring expect a array of bytes"); let u0, u1, u2, u3, u4, u5; let idx = 0; @@ -181,7 +185,7 @@ const to_luastring = function(str, cache) { if (cache) { let cached = to_luastring_cache[str]; - if (Array.isArray(cached)) return cached; + if (is_luastring(cached)) return cached; } let outU8Array = []; @@ -403,5 +407,6 @@ module.exports.constant_types = constant_types; module.exports.lua_Debug = lua_Debug; module.exports.lua_upvalueindex = lua_upvalueindex; module.exports.thread_status = thread_status; +module.exports.is_luastring = is_luastring; module.exports.to_jsstring = to_jsstring; module.exports.to_luastring = to_luastring; -- cgit v1.2.3-54-g00ecf