From ab76ca32ad353c3196357b02069e93267928751e Mon Sep 17 00:00:00 2001 From: Guillaume Crico Date: Mon, 17 Nov 2014 13:31:29 +0100 Subject: Fix Issue 202 - Catch RangeError thrown by native String.fromCodePoint (js implementation) When using a JS engine that provides a native String.fromCodePoint ES6 implementation (e.g. SpiderMonkey), a RangeError is thrown if the codepoint is invalid. When adding the from-code-point.js polyfill, the js implementation was modified in order to handle invalid code point by returning the 0xFFFD placeholder glyph. So this is not a real "polyfill", but an specific implementation (adapted to the parser needs). So, if a native String.fromCodePoint implementation is availbale, the fromCodePoint function should catch the RangeError and return the 0xFFFD placeholder glyph. --- js/lib/from-code-point.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/js/lib/from-code-point.js b/js/lib/from-code-point.js index 94eca65..037c35e 100644 --- a/js/lib/from-code-point.js +++ b/js/lib/from-code-point.js @@ -2,7 +2,16 @@ /*! http://mths.be/fromcodepoint v0.2.1 by @mathias */ if (String.fromCodePoint) { - module.exports = String.fromCodePoint; + module.exports = function (_) { + try { + return String.fromCodePoint(_); + } catch (e) { + if (e instanceof RangeError) { + return String.fromCharCode(0xFFFD); + } + throw e; + } + } } else { -- cgit v1.2.3