aboutsummaryrefslogtreecommitdiff
path: root/src/jsifier.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-06-28 16:36:36 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-07-03 15:31:04 -0700
commitf5c71a90e79a645ef9e44d6685907b86f8cf3c00 (patch)
tree16bb8b22271ea1a0504d864ed1a3b79547268466 /src/jsifier.js
parent11db72239d48da525e0978a608e4cdfb91168981 (diff)
clone aliased functions in shared modules
Diffstat (limited to 'src/jsifier.js')
-rw-r--r--src/jsifier.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index 83cb7517..5eae2018 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -390,6 +390,11 @@ function JSify(data, functionsOnly, givenFunctions) {
dependencies: set([value]),
JS: item.ident + ' = ' + value + ';' + fix
});
+ if ((MAIN_MODULE || SIDE_MODULE) && isFunctionType(item.type)) {
+ var target = item.value.ident;
+ if (!Functions.aliases[target]) Functions.aliases[target] = [];
+ Functions.aliases[target].push(item.ident);
+ }
return ret;
}
});
@@ -847,6 +852,19 @@ function JSify(data, functionsOnly, givenFunctions) {
}
func.JS = func.JS.replace(/\n *;/g, '\n'); // remove unneeded lines
+
+ if (MAIN_MODULE || SIDE_MODULE) {
+ // Clone the function for each of its aliases. We do not know which name it will be used by in another module,
+ // and we do not have a heavyweight metadata system to resolve aliases during linking
+ var aliases = Functions.aliases[func.ident];
+ if (aliases) {
+ var body = func.JS.substr(func.JS.indexOf('('));
+ aliases.forEach(function(alias) {
+ func.JS += '\n' + 'function ' + alias + body;
+ });
+ }
+ }
+
return func;
}
});