fix corner case in collapse_vars (#5482)

fixes #5481
This commit is contained in:
Alex Lam S.L
2022-06-01 19:42:39 +01:00
committed by GitHub
parent 3c9e1693d5
commit ad3a331ca3
3 changed files with 38 additions and 1 deletions

View File

@@ -2466,6 +2466,13 @@ Compressor.prototype.compress = function(node) {
abort = false;
return true;
}
if (node instanceof AST_Class) {
if (!in_try) return false;
var base = node.extends;
if (!base) return false;
if (base instanceof AST_SymbolRef) base = base.fixed_value();
return !safe_for_extends(base);
}
if (node instanceof AST_Exit) {
if (in_try) {
if (in_try.bfinally) return true;

View File

@@ -2852,3 +2852,33 @@ issue_5436: {
expect_stdout: "PASS"
node_version: ">=12"
}
issue_5481: {
options = {
collapse_vars: true,
}
input: {
"use strict";
var a = "FAIL 1", log = console.log;
try {
a = "PASS";
(class extends 42 {});
log("FAIL 2", a);
} catch (e) {
log(a);
}
}
expect: {
"use strict";
var a = "FAIL 1", log = console.log;
try {
a = "PASS";
(class extends 42 {});
log("FAIL 2", a);
} catch (e) {
log(a);
}
}
expect_stdout: "PASS"
node_version: ">=4"
}

View File

@@ -2398,7 +2398,7 @@ function patch_try_catch(orig, toplevel) {
"throw " + match[1] + ";",
].join("\n");
}
var new_code = code.slice(0, index) + insert + code.slice(index) + tail_throw;
var new_code = code.slice(0, index) + insert + code.slice(index) + tail_throw + "var UFUZZ_ERROR;";
var result = run_code(new_code, toplevel);
if (!sandbox.is_error(result)) {
if (!stack.filled && match[1]) stack.push({