summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--js/codeq.js14
1 files changed, 13 insertions, 1 deletions
diff --git a/js/codeq.js b/js/codeq.js
index e6a8a90..0ff78b2 100644
--- a/js/codeq.js
+++ b/js/codeq.js
@@ -716,8 +716,20 @@ window.phandler = null; // TODO: this is for debug only
*/
codeq.codePointCount = function (s) {
var n = 0, i, code;
+ if (typeof s !== 'string') {
+ code = 'codePointCount(): argument not a string: type = ' + typeof s + ', is null = ' + (s === null);
+ if ((typeof s === 'object') && (s !== null) && s.constructor) code += ', constructor = ' + s.constructor.name;
+ codeq.log.error(code);
+ return 0;
+ }
for (i = s.length - 1; i >= 0; i--) {
- code = s.charCodeAt(i);
+ try {
+ code = s.charCodeAt(i);
+ }
+ catch (e) {
+ codeq.log.error('Invocation of charCodeAt() failed at iteration #' + i + ': ' + e, e);
+ return 0;
+ }
if ((code >= 0xd800) && (code < 0xe000)) i++;
n++;
}