Skip to content

Commit

Permalink
[Robustness] stringify: cache Object.prototype.hasOwnProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Feb 14, 2019
1 parent 04a9017 commit 41c42b8
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var utils = require('./utils');
var formats = require('./formats');
var has = Object.prototype.hasOwnProperty;

var arrayPrefixGenerators = {
brackets: function brackets(prefix) { // eslint-disable-line func-name-matching
Expand Down Expand Up @@ -158,7 +159,7 @@ var normalizeStringifyOptions = function normalizeStringifyOptions(opts) {

var format = formats['default'];
if (typeof opts.format !== 'undefined') {
if (!Object.prototype.hasOwnProperty.call(formats.formatters, opts.format)) {
if (!has.call(formats.formatters, opts.format)) {
throw new TypeError('Unknown format option provided.');
}
format = opts.format;
Expand Down

0 comments on commit 41c42b8

Please sign in to comment.