summaryrefslogtreecommitdiff
path: root/src/defs.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2018-01-07 02:52:40 +1100
committerdaurnimator <quae@daurnimator.com>2018-01-07 03:34:56 +1100
commite46d3e7d8d7226d49aad05f5a9c639c77d53bb04 (patch)
treefe3e99cbfce31d7d3495c0f861cbdc0aad67167a /src/defs.js
parent6ffe07fc5d16ee9acdcd6651d433ce13b193cd15 (diff)
downloadfengari-e46d3e7d8d7226d49aad05f5a9c639c77d53bb04.tar.gz
fengari-e46d3e7d8d7226d49aad05f5a9c639c77d53bb04.tar.bz2
fengari-e46d3e7d8d7226d49aad05f5a9c639c77d53bb04.zip
Introduce luastring_indexOf as Uint8Array.indexOf doesn't exist everywhere
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;