|
43 | 43 |
|
44 | 44 | "use strict"; |
45 | 45 |
|
46 | | -var builtins = function() { |
| 46 | +function get_builtins() { |
47 | 47 | var names = new Dictionary(); |
48 | | - // NaN will be included due to Number.NaN |
| 48 | + // constants |
49 | 49 | [ |
| 50 | + "NaN", |
50 | 51 | "null", |
51 | 52 | "true", |
52 | 53 | "false", |
53 | 54 | "Infinity", |
54 | 55 | "-Infinity", |
55 | 56 | "undefined", |
56 | 57 | ].forEach(add); |
| 58 | + // global functions |
57 | 59 | [ |
58 | | - Array, |
59 | | - Boolean, |
60 | | - Date, |
61 | | - Error, |
62 | | - Function, |
63 | | - Math, |
64 | | - Number, |
65 | | - Object, |
66 | | - RegExp, |
67 | | - String, |
68 | | - ].forEach(function(ctor) { |
| 60 | + "encodeURI", |
| 61 | + "encodeURIComponent", |
| 62 | + "escape", |
| 63 | + "eval", |
| 64 | + "decodeURI", |
| 65 | + "decodeURIComponent", |
| 66 | + "isFinite", |
| 67 | + "isNaN", |
| 68 | + "parseFloat", |
| 69 | + "parseInt", |
| 70 | + "unescape", |
| 71 | + ].forEach(add); |
| 72 | + // global constructors & objects |
| 73 | + var global = Function("return this")(); |
| 74 | + [ |
| 75 | + "Array", |
| 76 | + "ArrayBuffer", |
| 77 | + "Atomics", |
| 78 | + "BigInt", |
| 79 | + "Boolean", |
| 80 | + "console", |
| 81 | + "DataView", |
| 82 | + "Date", |
| 83 | + "Error", |
| 84 | + "Function", |
| 85 | + "Int8Array", |
| 86 | + "Intl", |
| 87 | + "JSON", |
| 88 | + "Map", |
| 89 | + "Math", |
| 90 | + "Number", |
| 91 | + "Object", |
| 92 | + "Promise", |
| 93 | + "Proxy", |
| 94 | + "Reflect", |
| 95 | + "RegExp", |
| 96 | + "Set", |
| 97 | + "String", |
| 98 | + "Symbol", |
| 99 | + "WebAssembly", |
| 100 | + ].forEach(function(name) { |
| 101 | + add(name); |
| 102 | + var ctor = global[name]; |
| 103 | + if (!ctor) return; |
69 | 104 | Object.getOwnPropertyNames(ctor).map(add); |
70 | | - if (ctor.prototype) { |
| 105 | + if (typeof ctor != "function") return; |
| 106 | + if (ctor.__proto__) Object.getOwnPropertyNames(ctor.__proto__).map(add); |
| 107 | + if (ctor.prototype) Object.getOwnPropertyNames(ctor.prototype).map(add); |
| 108 | + try { |
71 | 109 | Object.getOwnPropertyNames(new ctor()).map(add); |
72 | | - Object.getOwnPropertyNames(ctor.prototype).map(add); |
| 110 | + } catch (e) { |
| 111 | + try { |
| 112 | + Object.getOwnPropertyNames(ctor()).map(add); |
| 113 | + } catch (e) {} |
73 | 114 | } |
74 | 115 | }); |
75 | | - return names; |
| 116 | + return (get_builtins = function() { |
| 117 | + return names.clone(); |
| 118 | + })(); |
76 | 119 |
|
77 | 120 | function add(name) { |
78 | 121 | names.set(name, true); |
79 | 122 | } |
80 | | -}(); |
| 123 | +} |
81 | 124 |
|
82 | 125 | function reserve_quoted_keys(ast, reserved) { |
83 | 126 | ast.walk(new TreeWalker(function(node) { |
@@ -116,7 +159,7 @@ function mangle_properties(ast, options) { |
116 | 159 | reserved: null, |
117 | 160 | }, true); |
118 | 161 |
|
119 | | - var reserved = options.builtins ? new Dictionary() : builtins.clone(); |
| 162 | + var reserved = options.builtins ? new Dictionary() : get_builtins(); |
120 | 163 | if (Array.isArray(options.reserved)) options.reserved.forEach(function(name) { |
121 | 164 | reserved.set(name, true); |
122 | 165 | }); |
|
0 commit comments