expand builtins exclusions (#5601)

closes #5600
This commit is contained in:
Alex Lam S.L
2022-08-05 06:37:02 +01:00
committed by GitHub
parent 41b65af6e2
commit 8a07f1202c
3 changed files with 97 additions and 50 deletions

View File

@@ -43,10 +43,11 @@
"use strict";
var builtins = function() {
function get_builtins() {
var names = new Dictionary();
// NaN will be included due to Number.NaN
// constants
[
"NaN",
"null",
"true",
"false",
@@ -54,30 +55,72 @@ var builtins = function() {
"-Infinity",
"undefined",
].forEach(add);
// global functions
[
Array,
Boolean,
Date,
Error,
Function,
Math,
Number,
Object,
RegExp,
String,
].forEach(function(ctor) {
"encodeURI",
"encodeURIComponent",
"escape",
"eval",
"decodeURI",
"decodeURIComponent",
"isFinite",
"isNaN",
"parseFloat",
"parseInt",
"unescape",
].forEach(add);
// global constructors & objects
var global = Function("return this")();
[
"Array",
"ArrayBuffer",
"Atomics",
"BigInt",
"Boolean",
"console",
"DataView",
"Date",
"Error",
"Function",
"Int8Array",
"Intl",
"JSON",
"Map",
"Math",
"Number",
"Object",
"Promise",
"Proxy",
"Reflect",
"RegExp",
"Set",
"String",
"Symbol",
"WebAssembly",
].forEach(function(name) {
add(name);
var ctor = global[name];
if (!ctor) return;
Object.getOwnPropertyNames(ctor).map(add);
if (ctor.prototype) {
if (typeof ctor != "function") return;
if (ctor.__proto__) Object.getOwnPropertyNames(ctor.__proto__).map(add);
if (ctor.prototype) Object.getOwnPropertyNames(ctor.prototype).map(add);
try {
Object.getOwnPropertyNames(new ctor()).map(add);
Object.getOwnPropertyNames(ctor.prototype).map(add);
} catch (e) {
try {
Object.getOwnPropertyNames(ctor()).map(add);
} catch (e) {}
}
});
return names;
return (get_builtins = function() {
return names.clone();
})();
function add(name) {
names.set(name, true);
}
}();
}
function reserve_quoted_keys(ast, reserved) {
ast.walk(new TreeWalker(function(node) {
@@ -116,7 +159,7 @@ function mangle_properties(ast, options) {
reserved: null,
}, true);
var reserved = options.builtins ? new Dictionary() : builtins.clone();
var reserved = options.builtins ? new Dictionary() : get_builtins();
if (Array.isArray(options.reserved)) options.reserved.forEach(function(name) {
reserved.set(name, true);
});