From 4b7310d0cb2e07b6268f3833b021d6ddba2f33f5 Mon Sep 17 00:00:00 2001 From: Francisco Ryan Tolmasky I Date: Fri, 29 Jan 2010 15:16:22 -0800 Subject: [PATCH] More consistent naming scheme. Reviewed by me. --- Foundation/CPBundle.j | 21 +- Foundation/CPData.j | 6 +- Objective-J/Bootstrap.js | 4 +- Objective-J/{Bundle.js => CFBundle.js} | 184 +++++++++++------- Objective-J/{Data.js => CFData.js} | 37 ++-- .../{Dictionary.js => CFDictionary.js} | 47 +++-- .../{PropertyList.js => CFPropertyList.js} | 128 ++++++------ .../lib/objective-j/jake/bundletask.js | 10 +- Objective-J/Executable.js | 16 +- Objective-J/HTTPRequest.js | 8 +- Objective-J/Includes.js | 8 +- Objective-J/Runtime.js | 8 +- Objective-J/Scope.js | 36 +--- Objective-J/StaticResourceNode.js | 2 +- 14 files changed, 269 insertions(+), 246 deletions(-) rename Objective-J/{Bundle.js => CFBundle.js} (55%) rename Objective-J/{Data.js => CFData.js} (80%) rename Objective-J/{Dictionary.js => CFDictionary.js} (68%) rename Objective-J/{PropertyList.js => CFPropertyList.js} (76%) diff --git a/Foundation/CPBundle.j b/Foundation/CPBundle.j index 663ccdde3..d49d3d3a2 100644 --- a/Foundation/CPBundle.j +++ b/Foundation/CPBundle.j @@ -36,6 +36,7 @@ var CPBundlesForPaths = { }; @implementation CPBundle : CPObject { CFBundle _bundle; + id _delegate; } + (CPBundle)bundleWithPath:(CPString)aPath @@ -125,11 +126,10 @@ var CPBundlesForPaths = { }; - (void)loadWithDelegate:(id)aDelegate { - _bundle.load(); + _delegate = aDelegate; _bundle.addEventListener("load", function() { -// if (!fileExecutable.hasLoadedFileDependencies()) [_delegate bundleDidFinishLoading:self]; }); @@ -137,6 +137,21 @@ var CPBundlesForPaths = { }; { CPLog.error("Could not find bundle: " + self); }); + + _bundle.load(NO); +} + +- (CPArray)staticResourceURLs +{ + var staticResourceURLs = [], + staticResources = _bundle.staticResources(), + index = 0, + count = [staticResources count]; + + for (; index < count; ++index) + [staticResourceURLs addObject:[CPURL URLWithString:staticResources[index].path()]]; + + return staticResourceURLs; } - (CPArray)environments @@ -151,7 +166,7 @@ var CPBundlesForPaths = { }; - (CPString)description { - return [super description] + "(" + path + ")"; + return [super description] + "(" + [self bundlePath] + ")"; } @end diff --git a/Foundation/CPData.j b/Foundation/CPData.j index 545ef3d35..a418362e4 100644 --- a/Foundation/CPData.j +++ b/Foundation/CPData.j @@ -37,7 +37,7 @@ + (id)alloc { - return new MutableData(); + return new CFMutableData(); } + (CPData)data @@ -127,5 +127,5 @@ @end -Data.prototype.isa = CPData; -MutableData.prototype.isa = CPData; +CFData.prototype.isa = CPData; +CFMutableData.prototype.isa = CPData; diff --git a/Objective-J/Bootstrap.js b/Objective-J/Bootstrap.js index fb314e625..7ac03d270 100644 --- a/Objective-J/Bootstrap.js +++ b/Objective-J/Bootstrap.js @@ -3,10 +3,11 @@ makeExportsGlobal(); var rootNode = new StaticResourceNode("", null, StaticResourceNode.DirectoryType, YES), cwd = FILE.cwd(); - +#ifndef COMMONJS rootNode.nodeAtSubPath(FILE.dirname(cwd), YES); rootNode.resolveSubPath(cwd, StaticResourceNode.DirectoryType, function(cwdNode) { + var includePaths = exports.includePaths(), index = 0, count = includePaths.length; @@ -22,6 +23,7 @@ rootNode.resolveSubPath(cwd, StaticResourceNode.DirectoryType, function(cwdNode) }); #endif }); +#endif #ifdef BROWSER function afterDocumentLoad(/*Function*/ aFunction) diff --git a/Objective-J/Bundle.js b/Objective-J/CFBundle.js similarity index 55% rename from Objective-J/Bundle.js rename to Objective-J/CFBundle.js index d673e0d1b..ce79d083d 100644 --- a/Objective-J/Bundle.js +++ b/Objective-J/CFBundle.js @@ -1,41 +1,41 @@ +var CFBundleUnloaded = 0, + CFBundleLoading = 1 << 0, + CFBundleLoadingInfoPlist = 1 << 1, + CFBundleLoadingExecutable = 1 << 2, + CFBundleLoadingResources = 1 << 3, + CFBundleLoaded = 1 << 4; -Bundle.Unloaded = 0; -Bundle.Loading = 1 << 0; -Bundle.LoadingInfoPlist = 1 << 1; -Bundle.LoadingExecutable = 1 << 2; -Bundle.LoadingResources = 1 << 3; -Bundle.Loaded = 1 << 4; +var CFBundlesForPaths = { }, + CFBundlesForClasses = { }; -var BundlesForPaths = { }; - -function Bundle(/*String*/ aPath) +function CFBundle(/*String*/ aPath) { aPath = FILE.absolute(aPath); - var existingBundle = BundlesForPaths[aPath]; + var existingBundle = CFBundlesForPaths[aPath]; if (existingBundle) return existingBundle; -console.log("created bundle for " + aPath); - BundlesForPaths[aPath] = this; +CPLog("created bundle for " + aPath); + CFBundlesForPaths[aPath] = this; this._path = aPath; this._name = FILE.basename(aPath); - this._loadStatus = Bundle.Unloaded; + this._loadStatus = CFBundleUnloaded; this._staticResourceNode = NULL; this._infoDictionary = NULL; this._eventDispatcher = new EventDispatcher(this); } -Bundle.bundleContainingPath = function(/*String*/ aPath) +CFBundle.bundleContainingPath = function(/*String*/ aPath) { aPath = FILE.absolute(aPath); while (aPath !== "/") { - var bundle = BundlesForPaths[aPath]; + var bundle = CFBundlesForPaths[aPath]; if (bundle) return bundle; @@ -46,40 +46,38 @@ Bundle.bundleContainingPath = function(/*String*/ aPath) return NULL; } -Bundle.mainBundle = function() +CFBundle.mainBundle = function() { - return new Bundle(FILE.cwd()); + return new CFBundle(FILE.cwd()); } -var bundlesForClasses = { }; - function addClassToBundle(aClass, aBundle) { if (aBundle) - bundlesForClasses[aClass.name] = aBundle; + CFBundlesForClasses[aClass.name] = aBundle; } -Bundle.bundleForClass = function(/*Class*/ aClass) +CFBundle.bundleForClass = function(/*Class*/ aClass) { - return bundlesForClasses[aClass.name] || Bundle.mainBundle(); + return CFBundlesForClasses[aClass.name] || CFBundle.mainBundle(); } -Bundle.prototype.path = function() +CFBundle.prototype.path = function() { return this._path; } -Bundle.prototype.infoDictionary = function() +CFBundle.prototype.infoDictionary = function() { return this._infoDictionary; } -Bundle.prototype.valueForInfoDictionary = function(/*String*/ aKey) +CFBundle.prototype.valueForInfoDictionary = function(/*String*/ aKey) { return this._infoDictionary.valueForKey(aKey); } -Bundle.prototype.executablePath = function() +CFBundle.prototype.executablePath = function() { var executableSubPath = this._infoDictionary.valueForKey("CPBundleExecutable"); @@ -89,12 +87,12 @@ Bundle.prototype.executablePath = function() return NULL; } -Bundle.prototype.environments = function() +CFBundle.prototype.environments = function() { return this._infoDictionary.valueForKey("CPBundleEnvironments") || ["ObjJ"]; } -Bundle.prototype.mostEligibleEnvironment = function(/*Array*/ environments) +CFBundle.prototype.mostEligibleEnvironment = function(/*Array*/ environments) { environments = environments || this.environments(); @@ -117,30 +115,27 @@ Bundle.prototype.mostEligibleEnvironment = function(/*Array*/ environments) return NULL; } -Bundle.prototype.isLoading = function() +CFBundle.prototype.isLoading = function() { - return this._loadStatus & Bundle.Loading; + return this._loadStatus & CFBundleLoading; } -Bundle.prototype.load = function(/*BOOL*/ shouldEvaluate) +CFBundle.prototype.load = function(/*BOOL*/ shouldExecute) { - if (this._loadStatus !== Bundle.Unloaded) + if (this._loadStatus !== CFBundleUnloaded) return; var self = this; - self._loadStatus = Bundle.Loading | Bundle.LoadingInfoPlist; -/* print(FILE.cwd()); - print(self.path()); - print(rootNode); -print("will resolve: " + FILE.dirname(self.path()));*/ + self._loadStatus = CFBundleLoading | CFBundleLoadingInfoPlist; + rootNode.resolveSubPath(FILE.dirname(self.path()), StaticResourceNode.DirectoryType, function(aStaticResourceNode) - {//print("found: " + FILE.dirname(self.path())); + { self._staticResourceNode = new StaticResourceNode(FILE.basename(self.path()), aStaticResourceNode, StaticResourceNode.DirectoryType, NO); function onsuccess(/*Event*/ anEvent) { - self._loadStatus &= ~Bundle.LoadingInfoPlist; + self._loadStatus &= ~CFBundleLoadingInfoPlist; self._infoDictionary = anEvent.request.responsePropertyList(); if (!self._infoDictionary) @@ -154,12 +149,13 @@ print("will resolve: " + FILE.dirname(self.path()));*/ return; } - loadExecutableAndResources(self); + loadExecutableAndResources(self, shouldExecute); } function onfailure() { - self._loadStatus = Bundle.Unloaded; + self._staticResourceNode._isResolved = YES; + self._loadStatus = CFBundleUnloaded; self._eventDispatcher.dispatchEvent( { type:"error", @@ -171,9 +167,9 @@ print("will resolve: " + FILE.dirname(self.path()));*/ }); } -function loadExecutableAndResources(/*Bundle*/ aBundle) +function loadExecutableAndResources(/*Bundle*/ aBundle, /*BOOL*/ shouldExecute) { - aBundle._loadStatus |= (aBundle.executablePath() && Bundle.LoadingExecutable); + aBundle._loadStatus |= (aBundle.executablePath() && CFBundleLoadingExecutable); //aBundle._loadStatus |= (aBundle.mappedResourcesPath() && Bundle.LoadingResources); function failure() @@ -190,7 +186,7 @@ function loadExecutableAndResources(/*Bundle*/ aBundle) aBundle._loadResourcesRequest = NULL; } - aBundle._loadStatus = Bundle.Unloaded; + aBundle._loadStatus = CFBundleUnloaded; resolveStaticResourceNode(aBundle._staticResourceNode, NO); @@ -206,48 +202,96 @@ function loadExecutableAndResources(/*Bundle*/ aBundle) function success() { - if (aBundle._loadStatus === Bundle.Loading) - aBundle._loadStatus = Bundle.Loaded; + if (aBundle._loadStatus === CFBundleLoading) + aBundle._loadStatus = CFBundleLoaded; + // 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). resolveStaticResourceNode(aBundle._staticResourceNode, NO); - aBundle._eventDispatcher.dispatchEvent( - { - type:"load", - bundle:aBundle - }); + function complete() + {CPLog("COMPLETED"); + aBundle._eventDispatcher.dispatchEvent( + { + type:"load", + bundle:aBundle + }); + + resolveStaticResourceNode(aBundle._staticResourceNode, YES); + } - resolveStaticResourceNode(aBundle._staticResourceNode, YES); +CPLog("IN HErE FOR " + aBundle.path()); + if (shouldExecute) + executeBundle(aBundle, complete); + else + complete(); } - if (aBundle._loadStatus === Bundle.Loading) + if (aBundle._loadStatus === CFBundleLoading) return success(); if (!aBundle.mostEligibleEnvironment()) failure(); - if (aBundle._loadStatus & Bundle.LoadingExecutable) + if (aBundle._loadStatus & CFBundleLoadingExecutable) { - aBundle._loadExecutableRequest = new HTTPRequest(); - - var loadExecutableRequest = aBundle._loadExecutableRequest; - - loadExecutableRequest.onsuccess = function() + function executableSuccess(/*Event*/ anEvent) { - decompileExecutable(aBundle, loadExecutableRequest.responseText()); + decompileExecutable(aBundle, anEvent.request.responseText()); - aBundle._loadStatus &= ~Bundle.LoadingExecutable; + aBundle._loadStatus &= ~CFBundleLoadingExecutable; success(); } - - loadExecutableRequest.onfailure = failure; - loadExecutableRequest.open("GET", aBundle.executablePath(), YES); - loadExecutableRequest.send(""); + new FileRequest(aBundle.executablePath(), executableSuccess, failure); } } +CFBundle.dataContentsAtPath = function(/*String*/ aPath) +{ + var data = new CFMutableData(); +CPLog("uh oh"); + data.setEncodedString(rootNode.nodeAtSubPath(aPath).contents()); + CPLog("it is: " + data._encodedString); +CPLog(data.encodedString()); + return data; +} + +function executeBundle(/*Bundle*/ aBundle) +{ + var staticResources = [aBundle._staticResourceNode]; + + function executeStaticResources(staticResources, index) + { + for (; index < staticResources.length; ++index) + { + var staticResource = staticResources[index]; + + if (staticResource.type() === StaticResourceNode.FileType) + { + var executable = new FileExecutable(staticResource.path()); + + if (staticResource.hasLoadedFileDependencies()) + executable.execute(); + + else + { + executable.addEventListeners("dependenciesload", function() + { + executeStaticResources(index); + }); + return; + } + } + else + staticResources = staticResources.concat(staticResource.children()); + } + } + + executeStaticResources(0); +} + var STATIC_MAGIC_NUMBER = "@STATIC", MARKER_PATH = "p", MARKER_URI = "u", @@ -306,21 +350,19 @@ function decompileExecutable(/*Bundle*/ aBundle, /*String*/ aString) // Event Managament -Bundle.prototype.addEventListener = function(/*String*/ anEventName, /*Function*/ anEventListener) +CFBundle.prototype.addEventListener = function(/*String*/ anEventName, /*Function*/ anEventListener) { this._eventDispatcher.addEventListener(anEventName, anEventListener); } -Bundle.prototype.removeEventListener = function(/*String*/ anEventName, /*Function*/ anEventListener) +CFBundle.prototype.removeEventListener = function(/*String*/ anEventName, /*Function*/ anEventListener) { this._eventDispatcher.removeEventListener(anEventName, anEventListener); } -Bundle.prototype.onerror = function(/*Event*/ anEvent) +CFBundle.prototype.onerror = function(/*Event*/ anEvent) { throw anEvent.error; } -exports.Bundle = Bundle; - -exports.CFBundle = Bundle; +exports.CFBundle = CFBundle; diff --git a/Objective-J/Data.js b/Objective-J/CFData.js similarity index 80% rename from Objective-J/Data.js rename to Objective-J/CFData.js index f119f9bca..da5e701ec 100644 --- a/Objective-J/Data.js +++ b/Objective-J/CFData.js @@ -1,5 +1,5 @@ -function Data() +function CFData() { this._encodedString = NULL; this._serializedPropertyList = NULL; @@ -8,22 +8,22 @@ function Data() this._base64 = NULL; } -Data.prototype.serializedPropertyList = function() +CFData.prototype.serializedPropertyList = function() { if (!this._serializedPropertyList) - this._serializedPropertyList = PropertyList.propertyListFromString(this.encodedString()); + this._serializedPropertyList = CFPropertyList.propertyListFromString(this.encodedString()); return this._serializedPropertyList; } -Data.prototype.encodedString = function() +CFData.prototype.encodedString = function() { if (this._encodedString === NULL) { var serializedPropertyList = this._serializedPropertyList; if (this._serializedPropertyList) - this._encodedString = PropertyList.stringFromPropertyList(serializedPropertyList); + this._encodedString = CFPropertyList.stringFromPropertyList(serializedPropertyList); // Ideally we would convert these bytes or base64 into a string. // else if (this._bytes) @@ -36,24 +36,24 @@ Data.prototype.encodedString = function() return this._encodedString; } -Data.prototype.bytes = function() +CFData.prototype.bytes = function() { return this._bytes; } -Data.prototype.base64 = function() +CFData.prototype.base64 = function() { return this._base64; } -function MutableData() +function CFMutableData() { - Data.call(this); + CFData.call(this); } -MutableData.prototype = new Data(); +CFMutableData.prototype = new CFData(); -function clearMutableData(/*MutableData*/ aData) +function clearMutableData(/*CFMutableData*/ aData) { this._encodedString = NULL; this._serializedPropertyList = NULL; @@ -62,28 +62,28 @@ function clearMutableData(/*MutableData*/ aData) this._base64 = NULL; } -MutableData.prototype.setSerializedPropertyList = function(/*PropertyList*/ aPropertyList) +CFMutableData.prototype.setSerializedPropertyList = function(/*PropertyList*/ aPropertyList) { clearMutableData(this); this._serializedPropertyList = aPropertyList; } -MutableData.prototype.setEncodedString = function(/*String*/ aString) +CFMutableData.prototype.setEncodedString = function(/*String*/ aString) { clearMutableData(this); this._encodedString = aString; } -MutableData.prototype.setBytes = function(/*Array*/ bytes) +CFMutableData.prototype.setBytes = function(/*Array*/ bytes) { clearMutableData(this); this._bytes = bytes; } -MutableData.prototype.setBase64String = function(/*String*/ aBase64String) +CFMutableData.prototype.setBase64String = function(/*String*/ aBase64String) { clearMutableData(this); @@ -190,8 +190,5 @@ function base64_encode_string(input) return base64_encode_array(temp); } -exports.Data = Data; -exports.CFData = Data; - -exports.MutableData = MutableData; -exports.CFMutableData = MutableData; +exports.CFData = CFData; +exports.CFMutableData = CFMutableData; diff --git a/Objective-J/Dictionary.js b/Objective-J/CFDictionary.js similarity index 68% rename from Objective-J/Dictionary.js rename to Objective-J/CFDictionary.js index 3f4bfcd47..17a233c91 100644 --- a/Objective-J/Dictionary.js +++ b/Objective-J/CFDictionary.js @@ -1,5 +1,5 @@ -function Dictionary(/*Dictionary*/ aDictionary) +function CFDictionary(/*CFDictionary*/ aDictionary) { this._keys = []; this._count = 0; @@ -10,13 +10,13 @@ function Dictionary(/*Dictionary*/ aDictionary) var indexOf = Array.prototype.indexOf, hasOwnProperty = Object.prototype.hasOwnProperty; -Dictionary.prototype.copy = function() +CFDictionary.prototype.copy = function() { // Immutable, so no need to actually copy. return this; } -Dictionary.prototype.mutableCopy = function() +CFDictionary.prototype.mutableCopy = function() { var newDictionary = new MutableDictionary(), keys = this._keys, @@ -39,12 +39,12 @@ Dictionary.prototype.mutableCopy = function() return newDictionary; } -Dictionary.prototype.containsKey = function(/*String*/ aKey) +CFDictionary.prototype.containsKey = function(/*String*/ aKey) { return hasOwnProperty.apply(this._buckets, [aKey]); } -Dictionary.prototype.containsValue = function(/*id*/ anObject) +CFDictionary.prototype.containsValue = function(/*id*/ anObject) { var keys = this._keys, buckets = this._buckets, @@ -58,17 +58,17 @@ Dictionary.prototype.containsValue = function(/*id*/ anObject) return NO; } -Dictionary.prototype.count = function() +CFDictionary.prototype.count = function() { return this._count; } -Dictionary.prototype.countOfKey = function(/*String*/ aKey) +CFDictionary.prototype.countOfKey = function(/*String*/ aKey) { return this.containsKey(aKey) ? 1 : 0; } -Dictionary.prototype.countOfValue = function(/*id*/ anObject) +CFDictionary.prototype.countOfValue = function(/*id*/ anObject) { var keys = this._keys, buckets = this._buckets, @@ -83,12 +83,12 @@ Dictionary.prototype.countOfValue = function(/*id*/ anObject) return countOfValue; } -Dictionary.prototype.keys = function() +CFDictionary.prototype.keys = function() { return this._keys.slice(); } -Dictionary.prototype.valueForKey = function(/*String*/ aKey) +CFDictionary.prototype.valueForKey = function(/*String*/ aKey) { var buckets = this._buckets; @@ -98,7 +98,7 @@ Dictionary.prototype.valueForKey = function(/*String*/ aKey) return buckets[aKey]; } -Dictionary.prototype.toString = function() +CFDictionary.prototype.toString = function() { var string = "{\n", keys = this._keys, @@ -115,19 +115,19 @@ Dictionary.prototype.toString = function() return string + "}"; } -MutableDictionary = function(/*Dictionary*/ aDictionary) +CFMutableDictionary = function(/*CFDictionary*/ aDictionary) { - Dictionary.apply(this, []); + CFDictionary.apply(this, []); } -MutableDictionary.prototype = new Dictionary(); +CFMutableDictionary.prototype = new CFDictionary(); -MutableDictionary.prototype.copy = function() +CFMutableDictionary.prototype.copy = function() { return this.mutableCopy(); } -MutableDictionary.prototype.addValueForKey = function(/*String*/ aKey, /*Object*/ aValue) +CFMutableDictionary.prototype.addValueForKey = function(/*String*/ aKey, /*Object*/ aValue) { if (this.containsKey(aKey)) return; @@ -138,7 +138,7 @@ MutableDictionary.prototype.addValueForKey = function(/*String*/ aKey, /*Object* this._buckets[aKey] = aValue; } -MutableDictionary.prototype.removeValueForKey = function(/*String*/ aKey) +CFMutableDictionary.prototype.removeValueForKey = function(/*String*/ aKey) { var indexOfKey = -1; @@ -167,14 +167,14 @@ MutableDictionary.prototype.removeValueForKey = function(/*String*/ aKey) delete this._buckets[aKey]; } -MutableDictionary.prototype.removeAllValues = function() +CFMutableDictionary.prototype.removeAllValues = function() { this._count = 0; this._keys = []; this._buckets = { }; } -MutableDictionary.prototype.replaceValueForKey = function(/*String*/ aKey, /*Object*/ aValue) +CFMutableDictionary.prototype.replaceValueForKey = function(/*String*/ aKey, /*Object*/ aValue) { if (!this.containsKey(aKey)) return; @@ -182,7 +182,7 @@ MutableDictionary.prototype.replaceValueForKey = function(/*String*/ aKey, /*Obj this._buckets[aKey] = aValue; } -MutableDictionary.prototype.setValueForKey = function(/*String*/ aKey, /*Object*/ aValue) +CFMutableDictionary.prototype.setValueForKey = function(/*String*/ aKey, /*Object*/ aValue) { if (this.containsKey(aKey)) this.replaceValueForKey(aKey, aValue); @@ -193,8 +193,5 @@ MutableDictionary.prototype.setValueForKey = function(/*String*/ aKey, /*Object* // Exports -exports.Dictionary = Dictionary; -exports.CFDictionary = Dictionary; - -exports.MutableDictionary = MutableDictionary; -exports.CFMutableDictionary = MutableDictionary; +exports.CFDictionary = CFDictionary; +exports.CFMutableDictionary = CFMutableDictionary; diff --git a/Objective-J/PropertyList.js b/Objective-J/CFPropertyList.js similarity index 76% rename from Objective-J/PropertyList.js rename to Objective-J/CFPropertyList.js index 57bb0d40b..fb5ca092d 100644 --- a/Objective-J/PropertyList.js +++ b/Objective-J/CFPropertyList.js @@ -6,60 +6,64 @@ function generateObjectUID() return OBJECT_COUNT++; } -function PropertyList() +function CFPropertyList() { this._UID = generateObjectUID(); } -PropertyList.PLISTRE = /^\s*<\s*plist\s*>/i; -PropertyList.DTDRE = /^\s*<\?\s*xml\s+version\s*=\s*\"1.0\"[^>]*\?>\s*<\!DOCTYPE\s+plist\s+PUBLIC\s+\"-\/\/Apple(?:\sComputer)?\/\/DTD\s+PLIST\s+1.0\/\/EN\"\s+\"http:\/\/www\.apple\.com\/DTDs\/PropertyList-1\.0\.dtd\"\s*>/i; +CFPropertyList.PLISTRE = /^\s*<\s*plist\s*>/i; +CFPropertyList.DTDRE = /^\s*<\?\s*xml\s+version\s*=\s*\"1.0\"[^>]*\?>\s*<\!DOCTYPE\s+plist\s+PUBLIC\s+\"-\/\/Apple(?:\sComputer)?\/\/DTD\s+PLIST\s+1.0\/\/EN\"\s+\"http:\/\/www\.apple\.com\/DTDs\/PropertyList-1\.0\.dtd\"\s*>/i; -PropertyList.FormatXMLDTD = "\n"; -PropertyList.Format280NorthMagicNumber = "280NPLIST"; +CFPropertyList.FormatXMLDTD = "\n"; +CFPropertyList.Format280NorthMagicNumber = "280NPLIST"; // Serialization Formats -PropertyList.FormatOpenStep = 1, -PropertyList.FormatXML_v1_0 = 100, -PropertyList.FormatBinary_v1_0 = 200, -PropertyList.Format280North_v1_0 = -1000; +CFPropertyList.FormatOpenStep = 1, +CFPropertyList.FormatXML_v1_0 = 100, +CFPropertyList.FormatBinary_v1_0 = 200, +CFPropertyList.Format280North_v1_0 = -1000; -PropertyList.sniffedFormatOfString = function(/*String*/ aString) +CFPropertyList.sniffedFormatOfString = function(/*String*/ aString) { // If the string starts with the plist DTD - if (aString.match(PropertyList.DTDRE)) - return PropertyList.FormatXML_v1_0; + if (aString.match(CFPropertyList.DTDRE)) + return CFPropertyList.FormatXML_v1_0; // If the string starts with ... - if (aString.match(PropertyList.PLISTRE)) - return PropertyList.FormatXML_v1_0; + if (aString.match(CFPropertyList.PLISTRE)) + return CFPropertyList.FormatXML_v1_0; - if (aString.substr(0, PropertyList.Format280NorthMagicNumber.length) === PropertyList.Format280NorthMagicNumber) - return PropertyList.Format280North_v1_0; + if (aString.substr(0, CFPropertyList.Format280NorthMagicNumber.length) === CFPropertyList.Format280NorthMagicNumber) + return CFPropertyList.Format280North_v1_0; return null; } // Serialization -PropertyList.dataFromPropertyList = function(/*PropertyList*/ aPropertyList, /*Format*/ aFormat) +CFPropertyList.dataFromPropertyList = function(/*CFPropertyList*/ aPropertyList, /*Format*/ aFormat) { - return new Data(PropertyList.stringFromPropertyList(aPropertyList, aFormat)); + var data = new CFMutableData(); + + data.setEncodedString(CFPropertyList.stringFromPropertyList(aPropertyList, aFormat)); + + return data; } -PropertyList.stringFromPropertyList = function(/*PropertyList*/ aPropertyList, /*Format*/ aFormat) +CFPropertyList.stringFromPropertyList = function(/*CFPropertyList*/ aPropertyList, /*Format*/ aFormat) { if (!aFormat) - aFormat = PropertyList.Format280North_v1_0; + aFormat = CFPropertyList.Format280North_v1_0; - var serializers = PropertyListSerializers[aFormat]; + var serializers = CFPropertyListSerializers[aFormat]; return serializers["start"]() + serializePropertyList(aPropertyList, serializers) + serializers["finish"](); } -function serializePropertyList(/*PropertyList*/ aPropertyList, /*Object*/ serializers) +function serializePropertyList(/*CFPropertyList*/ aPropertyList, /*Object*/ serializers) { var type = typeof aPropertyList, valueOf = aPropertyList.valueOf(), @@ -94,13 +98,13 @@ function serializePropertyList(/*PropertyList*/ aPropertyList, /*Object*/ serial return serializers[type](aPropertyList, serializers); } -var PropertyListSerializers = { }; +var CFPropertyListSerializers = { }; -PropertyListSerializers[PropertyList.FormatXML_v1_0] = +CFPropertyListSerializers[CFPropertyList.FormatXML_v1_0] = { "start": function() { - return PropertyList.FormatXMLDTD + ""; + return CFPropertyList.FormatXMLDTD + ""; }, "finish": function() @@ -140,7 +144,7 @@ PropertyListSerializers[PropertyList.FormatXML_v1_0] = return ""; }, - "dictionary": function(/*Dictionary*/ aDictionary, /*Object*/ serializers) + "dictionary": function(/*CFDictionary*/ aDictionary, /*Object*/ serializers) { var keys = aDictionary._keys, index = 0, @@ -171,11 +175,11 @@ var ARRAY_MARKER = "A", KEY_MARKER = "K", END_MARKER = "E"; -PropertyListSerializers[PropertyList.Format280North_v1_0] = +CFPropertyListSerializers[CFPropertyList.Format280North_v1_0] = { "start": function() { - return PropertyList.Format280NorthMagicNumber + ";1.0;"; + return CFPropertyList.Format280NorthMagicNumber + ";1.0;"; }, "finish": function() @@ -331,20 +335,20 @@ var _plist_traverseNextNode = function(anXMLNode, stayWithin, stack) return null; } -PropertyList.propertyListFromData = function(/*Data*/ aData) +CFPropertyList.propertyListFromData = function(/*Data*/ aData) { - return PropertyList.propertyListFromString(aData.encodedString(), aFormat); + return CFPropertyList.propertyListFromString(aData.encodedString(), aFormat); } -PropertyList.propertyListFromString = function(/*String*/ aString, /*Format*/ aFormat) +CFPropertyList.propertyListFromString = function(/*String*/ aString, /*Format*/ aFormat) { if (!aFormat) - aFormat = PropertyList.sniffedFormatOfString(aString); + aFormat = CFPropertyList.sniffedFormatOfString(aString); - if (aFormat === PropertyList.FormatXML_v1_0) - return PropertyList.propertyListFromXML(aString); + if (aFormat === CFPropertyList.FormatXML_v1_0) + return CFPropertyList.propertyListFromXML(aString); - if (aFormat === PropertyList.Format280North_v1_0) + if (aFormat === CFPropertyList.Format280North_v1_0) return propertyListFrom280NorthString(aString); return null; @@ -399,7 +403,7 @@ function propertyListFrom280NorthString(/*String*/ aString) case ARRAY_MARKER: object = [] containers.push(object); break; - case DICTIONARY_MARKER: object = new MutableDictionary(); + case DICTIONARY_MARKER: object = new CFMutableDictionary(); containers.push(object); break; @@ -443,7 +447,7 @@ function decodeHTMLComponent(/*String*/ aString) return aString.replace(/"/g, '"').replace(/'/g, '\'').replace(/</g,'<').replace(/>/g,'>').replace(/&/g,'&'); } -PropertyList.propertyListFromXML = function(/*String | XMLNode*/ aStringOrXMLNode) +CFPropertyList.propertyListFromXML = function(/*String | XMLNode*/ aStringOrXMLNode) { var XMLNode = aStringOrXMLNode; @@ -456,8 +460,8 @@ PropertyList.propertyListFromXML = function(/*String | XMLNode*/ aStringOrXMLNod { XMLNode = new ActiveXObject("Microsoft.XMLDOM"); - if (aStringOrXMLNode.substr(0, PropertyList.DTD.length) === PropertyList.DTD) - aStringOrXMLNode = aStringOrXMLNode.substr(PropertyList.DTD.length); + if (aStringOrXMLNode.substr(0, CFPropertyList.DTD.length) === CFPropertyList.DTD) + aStringOrXMLNode = aStringOrXMLNode.substr(CFPropertyList.DTD.length); XMLNode.loadXML(aStringOrXMLNode); } @@ -502,7 +506,7 @@ PropertyList.propertyListFromXML = function(/*String | XMLNode*/ aStringOrXMLNod case PLIST_ARRAY: object = [] containers.push(object); break; - case PLIST_DICTIONARY: object = new MutableDictionary(); + case PLIST_DICTIONARY: object = new CFMutableDictionary(); containers.push(object); break; @@ -519,7 +523,7 @@ PropertyList.propertyListFromXML = function(/*String | XMLNode*/ aStringOrXMLNod case PLIST_BOOLEAN_FALSE: object = false; break; - case PLIST_DATA: object = new MutableData(); + case PLIST_DATA: object = new CFMutableData(); object.bytes = FIRST_CHILD(XMLNode) ? base64_decode_to_array(CHILD_VALUE(XMLNode), true) : []; break; @@ -541,50 +545,44 @@ PropertyList.propertyListFromXML = function(/*String | XMLNode*/ aStringOrXMLNod } exports.generateObjectUID = generateObjectUID; -exports.PropertyList = PropertyList; +exports.CFPropertyList = CFPropertyList; -global.CFPropertyList = PropertyList; -global.CFPropertyListCreate = function() +exports.CFPropertyListCreate = function() { - return new PropertyList(); + return new CFPropertyList(); } -global.kCFPropertyListOpenStepFormat = PropertyList.FormatOpenStep; -global.kCFPropertyListXMLFormat_v1_0 = PropertyList.FormatXML_v1_0; -global.kCFPropertyListBinaryFormat_v1_0 = PropertyList.FormatBinary_v1_0; -global.kCFPropertyList280NorthFormat_v1_0 = PropertyList.Format280North_v1_0; +exports.kCFPropertyListOpenStepFormat = CFPropertyList.FormatOpenStep; +exports.kCFPropertyListXMLFormat_v1_0 = CFPropertyList.FormatXML_v1_0; +exports.kCFPropertyListBinaryFormat_v1_0 = CFPropertyList.FormatBinary_v1_0; +exports.kCFPropertyList280NorthFormat_v1_0 = CFPropertyList.Format280North_v1_0; -global.CFPropertyListCreateFromXMLData = function(/*Data*/ data) +exports.CFPropertyListCreateFromXMLData = function(/*Data*/ data) { - return PropertyList.createFromDataWithFormat(data, PropertyList.FormatXML_v1_0); + return CFPropertyList.createFromDataWithFormat(data, CFPropertyList.FormatXML_v1_0); } -global.CFPropertyListCreateXMLData = function(/*PropertyList*/ aPropertyList) +exports.CFPropertyListCreateXMLData = function(/*PropertyList*/ aPropertyList) { - return aPropertyList.createDataWithFormat(PropertyList.FormatXML_v1_0); + return aPropertyList.createDataWithFormat(CFPropertyList.FormatXML_v1_0); } -global.CFPropertyListCreateFrom280NorthData = function(/*Data*/ data) +exports.CFPropertyListCreateFrom280NorthData = function(/*Data*/ data) { - return PropertyList.createFromDataWithFormat(data, PropertyList.Format280North_v1_0); + return CFPropertyList.createFromDataWithFormat(data, CFPropertyList.Format280North_v1_0); } -global.CFPropertyListCreate280NorthData = function(/*PropertyList*/ aPropertyList) +exports.CFPropertyListCreate280NorthData = function(/*PropertyList*/ aPropertyList) { - return aPropertyList.createDataWithFormat(PropertyList.Format280North_v1_0); + return aPropertyList.createDataWithFormat(CFPropertyList.Format280North_v1_0); } -global.CPPropertyListCreateFromXMLData = CFPropertyListCreateFromXMLData; -global.CPPropertyListCreateXMLData = CFPropertyListCreateXMLData; -global.CPPropertyListCreateFrom280NorthData = CFPropertyListCreateFrom280NorthData; -global.CPPropertyListCreate280NorthData = CFPropertyListCreate280NorthData; - -global.CPPropertyListCreateFromData = function(/*PropertyList*/ aPropertyList) +exports.CPPropertyListCreateFromData = function(/*PropertyList*/ aPropertyList) { - return PropertyList.createFromDataWithFormat(aPropertyList); + return CFPropertyList.createFromDataWithFormat(aPropertyList); } -global.CPPropertyListCreateData = function(/*PropertyList*/ aPropertyList) +exports.CPPropertyListCreateData = function(/*PropertyList*/ aPropertyList) { return aPropertyList.createDataWithFormat(aPropertyList) } diff --git a/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js b/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js index 1c178e308..d5f492f42 100644 --- a/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js +++ b/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js @@ -8,8 +8,8 @@ var FILE = require("file"), CLOBBER = require("jake/clean").CLOBBER, base64 = require("base64"), environment = require("objective-j/jake/environment"), - PropertyList = require("objective-j/core").PropertyList, - MutableDictionary = require("objective-j/core").MutableDictionary; + CFPropertyList = require("objective-j/core").CFPropertyList, + CFMutableDictionary = require("objective-j/core").CFMutableDictionary; var Task = Jake.Task, filedir = Jake.filedir; @@ -345,9 +345,9 @@ BundleTask.prototype.infoPlist = function() var infoPlistPath = this.infoPlistPath(); if (infoPlistPath && FILE.exists(infoPlistPath)) - var infoPlist = PropertyList.propertyListFromString(FILE.read(infoPlistPath, { charset:"UTF-8" })); + var infoPlist = CFPropertyList.propertyListFromString(FILE.read(infoPlistPath, { charset:"UTF-8" })); else - var infoPlist = new MutableDictionary(); + var infoPlist = new CFMutableDictionary(); // FIXME: Should all of these unconditionally overwrite? infoPlist.setValueForKey("CPBundleInfoDictionaryVersion", 6.0); @@ -376,7 +376,7 @@ BundleTask.prototype.defineInfoPlistTask = function() filedir (infoPlistProductPath, function() { - FILE.write(infoPlistProductPath, PropertyList.stringFromPropertyList(bundleTask.infoPlist(), PropertyList.Format280North_v1_0), { charset:"UTF-8" }); + FILE.write(infoPlistProductPath, CFPropertyList.stringFromPropertyList(bundleTask.infoPlist(), CFPropertyList.Format280North_v1_0), { charset:"UTF-8" }); }); var infoPlistPath = this.infoPlistPath(); diff --git a/Objective-J/Executable.js b/Objective-J/Executable.js index 7dbe719e8..1968061a7 100644 --- a/Objective-J/Executable.js +++ b/Objective-J/Executable.js @@ -73,7 +73,9 @@ Executable.prototype.path = function() Executable.prototype.functionParameters = function() { - var functionParameters = exportedNames().concat("objj_executeFile", "objj_importFile"); + var functionParameters = ["objj_executeFile", "objj_importFile"]; + +//exportedNames().concat("objj_executeFile", "objj_importFile"); #ifdef COMMONJS functionParameters = functionParameters.concat("require", "exports", "module", "system", "print", "window"); @@ -84,8 +86,10 @@ Executable.prototype.functionParameters = function() Executable.prototype.functionArguments = function() { - var path = this.path() - functionArguments = exportedValues().concat(fileExecuterForPath(path), fileImporterForPath(path)); + var path = this.path(), + functionArguments = [fileExecuterForPath(path), fileImporterForPath(path)]; + +//functionArguments = exportedValues().concat(fileExecuterForPath(path), fileImporterForPath(path)); #ifdef COMMONJS functionArguments = functionArguments.concat(Executable.commonJSArguments()); @@ -123,7 +127,7 @@ Executable.prototype.execute = function() #endif var oldContextBundle = CONTEXT_BUNDLE; - CONTEXT_BUNDLE = Bundle.bundleContainingPath(this.path()); + CONTEXT_BUNDLE = CFBundle.bundleContainingPath(this.path()); var result = this._function.apply(global, this.functionArguments()); @@ -165,8 +169,8 @@ Executable.prototype.loadFileDependencies = function() var searchedPaths = [{ }, { }], foundExecutablePaths = { }, - fileExecutableSearches = new MutableDictionary(), - incompleteFileExecutableSearches = new MutableDictionary(); + fileExecutableSearches = new CFMutableDictionary(), + incompleteFileExecutableSearches = new CFMutableDictionary(); foundExecutablePaths[this.path()] = this; diff --git a/Objective-J/HTTPRequest.js b/Objective-J/HTTPRequest.js index a24b3054a..6d8e7ce20 100644 --- a/Objective-J/HTTPRequest.js +++ b/Objective-J/HTTPRequest.js @@ -114,10 +114,10 @@ HTTPRequest.prototype.responsePropertyList = function() { var responseText = this.responseText(); - if (PropertyList.sniffedFormatOfString(responseText) === PropertyList.FormatXML_v1_0) - return PropertyList.propertyListFromXML(this.responseXML()); + if (CFPropertyList.sniffedFormatOfString(responseText) === CFPropertyList.FormatXML_v1_0) + return CFPropertyList.propertyListFromXML(this.responseXML()); - return PropertyList.propertyListFromString(responseText); + return CFPropertyList.propertyListFromString(responseText); } HTTPRequest.prototype.responseText = function() @@ -207,7 +207,7 @@ FileRequest.prototype.responseXML = function() FileRequest.prototype.responsePropertyList = function() { - return PropertyList.propertyListFromString(this.responseText()); + return CFPropertyList.propertyListFromString(this.responseText()); } #endif diff --git a/Objective-J/Includes.js b/Objective-J/Includes.js index 569bfe5e0..ec8f785f1 100644 --- a/Objective-J/Includes.js +++ b/Objective-J/Includes.js @@ -3,11 +3,11 @@ #include "Constants.js" #include "EventDispatcher.js" #include "HTTPRequest.js" -#include "PropertyList.js" -#include "Dictionary.js" -#include "Data.js" +#include "CFPropertyList.js" +#include "CFDictionary.js" +#include "CFData.js" #include "MarkedStream.js" -#include "Bundle.js" +#include "CFBundle.js" #include "StaticResourceNode.js" #include "Preprocessor.js" #include "FileDependency.js" diff --git a/Objective-J/Runtime.js b/Objective-J/Runtime.js index f52da4c0c..d5cf52694 100644 --- a/Objective-J/Runtime.js +++ b/Objective-J/Runtime.js @@ -236,7 +236,8 @@ function class_replaceMethod(/*Class*/ aClass, /*SEL*/ aSelector, /*IMP*/ aMetho return method_imp; } -var _class_initialize = function(/*Class*/ aClass) +// Private: Don't exports. +function _class_initialize(/*Class*/ aClass) { var meta = GETMETA(aClass); @@ -533,7 +534,7 @@ function sel_registerName(aName) return aName; } -// Exports +// Exports and Globals exports.objj_ivar = objj_ivar; exports.objj_method = objj_method; @@ -585,4 +586,5 @@ exports.sel_getUid = sel_getUid; exports.sel_isEqual = sel_isEqual; exports.sel_registerName = sel_registerName; -global._objj_generateObjectHash = generateObjectUID; +exports.objj_generateObjectUID = generateObjectUID; +exports._objj_generateObjectHash = generateObjectUID; diff --git a/Objective-J/Scope.js b/Objective-J/Scope.js index 0608efa55..bf7cab3e5 100644 --- a/Objective-J/Scope.js +++ b/Objective-J/Scope.js @@ -1,4 +1,5 @@ +// For now just make these global. function makeExportsGlobal() { for (var exportName in exports) @@ -6,41 +7,6 @@ function makeExportsGlobal() global[exportName] = exports[exportName]; } -var cachedExportedNames = [], - cachedExportedValues = []; - -function cacheExportedNamesAndValues() -{ - for (var exportName in exports) - if (hasOwnProperty.apply(exports, [exportName])) - { - cachedExportedNames.push(exportName); - cachedExportedValues.push(exports[exportName]); - } - - exportedNames = function() - { - return cachedExportedNames; - } - - exportedValues = function() - { - return cachedExportedValues; - } -} - -function exportedNames() -{ - cacheExportedNamesAndValues(); - return exportedNames(); -} - -function exportedValues() -{ - cacheExportedNamesAndValues(); - return exportedValues(); -} - function importablePath(/*String*/ aPath, /*BOOL*/ isLocal, /*String*/ aCWD) { aPath = FILE.normal(aPath); diff --git a/Objective-J/StaticResourceNode.js b/Objective-J/StaticResourceNode.js index 61f9c31f5..e8f9c42cd 100644 --- a/Objective-J/StaticResourceNode.js +++ b/Objective-J/StaticResourceNode.js @@ -246,7 +246,7 @@ function resolvePathComponents(/*StaticResourceNode*/ startNode, /*Type*/aType, if (index + 1 < count || aType === StaticResourceNode.DirectoryType) { - var bundle = new Bundle(components.slice(0, index + 1).join("/")); + var bundle = new CFBundle(components.slice(0, index + 1).join("/")); // Eat any errors. bundle.onerror = function() { };