Bug 1401528 - check of existence of softMargin and hardMargin in options to HeaderEmitter. r=jcranmer
authoraceman <acelists@atlas.sk>
Sun, 24 Sep 2017 22:41:00 +0200
changeset 29241 4fd348dc8b0c427e538ce1411df0a4b240c8760e
parent 29240 d09475dacd052181deeb6a8364807293ed9d938d
child 29242 c82304da41745162f4d7c0d71b150ca78bbae9d4
push id2068
push userclokep@gmail.com
push dateMon, 13 Nov 2017 19:02:14 +0000
treeherdercomm-beta@9c7e7ce8672b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjcranmer
bugs1401528
Bug 1401528 - check of existence of softMargin and hardMargin in options to HeaderEmitter. r=jcranmer
mailnews/mime/jsmime/jsmime.js
--- a/mailnews/mime/jsmime/jsmime.js
+++ b/mailnews/mime/jsmime/jsmime.js
@@ -2522,20 +2522,22 @@ var mimeutils = require('./mimeutils');
 // Get the default structured encoders and add them to the map
 var structuredHeaders = require('./structuredHeaders');
 var encoders = new Map();
 var preferredSpellings = structuredHeaders.spellings;
 for (let [header, encoder] of structuredHeaders.encoders) {
   addStructuredEncoder(header, encoder);
 }
 
-/// Clamp a value in the range [min, max], defaulting to def if it is undefined.
-function clamp(value, min, max, def) {
-  if (value === undefined)
+/// Clamp a value in the range [min, max], defaulting to def
+/// if the object[property] does not contain the value.
+function clamp(object, property, min, max, def) {
+  if (!(property in object))
     return def;
+  let value = object[property];
   if (value < min)
     return min;
   if (value > max)
     return max;
   return value;
 }
 
 /**
@@ -2598,18 +2600,18 @@ function HeaderEmitter(handler, options)
   // Our bounds for soft and margins are not completely arbitrary. The minimum
   // amount we need to encode is 20 characters, which can encode a single
   // non-BMP character with RFC 2047. The value of 30 is chosen to give some
   // breathing room for delimiters or other unbreakable characters. The maximum
   // length is 998 octets, per RFC 5322; soft margins are slightly lower to
   // allow for breathing room as well. The default of 78 for the soft margin is
   // recommended by RFC 5322; the default of 332 for the hard margin ensures
   // that UTF-8 encoding the output never violates the 998 octet limit.
-  this._softMargin = clamp(options.softMargin, 30, 900, 78);
-  this._hardMargin = clamp(options.hardMargin, this._softMargin, 998, 332);
+  this._softMargin = clamp(options, "softMargin", 30, 900, 78);
+  this._hardMargin = clamp(options, "hardMargin", this._softMargin, 998, 332);
 
   /**
    * The index of the last preferred breakable position in the current line.
    *
    * @type Integer
    * @private
    */
   this._preferredBreakpoint = 0;