aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2019-05-15 23:26:57 +0800
committerGitHub <noreply@github.com>2019-05-15 23:26:57 +0800
commita21c348d93fba14715ef8c1c597a26328cf1a947 (patch)
tree6f4b888001409622837e4342855fd0426141f72e /lib
parent1f0def10ebc637ddd6c24094942ae616f94ed25f (diff)
downloadtracifyjs-a21c348d93fba14715ef8c1c597a26328cf1a947.tar.gz
tracifyjs-a21c348d93fba14715ef8c1c597a26328cf1a947.zip
improve sandbox fidelity (#3415)
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js13
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/compress.js b/lib/compress.js
index f7730cd5..5d6567f7 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -451,6 +451,7 @@ merge(Compressor.prototype, {
if (tw.safe_ids[def.id]) {
if (def.fixed == null) {
if (is_arguments(def)) return false;
+ if (def.global && def.name == "arguments") return false;
def.fixed = make_node(AST_Undefined, def.orig);
}
return true;
@@ -894,9 +895,13 @@ merge(Compressor.prototype, {
return orig.length == 1 && orig[0] instanceof AST_SymbolLambda;
});
- function is_lhs_read_only(lhs) {
+ function is_lhs_read_only(lhs, compressor) {
if (lhs instanceof AST_This) return true;
- if (lhs instanceof AST_SymbolRef) return lhs.definition().orig[0] instanceof AST_SymbolLambda;
+ if (lhs instanceof AST_SymbolRef) {
+ var def = lhs.definition();
+ return def.orig[0] instanceof AST_SymbolLambda
+ || compressor.exposed(def) && identifier_atom[def.name];
+ }
if (lhs instanceof AST_PropAccess) {
lhs = lhs.expression;
if (lhs instanceof AST_SymbolRef) {
@@ -905,7 +910,7 @@ merge(Compressor.prototype, {
}
if (!lhs) return true;
if (lhs.is_constant()) return true;
- return is_lhs_read_only(lhs);
+ return is_lhs_read_only(lhs, compressor);
}
return false;
}
@@ -1220,7 +1225,7 @@ merge(Compressor.prototype, {
var stop_if_hit = null;
var lhs = get_lhs(candidate);
var side_effects = lhs && lhs.has_side_effects(compressor);
- var scan_lhs = lhs && !side_effects && !is_lhs_read_only(lhs);
+ var scan_lhs = lhs && !side_effects && !is_lhs_read_only(lhs, compressor);
var scan_rhs = foldable(get_rhs(candidate));
if (!scan_lhs && !scan_rhs) continue;
// Locate symbols which may execute code outside of scanning range