aboutsummaryrefslogtreecommitdiff
path: root/src/defs.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/defs.js')
-rw-r--r--src/defs.js15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/defs.js b/src/defs.js
index c0b3bda..fc18707 100644
--- a/src/defs.js
+++ b/src/defs.js
@@ -144,6 +144,20 @@ if (typeof Uint8Array.from === "function") {
};
}
+let luastring_indexOf;
+if (typeof (new Uint8Array().indexOf) === "function") {
+ luastring_indexOf = function(s, v, i) {
+ return s.indexOf(v, i);
+ };
+} else {
+ /* Browsers that don't support Uint8Array.indexOf seem to allow using Array.indexOf on Uint8Array objects e.g. IE11 */
+ let array_indexOf = [].indexOf;
+ if (array_indexOf.call(new Uint8Array(1), 0) !== 0) throw Error("missing .indexOf");
+ luastring_indexOf = function(s, v, i) {
+ return array_indexOf.call(s, v, i);
+ };
+}
+
let luastring_of;
if (typeof Uint8Array.of === "function") {
luastring_of = Uint8Array.of.bind(Uint8Array);
@@ -482,6 +496,7 @@ module.exports.thread_status = thread_status;
module.exports.is_luastring = is_luastring;
module.exports.luastring_eq = luastring_eq;
module.exports.luastring_from = luastring_from;
+module.exports.luastring_indexOf = luastring_indexOf;
module.exports.luastring_of = luastring_of;
module.exports.to_jsstring = to_jsstring;
module.exports.to_luastring = to_luastring;