[Pkg-javascript-commits] [uglifyjs] 130/491: fix iteration over object with inherited properties (#2068)
Jonas Smedegaard
dr at jones.dk
Wed Feb 14 19:51:28 UTC 2018
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag debian/3.3.10-1
in repository uglifyjs.
commit 9c306406f14087ad0a62141bf7bb9e12afcc1a75
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date: Thu Jun 8 03:27:03 2017 +0800
fix iteration over object with inherited properties (#2068)
fixes #2055
---
lib/compress.js | 2 +-
lib/minify.js | 4 ++--
test/mocha/minify.js | 19 +++++++++++++++++++
3 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/lib/compress.js b/lib/compress.js
index 81b9cca..5f2ac2b 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1419,7 +1419,7 @@ merge(Compressor.prototype, {
});
if (value && typeof value == "object") {
var props = [];
- for (var key in value) {
+ for (var key in value) if (HOP(value, key)) {
props.push(make_node(AST_ObjectKeyVal, orig, {
key: key,
value: to_node(value[key], orig)
diff --git a/lib/minify.js b/lib/minify.js
index 16f5b18..cc638be 100644
--- a/lib/minify.js
+++ b/lib/minify.js
@@ -86,7 +86,7 @@ function minify(files, options) {
}
options.parse = options.parse || {};
options.parse.toplevel = null;
- for (var name in files) {
+ for (var name in files) if (HOP(files, name)) {
options.parse.filename = name;
options.parse.toplevel = parse(files[name], options.parse);
if (options.sourceMap && options.sourceMap.content == "inline") {
@@ -134,7 +134,7 @@ function minify(files, options) {
if (options.sourceMap.includeSources) {
if (files instanceof AST_Toplevel) {
throw new Error("original source content unavailable");
- } else for (var name in files) {
+ } else for (var name in files) if (HOP(files, name)) {
options.output.source_map.get().setSourceContent(name, files[name]);
}
}
diff --git a/test/mocha/minify.js b/test/mocha/minify.js
index 519b725..638e79f 100644
--- a/test/mocha/minify.js
+++ b/test/mocha/minify.js
@@ -13,6 +13,13 @@ describe("minify", function() {
assert.strictEqual(result.code, 'function foo(n){return n?3:7}');
});
+ it("Should skip inherited keys from `files`", function() {
+ var files = Object.create({ skip: this });
+ files[0] = "alert(1 + 1)";
+ var result = Uglify.minify(files);
+ assert.strictEqual(result.code, "alert(2);");
+ });
+
describe("keep_quoted_props", function() {
it("Should preserve quotes in object literals", function() {
var js = 'var foo = {"x": 1, y: 2, \'z\': 3};';
@@ -207,5 +214,17 @@ describe("minify", function() {
assert.ok(err instanceof Error);
assert.strictEqual(err.stack.split(/\n/)[0], "Error: Can't handle expression: debugger");
});
+ it("should skip inherited properties", function() {
+ var foo = Object.create({ skip: this });
+ foo.bar = 42;
+ var result = Uglify.minify("alert(FOO);", {
+ compress: {
+ global_defs: {
+ FOO: foo
+ }
+ }
+ });
+ assert.strictEqual(result.code, "alert({bar:42});");
+ });
});
});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git
More information about the Pkg-javascript-commits
mailing list