From 931723737204d0a042604f8051ca3af8aa08a1c7 Mon Sep 17 00:00:00 2001 From: Mihai Bazon Date: Thu, 7 Apr 2016 13:15:28 +0300 Subject: [PATCH] Avoid using inherited hasOwnProperty Fix #1031 --- lib/ast.js | 2 +- lib/compress.js | 2 +- lib/utils.js | 14 +++++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/ast.js b/lib/ast.js index 0ac14dc9..2a461834 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -71,7 +71,7 @@ function DEFNODE(type, props, methods, base) { if (type) { ctor.prototype.TYPE = ctor.TYPE = type; } - if (methods) for (i in methods) if (methods.hasOwnProperty(i)) { + if (methods) for (i in methods) if (HOP(methods, i)) { if (/^\$/.test(i)) { ctor[i.substr(1)] = methods[i]; } else { diff --git a/lib/compress.js b/lib/compress.js index 26c11bd9..d42f84d1 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -2509,7 +2509,7 @@ merge(Compressor.prototype, { if (self.undeclared() && !isLHS(self, compressor.parent())) { var defines = compressor.option("global_defs"); - if (defines && defines.hasOwnProperty(self.name)) { + if (defines && HOP(defines, self.name)) { return make_node_from_constant(compressor, defines[self.name], self); } switch (self.name) { diff --git a/lib/utils.js b/lib/utils.js index 4612a322..c81ca71f 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -97,17 +97,17 @@ function defaults(args, defs, croak) { if (args === true) args = {}; var ret = args || {}; - if (croak) for (var i in ret) if (ret.hasOwnProperty(i) && !defs.hasOwnProperty(i)) + if (croak) for (var i in ret) if (HOP(ret, i) && !HOP(defs, i)) DefaultsError.croak("`" + i + "` is not a supported option", defs); - for (var i in defs) if (defs.hasOwnProperty(i)) { - ret[i] = (args && args.hasOwnProperty(i)) ? args[i] : defs[i]; + for (var i in defs) if (HOP(defs, i)) { + ret[i] = (args && HOP(args, i)) ? args[i] : defs[i]; } return ret; }; function merge(obj, ext) { var count = 0; - for (var i in ext) if (ext.hasOwnProperty(i)) { + for (var i in ext) if (HOP(ext, i)) { obj[i] = ext[i]; count++; } @@ -150,7 +150,7 @@ var MAP = (function(){ } } else { - for (i in a) if (a.hasOwnProperty(i)) if (doit()) break; + for (i in a) if (HOP(a, i)) if (doit()) break; } return top.concat(ret); }; @@ -308,3 +308,7 @@ Dictionary.fromObject = function(obj) { dict._size = merge(dict._values, obj); return dict; }; + +function HOP(obj, prop) { + return Object.prototype.hasOwnProperty.call(obj, prop); +} -- 2.34.1