Add setCode to Executable; use toMarkedString() in compiler; more robust function wrapper stripping in compressor

This commit is contained in:
Tom Robinson
2010-02-09 14:55:50 -08:00
parent 7837e1ad81
commit 04529897dc
2 changed files with 34 additions and 39 deletions
@@ -87,26 +87,16 @@ function compileWithResolvedFlags(aFilePath, objjcFlags, gccFlags)
throw errorInfo;
}
var preprocessed = "@STATIC;1.0;",
fileDependencies = executable.fileDependencies(),
index = 0,
count = fileDependencies.length;
for (; index < count; ++index)
preprocessed += fileDependencies[index].toMarkedString();
var code = executable.code();
if (shouldCompress)
{
var code = compress("function(){" + code + "}", FILE.basename(aFilePath));
code = code.substr("function(){".length, code.length - "function(){};\n\n".length);
var code = executable.code();
code = compress("function(){" + code + "}", FILE.basename(aFilePath));
// more robust function wrapper stripping
code = code.replace(/^\s*function\s*\(\s*\)\s*{|}\s*;?\s*$/g, "");
executable.setCode(code);
}
preprocessed += "t;" + code.length + ";" + code;
return preprocessed;
return executable.toMarkedString();
}
function resolveFlags(args)
+28 -23
View File
@@ -41,29 +41,7 @@ function Executable(/*String*/ aCode, /*Array*/ fileDependencies, /*String*/ aSc
if (this._function)
return;
var code = this._code;
#if COMMONJS
code = "function(" + this.functionParameters().join(" , ") + "){" + code + "/**/\n}";
if (typeof system !== "undefined" && system.engine === "rhino")
this._function = Packages.org.mozilla.javascript.Context.getCurrentContext().compileFunction(window, code, this._scope, 0, NULL);
else
this._function = eval("(" + code + ")");
#else
// "//@ sourceURL=" at the end lets us name our eval'd files for debuggers, etc.
// * WebKit: http://pmuellr.blogspot.com/2009/06/debugger-friendly.html
// * Firebug: http://blog.getfirebug.com/2009/08/11/give-your-eval-a-name-with-sourceurl/
//if (YES) {
code += "/**/\n//@ sourceURL=" + this._scope;
this._function = new Function(this.functionParameters(), code);
//} else {
// // Firebug only does it for "eval()", not "new Function()". Ugh. Slower.
// var functionText = "(function(){"+GET_CODE(aFragment)+"/**/\n})\n//@ sourceURL="+GET_FILE(aFragment).path;
// compiled = eval(functionText);
//}
this._function.displayName = this._scope;
#endif
this.setCode(aCode);
}
Executable.prototype.path = function()
@@ -156,6 +134,33 @@ Executable.prototype.code = function()
return this._code;
}
Executable.prototype.setCode = function(code)
{
this._code = code;
#if COMMONJS
code = "function(" + this.functionParameters().join(" , ") + "){" + code + "/**/\n}";
if (typeof system !== "undefined" && system.engine === "rhino")
this._function = Packages.org.mozilla.javascript.Context.getCurrentContext().compileFunction(window, code, this._scope, 0, NULL);
else
this._function = eval("(" + code + ")");
#else
// "//@ sourceURL=" at the end lets us name our eval'd files for debuggers, etc.
// * WebKit: http://pmuellr.blogspot.com/2009/06/debugger-friendly.html
// * Firebug: http://blog.getfirebug.com/2009/08/11/give-your-eval-a-name-with-sourceurl/
//if (YES) {
code += "/**/\n//@ sourceURL=" + this._scope;
this._function = new Function(this.functionParameters(), code);
//} else {
// // Firebug only does it for "eval()", not "new Function()". Ugh. Slower.
// var functionText = "(function(){"+GET_CODE(aFragment)+"/**/\n})\n//@ sourceURL="+GET_FILE(aFragment).path;
// compiled = eval(functionText);
//}
this._function.displayName = this._scope;
#endif
}
Executable.prototype.fileDependencies = function()
{
return this._fileDependencies;