diff --git a/lib/utils.js b/lib/utils.js index 6859abf1..4f0be041 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -99,9 +99,14 @@ exports.escapeXML = function (markup) { : String(markup) .replace(_MATCH_HTML, encode_char); }; -exports.escapeXML.toString = function () { + +// If the Object prototype is frozen, the "toString" property is non-writable. This means that any objects which inherit this property +// cannot have the property changed using an assignment. If using strict mode, attempting that will cause an error. If not using strict +// mode, attempting that will be silently ignored. +// However, we can still explicitly shadow the prototype's "toString" property by defining a new "toString" property on this object. +Object.defineProperty(exports.escapeXML, 'toString', function () { return Function.prototype.toString.call(this) + ';\n' + escapeFuncStr; -}; +}); /** * Naive copy of properties from one object to another.