diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-06-25 07:49:01 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-06-25 07:49:01 -0700 |
commit | 936ccd93b961b99817e68a9e628a2986f6c7b297 (patch) | |
tree | cfcfdd7bf397631ef81f657e646f840e86926599 /src/parseTools.js | |
parent | c9b968a4467fc1c004da69dc2f0000728fbf108e (diff) |
indexize Math.* properly. fixes issue 29
Diffstat (limited to 'src/parseTools.js')
-rw-r--r-- | src/parseTools.js | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/parseTools.js b/src/parseTools.js index 98ebd32c..e520f919 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -692,14 +692,21 @@ function makeGetValue(ptr, pos, type, noNeedFirst, unsigned) { } } -function indexizeFunctions(value) { // TODO: Also check for externals +function indexizeFunctions(value) { if (value in Functions.currFunctions) { return Functions.getIndex(value); } if (value && value[0] && value[0] == '_') { var rootIdent = LibraryManager.getRootIdent(value.slice(1)); - if (rootIdent && typeof Library[rootIdent] === 'function') { + if (!rootIdent) return value; + if (typeof Library[rootIdent] === 'function') { return Functions.getIndex('_' + rootIdent); + } else if (rootIdent.substr(0, 5) === 'Math.') { + // Library[..] can be a string, in which case we apply that string. There is one + // case where this can be a function: Math.*, since we try to optimize those as much + // as possible. In other words, we don't want to have a wrapper function(x) return Math.sqrt(x). + // If other functions are deemed important as well, we will need to add them here. + return Functions.getIndex(rootIdent); } } return value; |