diff --git a/Objective-J/Bootstrap.js b/Objective-J/Bootstrap.js index 42b523d06..bf3bcace0 100644 --- a/Objective-J/Bootstrap.js +++ b/Objective-J/Bootstrap.js @@ -17,7 +17,7 @@ rootNode.resolveSubPath(cwd, StaticResourceNode.DirectoryType, function(cwdNode) #ifdef BROWSER OBJJ_MAIN_FILE = "main.j"; - fileImporterForPath(FILE.join(cwd, "main.j"))("main.j", YES, function() + fileImporterForPath(cwd)("main.j", YES, function() { afterDocumentLoad(main); }); diff --git a/Objective-J/CommonJS/lib/objective-j.js b/Objective-J/CommonJS/lib/objective-j.js index bb856ecf1..64a92ff5b 100644 --- a/Objective-J/CommonJS/lib/objective-j.js +++ b/Objective-J/CommonJS/lib/objective-j.js @@ -111,6 +111,30 @@ exports.run = function(args) } } +function objj_eval(/*String*/ aString) +{ + // We need this while code still refers to window. + Executable.setCommonJSArguments(require, exports, module, system, print, window); + + var executable = preprocess(aString, "", 0); + + if (!executable.hasLoadedFileDependencies()) + executable.loadFileDependencies(); + + // A bit of a hack. Executable compiles the code itself into a function, but we want + // the raw code to eval here. + var code = executable._code; + + // Not clear why these should be global, varing them doesn't seem to take effect with evaluateString. + global.objj_executeFile = fileExecuterForPath(FILE.cwd()); + global.objj_importFile = fileImporterForPath(FILE.cwd()); + + if (typeof system !== "undefined" && system.engine === "rhino") + return Packages.org.mozilla.javascript.Context.getCurrentContext().evaluateString(global, code, "objj_eval", 0, NULL); + + return eval(code); +} + Executable.setCommonJSParameters("require", "exports", "module", "system", "print", "window"); // creates a narwhal factory function in the objj module scope @@ -120,7 +144,7 @@ exports.make_narwhal_factory = function(path) { Executable.setCommonJSArguments(require, exports, module, system, print, window); - fileImporterForPath(path)(FILE.basename(path), function() + fileImporterForPath(FILE.dirname(path))(path, function() { print("all done"); }); diff --git a/Objective-J/Executable.js b/Objective-J/Executable.js index aa714ebe3..d838db98e 100644 --- a/Objective-J/Executable.js +++ b/Objective-J/Executable.js @@ -86,8 +86,8 @@ Executable.prototype.functionParameters = function() Executable.prototype.functionArguments = function() { - var path = this.path(), - functionArguments = [global, fileExecuterForPath(path), fileImporterForPath(path)]; + var dirname = FILE.dirname(this.path()), + functionArguments = [global, fileExecuterForPath(dirname), fileImporterForPath(dirname)]; //functionArguments = exportedValues().concat(fileExecuterForPath(path), fileImporterForPath(path)); @@ -170,9 +170,8 @@ Executable.prototype.loadFileDependencies = function() var searchedPaths = [{ }, { }], foundExecutablePaths = { }, fileExecutableSearches = new CFMutableDictionary(), - incompleteFileExecutableSearches = new CFMutableDictionary(); - - foundExecutablePaths[this.path()] = this; + incompleteFileExecutableSearches = new CFMutableDictionary(), + executablesNeedingEventDispatch = [this]; function searchForFileDependencies(/*Executable*/ anExecutable) { @@ -249,7 +248,6 @@ Executable.prototype.loadFileDependencies = function() CPLog("DEPENDENCY: Ended"); #end - var fileExecutablesNeedingEventDispatch = []; for (var executablePath in foundExecutablePaths) if (hasOwnProperty.apply(foundExecutablePaths, [executablePath])) @@ -259,16 +257,16 @@ Executable.prototype.loadFileDependencies = function() if (fileExecutable.hasLoadedFileDependencies()) continue; - fileExecutablesNeedingEventDispatch.push(fileExecutable); + executablesNeedingEventDispatch.push(fileExecutable); fileExecutable._fileDependencyLoadStatus = FileExecutableLoadedDependencies; } var index = 0, - count = fileExecutablesNeedingEventDispatch.length; + count = executablesNeedingEventDispatch.length; for (; index < count; ++index) { - var fileExecutable = fileExecutablesNeedingEventDispatch[index]; + var fileExecutable = executablesNeedingEventDispatch[index]; fileExecutable._eventDispatcher.dispatchEvent( { diff --git a/Objective-J/Scope.js b/Objective-J/Scope.js index bf7cab3e5..e39243776 100644 --- a/Objective-J/Scope.js +++ b/Objective-J/Scope.js @@ -24,15 +24,15 @@ var cachedFileExecutersForPaths = { }; function fileExecuterForPath(/*String*/ referencePath) { + referencePath = FILE.normal(referencePath); + var fileExecuter = cachedFileExecutersForPaths[referencePath]; if (!fileExecuter) { - var dirname = FILE.dirname(referencePath); - fileExecuter = function(/*String*/ aPath, /*BOOL*/ isLocal, /*BOOL*/ shouldForce) { - aPath = importablePath(aPath, isLocal, dirname); + aPath = importablePath(aPath, isLocal, referencePath); var fileExecutableSearch = new FileExecutableSearch(aPath, isLocal), fileExecutable = fileExecutableSearch.result(); @@ -53,15 +53,15 @@ var cachedImportersForPaths = { }; function fileImporterForPath(/*String*/ referencePath) { + referencePath = FILE.normal(referencePath); + var cachedImporter = cachedImportersForPaths[referencePath]; if (!cachedImporter) { - var dirname = FILE.dirname(referencePath); - cachedImporter = function(/*String*/ aPath, /*BOOL*/ isLocal, /*Function*/ aCallback) { - aPath = importablePath(aPath, isLocal, dirname); + aPath = importablePath(aPath, isLocal, referencePath); var fileExecutableSearch = new FileExecutableSearch(aPath, isLocal);