Avoid Firefox's unoptimized Function constructor.

Former-commit-id: 7cc5fc63c0cebd1410edde47c88e580c64fa2b98
This commit is contained in:
John-David Dalton
2012-11-22 23:53:16 -06:00
parent 77bac4cf9e
commit 383b1a5769
4 changed files with 96 additions and 47 deletions

View File

@@ -329,7 +329,7 @@
precompiled = getFunctionSource(_.template(text, null, options)),
prop = filename.replace(/\..*$/, '');
source.push(" templates['" + prop.replace(/'/g, "\\'") + "'] = " + precompiled + ';', '');
source.push(" templates['" + prop.replace(/['\n\r\t]/g, '\\$&') + "'] = " + precompiled + ';', '');
}
});
@@ -637,6 +637,18 @@
return _.uniq(_.intersection(allMethods, methodNames));
}
/**
* Removes the `createFunction` function from `source`.
*
* @private
* @param {String} source The source to process.
* @returns {String} Returns the modified source.
*/
function removeCreateFunction(source) {
return removeFunction(source, 'createFunction')
.replace(/\n *try *{\s*createFunction[\s\S]+?catch[^}]+}\n/, '');
}
/**
* Removes the all references to `refName` from `createIterator` in `source`.
*
@@ -663,7 +675,7 @@
* @private
* @param {String} source The source to process.
* @param {String} funcName The name of the function to remove.
* @returns {String} Returns the source with the function removed.
* @returns {String} Returns the modified source.
*/
function removeFunction(source, funcName) {
// remove function
@@ -690,7 +702,7 @@
*
* @private
* @param {String} source The source to process.
* @returns {String} Returns the source with the `isArguments` fallback removed.
* @returns {String} Returns the modified source.
*/
function removeIsArgumentsFallback(source) {
return source.replace(getIsArgumentsFallback(source), '');
@@ -701,7 +713,7 @@
*
* @private
* @param {String} source The source to process.
* @returns {String} Returns the source with the `isFunction` fallback removed.
* @returns {String} Returns the modified source.
*/
function removeIsFunctionFallback(source) {
return source.replace(getIsFunctionFallback(source), '');
@@ -785,7 +797,7 @@
* @private
* @param {String} source The source to process.
* @param {String} varName The name of the variable to remove.
* @returns {String} Returns the source with the variable removed.
* @returns {String} Returns the modified source.
*/
function removeVar(source, varName) {
// simplify `cloneableClasses`
@@ -823,7 +835,7 @@
* @private
* @param {String} source The source to inspect.
* @param {String} varName The name of the function to replace.
* @returns {String} Returns the source with the function replaced.
* @returns {String} Returns the modified source.
*/
function replaceFunction(source, funcName, funcValue) {
var match = matchFunction(source, funcName);
@@ -843,7 +855,7 @@
* @private
* @param {String} source The source to inspect.
* @param {String} varName The name of the variable to replace.
* @returns {String} Returns the source with the variable replaced.
* @returns {String} Returns the modified source.
*/
function replaceVar(source, varName, varValue) {
// replace a variable that's not part of a declaration list
@@ -1710,6 +1722,7 @@
source = removeVar(source, 'extendIteratorOptions');
source = removeVar(source, 'iteratorTemplate');
source = removeVar(source, 'noCharByIndex');
source = removeCreateFunction(source);
source = removeNoArgsClass(source);
source = removeNoNodeClass(source);
}