summaryrefslogtreecommitdiff
path: root/src/defs.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2018-04-03 22:06:02 +1000
committerdaurnimator <quae@daurnimator.com>2018-04-03 22:06:02 +1000
commit1c31a0cf7b6cea874be6f41a81049818686229a2 (patch)
tree7daf9221f8ccae190274a6f690ab7686fc1b7a8e /src/defs.js
parentc8392f40edd45367b4cde01ac80c070ae5a8240b (diff)
downloadfengari-1c31a0cf7b6cea874be6f41a81049818686229a2.tar.gz
fengari-1c31a0cf7b6cea874be6f41a81049818686229a2.tar.bz2
fengari-1c31a0cf7b6cea874be6f41a81049818686229a2.zip
src/defs.js: Hoist to_jsstring error message
Should save on final bundled size
Diffstat (limited to 'src/defs.js')
-rw-r--r--src/defs.js21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/defs.js b/src/defs.js
index 98269ea..daa5f70 100644
--- a/src/defs.js
+++ b/src/defs.js
@@ -56,6 +56,7 @@ const luastring_eq = function(a, b) {
return true;
};
+const unicode_error_message = "cannot convert invalid utf8 to javascript string";
const to_jsstring = function(value, from, to, replacement_char) {
if (!is_luastring(value)) throw new TypeError("to_jsstring expects a Uint8Array");
@@ -72,18 +73,18 @@ const to_jsstring = function(value, from, to, replacement_char) {
/* single byte sequence */
str += String.fromCharCode(u0);
} else if (u0 < 0xC2 || u0 > 0xF4) {
- if (!replacement_char) throw RangeError("cannot convert invalid utf8 to javascript string");
+ if (!replacement_char) throw RangeError(unicode_error_message);
str += "�";
} else if (u0 <= 0xDF) {
/* two byte sequence */
if (i >= to) {
- if (!replacement_char) throw RangeError("cannot convert invalid utf8 to javascript string");
+ if (!replacement_char) throw RangeError(unicode_error_message);
str += "�";
continue;
}
let u1 = value[i++];
if ((u1&0xC0) !== 0x80) {
- if (!replacement_char) throw RangeError("cannot convert invalid utf8 to javascript string");
+ if (!replacement_char) throw RangeError(unicode_error_message);
str += "�";
continue;
}
@@ -91,19 +92,19 @@ const to_jsstring = function(value, from, to, replacement_char) {
} else if (u0 <= 0xEF) {
/* three byte sequence */
if (i+1 >= to) {
- if (!replacement_char) throw RangeError("cannot convert invalid utf8 to javascript string");
+ if (!replacement_char) throw RangeError(unicode_error_message);
str += "�";
continue;
}
let u1 = value[i++];
if ((u1&0xC0) !== 0x80) {
- if (!replacement_char) throw RangeError("cannot convert invalid utf8 to javascript string");
+ if (!replacement_char) throw RangeError(unicode_error_message);
str += "�";
continue;
}
let u2 = value[i++];
if ((u2&0xC0) !== 0x80) {
- if (!replacement_char) throw RangeError("cannot convert invalid utf8 to javascript string");
+ if (!replacement_char) throw RangeError(unicode_error_message);
str += "�";
continue;
}
@@ -119,25 +120,25 @@ const to_jsstring = function(value, from, to, replacement_char) {
} else {
/* four byte sequence */
if (i+2 >= to) {
- if (!replacement_char) throw RangeError("cannot convert invalid utf8 to javascript string");
+ if (!replacement_char) throw RangeError(unicode_error_message);
str += "�";
continue;
}
let u1 = value[i++];
if ((u1&0xC0) !== 0x80) {
- if (!replacement_char) throw RangeError("cannot convert invalid utf8 to javascript string");
+ if (!replacement_char) throw RangeError(unicode_error_message);
str += "�";
continue;
}
let u2 = value[i++];
if ((u2&0xC0) !== 0x80) {
- if (!replacement_char) throw RangeError("cannot convert invalid utf8 to javascript string");
+ if (!replacement_char) throw RangeError(unicode_error_message);
str += "�";
continue;
}
let u3 = value[i++];
if ((u3&0xC0) !== 0x80) {
- if (!replacement_char) throw RangeError("cannot convert invalid utf8 to javascript string");
+ if (!replacement_char) throw RangeError(unicode_error_message);
str += "�";
continue;
}