summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/lstrlib.js4
-rw-r--r--tests/test-suite/db.js2
-rw-r--r--tests/test-suite/ltests.js23
-rw-r--r--tests/tests.js2
4 files changed, 10 insertions, 21 deletions
diff --git a/tests/lstrlib.js b/tests/lstrlib.js
index a55fca1..bdf68d8 100644
--- a/tests/lstrlib.js
+++ b/tests/lstrlib.js
@@ -442,9 +442,9 @@ test('string.dump', function (t) {
lua.lua_call(L, 0, -1);
- let dv = lua.lua_todataview(L, -1);
+ let str = lua.lua_tostring(L, -1);
- lua.lua_load(L, function(L, s) { let r = s.dv; s.dv = null; return r; }, {dv: dv}, lua.to_luastring("test"), lua.to_luastring("binary"));
+ lua.lua_load(L, function(L, s) { let r = s.str; s.str = null; return r; }, {str: str}, lua.to_luastring("test"), lua.to_luastring("binary"));
lua.lua_call(L, 0, -1);
diff --git a/tests/test-suite/db.js b/tests/test-suite/db.js
index a2e3ce6..ff13ecb 100644
--- a/tests/test-suite/db.js
+++ b/tests/test-suite/db.js
@@ -64,7 +64,7 @@ test("[test-suite] db: getinfo, ...line...", function (t) {
});
-test("[test-suite] db: test file ad string names truncation", function (t) {
+test("[test-suite] db: test file and string names truncation", function (t) {
let luaCode = `
a = "function f () end"
local function dostring (s, x) return load(s, x)() end
diff --git a/tests/test-suite/ltests.js b/tests/test-suite/ltests.js
index 8d89102..08bb603 100644
--- a/tests/test-suite/ltests.js
+++ b/tests/test-suite/ltests.js
@@ -60,8 +60,7 @@ const getstring = function(L, buff, pc) {
while (pc.script[pc.offset] !== 0 && pc.offset < pc.script.length && delimits.indexOf(pc.script[pc.offset]) < 0)
buff[i++] = pc.script[pc.offset++];
}
- buff.length = i;
- return buff;
+ return buff.subarray(0, i);
};
const getindex = function(L, L1, pc) {
@@ -100,7 +99,7 @@ const printstack = function(L) {
const ops = "+-*%^/\\&|~<>_!".split('').map(e => e.charCodeAt(0));
const runJS = function(L, L1, pc) {
- let buff = [];
+ let buff = new Uint8Array(300);
let status = 0;
if (!pc || !pc.script) return lauxlib.luaL_error(L, lua.to_luastring("attempt to runJS null script"));
for (;;) {
@@ -527,25 +526,15 @@ const udataval = function(L) {
const d2s = function(L) {
let d = lauxlib.luaL_checknumber(L, 1);
-
- let dv = new DataView(new ArrayBuffer(8));
- dv.setFloat64(0, d, true);
-
- let b = [];
- for (let i = 0; i < 8; i++)
- b.push(dv.getUint8(i, true));
-
- lua.lua_pushlstring(L, b, 8);
+ let b = new ArrayBuffer(8);
+ new DataView(b).setFloat64(0, d, true);
+ lua.lua_pushlstring(L, new Uint8Array(b), 8);
return 1;
};
const s2d = function(L) {
let b = lauxlib.luaL_checkstring(L, 1);
-
- let dv = new DataView(new ArrayBuffer(8));
- for (let i = 0; i < b.length; i++)
- dv.setUint8(i, b[i], true);
-
+ let dv = new DataView(b.buffer);
lua.lua_pushnumber(L, dv.getFloat64(0, true));
return 1;
};
diff --git a/tests/tests.js b/tests/tests.js
index 1bc4fc6..1ad9900 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -11,7 +11,7 @@ const toByteCode = function(luaCode) {
return 0;
}, b, false) !== 0)
throw Error("unable to dump given function");
- return new DataView(Uint8Array.from(b).buffer);
+ return Uint8Array.from(b);
};
const getState = function(luaCode) {