Permalink
Browse files

Major cleanup of globals and exports. Removed many accidental globals…

… and no more need for eval in the initialization process. Also fixes Theme Showcase.

Reviewed by me.
  • Loading branch information...
1 parent 338860d commit 841ed9ea89ef4906bf281355e5a705e0cd1022a3 @tolmasky tolmasky committed Feb 20, 2010
View
@@ -24,8 +24,8 @@
@import "CPObjJRuntime.j"
-var __placeholder = new Number(),
- _CPNumberHashes = { };
+var __placeholder = new Number(),
+ CPNumberUIDs = new CFMutableDictionary();
/*!
@class CPNumber
@@ -55,7 +55,7 @@ var __placeholder = new Number(),
{
if (aChar.charCodeAt)
return aChar.charCodeAt(0);
-
+
return aChar;
}
@@ -190,10 +190,15 @@ var __placeholder = new Number(),
- (CPString)UID
{
- if (!_CPNumberHashes[self])
- _CPNumberHashes[self] = _objj_generateObjectHash();
-
- return _CPNumberHashes[self];
+ var UID = CPNumberUIDs.valueForKey(self);
+
+ if (!UID)
+ {
+ UID = objj_generateObjectUID();
+ CPNumberUIDs.setValueForKey(self, UID);
+ }
+
+ return UID + "";
}
- (BOOL)boolValue
@@ -477,10 +477,10 @@ CPLog(@"Got some class: %@", inst);
- (CPString)UID
{
- if (typeof self.__address === "undefined")
- self.__address = _objj_generateObjectHash();
+ if (typeof self._UID === "undefined")
+ self._UID = objj_generateObjectUID();
- return __address + "";
+ return _UID + "";
}
/*!
@@ -77,10 +77,10 @@
- (unsigned)UID
{
- if (typeof self.__address === "undefined")
- self.__address = _objj_generateObjectHash();
+ if (typeof self._UID === "undefined")
+ self._UID = objj_generateObjectUID();
- return __address;
+ return _UID;
}
- (BOOL)isEqual:(id)anObject
View
@@ -56,7 +56,7 @@ CPAnchoredSearch = 8;
*/
CPNumericSearch = 64;
-var CPStringHashes = new CFMutableDictionary();
+var CPStringUIDs = new CFMutableDictionary();
var CPStringRegexSpecialCharacters = [
'/', '.', '*', '+', '?', '|', '$', '^',
@@ -526,15 +526,15 @@ var CPStringRegexSpecialCharacters = [
*/
- (unsigned)UID
{
- var hash = CPStringHashes.valueForKey(self);
+ var UID = CPStringUIDs.valueForKey(self);
- if (!hash)
+ if (!UID)
{
- hash = _objj_generateObjectHash();
- CPStringHashes.setValueForKey(self, hash);
+ UID = objj_generateObjectUID();
+ CPStringUIDs.setValueForKey(self, UID);
}
- return hash;
+ return UID + "";
}
/*!
@@ -98,7 +98,7 @@ var CPURLConnectionDelegate = nil;
{
try
{
- var request = new HTTPRequest();
+ var request = new CFHTTPRequest();
request.open([aRequest HTTPMethod], [[aRequest URL] absoluteString], NO);
@@ -157,7 +157,7 @@ var CPURLConnectionDelegate = nil;
window.location &&
(window.location.protocol === "file:" || window.location.protocol === "app:"));
- _HTTPRequest = new HTTPRequest();
+ _HTTPRequest = new CFHTTPRequest();
if (shouldStartImmediately)
[self start];
@@ -233,7 +233,7 @@ var CPURLConnectionDelegate = nil;
/* @ignore */
- (void)_readyStateDidChange
{
- if (_HTTPRequest.readyState() === HTTPRequest.CompleteState)
+ if (_HTTPRequest.readyState() === CFHTTPRequest.CompleteState)
{
var statusCode = _HTTPRequest.status(),
URL = [_request URL];
@@ -1,6 +1,6 @@
var cwd = FILE.cwd(),
- rootResource = new StaticResource("", NULL, StaticResource.DirectoryType, cwd !== "/");
+ rootResource = new StaticResource("", NULL, YES, cwd !== "/");
StaticResource.root = rootResource;
@@ -18,9 +18,9 @@ else
function resolveCWD()
{
- rootResource.resolveSubPath(cwd, StaticResource.DirectoryType, function(/*StaticResource*/ aResource)
+ rootResource.resolveSubPath(cwd, YES, function(/*StaticResource*/ aResource)
{
- var includePaths = exports.includePaths(),
+ var includePaths = StaticResource.includePaths(),
index = 0,
count = includePaths.length;
@@ -30,7 +30,7 @@ function resolveCWD()
if (typeof OBJJ_MAIN_FILE === "undefined")
OBJJ_MAIN_FILE = "main.j";
- fileImporterForPath(cwd)(OBJJ_MAIN_FILE || "main.j", YES, function()
+ Executable.fileImporterForPath(cwd)(OBJJ_MAIN_FILE || "main.j", YES, function()
{
afterDocumentLoad(main);
});
@@ -56,5 +56,3 @@ afterDocumentLoad(function()
documentLoaded = YES;
});
#endif
-
-makeExportsGlobal();
@@ -1,27 +1,7 @@
-var global = { },
- ObjectiveJ = { };
+var ObjectiveJ = { };
-(function (global, exports, namespace)
+(function (global, exports)
{
- var GLOBAL_NAMESPACE = namespace;
#include "Includes.js"
-})(global, ObjectiveJ, window);
-
-var hasOwnProperty = Object.prototype.hasOwnProperty;
-
-// If we can't trust the host object, don't treat it as global
-// and fall back to inferred global through eval. In IE this
-// make a difference.
-if (window.window !== window)
-{
- for (key in global)
- if (hasOwnProperty.call(global, key))
- eval(key + " = global[\"" + key + "\"];");
-}
-else
-{
- for (key in global)
- if (hasOwnProperty.call(global, key))
- window[key] = global[key];
-}
+})(window, ObjectiveJ);
@@ -10,7 +10,7 @@ var CFBundlesForPaths = { },
CFBundlesForClasses = { },
CFCacheBuster = new Date().getTime();
-function CFBundle(/*String*/ aPath)
+GLOBAL(CFBundle) = function(/*String*/ aPath)
{
aPath = FILE.absolute(aPath);
@@ -34,6 +34,12 @@ function CFBundle(/*String*/ aPath)
this._eventDispatcher = new EventDispatcher(this);
}
+CFBundle.environments = function()
+{
+ // Passed in by GCC.
+ return ENVIRONMENTS;
+}
+
CFBundle.bundleContainingPath = function(/*String*/ aPath)
{
aPath = FILE.absolute(aPath);
@@ -130,7 +136,7 @@ CFBundle.prototype.mostEligibleEnvironment = function(/*Array*/ environments)
{
environments = environments || this.environments();
- var objj_environments = exports.environments(),
+ var objj_environments = CFBundle.environments(),
index = 0,
count = objj_environments.length,
innerCount = environments.length;
@@ -163,7 +169,7 @@ CFBundle.prototype.load = function(/*BOOL*/ shouldExecute)
var self = this;
- rootResource.resolveSubPath(FILE.dirname(self.path()), StaticResource.DirectoryType, function(aStaticResource)
+ rootResource.resolveSubPath(FILE.dirname(self.path()), YES, function(aStaticResource)
{
var path = self.path();
@@ -178,7 +184,7 @@ CFBundle.prototype.load = function(/*BOOL*/ shouldExecute)
self._staticResource = aStaticResource._children[name];
if (!self._staticResource)
- self._staticResource = new StaticResource(name, aStaticResource, StaticResource.DirectoryType, NO);
+ self._staticResource = new StaticResource(name, aStaticResource, YES, NO);
}
function onsuccess(/*Event*/ anEvent)
@@ -444,10 +450,12 @@ function executeBundle(/*Bundle*/ aBundle, /*Function*/ aCallback)
{
for (; index < staticResources.length; ++index)
{
- var staticResource = staticResources[index],
- type = staticResource.type();
+ var staticResource = staticResources[index];
- if (type === StaticResource.FileType)
+ if (staticResource.isNotFound())
+ continue;
+
+ if (staticResource.isFile())
{
var executable = new FileExecutable(staticResource.path());
@@ -464,7 +472,7 @@ function executeBundle(/*Bundle*/ aBundle, /*Function*/ aCallback)
return;
}
}
- else if (type === StaticResource.DirectoryType)
+ else //if (staticResource.isDirectory())
{
// We don't want to execute resources.
if (staticResource.path() === aBundle.resourcesPath())
@@ -514,7 +522,7 @@ function decompileStaticFile(/*Bundle*/ aBundle, /*String*/ aString, /*String*/
var absolutePath = FILE.join(bundlePath, text),
parent = rootResource.nodeAtSubPath(FILE.dirname(absolutePath), YES);
- file = new StaticResource(FILE.basename(absolutePath), parent, StaticResource.FileType, YES);
+ file = new StaticResource(FILE.basename(absolutePath), parent, NO, YES);
}
else if (marker === MARKER_URI)
@@ -539,7 +547,7 @@ function decompileStaticFile(/*Bundle*/ aBundle, /*String*/ aString, /*String*/
// The unresolved directories must not be bundles.
var parent = rootResource.nodeAtSubPath(FILE.join(bundlePath, FILE.dirname(text)), YES);
- new StaticResource(FILE.basename(text), parent, StaticResource.FileType, YES);
+ new StaticResource(FILE.basename(text), parent, NO, YES);
}
else if (marker === MARKER_TEXT)
@@ -563,5 +571,3 @@ CFBundle.prototype.onerror = function(/*Event*/ anEvent)
{
throw anEvent.error;
}
-
-exports.CFBundle = CFBundle;
View
@@ -1,5 +1,5 @@
-function CFData()
+GLOBAL(CFData) = function()
{
this._encodedString = NULL;
this._serializedPropertyList = NULL;
@@ -46,7 +46,7 @@ CFData.prototype.base64 = function()
return this._base64;
}
-function CFMutableData()
+GLOBAL(CFMutableData) = function()
{
CFData.call(this);
}
@@ -173,22 +173,18 @@ function base64_decode_to_string(input, strip)
return bytes_to_string(base64_decode_to_array(input, strip));
}
-function bytes_to_string(bytes)
+GLOBAL(bytes_to_string) = function(bytes)
{
// This is relatively efficient, I think:
return String.fromCharCode.apply(NULL, bytes);
}
-exports.bytes_to_string = bytes_to_string;
-function base64_encode_string(input)
+GLOBAL(base64_encode_string) = function(input)
{
var temp = [];
for (var i = 0; i < input.length; i++)
temp.push(input.charCodeAt(i));
return base64_encode_array(temp);
}
-
-exports.CFData = CFData;
-exports.CFMutableData = CFMutableData;
@@ -1,10 +1,10 @@
-function CFDictionary(/*CFDictionary*/ aDictionary)
+GLOBAL(CFDictionary) = function(/*CFDictionary*/ aDictionary)
{
this._keys = [];
this._count = 0;
this._buckets = { };
- this._UID = generateObjectUID();
+ this._UID = objj_generateObjectUID();
}
var indexOf = Array.prototype.indexOf,
@@ -115,7 +115,7 @@ CFDictionary.prototype.toString = function()
return string + "}";
}
-CFMutableDictionary = function(/*CFDictionary*/ aDictionary)
+GLOBAL(CFMutableDictionary) = function(/*CFDictionary*/ aDictionary)
{
CFDictionary.apply(this, []);
}
@@ -193,8 +193,3 @@ CFMutableDictionary.prototype.setValueForKey = function(/*String*/ aKey, /*Objec
else
this.addValueForKey(aKey, aValue);
}
-
-// Exports
-
-exports.CFDictionary = CFDictionary;
-exports.CFMutableDictionary = CFMutableDictionary;
Oops, something went wrong.

0 comments on commit 841ed9e

Please sign in to comment.