mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 21:17:03 +00:00
Fixed press to work with static'd app code and toll free bridging
[#83 state:resolved responsible:tlrobinson] [#84 state:resolved responsible:tlrobinson]
This commit is contained in:
@@ -192,15 +192,48 @@ function findGlobalDefines(context, scope, rootPath)
|
||||
//
|
||||
// return result;
|
||||
//}
|
||||
|
||||
var needsPatch = true;
|
||||
|
||||
var fragment_evaluate_file_original = scope.fragment_evaluate_file;
|
||||
scope.fragment_evaluate_file = function(aFragment)
|
||||
{
|
||||
// patch Foundation.j (HACK for Rhino bug #374918)
|
||||
if (needsPatch && aFragment.file && (/Foundation\.j$/).test(aFragment.file.path))
|
||||
{
|
||||
CPLog.error("Patching Foundation.j");
|
||||
|
||||
var patchFragment = new objj_fragment();
|
||||
patchFragment.info = "__RHINO_FIRST_SCOPE.String.prototype.isa=CPString;__RHINO_FIRST_SCOPE.Number.prototype.isa=CPNumber;__RHINO_FIRST_SCOPE.Boolean.prototype.isa=CPNumber;print('PATCHED!');";
|
||||
patchFragment.type = FRAGMENT_CODE;
|
||||
patchFragment.file = aFragment.file;
|
||||
patchFragment.bundle = aFragment.bundle;
|
||||
patchFragment.context = aFragment.context;
|
||||
|
||||
for (var i = 0; i < aFragment.context.fragments.length; i++)
|
||||
{
|
||||
if ((aFragment.context.fragments[i].type & FRAGMENT_IMPORT) && (/Foundation\//).test(aFragment.context.fragments[i].info))
|
||||
{
|
||||
CPLog.error("Inserting patch");
|
||||
aFragment.context.fragments.splice(i, 0, patchFragment);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
needsPatch = false;
|
||||
}
|
||||
|
||||
return fragment_evaluate_file_original(aFragment);
|
||||
}
|
||||
|
||||
scope.fragment_evaluate_code_original = scope.fragment_evaluate_code;
|
||||
var fragment_evaluate_code_original = scope.fragment_evaluate_code;
|
||||
scope.fragment_evaluate_code = function(aFragment)
|
||||
{
|
||||
CPLog.debug("Evaling "+aFragment.file.path + " / " + aFragment.bundle.path);
|
||||
|
||||
var before = cloneProperties(scope);
|
||||
|
||||
var result = scope.fragment_evaluate_code_original(aFragment);
|
||||
|
||||
var result = fragment_evaluate_code_original(aFragment);
|
||||
|
||||
var definedGlobals = {};
|
||||
diff(before, scope, ignore, definedGlobals, definedGlobals, null);
|
||||
@@ -257,14 +290,18 @@ function makeObjjScope(context, debug)
|
||||
}
|
||||
|
||||
// give the scope "print"
|
||||
scope.print = function(value) { Packages.java.lang.System.out.println(value); };
|
||||
scope.print = function(value) { Packages.java.lang.System.out.println(String(value)); };
|
||||
|
||||
// HACK for Rhino bug #374918 (fix toll free bridging)
|
||||
scope.__RHINO_FIRST_SCOPE = this;
|
||||
CPLog.info("__RHINO_FIRST_SCOPE="+scope.__RHINO_FIRST_SCOPE);
|
||||
|
||||
// load and eval fake browser environment
|
||||
var envSource = readFile(envPath);
|
||||
if (envSource)
|
||||
context.evaluateString(scope, envSource, "env.js", 1, null);
|
||||
else
|
||||
CPLog.warn("Missing env.js");
|
||||
//var envSource = readFile(envPath);
|
||||
//if (envSource)
|
||||
// context.evaluateString(scope, envSource, "env.js", 1, null);
|
||||
//else
|
||||
// CPLog.warn("Missing env.js");
|
||||
|
||||
// load and eval the bridge
|
||||
var bridgeSource = readFile(bridgePath);
|
||||
|
||||
+12
-9
@@ -4,7 +4,6 @@ import "objj-analysis-tools.j"
|
||||
|
||||
CPLogRegister(CPLogPrint);
|
||||
|
||||
|
||||
function main()
|
||||
{
|
||||
var rootPath = null,
|
||||
@@ -33,7 +32,6 @@ function main()
|
||||
print("Usage: press input_base_file.j output_directory");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var rootPath = args[0],
|
||||
sourceDirectory = dirname(rootPath) || ".",
|
||||
@@ -44,11 +42,9 @@ function main()
|
||||
|
||||
var frameworks = rootPath.substring(0, rootPath.lastIndexOf("/")+1) + "Frameworks/";
|
||||
scope.OBJJ_INCLUDE_PATHS = [frameworks];
|
||||
|
||||
CPLog.info("OBJJ_INCLUDE_PATHS="+scope.OBJJ_INCLUDE_PATHS);
|
||||
|
||||
// phase 1: get global defines
|
||||
|
||||
var globals = findGlobalDefines(cx, scope, rootPath);
|
||||
|
||||
// coalesce the results
|
||||
@@ -73,6 +69,7 @@ function main()
|
||||
}
|
||||
}
|
||||
|
||||
requiredFiles[rootPath] = true;
|
||||
traverseDependencies(context, scope.objj_files[rootPath]);
|
||||
|
||||
var count = 0,
|
||||
@@ -272,7 +269,7 @@ function pathRelativeTo(target, relativeTo)
|
||||
{
|
||||
var components = [],
|
||||
targetParts = target.split("/"),
|
||||
relativeParts = relativeTo.split("/");
|
||||
relativeParts = relativeTo ? relativeTo.split("/") : [];
|
||||
|
||||
var i = 0;
|
||||
while (i < targetParts.length)
|
||||
@@ -287,12 +284,16 @@ function pathRelativeTo(target, relativeTo)
|
||||
|
||||
for (var j = i; j < targetParts.length; j++)
|
||||
components.push(targetParts[j]);
|
||||
|
||||
return components.join("/");
|
||||
|
||||
var result = components.join("/");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function exec()
|
||||
{
|
||||
var printOutput = false;
|
||||
|
||||
var runtime = Packages.java.lang.Runtime.getRuntime()
|
||||
var p = runtime.exec.apply(runtime, arguments);
|
||||
|
||||
@@ -308,13 +309,15 @@ function exec()
|
||||
if (s = stdout.readLine())
|
||||
{
|
||||
stdoutString += s;
|
||||
CPLog.info("exec: " + s);
|
||||
if (printOutput)
|
||||
CPLog.info("exec: " + s);
|
||||
done = false;
|
||||
}
|
||||
if (s = stderr.readLine())
|
||||
{
|
||||
stderrString += s;
|
||||
CPLog.warn("exec: " + s);
|
||||
//if (printOutput)
|
||||
CPLog.warn("exec: " + s);
|
||||
done = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user