mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-24 11:20:42 +00:00
Add setCode to Executable; use toMarkedString() in compiler; more robust function wrapper stripping in compressor
This commit is contained in:
@@ -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
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user