Migrate to use INTERPRETER.Context

This commit is contained in:
Tom Robinson
2010-01-19 16:58:41 -08:00
parent 0395287906
commit 2e1d6f2412
2 changed files with 31 additions and 53 deletions
+6 -7
View File
@@ -13,6 +13,7 @@ var ARGS = require("args");
var FILE = require("file");
var OS = require("os");
var DOM = require("browser/dom");
var INTERPRETER = require("interpreter");
var serializer = new DOM.XMLSerializer();
@@ -148,8 +149,8 @@ function pressEnvironment(rootPath, outputFiles, environment, options) {
CPLog.info("Environment: " + environment);
// get a Rhino context
var ctx = Packages.org.mozilla.javascript.Context.getCurrentContext();
var scope = makeObjjScope(ctx); // "scope" is the same as require("objective-j").window;
var context = new INTERPRETER.Context();
var scope = setupObjectiveJ(context);
scope.OBJJ_INCLUDE_PATHS = frameworks;
scope.OBJJ_ENVIRONMENTS = [environment, "ObjJ"];
@@ -178,11 +179,9 @@ function pressEnvironment(rootPath, outputFiles, environment, options) {
exectuableResponses.push(aResponse);
});
var context = {
ctx : ctx,
scope : scope,
rootPath : rootPath
};
// lets just use the Context object as our con
context.rootPath = rootPath;
context.scope = scope;
// phase 1: get global defines
CPLog.error("PHASE 1: Loading application...");
+25 -46
View File
@@ -2,8 +2,7 @@ var FILE = require("file");
/*
param context includes
scope: a global variable containing objj_files hash
ctx: js context
scope: the objective-j scope
dependencies: hash mapping from paths to an array of global variables defined by that file
[importCallback]: callback function that is called for each imported file (takes importing file path, and imported file path parameters)
[referencedCallback]: callback function that is called for each referenced file (takes referencing file path, referenced file path parameters, and list of tokens)
@@ -267,27 +266,27 @@ function findGlobalDefines(context, mainPath, evaledFragments, bundleCallback)
var bundleDelegate = [[PressBundleDelgate alloc] initWithCallback:bundleCallback];
var bundlePaths = [];
runWithScope(context, function(mainPath, bundleDelegate, bundlePaths) {
// **************************************************
objj_import(mainPath, true, function() {
print("bundleDelegate="+bundleDelegate)
[bundleDelegate bundleDidFinishLoading:"foo"];
(context.eval("("+(function(mainPath, bundleDelegate, bundlePaths) {
with (require("objective-j").window) {
objj_import(mainPath, true, function() {
bundlePaths = bundlePaths || [];
bundlePaths = bundlePaths || [];
// load default theme bundle
var themePath = [[CPBundle bundleForClass:[CPApplication class]] pathForResource:[CPApplication defaultThemeName]];
var themeBundle = [[CPBundle alloc] initWithPath:themePath + "/Info.plist"];
[themeBundle loadWithDelegate:bundleDelegate];
// load default theme bundle
var themePath = [[CPBundle bundleForClass:[CPApplication class]] pathForResource:[CPApplication defaultThemeName]];
var themeBundle = [[CPBundle alloc] initWithPath:themePath + "/Info.plist"];
[themeBundle loadWithDelegate:bundleDelegate];
// load additional bundles
bundlePaths.forEach(function(bundlePath) {
var bundle = [[CPBundle alloc] initWithPath:bundlePath];
[bundle loadWithDelegate:bundleDelegate];
});
});
}
})+")"))(mainPath, bundleDelegate, bundlePaths);
// load additional bundles
bundlePaths.forEach(function(bundlePath) {
var bundle = [[CPBundle alloc] initWithPath:bundlePath];
[bundle loadWithDelegate:bundleDelegate];
})
});
// **************************************************
}, [mainPath, bundleDelegate, bundlePaths]);
// run the "event loop"
context.scope.require('browser/timeout').serviceTimeouts();
return dependencies;
}
@@ -314,26 +313,18 @@ function coalesceGlobalDefines(globals)
}
// create a new scope loaded with Narwhal and Objective-J
function makeObjjScope(ctx, debug)
function setupObjectiveJ(context, debug)
{
// init standard JS scope objects
var scope = ctx.initStandardObjects();
// set these properties required for Narwhal bootstrapping
scope.NARWHAL_HOME = system.prefix;
scope.NARWHAL_ENGINE_HOME = FILE.join(system.prefix, "engines", "rhino");
context.global.NARWHAL_HOME = system.prefix;
context.global.NARWHAL_ENGINE_HOME = FILE.join(system.prefix, "engines", "rhino");
// load the bootstrap.js for narwhal-rhino
var bootstrapPath = FILE.join(scope.NARWHAL_ENGINE_HOME, "bootstrap.js");
ctx.evaluateReader(scope,
new Packages.java.io.FileReader(bootstrapPath),
"bootstrap.js",
1,
null
);
var bootstrapPath = FILE.join(context.global.NARWHAL_ENGINE_HOME, "bootstrap.js");
context.evalFile(bootstrapPath);
// get the Objective-J module from this scope, return the window object.
var OBJJ = scope.require("objective-j");
var OBJJ = context.global.require("objective-j");
addMockBrowserEnvironment(OBJJ.window);
@@ -367,18 +358,6 @@ function addMockBrowserEnvironment(scope)
}
}
// run a function within the given scope (func can be a function object if the source of the function is returned by toString() as it is by default)
function runWithScope(context, func, args)
{
var functionInScope = context.ctx.compileFunction(context.scope, String(func), "<runWithScope>", 1, null);
var result = functionInScope.apply(context.scope, args);
context.scope.require('browser/timeout').serviceTimeouts();
return result;
}
// does a shallow copy of an object. if onlyList is true, it sets each property to "true" instead of the actual value
function cloneProperties(object, onlyList)
{