enhance unsafe evaluate (#3564)
This commit is contained in:
@@ -2995,6 +2995,7 @@ merge(Compressor.prototype, {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
convert_to_predicate(static_values);
|
convert_to_predicate(static_values);
|
||||||
|
var regexp_props = makePredicate("global ignoreCase multiline source");
|
||||||
def(AST_PropAccess, function(compressor, cached, depth) {
|
def(AST_PropAccess, function(compressor, cached, depth) {
|
||||||
if (compressor.option("unsafe")) {
|
if (compressor.option("unsafe")) {
|
||||||
var key = this.property;
|
var key = this.property;
|
||||||
@@ -3010,9 +3011,12 @@ merge(Compressor.prototype, {
|
|||||||
val = global_objs[exp.name];
|
val = global_objs[exp.name];
|
||||||
} else {
|
} else {
|
||||||
val = exp._eval(compressor, cached, depth + 1);
|
val = exp._eval(compressor, cached, depth + 1);
|
||||||
if (!val || val === exp) return this;
|
if (val == null || val === exp) return this;
|
||||||
if (typeof val == "object" && !HOP(val, key)) return this;
|
if (val instanceof RegExp) {
|
||||||
if (typeof val == "function") switch (key) {
|
if (!regexp_props[key]) return this;
|
||||||
|
} else if (typeof val == "object") {
|
||||||
|
if (!HOP(val, key)) return this;
|
||||||
|
} else if (typeof val == "function") switch (key) {
|
||||||
case "name":
|
case "name":
|
||||||
return val.node.name ? val.node.name.name : "";
|
return val.node.name ? val.node.name.name : "";
|
||||||
case "length":
|
case "length":
|
||||||
@@ -3060,7 +3064,7 @@ merge(Compressor.prototype, {
|
|||||||
val = global_objs[e.name];
|
val = global_objs[e.name];
|
||||||
} else {
|
} else {
|
||||||
val = e._eval(compressor, cached, depth + 1);
|
val = e._eval(compressor, cached, depth + 1);
|
||||||
if (val === e || !val) return this;
|
if (val == null || val === e) return this;
|
||||||
var native_fn = native_fns[val.constructor.name];
|
var native_fn = native_fns[val.constructor.name];
|
||||||
if (!native_fn || !native_fn[key]) return this;
|
if (!native_fn || !native_fn[key]) return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -237,22 +237,39 @@ unsafe_constant: {
|
|||||||
unsafe: true,
|
unsafe: true,
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
console.log(
|
console.log(true.a, false.a);
|
||||||
true.a,
|
console.log(true.valueOf(), false.valueOf());
|
||||||
false.a,
|
try {
|
||||||
null.a,
|
console.log(null.a);
|
||||||
undefined.a
|
} catch (e) {
|
||||||
);
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
console.log(undefined.a);
|
||||||
|
} catch (e) {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
console.log(
|
console.log(void 0, void 0);
|
||||||
void 0,
|
console.log(true, false);
|
||||||
false.a,
|
try {
|
||||||
null.a,
|
console.log(null.a);
|
||||||
(void 0).a
|
} catch (e) {
|
||||||
);
|
console.log("PASS");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
console.log((void 0).a);
|
||||||
|
} catch (e) {
|
||||||
|
console.log("PASS");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: [
|
||||||
|
"undefined undefined",
|
||||||
|
"true false",
|
||||||
|
"PASS",
|
||||||
|
"PASS",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_object: {
|
unsafe_object: {
|
||||||
|
|||||||
@@ -36,6 +36,20 @@ regexp_2: {
|
|||||||
expect_stdout: '["PASS","pass"]'
|
expect_stdout: '["PASS","pass"]'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
regexp_properties: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(/abc/g.source, /abc/g.global, /abc/g.ignoreCase, /abc/g.lastIndex, /abc/g.multiline);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("abc", true, false, /abc/g.lastIndex, false);
|
||||||
|
}
|
||||||
|
expect_stdout: "abc true false 0 false"
|
||||||
|
}
|
||||||
|
|
||||||
issue_3434_1: {
|
issue_3434_1: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user