Asm.js: compliant name mangling

This commit is contained in:
Artem S Vybornov 2013-12-16 21:28:30 +04:00
parent 92e4340732
commit b91dca87ee

View File

@ -260,6 +260,14 @@ AST_Scope.DEFMETHOD("def_variable", function(symbol){
AST_Scope.DEFMETHOD("next_mangled", function(options){
var ext = this.enclosed;
// asm.js: don't mask module-scope names
var asm = this.has_directive("use asm"),
pasm = this.parent_scope ? this.parent_scope.has_directive("use asm") : false;
if (pasm) {
this.cname = this.parent_scope.cname;
}
out: while (true) {
var m = base54(++this.cname);
if (!is_identifier(m)) continue; // skip over "do"
@ -268,6 +276,21 @@ AST_Scope.DEFMETHOD("next_mangled", function(options){
// shadow a name excepted from mangling.
if (options.except.indexOf(m) >= 0) continue;
// asm.js: don't reuse module name although it is out of the current scope
if (asm) {
var sym = this.name;
var penc = this.parent_scope.enclosed;
if (sym && penc.length) {
for (var i = 0; i < penc.length; i++) {
var psym = penc[i];
if (sym.name == psym.name) {
var name = psym.mangled_name || (psym.unmangleable(options) && psym.name);
if (m == name) continue out;
}
}
}
}
// we must ensure that the mangled name does not shadow a name
// from some parent scope that is referenced in this or in
// inner scopes.