@@ -100,13 +100,24 @@ exports.escapeXML = function (markup) {
100100 . replace ( _MATCH_HTML , encode_char ) ;
101101} ;
102102
103- // If the Object prototype is frozen, the "toString" property is non-writable. This means that any objects which inherit this property
104- // cannot have the property changed using an assignment. If using strict mode, attempting that will cause an error. If not using strict
105- // mode, attempting that will be silently ignored.
106- // However, we can still explicitly shadow the prototype's "toString" property by defining a new "toString" property on this object.
107- Object . defineProperty ( exports . escapeXML , 'toString' , function ( ) {
103+ function escapeXMLToString ( ) {
108104 return Function . prototype . toString . call ( this ) + ';\n' + escapeFuncStr ;
109- } ) ;
105+ }
106+
107+ try {
108+ if ( typeof Object . defineProperty === 'function' ) {
109+ // If the Function prototype is frozen, the "toString" property is non-writable. This means that any objects which inherit this property
110+ // cannot have the property changed using an assignment. If using strict mode, attempting that will cause an error. If not using strict
111+ // mode, attempting that will be silently ignored.
112+ // However, we can still explicitly shadow the prototype's "toString" property by defining a new "toString" property on this object.
113+ Object . defineProperty ( exports . escapeXML , 'toString' , { value : escapeXMLToString } ) ;
114+ } else {
115+ // If Object.defineProperty() doesn't exist, attempt to shadow this property using the assignment operator.
116+ exports . escapeXML . toString = escapeXMLToString ;
117+ }
118+ } catch ( err ) {
119+ console . warn ( 'Unable to set escapeXML.toString (is the Function prototype frozen?)' ) ;
120+ }
110121
111122/**
112123 * Naive copy of properties from one object to another.
0 commit comments