Some renaming.

Reviewed by me.
This commit is contained in:
Francisco Ryan Tolmasky I committed 2010-02-14 19:17:50 -08:00
1 parent 2564003c85
commit f12b4520f6
6 files changed
+110 -119

No files matched your search

+8 -9
View File
@@ -1,23 +1,24 @@
var cwd = FILE.cwd(),
root = new StaticResourceNode("", NULL, StaticResourceNode.DirectoryType, cwd !== "/"),
rootNode = root;
rootResource = new StaticResource("", NULL, StaticResource.DirectoryType, cwd !== "/");
StaticResource.root = rootResource;
#ifdef BROWSER
if (root.isResolved())
if (rootResource.isResolved())
{
root.nodeAtSubPath(FILE.dirname(cwd), YES);
rootResource.nodeAtSubPath(FILE.dirname(cwd), YES);
resolveCWD();
}
else
{
root.resolve();
root.addEventListener("resolve", resolveCWD);
rootResource.resolve();
rootResource.addEventListener("resolve", resolveCWD);
}
function resolveCWD()
{
root.resolveSubPath(cwd, StaticResourceNode.DirectoryType, function(/*StaticResource*/ aResource)
rootResource.resolveSubPath(cwd, StaticResource.DirectoryType, function(/*StaticResource*/ aResource)
{
var includePaths = exports.includePaths(),
index = 0,
@@ -56,6 +57,4 @@ afterDocumentLoad(function()
});
#endif
exports.rootNode = rootNode;
makeExportsGlobal();
+18 -17
View File
@@ -23,7 +23,7 @@ function CFBundle(/*String*/ aPath)
this._path = aPath;
this._name = FILE.basename(aPath);
this._staticResourceNode = NULL;
this._staticResource = NULL;
this._loadStatus = CFBundleUnloaded;
this._loadRequests = [];
@@ -163,22 +163,22 @@ CFBundle.prototype.load = function(/*BOOL*/ shouldExecute)
var self = this;
rootNode.resolveSubPath(FILE.dirname(self.path()), StaticResourceNode.DirectoryType, function(aStaticResourceNode)
rootResource.resolveSubPath(FILE.dirname(self.path()), StaticResource.DirectoryType, function(aStaticResource)
{
var path = self.path();
// If this bundle exists at the root path, no need to create a node.
if (path === "/")
self._staticResourceNode = rootNode;
self._staticResource = rootResource;
else
{
var name = FILE.basename(path);
self._staticResourceNode = aStaticResourceNode._childNodes[name];
self._staticResource = aStaticResource._children[name];
if (!self._staticResourceNode)
self._staticResourceNode = new StaticResourceNode(name, aStaticResourceNode, StaticResourceNode.DirectoryType, NO);
if (!self._staticResource)
self._staticResource = new StaticResource(name, aStaticResource, StaticResource.DirectoryType, NO);
}
function onsuccess(/*Event*/ anEvent)
@@ -209,7 +209,7 @@ CFBundle.prototype.load = function(/*BOOL*/ shouldExecute)
function finishBundleLoadingWithError(/*CFBundle*/ aBundle, /*Event*/ anError)
{
resolveStaticResource(aBundle._staticResourceNode);
resolveStaticResource(aBundle._staticResource);
aBundle._eventDispatcher.dispatchEvent(
{
@@ -254,7 +254,7 @@ function loadExecutableAndResources(/*Bundle*/ aBundle, /*BOOL*/ shouldExecute)
// Set resolved to true here in case during evaluation this bundle
// needs to resolve another bundle which in turn needs it to be resolved (cycle).
resolveStaticResource(aBundle._staticResourceNode);
resolveStaticResource(aBundle._staticResource);
function complete()
{
@@ -421,14 +421,14 @@ CFBundle.dataContentsAtPath = function(/*String*/ aPath)
{
var data = new CFMutableData();
data.setEncodedString(rootNode.nodeAtSubPath(aPath).contents());
data.setEncodedString(rootResource.nodeAtSubPath(aPath).contents());
return data;
}
function executeBundle(/*Bundle*/ aBundle)
{
var staticResources = [aBundle._staticResourceNode];
var staticResources = [aBundle._staticResource];
function executeStaticResources(staticResources, index)
{
@@ -436,7 +436,7 @@ function executeBundle(/*Bundle*/ aBundle)
{
var staticResource = staticResources[index];
if (staticResource.type() === StaticResourceNode.FileType)
if (staticResource.type() === StaticResource.FileType)
{
var executable = new FileExecutable(staticResource.path());
@@ -479,7 +479,8 @@ function decompileStaticFile(/*Bundle*/ aBundle, /*String*/ aString)
throw new Error("Could not read static file.");
var marker,
bundlePath = aBundle.path();
bundlePath = aBundle.path(),
file = NULL;
while (marker = stream.getMarker())
{
@@ -488,9 +489,9 @@ function decompileStaticFile(/*Bundle*/ aBundle, /*String*/ aString)
if (marker === MARKER_PATH)
{
var absolutePath = FILE.join(bundlePath, text),
parentNode = rootNode.nodeAtSubPath(FILE.dirname(absolutePath), YES);
parent = rootResource.nodeAtSubPath(FILE.dirname(absolutePath), YES);
fileNode = new StaticResourceNode(FILE.basename(absolutePath), parentNode, StaticResourceNode.FileType, YES);
file = new StaticResource(FILE.basename(absolutePath), parent, StaticResource.FileType, YES);
}
else if (marker === MARKER_URI)
@@ -503,13 +504,13 @@ function decompileStaticFile(/*Bundle*/ aBundle, /*String*/ aString)
aBundle._URIMap[text] = URI;
// The unresolved directories must not be bundles.
var parentNode = rootNode.nodeAtSubPath(FILE.join(bundlePath, FILE.dirname(text)), YES);
var parent = rootResource.nodeAtSubPath(FILE.join(bundlePath, FILE.dirname(text)), YES);
new StaticResourceNode(FILE.basename(text), parentNode, StaticResourceNode.FileType, YES);
new StaticResource(FILE.basename(text), parent, StaticResource.FileType, YES);
}
else if (marker === MARKER_TEXT)
fileNode.write(text);
file.write(text);
}
}
+1 -1
View File
@@ -34,7 +34,7 @@ function FileExecutable(/*String*/ aPath)
FileExecutablesForPaths[aPath] = this;
var fileContents = rootNode.nodeAtSubPath(aPath).contents(),
var fileContents = rootResource.nodeAtSubPath(aPath).contents(),
executable = NULL;
if (!fileContents.match(/^@STATIC;/))
+5 -5
View File
@@ -43,12 +43,12 @@ function FileExecutableSearch(/*String*/ aPath, /*BOOL*/ isLocal)
var self = this;
function completed(/*String*/ aStaticResourceNode)
function completed(/*String*/ aStaticResource)
{
if (!aStaticResourceNode)
if (!aStaticResource)
throw new Error("Could not load file at " + aPath);
self._result = new FileExecutable(aStaticResourceNode.path());
self._result = new FileExecutable(aStaticResource.path());
self._isComplete = YES;
self._eventDispatcher.dispatchEvent(
@@ -59,9 +59,9 @@ function FileExecutableSearch(/*String*/ aPath, /*BOOL*/ isLocal)
}
if (isLocal)
rootNode.resolveSubPath(aPath, StaticResourceNode.FileType, completed);
rootResource.resolveSubPath(aPath, StaticResource.FileType, completed);
else
StaticResourceNode.resolveStandardNodeAtPath(aPath, completed);
StaticResource.resolveStandardNodeAtPath(aPath, completed);
}
FileExecutableSearch.prototype.path = function()
+70 -79
View File
@@ -113,37 +113,28 @@ else
#endif
StaticResourceNode.FileType = 0;
StaticResourceNode.DirectoryType = 1;
StaticResourceNode.NotFoundType = 2;
StaticResource.FileType = 0;
StaticResource.DirectoryType = 1;
StaticResource.NotFoundType = 2;
function StaticResourceNode(/*String*/ aName, /*StaticResourceNode*/ aParentNode, /*Type*/ aType, /*BOOL*/ isResolved)
function StaticResource(/*String*/ aName, /*StaticResource*/ aParent, /*Type*/ aType, /*BOOL*/ isResolved)
{
this._parentNode = aParentNode;
this._rootNode = aParentNode ? aParentNode._rootNode : this;
this._parent = aParent;
this._eventDispatcher = new EventDispatcher(this);
this._name = aName;
this._isResolved = !!isResolved;
if (!aParentNode)
this._path = "/";
else if (aParentNode === this._rootNode)
this._path = "/" + aName;
else
this._path = aParentNode.path() + "/" + aName;
this._path = FILE.join(aParent ? aParent.path() : "", aName);
this._type = aType;
if (aParentNode)
aParentNode._childNodes[aName] = this;
if (aParent)
aParent._children[aName] = this;
if (aType === StaticResourceNode.DirectoryType)
this._childNodes = { };
if (aType === StaticResource.DirectoryType)
this._children = { };
else if (aType === StaticResourceNode.FileType)
else if (aType === StaticResource.FileType)
this._contents = "";
}
@@ -153,13 +144,13 @@ function resolveStaticResource(/*StaticResource*/ aResource)
aResource._eventDispatcher.dispatchEvent(
{
type:"resolve",
staticResourceNode:aResource
staticResource:aResource
});
}
StaticResourceNode.prototype.resolve = function()
StaticResource.prototype.resolve = function()
{
if (this.type() === StaticResourceNode.DirectoryType)
if (this.type() === StaticResource.DirectoryType)
{
var bundle = new CFBundle(this.path());
@@ -181,7 +172,7 @@ StaticResourceNode.prototype.resolve = function()
function onfailure()
{
self._type = StaticResourceNode.NotFoundType;
self._type = StaticResource.NotFoundType;
resolveStaticResource(self);
}
@@ -189,183 +180,183 @@ StaticResourceNode.prototype.resolve = function()
}
}
StaticResourceNode.prototype.name = function()
StaticResource.prototype.name = function()
{
return this._name;
}
StaticResourceNode.prototype.path = function()
StaticResource.prototype.path = function()
{
return this._path;
}
StaticResourceNode.prototype.contents = function()
StaticResource.prototype.contents = function()
{
return this._contents;
}
StaticResourceNode.prototype.type = function()
StaticResource.prototype.children = function()
{
return this._children;
}
StaticResource.prototype.type = function()
{
return this._type;
}
StaticResourceNode.prototype.parentNode = function()
StaticResource.prototype.parent = function()
{
return this._parentNode;
return this._parent;
}
StaticResourceNode.prototype.rootNode = function()
{
return this._rootNode;
}
StaticResourceNode.prototype.isResolved = function()
StaticResource.prototype.isResolved = function()
{
return this._isResolved;
}
StaticResourceNode.prototype.write = function(/*String*/ aString)
StaticResource.prototype.write = function(/*String*/ aString)
{
this._contents += aString;
}
StaticResourceNode.prototype.resolveSubPath = function(/*String*/ aPath, /*Type*/ aType, /*Function*/ aCallback)
StaticResource.prototype.resolveSubPath = function(/*String*/ aPath, /*Type*/ aType, /*Function*/ aCallback)
{
aPath = FILE.normal(aPath);
if (aPath === "/")
return aCallback(rootNode);
return aCallback(rootResource);
if (!FILE.isAbsolute(aPath))
aPath = FILE.join(this.path(), aPath);
var components = FILE.split(aPath),
index = this === this.rootNode() ? 1 : FILE.split(this.path()).length;
index = this === rootResource ? 1 : FILE.split(this.path()).length;
resolvePathComponents(this, aType, components, index, aCallback);
}
function resolvePathComponents(/*StaticResourceNode*/ startNode, /*Type*/aType, /*Array*/ components, /*Integer*/ index, /*Function*/ aCallback)
function resolvePathComponents(/*StaticResource*/ startResource, /*Type*/aType, /*Array*/ components, /*Integer*/ index, /*Function*/ aCallback)
{
var count = components.length,
parentNode = startNode;
parent = startResource;
function continueResolution()
{
resolvePathComponents(parentNode, aType, components, index, aCallback);
resolvePathComponents(parent, aType, components, index, aCallback);
}
for (; index < count; ++index)
{
var name = components[index],
childNode = parentNode._childNodes[name];
child = parent._children[name];
//CPLog(index + " " + components + ":" + (childNode && childNode.isResolved()) + ":");
//CPLog(name + " of " + parentNode.name() + " " + (childNode && childNode.name()));
//CPLog(parentNode._childNodes);
// + "(" + components + ")" + " " + index + "/" + count + ":" + (childNode && childNode.name()) +">" + (childNode ? 1:0) + " " + (childNode && childNode.isResolved()));
if (!childNode)
if (!child)
{
var type = index + 1 < count || aType === StaticResourceNode.DirectoryType ? StaticResourceNode.DirectoryType : StaticResourceNode.FileType;
var type = index + 1 < count || aType === StaticResource.DirectoryType ? StaticResource.DirectoryType : StaticResource.FileType;
childNode = new StaticResourceNode(name, parentNode, type, NO);
childNode.resolve();
child = new StaticResource(name, parent, type, NO);
child.resolve();
}
// If this node is still being resolved, just wait and rerun this same method when it's ready.
if (!childNode.isResolved())
return childNode.addEventListener("resolve", continueResolution);
// If this resource is still being resolved, just wait and rerun this same method when it's ready.
if (!child.isResolved())
return child.addEventListener("resolve", continueResolution);
// If we've already determined that this file doesn't exist...
if (childNode.isNotFound())
if (child.isNotFound())
return aCallback(null, new Error("File not found: " + components.join("/")));
// If we have more path components and this is not a directory...
if ((index + 1 < count) && childNode.type() !== StaticResourceNode.DirectoryType)
if ((index + 1 < count) && child.type() !== StaticResource.DirectoryType)
return aCallback(null, new Error("File is not a directory: " + components.join("/")));
parentNode = childNode;
parent = child;
}
return aCallback(parentNode);
return aCallback(parent);
}
StaticResourceNode.prototype.addEventListener = function(/*String*/ anEventName, /*Function*/ anEventListener)
StaticResource.prototype.addEventListener = function(/*String*/ anEventName, /*Function*/ anEventListener)
{
this._eventDispatcher.addEventListener(anEventName, anEventListener);
}
StaticResourceNode.prototype.removeEventListener = function(/*String*/ anEventName, /*Function*/ anEventListener)
StaticResource.prototype.removeEventListener = function(/*String*/ anEventName, /*Function*/ anEventListener)
{
this._eventDispatcher.removeEventListener(anEventName, anEventListener);
}
StaticResourceNode.prototype.isNotFound = function()
StaticResource.prototype.isNotFound = function()
{
return this.type() === StaticResourceNode.NotFoundType;
return this.type() === StaticResource.NotFoundType;
}
StaticResourceNode.prototype.toString = function(/*BOOL*/ includeNotFounds)
StaticResource.prototype.toString = function(/*BOOL*/ includeNotFounds)
{
if (this.isNotFound())
return "<file not found: " + this.name() + ">";
var string = this.parentNode() ? this.name() : "/",
var string = this.parent() ? this.name() : "/",
type = this.type();
if (type === StaticResourceNode.DirectoryType)
if (type === StaticResource.DirectoryType)
{
var childNodes = this._childNodes;
var children = this._children;
for (var name in childNodes)
if (childNodes.hasOwnProperty(name))
for (var name in children)
if (children.hasOwnProperty(name))
{
var childNode = childNodes[name];
var child = children[name];
if (includeNotFounds || !childNode.isNotFound())
string += "\n\t" + childNodes[name].toString(includeNotFounds).split('\n').join("\n\t");
if (includeNotFounds || !child.isNotFound())
string += "\n\t" + children[name].toString(includeNotFounds).split('\n').join("\n\t");
}
}
return string;
}
StaticResourceNode.prototype.nodeAtSubPath = function(/*String*/ aPath, /*BOOL*/ shouldResolveAsDirectories)
StaticResource.prototype.nodeAtSubPath = function(/*String*/ aPath, /*BOOL*/ shouldResolveAsDirectories)
{
aPath = FILE.normal(aPath);
var components = FILE.split(FILE.isAbsolute(aPath) ? aPath : FILE.join(this.path(), aPath)),
index = 1,
count = components.length,
parentNode = this.rootNode();
parent = rootResource;
for (; index < count; ++index)
{
var name = components[index];
if (hasOwnProperty.call(parentNode._childNodes, name))
parentNode = parentNode._childNodes[name];
if (hasOwnProperty.call(parent._children, name))
parent = parent._children[name];
else if (shouldResolveAsDirectories)
parentNode = new StaticResourceNode(name, parentNode, StaticResourceNode.DirectoryType, YES);
parent = new StaticResource(name, parent, StaticResource.DirectoryType, YES);
else
throw NULL;
}
return parentNode;
return parent;
}
StaticResourceNode.resolveStandardNodeAtPath = function(/*String*/ aPath, /*Function*/ aCallback)
StaticResource.resolveStandardNodeAtPath = function(/*String*/ aPath, /*Function*/ aCallback)
{
var includePaths = exports.includePaths(),
resolveStandardNodeAtPath = function(/*String*/ aPath, /*int*/ anIndex)
{
var searchPath = FILE.absolute(FILE.join(includePaths[anIndex], FILE.normal(aPath)));
rootNode.resolveSubPath(searchPath, StaticResourceNode.FileType, function(/*StaticResourceNode*/ aStaticResourceNode)
rootResource.resolveSubPath(searchPath, StaticResource.FileType, function(/*StaticResource*/ aStaticResource)
{
if (!aStaticResourceNode)
if (!aStaticResource)
{
if (anIndex + 1< includePaths.length)
resolveStandardNodeAtPath(aPath, anIndex + 1);
@@ -375,7 +366,7 @@ StaticResourceNode.resolveStandardNodeAtPath = function(/*String*/ aPath, /*Func
return;
}
aCallback(aStaticResourceNode);
aCallback(aStaticResource);
});
};
@@ -387,4 +378,4 @@ exports.includePaths = function()
return global.OBJJ_INCLUDE_PATHS || ["Frameworks", "Frameworks/Debug"];
}
exports.StaticResourceNode = StaticResourceNode;
exports.StaticResource = StaticResource;
+8 -8
View File
@@ -36,7 +36,7 @@ function main(args)
analyzer.load(rootPath.join("main.j"));
analyzer.finishLoading();
var rootNode = analyzer.require("objective-j").rootNode;
var rootNode = analyzer.require("objective-j").StaticResource.root;
print("rootNode="+rootNode);
var buffer = [];
@@ -44,7 +44,7 @@ function main(args)
buffer.push("var nodeStack = [];");
buffer.push("var currentNode = null;");
buffer.push("var newNode;")
serializeStaticResourceNodes(buffer, rootNode);
serializeStaticResources(buffer, rootNode);
buffer.push("})();");
var code = buffer.join("\n");
@@ -53,14 +53,14 @@ function main(args)
rootPath.join("Application.js").write(code);
}
function serializeStaticResourceNodes(buffer, node, depth) {
function serializeStaticResource(buffer, node, depth) {
depth = depth || 0;
//print(Array(depth+1).join(" ") + node);
// not the root node:
if (node.parentNode()) {
buffer.push("newNode = new StaticResourceNode(" +
if (node.parent()) {
buffer.push("newNode = new StaticResource(" +
JSON.stringify(node.name()) +
", currentNode, " +
JSON.stringify(node.type()) + ", " +
@@ -72,14 +72,14 @@ function serializeStaticResourceNodes(buffer, node, depth) {
if (node.contents())
buffer.push("newNode._contents = " + JSON.stringify(node.contents()) + ";");
if (!node._childNodes)
if (!node.children())
return;
buffer.push("nodeStack.push(currentNode);");
buffer.push("currentNode = newNode;");
for (var name in node._childNodes) {
serializeStaticResourceNodes(buffer, node._childNodes[name], depth+1);
for (var name in node.children()) {
serializeStaticResources(buffer, node.children()[name], depth+1);
}
buffer.push("currentNode = nodeStack.pop();");