Merge branch 'master' of git://github.com/280north/cappuccino

This commit is contained in:
Randall Luecke committed 2010-02-20 17:46:09 -05:00
commit 0dd36b2275
34 files changed
+519 -588

No files matched your search

+12 -7
View File
@@ -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
+3 -3
View File
@@ -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 + "";
}
/*!
+3 -3
View File
@@ -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
+6 -6
View File
@@ -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 + "";
}
/*!
+3 -3
View File
@@ -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];
+4 -6
View File
@@ -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();
+3 -23
View File
@@ -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);
+22 -15
View File
@@ -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)
@@ -252,7 +258,7 @@ function loadExecutableAndResources(/*Bundle*/ aBundle, /*BOOL*/ shouldExecute)
else
return;
// Set resolved to true here in case during evaluation this bundle
// 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._staticResource);
@@ -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())
@@ -473,7 +481,8 @@ function executeBundle(/*Bundle*/ aBundle, /*Function*/ aCallback)
var children = staticResource.children();
for (var name in children)
staticResources.push(children[name]);
if (hasOwnProperty.call(children, name))
staticResources.push(children[name]);
}
}
@@ -505,7 +514,7 @@ function decompileStaticFile(/*Bundle*/ aBundle, /*String*/ aString, /*String*/
bundlePath = aBundle.path(),
file = NULL;
while (marker = stream.getMarker())
while (marker = stream.getMarker())
{
var text = stream.getString();
@@ -514,7 +523,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 +548,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 +572,3 @@ CFBundle.prototype.onerror = function(/*Event*/ anEvent)
{
throw anEvent.error;
}
exports.CFBundle = CFBundle;
+4 -8
View File
@@ -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,15 +173,14 @@ 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++)
@@ -189,6 +188,3 @@ function base64_encode_string(input)
return base64_encode_array(temp);
}
exports.CFData = CFData;
exports.CFMutableData = CFMutableData;
+3 -8
View File
@@ -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;
@@ -5,7 +5,7 @@ var asynchronousTimeoutCount = 0,
function Asynchronous(/*Function*/ aFunction)
{
currentAsynchronousTimeoutCount = asynchronousTimeoutCount;
var currentAsynchronousTimeoutCount = asynchronousTimeoutCount;
if (asynchronousTimeoutId === null)
{
@@ -37,7 +37,7 @@ function Asynchronous(/*Function*/ aFunction)
var NativeRequest = null;
// We check ActiveXObject first, because we require local file access and
// We check ActiveXObject first, because we require local file access and
// overrideMimeType feature (which the native XMLHttpRequest does not have in IE).
if (window.ActiveXObject !== undefined)
{
@@ -69,7 +69,7 @@ if (window.ActiveXObject !== undefined)
if (!NativeRequest)
NativeRequest = window.XMLHttpRequest;
function HTTPRequest()
GLOBAL(CFHTTPRequest) = function()
{
this._eventDispatcher = new EventDispatcher(this);
this._nativeRequest = new NativeRequest();
@@ -82,13 +82,13 @@ function HTTPRequest()
}
}
HTTPRequest.UninitializedState = 0;
HTTPRequest.LoadingState = 1;
HTTPRequest.LoadedState = 2;
HTTPRequest.InteractiveState = 3;
HTTPRequest.CompleteState = 4;
CFHTTPRequest.UninitializedState = 0;
CFHTTPRequest.LoadingState = 1;
CFHTTPRequest.LoadedState = 2;
CFHTTPRequest.InteractiveState = 3;
CFHTTPRequest.CompleteState = 4;
HTTPRequest.prototype.status = function()
CFHTTPRequest.prototype.status = function()
{
try
{
@@ -100,7 +100,7 @@ HTTPRequest.prototype.status = function()
}
}
HTTPRequest.prototype.statusText = function()
CFHTTPRequest.prototype.statusText = function()
{
try
{
@@ -112,24 +112,24 @@ HTTPRequest.prototype.statusText = function()
}
}
HTTPRequest.prototype.readyState = function()
CFHTTPRequest.prototype.readyState = function()
{
return this._nativeRequest.readyState;
}
HTTPRequest.prototype.success = function()
CFHTTPRequest.prototype.success = function()
{
var status = this.status();
if (status >= 200 && status < 300)
return YES;
// file:// requests return with status 0, to know if they succeeded, we
// file:// requests return with status 0, to know if they succeeded, we
// need to know if there was any content.
return status === 0 && this.responseText() && this.responseText().length;
}
HTTPRequest.prototype.responseXML = function()
CFHTTPRequest.prototype.responseXML = function()
{
var responseXML = this._nativeRequest.responseXML;
@@ -139,7 +139,7 @@ HTTPRequest.prototype.responseXML = function()
return parseXML(this.responseText());
}
HTTPRequest.prototype.responsePropertyList = function()
CFHTTPRequest.prototype.responsePropertyList = function()
{
var responseText = this.responseText();
@@ -149,38 +149,38 @@ HTTPRequest.prototype.responsePropertyList = function()
return CFPropertyList.propertyListFromString(responseText);
}
HTTPRequest.prototype.responseText = function()
CFHTTPRequest.prototype.responseText = function()
{
return this._nativeRequest.responseText;
}
HTTPRequest.prototype.setRequestHeader = function(/*String*/ aHeader, /*Object*/ aValue)
CFHTTPRequest.prototype.setRequestHeader = function(/*String*/ aHeader, /*Object*/ aValue)
{
return this._nativeRequest.setRequestHeader(aHeader, aValue);
}
HTTPRequest.prototype.getResponseHeader = function(/*String*/ aHeader)
CFHTTPRequest.prototype.getResponseHeader = function(/*String*/ aHeader)
{
return this._nativeRequest.getResponseHeader(aHeader);
}
HTTPRequest.prototype.getAllResponseHeaders = function()
CFHTTPRequest.prototype.getAllResponseHeaders = function()
{
return this._nativeRequest.getAllResponseHeaders();
}
HTTPRequest.prototype.overrideMimeType = function(/*String*/ aMimeType)
CFHTTPRequest.prototype.overrideMimeType = function(/*String*/ aMimeType)
{
if ("overrideMimeType" in this._nativeRequest)
return this._nativeRequest.overrideMimeType(aMimeType);
}
HTTPRequest.prototype.open = function(/*...*/)
CFHTTPRequest.prototype.open = function(/*...*/)
{
return this._nativeRequest.open(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4]);
}
HTTPRequest.prototype.send = function(/*Object*/ aBody)
CFHTTPRequest.prototype.send = function(/*Object*/ aBody)
{
try
{
@@ -193,22 +193,22 @@ HTTPRequest.prototype.send = function(/*Object*/ aBody)
}
}
HTTPRequest.prototype.abort = function()
CFHTTPRequest.prototype.abort = function()
{
return this._nativeRequest.abort();
}
HTTPRequest.prototype.addEventListener = function(/*String*/ anEventName, /*Function*/ anEventListener)
CFHTTPRequest.prototype.addEventListener = function(/*String*/ anEventName, /*Function*/ anEventListener)
{
this._eventDispatcher.addEventListener(anEventName, anEventListener);
}
HTTPRequest.prototype.removeEventListener = function(/*String*/ anEventName, /*Function*/ anEventListener)
CFHTTPRequest.prototype.removeEventListener = function(/*String*/ anEventName, /*Function*/ anEventListener)
{
this._eventDispatcher.removeEventListener(anEventName, anEventListener);
}
function determineAndDispatchHTTPRequestEvents(/*HTTPRequest*/ aRequest)
function determineAndDispatchHTTPRequestEvents(/*CFHTTPRequest*/ aRequest)
{
var eventDispatcher = aRequest._eventDispatcher;
@@ -234,7 +234,7 @@ function determineAndDispatchHTTPRequestEvents(/*HTTPRequest*/ aRequest)
function FileRequest(/*String*/ aFilePath, onsuccess, onfailure)
{
#ifdef BROWSER
var request = new HTTPRequest();
var request = new CFHTTPRequest();
request.onsuccess = Asynchronous(onsuccess);
request.onfailure = Asynchronous(onfailure);
@@ -270,5 +270,3 @@ FileRequest.prototype.responsePropertyList = function()
return CFPropertyList.propertyListFromString(this.responseText());
}
#endif
exports.HTTPRequest = HTTPRequest;
+19 -22
View File
@@ -1,14 +1,14 @@
var OBJECT_COUNT = 0;
function generateObjectUID()
GLOBAL(objj_generateObjectUID) = function()
{
return OBJECT_COUNT++;
}
function CFPropertyList()
GLOBAL(CFPropertyList) = function()
{
this._UID = generateObjectUID();
this._UID = objj_generateObjectUID();
}
// We are really liberal when accepting DOCTYPEs.
@@ -86,7 +86,7 @@ function serializePropertyList(/*CFPropertyList*/ aPropertyList, /*Object*/ seri
if (aPropertyList === YES || aPropertyList === NO)
type = "boolean";
else if (type === "number")
{
if (FLOOR(aPropertyList) === aPropertyList)
@@ -94,12 +94,12 @@ function serializePropertyList(/*CFPropertyList*/ aPropertyList, /*Object*/ seri
else
type = "real";
}
else if (type !== "string")
{
if (aPropertyList.slice)
type = "array";
else
type = "dictionary";
}
@@ -149,7 +149,7 @@ CFPropertyListSerializers[CFPropertyList.FormatXML_v1_0] =
for (; index < count; ++index)
string += serializePropertyList(anArray[index], serializers);
return string + "</array>";
},
@@ -200,7 +200,7 @@ CFPropertyListSerializers[CFPropertyList.Format280North_v1_0] =
{
return STRING_MARKER + ';' + aString.length + ';' + aString;
},
"boolean" : function(/*Boolean*/ aBoolean)
{
return (aBoolean ? TRUE_MARKER : FALSE_MARKER) + ';';
@@ -563,45 +563,42 @@ CFPropertyList.propertyListFromXML = function(/*String | XMLNode*/ aStringOrXMLN
return plistObject;
}
exports.generateObjectUID = generateObjectUID;
exports.CFPropertyList = CFPropertyList;
GLOBAL(kCFPropertyListOpenStepFormat) = CFPropertyList.FormatOpenStep;
GLOBAL(kCFPropertyListXMLFormat_v1_0) = CFPropertyList.FormatXML_v1_0;
GLOBAL(kCFPropertyListBinaryFormat_v1_0) = CFPropertyList.FormatBinary_v1_0;
GLOBAL(kCFPropertyList280NorthFormat_v1_0) = CFPropertyList.Format280North_v1_0;
exports.CFPropertyListCreate = function()
GLOBAL(CFPropertyListCreate) = function()
{
return new CFPropertyList();
}
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;
exports.CFPropertyListCreateFromXMLData = function(/*Data*/ data)
GLOBAL(CFPropertyListCreateFromXMLData) = function(/*Data*/ data)
{
return CFPropertyList.propertyListFromData(data, CFPropertyList.FormatXML_v1_0);
}
exports.CFPropertyListCreateXMLData = function(/*PropertyList*/ aPropertyList)
GLOBAL(CFPropertyListCreateXMLData) = function(/*PropertyList*/ aPropertyList)
{
return CFPropertyList.dataFromPropertyList(aPropertyList, CFPropertyList.FormatXML_v1_0);
}
exports.CFPropertyListCreateFrom280NorthData = function(/*Data*/ data)
GLOBAL(CFPropertyListCreateFrom280NorthData) = function(/*Data*/ data)
{
return CFPropertyList.propertyListFromData(data, CFPropertyList.Format280North_v1_0);
}
exports.CFPropertyListCreate280NorthData = function(/*PropertyList*/ aPropertyList)
GLOBAL(CFPropertyListCreate280NorthData) = function(/*PropertyList*/ aPropertyList)
{
return CFPropertyList.dataFromPropertyList(aPropertyList, CFPropertyList.Format280North_v1_0);
}
exports.CPPropertyListCreateFromData = function(/*CFData*/ data, /*Format*/ aFormat)
GLOBAL(CPPropertyListCreateFromData) = function(/*CFData*/ data, /*Format*/ aFormat)
{
return CFPropertyList.propertyListFromData(data, aFormat);
}
exports.CPPropertyListCreateData = function(/*PropertyList*/ aPropertyList, /*Format*/ aFormat)
GLOBAL(CPPropertyListCreateData) = function(/*PropertyList*/ aPropertyList, /*Format*/ aFormat)
{
return CFPropertyList.dataFromPropertyList(aPropertyList, aFormat);
}
+22 -22
View File
@@ -20,7 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
exports.CPLogDisable = false;
GLOBAL(CPLogDisable) = false;
var CPLogDefaultTitle = "Cappuccino";
@@ -36,13 +36,13 @@ var _CPLogRegistrations = {};
// Register Functions:
// Register a logger for all levels, or up to an optional max level
exports.CPLogRegister = function(aProvider, aMaxLevel)
GLOBAL(CPLogRegister) = function(aProvider, aMaxLevel)
{
exports.CPLogRegisterRange(aProvider, CPLogLevels[0], aMaxLevel || CPLogLevels[CPLogLevels.length-1]);
CPLogRegisterRange(aProvider, CPLogLevels[0], aMaxLevel || CPLogLevels[CPLogLevels.length-1]);
}
// Register a logger for a range of levels
exports.CPLogRegisterRange = function(aProvider, aMinLevel, aMaxLevel)
GLOBAL(CPLogRegisterRange) = function(aProvider, aMinLevel, aMaxLevel)
{
var min = _CPLogLevelsInverted[aMinLevel];
var max = _CPLogLevelsInverted[aMaxLevel];
@@ -53,7 +53,7 @@ exports.CPLogRegisterRange = function(aProvider, aMinLevel, aMaxLevel)
}
// Register a logger for a single level
exports.CPLogRegisterSingle = function(aProvider, aLevel)
GLOBAL(CPLogRegisterSingle) = function(aProvider, aLevel)
{
if (!_CPLogRegistrations[aLevel])
_CPLogRegistrations[aLevel] = [];
@@ -66,7 +66,7 @@ exports.CPLogRegisterSingle = function(aProvider, aLevel)
_CPLogRegistrations[aLevel].push(aProvider);
}
exports.CPLogUnregister = function(aProvider) {
GLOBAL(CPLogUnregister) = function(aProvider) {
for (var aLevel in _CPLogRegistrations)
for (var i = 0; i < _CPLogRegistrations[aLevel].length; i++)
if (_CPLogRegistrations[aLevel][i] === aProvider)
@@ -91,8 +91,8 @@ function _CPLogDispatch(parameters, aLevel, aTitle)
// Setup CPLog() and CPLog.xxx() aliases
var CPLog = exports.CPLog = function() { _CPLogDispatch(arguments); }
GLOBAL(CPLog) = function() { _CPLogDispatch(arguments); }
for (var i = 0; i < CPLogLevels.length; i++)
CPLog[CPLogLevels[i]] = (function(level) { return function() { _CPLogDispatch(arguments, level); }; })(CPLogLevels[i]);
@@ -172,7 +172,7 @@ function ANSITextApplyProperties(string, properties)
return ANSIControlCode(ANSI_TEXT_PROP, properties) + String(string) + ANSIControlCode(ANSI_TEXT_PROP);
}
exports.ANSITextColorize = function(string, color)
GLOBAL(ANSITextColorize) = function(string, color)
{
if (colorCodeMap[color] == undefined)
return string;
@@ -190,7 +190,7 @@ var levelColorMap = {
}
// CPLogConsole uses the built in "console" object
exports.CPLogConsole = function(aString, aLevel, aTitle)
GLOBAL(CPLogConsole) = function(aString, aLevel, aTitle)
{
if (typeof console != "undefined")
{
@@ -213,14 +213,14 @@ exports.CPLogConsole = function(aString, aLevel, aTitle)
}
#if COMMONJS
exports.CPLogPrint = function(aString, aLevel, aTitle)
GLOBAL(CPLogPrint) = function(aString, aLevel, aTitle)
{
if (typeof print != "undefined")
{
if (aLevel == "fatal" || aLevel == "error" || aLevel == "warn")
var message = exports.ANSITextColorize(_CPFormatLogMessage(aString, aLevel, aTitle), levelColorMap[aLevel]);
var message = ANSITextColorize(_CPFormatLogMessage(aString, aLevel, aTitle), levelColorMap[aLevel]);
else
var message = _CPFormatLogMessage(aString, exports.ANSITextColorize(aLevel, levelColorMap[aLevel]), aTitle);
var message = _CPFormatLogMessage(aString, ANSITextColorize(aLevel, levelColorMap[aLevel]), aTitle);
require("system").stderr.print(message);
}
@@ -228,21 +228,21 @@ exports.CPLogPrint = function(aString, aLevel, aTitle)
#else
// CPLogAlert uses basic browser alert() functions
exports.CPLogAlert = function(aString, aLevel, aTitle)
GLOBAL(CPLogAlert) = function(aString, aLevel, aTitle)
{
if (typeof alert != "undefined" && !exports.CPLogDisable)
if (typeof alert != "undefined" && !CPLogDisable)
{
var message = _CPFormatLogMessage(aString, aLevel, aTitle);
exports.CPLogDisable = !confirm(message + "\n\n(Click cancel to stop log alerts)");
CPLogDisable = !confirm(message + "\n\n(Click cancel to stop log alerts)");
}
}
// CPLogPopup uses a slick popup window in the browser:
var CPLogWindow = null;
exports.CPLogPopup = function(aString, aLevel, aTitle)
GLOBAL(CPLogPopup) = function(aString, aLevel, aTitle)
{
try {
if (exports.CPLogDisable || window.open == undefined)
if (CPLogDisable || window.open == undefined)
return;
if (!CPLogWindow || !CPLogWindow.document)
@@ -250,7 +250,7 @@ exports.CPLogPopup = function(aString, aLevel, aTitle)
CPLogWindow = window.open("", "_blank", "width=600,height=400,status=no,resizable=yes,scrollbars=yes");
if (!CPLogWindow) {
exports.CPLogDisable = !confirm(aString + "\n\n(Disable pop-up blocking for CPLog window; Click cancel to stop log alerts)");
CPLogDisable = !confirm(aString + "\n\n(Disable pop-up blocking for CPLog window; Click cancel to stop log alerts)");
return;
}
@@ -379,15 +379,15 @@ function _CPLogInitPopup(logWindow)
// Parent closing
window.addEventListener("unload", function() {
if (logWindow && logWindow.closeEnabled && logWindow.closeEnabled.checked) {
exports.CPLogDisable = true;
CPLogDisable = true;
logWindow.close();
}
}, false);
// Log popup closing
logWindow.addEventListener("unload", function() {
if (!exports.CPLogDisable) {
exports.CPLogDisable = !confirm("Click cancel to stop logging");
if (!CPLogDisable) {
CPLogDisable = !confirm("Click cancel to stop logging");
}
}, false);
}
+4 -4
View File
@@ -1,9 +1,9 @@
#!/usr/bin/env narwhal
var FILE = require("file");
var SYSTEM = require("system");
var OS = require("os");
var CFPropertyList = require("objective-j").CFPropertyList;
var FILE = require("file"),
SYSTEM = require("system"),
OS = require("os"),
ObjectiveJ = require("objective-j");
var parser = new (require("args").Parser)();
+3 -3
View File
@@ -155,8 +155,8 @@ exports.objj_eval = function(/*String*/ aString)
var code = executable._code;
// Not clear why these should be global, varing them doesn't seem to take effect with evaluateString.
global.objj_executeFile = exports.fileExecuterForPath(FILE.cwd());
global.objj_importFile = fileImporterForPath(FILE.cwd());
global.objj_executeFile = Executable.fileExecuterForPath(FILE.cwd());
global.objj_importFile = Executable.fileImporterForPath(FILE.cwd());
if (typeof system !== "undefined" && system.engine === "rhino")
return Packages.org.mozilla.javascript.Context.getCurrentContext().evaluateString(global, code, "objj_eval", 0, NULL);
@@ -173,7 +173,7 @@ exports.make_narwhal_factory = function(path)
{
Executable.setCommonJSArguments(require, exports, module, system, print, window);
fileImporterForPath(FILE.dirname(path))(path, function()
Executable.fileImporterForPath(FILE.dirname(path))(path, function()
{
print("all done");
});
@@ -5,11 +5,9 @@ var FILE = require("file"),
require("objective-j/rhino/regexp-rhino-patch");
var OBJJ_PREPROCESSOR_DEBUG_SYMBOLS = exports.OBJJ_PREPROCESSOR_DEBUG_SYMBOLS = ObjectiveJ.OBJJ_PREPROCESSOR_DEBUG_SYMBOLS;
var OBJJ_PREPROCESSOR_TYPE_SIGNATURES = exports.OBJJ_PREPROCESSOR_TYPE_SIGNATURES = ObjectiveJ.OBJJ_PREPROCESSOR_TYPE_SIGNATURES;
var OBJJ_PREPROCESSOR_PREPROCESS = exports.OBJJ_PREPROCESSOR_PREPROCESS = 1 << 10;
var OBJJ_PREPROCESSOR_COMPRESS = exports.OBJJ_PREPROCESSOR_COMPRESS = 1 << 11;
var OBJJ_PREPROCESSOR_SYNTAX = exports.OBJJ_PREPROCESSOR_SYNTAX = 1 << 12;
ObjectiveJ.Preprocessor.Flags.Preprocess = 1 << 10;
ObjectiveJ.Preprocessor.Flags.Compress = 1 << 11;
ObjectiveJ.Preprocessor.Flags.CheckSyntax = 1 << 12;
var compressors = {
ss : { id : "minify/shrinksafe" }
@@ -35,9 +33,9 @@ function compressor(code) {
function compileWithResolvedFlags(aFilePath, objjcFlags, gccFlags)
{
var shouldObjjPreprocess = objjcFlags & OBJJ_PREPROCESSOR_PREPROCESS,
shouldCheckSyntax = objjcFlags & OBJJ_PREPROCESSOR_SYNTAX,
shouldCompress = objjcFlags & OBJJ_PREPROCESSOR_COMPRESS,
var shouldObjjPreprocess = objjcFlags & ObjectiveJ.Preprocessor.Flags.Preprocess,
shouldCheckSyntax = objjcFlags & ObjectiveJ.Preprocessor.Flags.CheckSyntax,
shouldCompress = objjcFlags & ObjectiveJ.Preprocessor.Flags.Compress,
fileContents = "";
if (OS.popen("which gcc").stdout.read().length === 0)
@@ -97,7 +95,7 @@ function resolveFlags(args)
count = args.length,
gccFlags = [],
objjcFlags = OBJJ_PREPROCESSOR_PREPROCESS | OBJJ_PREPROCESSOR_SYNTAX;
objjcFlags = ObjectiveJ.Preprocessor.Flags.Preprocess | ObjectiveJ.Preprocessor.Flags.CheckSyntax;
for (; index < count; ++index)
{
@@ -116,16 +114,16 @@ function resolveFlags(args)
gccFlags.push(argument);
else if (argument.indexOf("-E") === 0)
objjcFlags &= ~OBJJ_PREPROCESSOR_PREPROCESS;
objjcFlags &= ~ObjectiveJ.Preprocessor.Flags.Preprocess;
else if (argument.indexOf("-S") === 0)
objjcFlags &= ~OBJJ_PREPROCESSOR_SYNTAX;
objjcFlags &= ~ObjectiveJ.Preprocessor.Flags.CheckSyntax;
else if (argument.indexOf("-g") === 0)
objjcFlags |= OBJJ_PREPROCESSOR_DEBUG_SYMBOLS;
objjcFlags |= ObjectiveJ.Preprocessor.Flags.IncludeDebugSymbols;
else if (argument.indexOf("-O") === 0)
objjcFlags |= OBJJ_PREPROCESSOR_COMPRESS;
objjcFlags |= ObjectiveJ.Preprocessor.Flags.Compress;
else
filePaths.push(argument);
@@ -7,13 +7,10 @@ var FILE = require("file"),
CLEAN = require("jake/clean").CLEAN,
CLOBBER = require("jake/clean").CLOBBER,
base64 = require("base64"),
environment = require("objective-j/jake/environment"),
ObjectiveJ = require("objective-j"),
environment = require("objective-j/jake/environment"),
task = Jake.task;
var CFPropertyList = ObjectiveJ.CFPropertyList,
CFMutableDictionary = ObjectiveJ.CFMutableDictionary;
var Task = Jake.Task,
filedir = Jake.filedir;
@@ -470,7 +467,11 @@ BundleTask.prototype.defineResourceTask = function(aResourcePath, aDestinationPa
FILE.write(spritedDestinationPath, base64.encode(FILE.read(aResourcePath, "b")), { charset:"UTF-8" });
});
task (anEnvironment.name() + "-sprites", [spritedDestinationPath]);
filedir (this.buildProductDataURLPathForEnvironment(anEnvironment), [spritedDestinationPath]);
filedir (this.buildProductMHTMLPathForEnvironment(anEnvironment), [spritedDestinationPath]);
filedir (this.buildProductMHTMLDataPathForEnvironment(anEnvironment), [spritedDestinationPath]);
filedir (this.buildProductMHTMLTestPathForEnvironment(anEnvironment), [spritedDestinationPath]);
}, this);
}
@@ -592,67 +593,109 @@ BundleTask.prototype.defineSpritedImagesTask = function()
return;
var folder = anEnvironment.name() + ".environment",
resourcesPath = FILE.join(this.buildIntermediatesProductPath(), folder, "Resources", ""),
dataURLPath = this.buildProductDataURLPathForEnvironment(anEnvironment),
MHTMLPath = this.buildProductMHTMLPathForEnvironment(anEnvironment),
MHTMLDataPath = this.buildProductMHTMLDataPathForEnvironment(anEnvironment),
MHTMLTestDestinationPath = this.buildProductMHTMLTestPathForEnvironment(anEnvironment),
productName = this.productName();
resourcesPath = FILE.join(this.buildIntermediatesProductPath(), folder, "Resources", "");
task(anEnvironment.name() + "-sprites", function(aTask)
function isDataResource(/*String*/ aFilename)
{
TERM.stream.print("Creating sprited images file... \0green(" + dataURLPath +"\0)");
return FILE.isFile(aFilename) && aFilename.indexOf(resourcesPath) === 0 && isImage(aFilename);
}
var dataURLStream = FILE.open(dataURLPath, "w+", { charset:"UTF-8" }),
MHTMLStream = FILE.open(MHTMLPath, "w+", { charset:"UTF-8" }),
MHTMLDataStream = FILE.open(MHTMLDataPath, "w+", { charset:"UTF-8" });
var productName = this.productName(),
dataURLPath = this.buildProductDataURLPathForEnvironment(anEnvironment);
filedir (dataURLPath, function(aTask)
{
TERM.stream.print("Creating data URLs file... \0green(" + dataURLPath +"\0)");
var dataURLStream = FILE.open(dataURLPath, "w+", { charset:"UTF-8" });
dataURLStream.write("@STATIC;1.0;");
MHTMLStream.write("@STATIC;1.0;");
MHTMLDataStream.write("/*\r\nContent-Type: multipart/related; boundary=\"_ANY_STRING_WILL_DO_AS_A_SEPARATOR\"\r\n\r\n");
aTask.prerequisites().forEach(function(aFilename)
{
if (!FILE.isFile(aFilename) || aFilename.indexOf(resourcesPath) !== 0 || !isImage(aFilename))
if (!isDataResource(aFilename))
return;
var resourcePath = "Resources/" + FILE.relative(resourcesPath, aFilename);
dataURLStream.write("u;" + resourcePath.length + ";" + resourcePath);
MHTMLStream.write("u;" + resourcePath.length + ";" + resourcePath);
// As data URL...
var contents = "data:" + mimeType(aFilename) +
";base64," + FILE.read(aFilename, "b").decodeToString("UTF-8");
dataURLStream.write(contents.length + ";" + contents);
});
// As MHTML...
contents = "mhtml:" + FILE.join(folder, "MHTMLData.txt!") + resourcePath;
dataURLStream.write("e;");
dataURLStream.close();
});
this.enhance([dataURLPath]);
var MHTMLPath = this.buildProductMHTMLPathForEnvironment(anEnvironment);
filedir (MHTMLPath, function(aTask)
{
TERM.stream.print("Creating MHTML paths file... \0green(" + MHTMLPath +"\0)");
var MHTMLStream = FILE.open(MHTMLPath, "w+", { charset:"UTF-8" });
MHTMLStream.write("@STATIC;1.0;");
aTask.prerequisites().forEach(function(aFilename)
{
if (!isDataResource(aFilename))
return;
var resourcePath = "Resources/" + FILE.relative(resourcesPath, aFilename);
MHTMLStream.write("u;" + resourcePath.length + ";" + resourcePath);
});
MHTMLStream.close();
});
this.enhance([MHTMLPath]);
var MHTMLDataPath = this.buildProductMHTMLDataPathForEnvironment(anEnvironment);
filedir (MHTMLDataPath, function(aTask)
{
TERM.stream.print("Creating MHTML images file... \0green(" + MHTMLDataPath +"\0)");
var MHTMLDataStream = FILE.open(MHTMLDataPath, "w+", { charset:"UTF-8" });
MHTMLDataStream.write("/*\r\nContent-Type: multipart/related; boundary=\"_ANY_STRING_WILL_DO_AS_A_SEPARATOR\"\r\n\r\n");
aTask.prerequisites().forEach(function(aFilename)
{
if (!isDataResource(aFilename))
return;
var resourcePath = "Resources/" + FILE.relative(resourcesPath, aFilename);
MHTMLDataStream.write("--_ANY_STRING_WILL_DO_AS_A_SEPARATOR\r\n");
MHTMLDataStream.write("Content-Location:" + resourcePath + "\r\nContent-Transfer-Encoding:base64\r\n\r\n");
MHTMLDataStream.write(FILE.read(aFilename, "b").decodeToString("UTF-8"));
MHTMLDataStream.write("\r\n");
MHTMLStream.write(contents.length + ";" + contents);
});
dataURLStream.write("e;");
dataURLStream.close();
MHTMLStream.write("e;");
MHTMLStream.close();
MHTMLDataStream.write("*/");
MHTMLDataStream.close();
});
this.enhance([MHTMLDataPath]);
var MHTMLTestDestinationPath = this.buildProductMHTMLTestPathForEnvironment(anEnvironment);
filedir (MHTMLTestDestinationPath, function(aTask)
{
TERM.stream.print("Copying MHTML test file... \0green(" + MHTMLTestDestinationPath +"\0)");
// copy the MHTML test file into this environment
FILE.copy(MHTMLTestPath, MHTMLTestDestinationPath);
});
this.enhance([anEnvironment.name() + "-sprites"]);
this.enhance([MHTMLTestDestinationPath]);
}, this);
}
+40 -80
View File
@@ -1,11 +1,6 @@
var undefined;
exports.environments = function()
{
return ENVIRONMENTS;
}
if (typeof window !== "undefined")
{
window.setNativeTimeout = window.setTimeout;
@@ -15,80 +10,45 @@ if (typeof window !== "undefined")
}
// Objective-J Constants
var NO = false,
YES = true,
nil = null,
Nil = null,
NULL = null,
GLOBAL(NO) = false;
GLOBAL(YES) = true;
ABS = Math.abs,
ASIN = Math.asin,
ACOS = Math.acos,
ATAN = Math.atan,
ATAN2 = Math.atan2,
SIN = Math.sin,
COS = Math.cos,
TAN = Math.tan,
EXP = Math.exp,
POW = Math.pow,
CEIL = Math.ceil,
FLOOR = Math.floor,
ROUND = Math.round,
MIN = Math.min,
MAX = Math.max,
RAND = Math.random,
SQRT = Math.sqrt,
E = Math.E,
LN2 = Math.LN2,
LN10 = Math.LN10,
LOG2E = Math.LOG2E,
LOG10E = Math.LOG10E,
PI = Math.PI,
PI2 = Math.PI * 2.0,
PI_2 = Math.PI / 2.0,
SQRT1_2 = Math.SQRT1_2,
SQRT2 = Math.SQRT2;
GLOBAL(nil) = null;
GLOBAL(Nil) = null;
GLOBAL(NULL) = null;
exports.NO = NO;
exports.YES = YES;
exports.nil = nil;
exports.Nil = Nil;
exports.NULL = NULL;
exports.ABS = ABS;
exports.ASIN = ASIN;
exports.ACOS = ACOS;
exports.ATAN = ATAN;
exports.ATAN2 = ATAN2;
exports.SIN = SIN;
exports.COS = COS;
exports.TAN = TAN;
exports.EXP = EXP;
exports.POW = POW;
exports.CEIL = CEIL;
exports.FLOOR = FLOOR;
exports.ROUND = ROUND;
exports.MIN = MIN;
exports.MAX = MAX;
exports.RAND = RAND;
exports.SQRT = SQRT;
exports.E = E;
exports.LN2 = LN2;
exports.LN10 = LN10;
exports.LOG2E = LOG2E;
exports.LOG10E = LOG10E;
exports.PI = PI;
exports.PI2 = PI * 2.0;
exports.PI_2 = PI / 2.0;
exports.SQRT1_2 = SQRT1_2;
exports.SQRT2 = SQRT2;
GLOBAL(ABS) = Math.abs;
GLOBAL(ASIN) = Math.asin;
GLOBAL(ACOS) = Math.acos;
GLOBAL(ATAN) = Math.atan;
GLOBAL(ATAN2) = Math.atan2;
GLOBAL(SIN) = Math.sin;
GLOBAL(COS) = Math.cos;
GLOBAL(TAN) = Math.tan;
GLOBAL(EXP) = Math.exp;
GLOBAL(POW) = Math.pow;
GLOBAL(CEIL) = Math.ceil;
GLOBAL(FLOOR) = Math.floor;
GLOBAL(ROUND) = Math.round;
GLOBAL(MIN) = Math.min;
GLOBAL(MAX) = Math.max;
GLOBAL(RAND) = Math.random;
GLOBAL(SQRT) = Math.sqrt;
GLOBAL(E) = Math.E;
GLOBAL(LN2) = Math.LN2;
GLOBAL(LN10) = Math.LN10;
GLOBAL(LOG2E) = Math.LOG2E;
GLOBAL(LOG10E) = Math.LOG10E;
GLOBAL(PI) = Math.PI;
GLOBAL(PI2) = Math.PI * 2.0;
GLOBAL(PI_2) = Math.PI / 2.0;
GLOBAL(SQRT1_2) = Math.SQRT1_2;
GLOBAL(SQRT2) = Math.SQRT2;
+1 -1
View File
@@ -2,7 +2,7 @@
function objj_debug_object_format(aReceiver)
{
return (aReceiver && aReceiver.isa) ? sprintf("<%s %#08x>", GETMETA(aReceiver).name, aReceiver.__address) : String(aReceiver);
return (aReceiver && aReceiver.isa) ? sprintf("<%s %#08x>", GETMETA(aReceiver).name, aReceiver._UID) : String(aReceiver);
}
function objj_debug_message_format(aReceiver, aSelector)
+3 -3
View File
@@ -26,9 +26,9 @@ EventDispatcher.prototype.addEventListener = function(/*String*/ anEventName, /*
while (index--)
if (eventListenersForEventName[index] === anEventListener)
return;
return;
eventListenersForEventName.push(anEventListener);
eventListenersForEventName.push(anEventListener);
}
EventDispatcher.prototype.removeEventListener = function(/*String*/ anEventName, /*Function*/ anEventListener)
@@ -43,7 +43,7 @@ EventDispatcher.prototype.removeEventListener = function(/*String*/ anEventName,
while (index--)
if (eventListenersForEventName[index] === anEventListener)
return eventListenersForEventName.splice(index, 1);
return eventListenersForEventName.splice(index, 1);
}
EventDispatcher.prototype.dispatchEvent = function(/*Event*/ anEvent)
+107 -5
View File
@@ -44,6 +44,8 @@ function Executable(/*String*/ aCode, /*Array*/ fileDependencies, /*String*/ aSc
this.setCode(aCode);
}
exports.Executable = Executable;
Executable.prototype.path = function()
{
return FILE.join(FILE.cwd(), "(Anonymous)");
@@ -64,10 +66,7 @@ Executable.prototype.functionParameters = function()
Executable.prototype.functionArguments = function()
{
var dirname = FILE.dirname(this.path()),
functionArguments = [global, exports.fileExecuterForPath(dirname), fileImporterForPath(dirname)];
//functionArguments = exportedValues().concat(exports.fileExecuterForPath(path), fileImporterForPath(path));
var functionArguments = [global, this.fileExecuter(), this.fileImporter()];
#ifdef COMMONJS
functionArguments = functionArguments.concat(Executable.commonJSArguments());
@@ -303,4 +302,107 @@ Executable.prototype.removeEventListener = function(/*String*/ anEventName, /*Fu
this._eventDispatcher.removeEventListener(anEventName, aListener);
}
exports.Executable = Executable;
function importablePath(/*String*/ aPath, /*BOOL*/ isLocal, /*String*/ aCWD)
{
aPath = FILE.normal(aPath);
if (FILE.isAbsolute(aPath))
return aPath;
if (isLocal)
aPath = FILE.normal(FILE.join(aCWD, aPath));
return aPath;
}
Executable.prototype.fileImporter = function()
{
return Executable.fileImporterForPath(FILE.dirname(this.path()));
}
Executable.prototype.fileExecuter = function()
{
return Executable.fileExecuterForPath(FILE.dirname(this.path()));
}
var cachedFileExecutersForPaths = { };
Executable.fileExecuterForPath = function(/*String*/ referencePath)
{
referencePath = FILE.normal(referencePath);
var fileExecuter = cachedFileExecutersForPaths[referencePath];
if (!fileExecuter)
{
fileExecuter = function(/*String*/ aPath, /*BOOL*/ isLocal, /*BOOL*/ shouldForce)
{
aPath = importablePath(aPath, isLocal, referencePath);
var fileExecutableSearch = new FileExecutableSearch(aPath, isLocal),
fileExecutable = fileExecutableSearch.result();
if (0 && !fileExecutable.hasLoadedFileDependencies())
throw "No executable loaded for file at path " + aPath;
fileExecutable.execute(shouldForce);
}
cachedFileExecutersForPaths[referencePath] = fileExecuter;
}
return fileExecuter;
}
var cachedImportersForPaths = { };
Executable.fileImporterForPath = function(/*String*/ referencePath)
{
referencePath = FILE.normal(referencePath);
var cachedImporter = cachedImportersForPaths[referencePath];
if (!cachedImporter)
{
cachedImporter = function(/*String*/ aPath, /*BOOL*/ isLocal, /*Function*/ aCallback)
{
aPath = importablePath(aPath, isLocal, referencePath);
var fileExecutableSearch = new FileExecutableSearch(aPath, isLocal);
function searchComplete(/*FileExecutableSearch*/ aFileExecutableSearch)
{
var fileExecutable = aFileExecutableSearch.result(),
fileExecuter = Executable.fileExecuterForPath(referencePath),
executeAndCallback = function ()
{
fileExecuter(aPath, isLocal);
if (aCallback)
aCallback();
}
if (!fileExecutable.hasLoadedFileDependencies())
{
fileExecutable.addEventListener("dependenciesload", executeAndCallback);
fileExecutable.loadFileDependencies();
}
else
executeAndCallback();
}
if (fileExecutableSearch.isComplete())
searchComplete(fileExecutableSearch);
else
fileExecutableSearch.addEventListener("complete", function(/*Event*/ anEvent)
{
searchComplete(anEvent.fileExecutableSearch);
});
}
cachedImportersForPaths[referencePath] = cachedImporter;
}
return cachedImporter;
}
+2 -2
View File
@@ -26,6 +26,8 @@ function FileDependency(/*String*/ aPath, /*BOOL*/ isLocal)
this._isLocal = isLocal;
}
exports.FileDependency = FileDependency;
FileDependency.prototype.path = function()
{
return this._path;
@@ -46,5 +48,3 @@ FileDependency.prototype.toString = function()
{
return (this.isLocal() ? "LOCAL: " : "STD: ") + this.path();
}
exports.FileDependency = FileDependency;
+18 -9
View File
@@ -20,10 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
var FileExecutableUnloadedDependencies = 0,
FileExecutableLoadingDependencies = 1,
FileExecutableLoadedDependencies = 2,
FileExecutablesForPaths = { };
var FileExecutablesForPaths = { };
function FileExecutable(/*String*/ aPath)
{
@@ -42,7 +39,7 @@ function FileExecutable(/*String*/ aPath)
executable = decompile(fileContents, aPath);
else if (extension === ".j" || extension === "")
executable = preprocess(fileContents, aPath, OBJJ_PREPROCESSOR_DEBUG_SYMBOLS);
executable = exports.preprocess(fileContents, aPath, Preprocessor.OBJJ_PREPROCESSOR_DEBUG_SYMBOLS);
else
executable = new Executable(fileContents, [], aPath);
@@ -53,8 +50,23 @@ function FileExecutable(/*String*/ aPath)
this._hasExecuted = NO;
}
exports.FileExecutable = FileExecutable;
FileExecutable.prototype = new Executable();
#ifdef COMMONJS
FileExecutable.allFileExecutables = function()
{
var fileExecutables = [];
for (path in FileExecutablesForPaths)
if (hasOwnProperty.call(FileExecutablesForPaths, path))
fileExecutables.push(FileExecutablesForPaths[path]);
return fileExecutables;
}
#endif
FileExecutable.prototype.execute = function(/*BOOL*/ shouldForce)
{
if (this._hasExecuted && !shouldForce)
@@ -62,7 +74,7 @@ FileExecutable.prototype.execute = function(/*BOOL*/ shouldForce)
this._hasExecuted = YES;
Executable.prototype.execute.apply(this, []);
Executable.prototype.execute.call(this);
}
FileExecutable.prototype.path = function()
@@ -102,6 +114,3 @@ function decompile(/*String*/ aString, /*String*/ aPath)
return new Executable(code, dependencies, aPath);
}
exports.FileExecutable = FileExecutable;
exports.FileExecutablesForPaths = FileExecutablesForPaths;
+4 -4
View File
@@ -34,7 +34,7 @@ function FileExecutableSearch(/*String*/ aPath, /*BOOL*/ isLocal)
FileExecutableSearchesForPaths[isLocal ? 1 : 0][aPath] = this;
this._UID = generateObjectUID();
this._UID = objj_generateObjectUID();
this._isComplete = NO;
this._eventDispatcher = new EventDispatcher(this);
this._path = aPath;
@@ -59,11 +59,13 @@ function FileExecutableSearch(/*String*/ aPath, /*BOOL*/ isLocal)
}
if (isLocal)
rootResource.resolveSubPath(aPath, StaticResource.FileType, completed);
rootResource.resolveSubPath(aPath, NO, completed);
else
StaticResource.resolveStandardNodeAtPath(aPath, completed);
}
exports.FileExecutableSearch = FileExecutableSearch;
FileExecutableSearch.prototype.path = function()
{
return this._path;
@@ -105,5 +107,3 @@ FileExecutableSearch.prototype.toString = function()
return "<FileExecutableSearch: " + this.path() + ">";
}
#endif
exports.FileExecutableSearch = FileExecutableSearch;
+5 -2
View File
@@ -1,11 +1,13 @@
#define GLOBAL(object) object
#include "DebugOptions.js"
#include "json2.js"
#include "sprintf.js"
#include "CPLog.js"
#include "Constants.js"
#include "EventDispatcher.js"
#include "HTTPRequest.js"
#include "CFHTTPRequest.js"
#include "CFPropertyList.js"
#include "CFDictionary.js"
#include "CFData.js"
@@ -17,7 +19,8 @@
#include "Executable.js"
#include "FileExecutable.js"
#include "FileExecutableSearch.js"
#include "Scope.js"
#include "Runtime.js"
#if DEBUG
#include "Debug.js"
#endif
#include "Bootstrap.js"
+3 -2
View File
@@ -33,6 +33,7 @@ $BUILD_OBJECTIVE_J = FILE.join($BUILD_CONFIGURATION_DIR, "Objective-J");
$BUILD_BROWSER_FILE = FILE.join($BUILD_OBJECTIVE_J, "Objective-J.js");
$INCLUDE_FLAGS = " -I" + FILE.cwd();
$DEBUG_FLAGS = $CONFIGURATION === "Debug" ? " -DDEBUG=1 " : "";
$OBJECTIVEJ_FILES = new FileList("*.js");
$BROWSER_FILES = new FileList($BROWSER_FILE).include($OBJECTIVEJ_FILES);
@@ -41,7 +42,7 @@ filedir($BUILD_BROWSER_FILE, $BROWSER_FILES, function(aTask)
{
gcc($BROWSER_FILE,
$BUILD_BROWSER_FILE,
environmentFlags("Browser", "ObjJ") + $INCLUDE_FLAGS, $CONFIGURATION !== "Debug");
environmentFlags("Browser", "ObjJ") + $INCLUDE_FLAGS + $DEBUG_FLAGS, $CONFIGURATION !== "Debug");
});
$LICENSE = FILE.join("CommonJS", "lib", "objective-j", "jake", "LICENSES", "LGPL-v2.1");
@@ -70,7 +71,7 @@ new FileList("CommonJS/**/*").forEach(function(aFilename)
else
gcc(aFilename,
buildFilename,
environmentFlags("CommonJS", "ObjJ") + $INCLUDE_FLAGS, false);
environmentFlags("CommonJS", "ObjJ") + $INCLUDE_FLAGS + $DEBUG_FLAGS, false);
});
if (FILE.dirname(aFilename) === FILE.join("CommonJS", "bin"))
-2
View File
@@ -67,5 +67,3 @@ MarkedStream.prototype.getString = function()
return text;
}
exports.MarkedStream = MarkedStream;
+17 -17
View File
@@ -20,9 +20,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
var OBJJ_PREPROCESSOR_DEBUG_SYMBOLS = 1 << 0,
OBJJ_PREPROCESSOR_TYPE_SIGNATURES = 1 << 1;
var TOKEN_ACCESSORS = "accessors",
TOKEN_CLASS = "class",
TOKEN_END = "end",
@@ -64,10 +61,10 @@ var TOKEN_ACCESSORS = "accessors",
#define IS_WORD(token) /^\w+$/.test(token)
// FIXME: Used fixed regex
function Lexer(/*String*/ aString)
{
this._index = -1;
// FIXME: Used fixed regex
this._tokens = (aString + '\n').match(/\/\/.*(\r|\n)?|\/\*(?:.|\n|\r)*?\*\/|\w+\b|[+-]?\d+(([.]\d+)*([eE][+-]?\d+))?|"[^"\\]*(\\[\s\S][^"\\]*)*"|'[^'\\]*(\\[\s\S][^'\\]*)*'|\s+|./g);
this._context = [];
@@ -128,6 +125,8 @@ Lexer.prototype.skip_whitespace= function(shouldMoveBackwards)
return token;
}
exports.Lexer = Lexer;
#define IS_NOT_EMPTY(buffer) buffer.atoms.length !== 0
#define CONCAT(buffer, atom) buffer.atoms[buffer.atoms.length] = atom
@@ -141,19 +140,17 @@ StringBuffer.prototype.toString = function()
return this.atoms.join("");
}
function preprocess(/*String*/ aString, /*String*/ aPath, /*unsigned*/ flags)
exports.preprocess = function(/*String*/ aString, /*String*/ aPath, /*unsigned*/ flags)
{
return new Preprocessor(aString, aPath, flags).executable();
}
objj_preprocess = preprocess;
objj_eval = function(/*String*/ aString)
exports.eval = function(/*String*/ aString)
{
return eval(objj_preprocess(aString).code());
return eval(exports.preprocess(aString).code());
}
function Preprocessor(/*String*/ aString, /*String*/ aPath, /*unsigned*/ flags)
var Preprocessor = function(/*String*/ aString, /*String*/ aPath, /*unsigned*/ flags)
{
// Remove the shebang.
aString = aString.replace(/^#[^\n]+\n/, "\n");
@@ -177,6 +174,13 @@ function Preprocessor(/*String*/ aString, /*String*/ aPath, /*unsigned*/ flags)
this.preprocess(this._tokens, this._buffer);
}
exports.Preprocessor = Preprocessor;
Preprocessor.Flags = { };
Preprocessor.Flags.IncludeDebugSymbols = 1 << 0;
Preprocessor.Flags.IncludeTypeSignatures = 1 << 1;
Preprocessor.prototype.executable = function()
{
if (!this._executable)
@@ -723,7 +727,7 @@ Preprocessor.prototype.method = function(/*Lexer*/ tokens)
this._currentSelector = selector;
if (this._flags & OBJJ_PREPROCESSOR_DEBUG_SYMBOLS)
if (this._flags & Preprocessor.Flags.IncludeDebugSymbols)
CONCAT(buffer, " $" + this._currentClass + "__" + selector.replace(/:/g, "_"));
CONCAT(buffer, "(self, _cmd");
@@ -737,8 +741,8 @@ Preprocessor.prototype.method = function(/*Lexer*/ tokens)
CONCAT(buffer, ")\n{ with(self)\n{");
CONCAT(buffer, this.preprocess(tokens, NULL, TOKEN_CLOSE_BRACE, TOKEN_OPEN_BRACE));
CONCAT(buffer, "}\n}");
// TODO: actually use OBJJ_PREPROCESSOR_TYPE_SIGNATURES flag instead of tying to OBJJ_PREPROCESSOR_DEBUG_SYMBOLS
if (this._flags & OBJJ_PREPROCESSOR_DEBUG_SYMBOLS) //OBJJ_PREPROCESSOR_TYPE_SIGNATURES)
// TODO: actually use Flags.IncludeTypeSignatures flag instead of tying to Flags.IncludeDebugSymbols
if (this._flags & Preprocessor.Flags.IncludeDebugSymbols) //flags.IncludeTypeSignatures)
CONCAT(buffer, ","+JSON.stringify(types));
CONCAT(buffer, ")");
@@ -1004,7 +1008,3 @@ Preprocessor.prototype.error_message = function(errorMessage)
(this._currentClass ? " Class: "+this._currentClass : "") +
(this._currentSelector ? " Method: "+this._currentSelector : "") +">";
}
exports.Lexer = Lexer;
exports.Preprocessor = Preprocessor;
exports.preprocess = preprocess;
+51 -110
View File
@@ -33,20 +33,20 @@ var CLS_CLASS = 0x1,
#define GETMETA(aClass) (ISMETA(aClass) ? aClass : aClass.isa)
#define ISINITIALIZED(aClass) GETINFO(GETMETA(aClass), CLS_INITIALIZED)
function objj_ivar(/*String*/ aName, /*String*/ aType)
GLOBAL(objj_ivar) = function(/*String*/ aName, /*String*/ aType)
{
this.name = aName;
this.type = aType;
}
function objj_method(/*String*/ aName, /*IMP*/ anImplementation, /*String*/ types)
GLOBAL(objj_method) = function(/*String*/ aName, /*IMP*/ anImplementation, /*String*/ types)
{
this.name = aName;
this.method_imp = anImplementation;
this.types = types;
}
function objj_class()
GLOBAL(objj_class) = function()
{
this.isa = NULL;
@@ -64,18 +64,18 @@ function objj_class()
this.method_dtable = this.method_store.prototype;
this.allocator = function() { };
this.__address = -1;
this._UID = -1;
}
function objj_object()
GLOBAL(objj_object) = function()
{
this.isa = NULL;
this.__address = -1;
this.isa = NULL;
this._UID = -1;
}
// Working with Classes
function class_getName(/*Class*/ aClass)
GLOBAL(class_getName) = function(/*Class*/ aClass)
{
if (aClass == Nil)
return "";
@@ -83,7 +83,7 @@ function class_getName(/*Class*/ aClass)
return aClass.name;
}
function class_isMetaClass(/*Class*/ aClass)
GLOBAL(class_isMetaClass) = function(/*Class*/ aClass)
{
if (!aClass)
return NO;
@@ -91,7 +91,7 @@ function class_isMetaClass(/*Class*/ aClass)
return ISMETA(aClass);
}
function class_getSuperclass(/*Class*/ aClass)
GLOBAL(class_getSuperclass) = function(/*Class*/ aClass)
{
if (aClass == Nil)
return Nil;
@@ -99,14 +99,14 @@ function class_getSuperclass(/*Class*/ aClass)
return aClass.super_class;
}
function class_setSuperclass(/*Class*/ aClass, /*Class*/ aSuperClass)
GLOBAL(class_setSuperclass) = function(/*Class*/ aClass, /*Class*/ aSuperClass)
{
// Set up the actual class hierarchy.
aClass.super_class = aSuperClass;
aClass.isa.super_class = aSuperClass.isa;
}
function class_addIvar(/*Class*/ aClass, /*String*/ aName, /*String*/ aType)
GLOBAL(class_addIvar) = function(/*Class*/ aClass, /*String*/ aName, /*String*/ aType)
{
var thePrototype = aClass.allocator.prototype;
@@ -119,7 +119,7 @@ function class_addIvar(/*Class*/ aClass, /*String*/ aName, /*String*/ aType)
return YES;
}
function class_addIvars(/*Class*/ aClass, /*Array*/ivars)
GLOBAL(class_addIvars) = function(/*Class*/ aClass, /*Array*/ivars)
{
var index = 0,
count = ivars.length,
@@ -138,7 +138,7 @@ function class_addIvars(/*Class*/ aClass, /*Array*/ivars)
}
}
function class_copyIvarList(/*Class*/ aClass)
GLOBAL(class_copyIvarList) = function(/*Class*/ aClass)
{
return aClass.ivars.slice(0);
}
@@ -147,7 +147,7 @@ function class_copyIvarList(/*Class*/ aClass)
#define METHOD_DISPLAY_NAME(aClass, aMethod) (ISMETA(aClass) ? '+' : '-') + " [" + class_getName(aClass) + ' ' + method_getName(aMethod) + ']'
function class_addMethod(/*Class*/ aClass, /*SEL*/ aName, /*IMP*/ anImplementation, /*Array<String>*/ types)
GLOBAL(class_addMethod) = function(/*Class*/ aClass, /*SEL*/ aName, /*IMP*/ anImplementation, /*Array<String>*/ types)
{
if (aClass.method_hash[aName])
return NO;
@@ -168,7 +168,7 @@ function class_addMethod(/*Class*/ aClass, /*SEL*/ aName, /*IMP*/ anImplementati
return YES;
}
function class_addMethods(/*Class*/ aClass, /*Array*/ methods)
GLOBAL(class_addMethods) = function(/*Class*/ aClass, /*Array*/ methods)
{
var index = 0,
count = methods.length,
@@ -195,7 +195,7 @@ function class_addMethods(/*Class*/ aClass, /*Array*/ methods)
class_addMethods(GETMETA(aClass), methods);
}
function class_getInstanceMethod(/*Class*/ aClass, /*SEL*/ aSelector)
GLOBAL(class_getInstanceMethod) = function(/*Class*/ aClass, /*SEL*/ aSelector)
{
if (!aClass || !aSelector)
return NULL;
@@ -205,7 +205,7 @@ function class_getInstanceMethod(/*Class*/ aClass, /*SEL*/ aSelector)
return method ? method : NULL;
}
function class_getClassMethod(/*Class*/ aClass, /*SEL*/ aSelector)
GLOBAL(class_getClassMethod) = function(/*Class*/ aClass, /*SEL*/ aSelector)
{
if (!aClass || !aSelector)
return NULL;
@@ -215,12 +215,12 @@ function class_getClassMethod(/*Class*/ aClass, /*SEL*/ aSelector)
return method ? method : NULL;
}
function class_copyMethodList(/*Class*/ aClass)
GLOBAL(class_copyMethodList) = function(/*Class*/ aClass)
{
return aClass.method_list.slice(0);
}
function class_replaceMethod(/*Class*/ aClass, /*SEL*/ aSelector, /*IMP*/ aMethodImplementation)
GLOBAL(class_replaceMethod) = function(/*Class*/ aClass, /*SEL*/ aSelector, /*IMP*/ aMethodImplementation)
{
if (!aClass || !aSelector)
return NULL;
@@ -236,8 +236,7 @@ function class_replaceMethod(/*Class*/ aClass, /*SEL*/ aSelector, /*IMP*/ aMetho
return method_imp;
}
// Private: Don't exports.
function _class_initialize(/*Class*/ aClass)
var _class_initialize = function(/*Class*/ aClass)
{
var meta = GETMETA(aClass);
@@ -274,7 +273,7 @@ var _objj_forward = new objj_method("forward", function(self, _cmd)
\
aMethodImplementation = method.method_imp;
function class_getMethodImplementation(/*Class*/ aClass, /*SEL*/ aSelector)
GLOBAL(class_getMethodImplementation) = function(/*Class*/ aClass, /*SEL*/ aSelector)
{
CLASS_GET_METHOD_IMPLEMENTATION(var implementation, aClass, aSelector);
@@ -282,10 +281,9 @@ function class_getMethodImplementation(/*Class*/ aClass, /*SEL*/ aSelector)
}
// Adding Classes
var GLOBAL_NAMESPACE = GLOBAL_NAMESPACE || global,
REGISTERED_CLASSES = { };
var REGISTERED_CLASSES = { };
function objj_allocateClassPair(/*Class*/ superclass, /*String*/ aName)
GLOBAL(objj_allocateClassPair) = function(/*Class*/ superclass, /*String*/ aName)
{
var classObject = new objj_class(),
metaClassObject = new objj_class(),
@@ -315,25 +313,25 @@ function objj_allocateClassPair(/*Class*/ superclass, /*String*/ aName)
}
else
classObject.allocator.prototype = new objj_object();
classObject.isa = metaClassObject;
classObject.name = aName;
classObject.info = CLS_CLASS;
classObject.__address = generateObjectUID();
classObject._UID = objj_generateObjectUID();
metaClassObject.isa = rootClassObject.isa;
metaClassObject.name = aName;
metaClassObject.info = CLS_META;
metaClassObject.__address = generateObjectUID();
metaClassObject._UID = objj_generateObjectUID();
return classObject;
}
var CONTEXT_BUNDLE = nil;
function objj_registerClassPair(/*Class*/ aClass)
GLOBAL(objj_registerClassPair) = function(/*Class*/ aClass)
{
GLOBAL_NAMESPACE[aClass.name] = aClass;
global[aClass.name] = aClass;
REGISTERED_CLASSES[aClass.name] = aClass;
addClassToBundle(aClass, CONTEXT_BUNDLE);
@@ -341,15 +339,15 @@ function objj_registerClassPair(/*Class*/ aClass)
// Instantiating Classes
function class_createInstance(/*Class*/ aClass)
GLOBAL(class_createInstance) = function(/*Class*/ aClass)
{
if (!aClass)
objj_exception_throw(new objj_exception(OBJJNilClassException, "*** Attempting to create object with Nil class."));
var object = new aClass.allocator;
var object = new aClass.allocator();
object.__address = generateObjectUID();
object.isa = aClass;
object._UID = objj_generateObjectUID();
return object;
}
@@ -401,7 +399,7 @@ class_createInstance = function(/*Class*/ aClass)
// Working with Instances
function object_getClassName(/*id*/ anObject)
GLOBAL(object_getClassName) = function(/*id*/ anObject)
{
if (!anObject)
return "";
@@ -412,14 +410,14 @@ function object_getClassName(/*id*/ anObject)
}
//objc_getClassList
function objj_lookUpClass(/*String*/ aName)
GLOBAL(objj_lookUpClass) = function(/*String*/ aName)
{
var theClass = REGISTERED_CLASSES[aName];
return theClass ? theClass : Nil;
}
function objj_getClass(/*String*/ aName)
GLOBAL(objj_getClass) = function(/*String*/ aName)
{
var theClass = REGISTERED_CLASSES[aName];
@@ -432,7 +430,7 @@ function objj_getClass(/*String*/ aName)
}
//objc_getRequiredClass
function objj_getMetaClass(/*String*/ aName)
GLOBAL(objj_getMetaClass) = function(/*String*/ aName)
{
var theClass = objj_getClass(aName);
@@ -441,19 +439,19 @@ function objj_getMetaClass(/*String*/ aName)
// Working with Instance Variables
function ivar_getName(anIvar)
GLOBAL(ivar_getName) = function(anIvar)
{
return anIvar.name;
}
function ivar_getTypeEncoding(anIvar)
GLOBAL(ivar_getTypeEncoding) = function(anIvar)
{
return anIvar.type;
}
// Sending Messages
function objj_msgSend(/*id*/ aReceiver, /*SEL*/ aSelector)
GLOBAL(objj_msgSend) = function(/*id*/ aReceiver, /*SEL*/ aSelector)
{
if (aReceiver == nil)
return nil;
@@ -470,7 +468,7 @@ function objj_msgSend(/*id*/ aReceiver, /*SEL*/ aSelector)
return implementation.apply(aReceiver, arguments);
}
function objj_msgSendSuper(/*id*/ aSuper, /*SEL*/ aSelector)
GLOBAL(objj_msgSendSuper) = function(/*id*/ aSuper, /*SEL*/ aSelector)
{
var super_class = aSuper.super_class;
@@ -483,17 +481,17 @@ function objj_msgSendSuper(/*id*/ aSuper, /*SEL*/ aSelector)
// Working with Methods
function method_getName(/*Method*/ aMethod)
GLOBAL(method_getName) = function(/*Method*/ aMethod)
{
return aMethod.name;
}
function method_getImplementation(/*Method*/ aMethod)
GLOBAL(method_getImplementation) = function(/*Method*/ aMethod)
{
return aMethod.method_imp;
}
function method_setImplementation(/*Method*/ aMethod, /*IMP*/ anImplementation)
GLOBAL(method_setImplementation) = function(/*Method*/ aMethod, /*IMP*/ anImplementation)
{
var oldImplementation = aMethod.method_imp;
@@ -502,7 +500,7 @@ function method_setImplementation(/*Method*/ aMethod, /*IMP*/ anImplementation)
return oldImplementation;
}
function method_exchangeImplementations(/*Method*/ lhs, /*Method*/ rhs)
GLOBAL(method_exchangeImplementations) = function(/*Method*/ lhs, /*Method*/ rhs)
{
var lhs_imp = method_getImplementation(lhs),
rhs_imp = method_getImplementation(rhs);
@@ -513,29 +511,29 @@ function method_exchangeImplementations(/*Method*/ lhs, /*Method*/ rhs)
// Working with Selectors
function sel_getName(aSelector)
GLOBAL(sel_getName) = function(aSelector)
{
return aSelector ? aSelector : "<null selector>";
}
function sel_getUid(/*String*/ aName)
GLOBAL(sel_getUid) = function(/*String*/ aName)
{
return aName;
}
function sel_isEqual(/*SEL*/ lhs, /*SEL*/ rhs)
GLOBAL(sel_isEqual) = function(/*SEL*/ lhs, /*SEL*/ rhs)
{
return lhs === rhs;
}
function sel_registerName(aName)
GLOBAL(sel_registerName) = function(/*String*/ aName)
{
return aName;
}
var fastEnumerationSelector = sel_getUid("countByEnumeratingWithState:objects:count:");
function objj_fastEnumerator(/*Object*/ anObject, /*Integer*/ anAssigneeCount)
GLOBAL(objj_fastEnumerator) = function(/*Object*/ anObject, /*Integer*/ anAssigneeCount)
{
// If this object doesn't respond to countByEnumeratingWithState:objects:count:
// (which is obviously the case for non-Objective-J objects), then just iterate
@@ -635,60 +633,3 @@ objj_fastEnumerator.prototype.e = function()
// fast enumeration method again.
return this.l > 0;
}
// Exports and Globals
exports.objj_ivar = objj_ivar;
exports.objj_method = objj_method;
exports.objj_class = objj_class;
exports.objj_object = objj_object;
exports.class_getName = class_getName;
exports.class_getSuperclass = class_getSuperclass;
exports.class_setSuperclass = class_setSuperclass;
exports.class_isMetaClass = class_isMetaClass;
exports.class_addIvar = class_addIvar;
exports.class_addIvars = class_addIvars;
exports.class_copyIvarList = class_copyIvarList;
exports.class_addMethod = class_addMethod;
exports.class_addMethods = class_addMethods;
exports.class_getInstanceMethod = class_getInstanceMethod;
exports.class_getClassMethod = class_getClassMethod;
exports.class_copyMethodList = class_copyMethodList;
exports.class_replaceMethod = class_replaceMethod;
exports.class_getMethodImplementation = class_getMethodImplementation;
exports.objj_allocateClassPair = objj_allocateClassPair;
exports.objj_registerClassPair = objj_registerClassPair;
exports.class_createInstance = class_createInstance;
exports.object_getClassName = object_getClassName;
exports.objj_lookUpClass = objj_lookUpClass;
exports.objj_getClass = objj_getClass;
exports.objj_getMetaClass = objj_getMetaClass;
exports.ivar_getName = ivar_getName;
exports.ivar_getTypeEncoding = ivar_getTypeEncoding;
exports.objj_msgSend = objj_msgSend;
exports.objj_msgSendSuper = objj_msgSendSuper;
exports.method_getName = method_getName;
exports.method_getImplementation = method_getImplementation;
exports.method_setImplementation = method_setImplementation;
exports.method_exchangeImplementations = method_exchangeImplementations;
exports.sel_getName = sel_getName;
exports.sel_getUid = sel_getUid;
exports.sel_isEqual = sel_isEqual;
exports.sel_registerName = sel_registerName;
exports.objj_fastEnumerator = objj_fastEnumerator;
exports.objj_generateObjectUID = generateObjectUID;
exports._objj_generateObjectHash = generateObjectUID;
-104
View File
@@ -1,104 +0,0 @@
// For now just make these global.
function makeExportsGlobal()
{
for (var exportName in exports)
if (hasOwnProperty.apply(exports, [exportName]))
global[exportName] = exports[exportName];
}
function importablePath(/*String*/ aPath, /*BOOL*/ isLocal, /*String*/ aCWD)
{
aPath = FILE.normal(aPath);
if (FILE.isAbsolute(aPath))
return aPath;
if (isLocal)
aPath = FILE.normal(FILE.join(aCWD, aPath));
return aPath;
}
var cachedFileExecutersForPaths = { };
exports.fileExecuterForPath = function(/*String*/ referencePath)
{
referencePath = FILE.normal(referencePath);
var fileExecuter = cachedFileExecutersForPaths[referencePath];
if (!fileExecuter)
{
fileExecuter = function(/*String*/ aPath, /*BOOL*/ isLocal, /*BOOL*/ shouldForce)
{
aPath = importablePath(aPath, isLocal, referencePath);
var fileExecutableSearch = new FileExecutableSearch(aPath, isLocal),
fileExecutable = fileExecutableSearch.result();
if (0 && !fileExecutable.hasLoadedFileDependencies())
throw "No executable loaded for file at path " + aPath;
fileExecutable.execute(shouldForce);
}
cachedFileExecutersForPaths[referencePath] = fileExecuter;
}
return fileExecuter;
}
var cachedImportersForPaths = { };
function fileImporterForPath(/*String*/ referencePath)
{
referencePath = FILE.normal(referencePath);
var cachedImporter = cachedImportersForPaths[referencePath];
if (!cachedImporter)
{
cachedImporter = function(/*String*/ aPath, /*BOOL*/ isLocal, /*Function*/ aCallback)
{
aPath = importablePath(aPath, isLocal, referencePath);
var fileExecutableSearch = new FileExecutableSearch(aPath, isLocal);
function searchComplete(/*FileExecutableSearch*/ aFileExecutableSearch)
{
var fileExecutable = aFileExecutableSearch.result(),
fileExecuter = exports.fileExecuterForPath(referencePath),
executeAndCallback = function ()
{
fileExecuter(aPath, isLocal);
if (aCallback)
aCallback();
}
if (!fileExecutable.hasLoadedFileDependencies())
{
fileExecutable.addEventListener("dependenciesload", executeAndCallback);
fileExecutable.loadFileDependencies();
}
else
executeAndCallback();
}
if (fileExecutableSearch.isComplete())
searchComplete(fileExecutableSearch);
else
fileExecutableSearch.addEventListener("complete", function(/*Event*/ anEvent)
{
searchComplete(anEvent.fileExecutableSearch);
});
}
cachedImportersForPaths[referencePath] = cachedImporter;
}
return cachedImporter;
}
exports.fileImporterForPath = fileImporterForPath;
+32 -29
View File
@@ -120,11 +120,7 @@ else
#endif
StaticResource.FileType = 0;
StaticResource.DirectoryType = 1;
StaticResource.NotFoundType = 2;
function StaticResource(/*String*/ aName, /*StaticResource*/ aParent, /*Type*/ aType, /*BOOL*/ isResolved)
function StaticResource(/*String*/ aName, /*StaticResource*/ aParent, /*BOOL*/ isDirectory, /*BOOL*/ isResolved)
{
this._parent = aParent;
this._eventDispatcher = new EventDispatcher(this);
@@ -133,18 +129,21 @@ function StaticResource(/*String*/ aName, /*StaticResource*/ aParent, /*Type*/ a
this._isResolved = !!isResolved;
this._path = FILE.join(aParent ? aParent.path() : "", aName);
this._type = aType;
this._isDirectory = !!isDirectory;
this._isNotFound = NO;
if (aParent)
aParent._children[aName] = this;
if (aType === StaticResource.DirectoryType)
if (isDirectory)
this._children = { };
else if (aType === StaticResource.FileType)
else
this._contents = "";
}
exports.StaticResource = StaticResource;
function resolveStaticResource(/*StaticResource*/ aResource)
{
aResource._isResolved = YES;
@@ -157,7 +156,7 @@ function resolveStaticResource(/*StaticResource*/ aResource)
StaticResource.prototype.resolve = function()
{
if (this.type() === StaticResource.DirectoryType)
if (this.isDirectory())
{
var bundle = new CFBundle(this.path());
@@ -179,7 +178,7 @@ StaticResource.prototype.resolve = function()
function onfailure()
{
self._type = StaticResource.NotFoundType;
self._isNotFound = YES;
resolveStaticResource(self);
}
@@ -227,7 +226,7 @@ StaticResource.prototype.write = function(/*String*/ aString)
this._contents += aString;
}
StaticResource.prototype.resolveSubPath = function(/*String*/ aPath, /*Type*/ aType, /*Function*/ aCallback)
StaticResource.prototype.resolveSubPath = function(/*String*/ aPath, /*BOOL*/ isDirectory, /*Function*/ aCallback)
{
aPath = FILE.normal(aPath);
@@ -240,17 +239,17 @@ StaticResource.prototype.resolveSubPath = function(/*String*/ aPath, /*Type*/ aT
var components = FILE.split(aPath),
index = this === rootResource ? 1 : FILE.split(this.path()).length;
resolvePathComponents(this, aType, components, index, aCallback);
resolvePathComponents(this, isDirectory, components, index, aCallback);
}
function resolvePathComponents(/*StaticResource*/ startResource, /*Type*/aType, /*Array*/ components, /*Integer*/ index, /*Function*/ aCallback)
function resolvePathComponents(/*StaticResource*/ startResource, /*BOOL*/ isDirectory, /*Array*/ components, /*Integer*/ index, /*Function*/ aCallback)
{
var count = components.length,
parent = startResource;
function continueResolution()
{
resolvePathComponents(parent, aType, components, index, aCallback);
resolvePathComponents(parent, isDirectory, components, index, aCallback);
}
for (; index < count; ++index)
@@ -264,9 +263,7 @@ function resolvePathComponents(/*StaticResource*/ startResource, /*Type*/aType,
if (!child)
{
var type = index + 1 < count || aType === StaticResource.DirectoryType ? StaticResource.DirectoryType : StaticResource.FileType;
child = new StaticResource(name, parent, type, NO);
child = new StaticResource(name, parent, index + 1 < count || isDirectory , NO);
child.resolve();
}
@@ -279,7 +276,7 @@ function resolvePathComponents(/*StaticResource*/ startResource, /*Type*/aType,
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) && child.type() !== StaticResource.DirectoryType)
if ((index + 1 < count) && child.isFile())
return aCallback(null, new Error("File is not a directory: " + components.join("/")));
parent = child;
@@ -300,7 +297,17 @@ StaticResource.prototype.removeEventListener = function(/*String*/ anEventName,
StaticResource.prototype.isNotFound = function()
{
return this.type() === StaticResource.NotFoundType;
return this._isNotFound;
}
StaticResource.prototype.isFile = function()
{
return !this._isDirectory;
}
StaticResource.prototype.isDirectory = function()
{
return this._isDirectory;
}
StaticResource.prototype.toString = function(/*BOOL*/ includeNotFounds)
@@ -311,7 +318,7 @@ StaticResource.prototype.toString = function(/*BOOL*/ includeNotFounds)
var string = this.parent() ? this.name() : "/",
type = this.type();
if (type === StaticResource.DirectoryType)
if (this.isDirectory())
{
var children = this._children;
@@ -345,7 +352,7 @@ StaticResource.prototype.nodeAtSubPath = function(/*String*/ aPath, /*BOOL*/ sho
parent = parent._children[name];
else if (shouldResolveAsDirectories)
parent = new StaticResource(name, parent, StaticResource.DirectoryType, YES);
parent = new StaticResource(name, parent, YES, YES);
else
throw NULL;
@@ -356,12 +363,12 @@ StaticResource.prototype.nodeAtSubPath = function(/*String*/ aPath, /*BOOL*/ sho
StaticResource.resolveStandardNodeAtPath = function(/*String*/ aPath, /*Function*/ aCallback)
{
var includePaths = exports.includePaths(),
var includePaths = StaticResource.includePaths(),
resolveStandardNodeAtPath = function(/*String*/ aPath, /*int*/ anIndex)
{
var searchPath = FILE.absolute(FILE.join(includePaths[anIndex], FILE.normal(aPath)));
rootResource.resolveSubPath(searchPath, StaticResource.FileType, function(/*StaticResource*/ aStaticResource)
rootResource.resolveSubPath(searchPath, NO, function(/*StaticResource*/ aStaticResource)
{
if (!aStaticResource)
{
@@ -380,13 +387,9 @@ StaticResource.resolveStandardNodeAtPath = function(/*String*/ aPath, /*Function
resolveStandardNodeAtPath(aPath, 0);
}
var GLOBAL_NAMESPACE = GLOBAL_NAMESPACE || global;
exports.includePaths = function()
StaticResource.includePaths = function()
{
return GLOBAL_NAMESPACE.OBJJ_INCLUDE_PATHS || ["Frameworks", "Frameworks/Debug"];
return global.OBJJ_INCLUDE_PATHS || ["Frameworks", "Frameworks/Debug"];
}
StaticResource.cwd = FILE.cwd();
exports.StaticResource = StaticResource;
+1 -1
View File
@@ -3,7 +3,7 @@
var formatRegex = new RegExp("([^%]+|%[\\+\\-\\ \\#0]*[0-9\\*]*(.[0-9\\*]+)?[hlL]?[cbBdieEfgGosuxXpn%@])", "g");
var tagRegex = new RegExp("(%)([\\+\\-\\ \\#0]*)([0-9\\*]*)((.[0-9\\*]+)?)([hlL]?)([cbBdieEfgGosuxXpn%@])");
exports.sprintf = function(format)
GLOBAL(sprintf) = function(format)
{
var format = arguments[0],
tokens = format.match(formatRegex),
+2 -3
View File
@@ -4,8 +4,7 @@
@import <Foundation/CPObject.j>
var FILE = require("file"),
SYSTEM = require("system"),
CFPropertyList = require("objective-j").CFPropertyList;
SYSTEM = require("system");
var DefaultDictionary = nil,
DefaultConfiguration = nil,
@@ -65,7 +64,7 @@ var DefaultDictionary = nil,
temporaryDictionary = [CPDictionary dictionary];
if (path && FILE.isReadable(path))
dictionary = CFPropertyList.propertyListFromString(FILE.read(path, { charset:"UTF-8" }));
dictionary = CFPropertyList.readPropertyListFromFile(path);
// readPlist will return nil if the file is empty
if (!dictionary)
+7 -5
View File
@@ -194,8 +194,10 @@ function pressEnvironment(rootPath, outputFiles, environment, options) {
var included = 0, total = 0;
var includedBytes = 0, totalBytes = 0;
var allFiles = analyzer.fileExecutables();
for (var path in allFiles) {
_OBJJ.FileExecutable.allFileExecutables().forEach(function(aFileExecutable) {
var path = aFileExecutable.path();
// mark all ".keytheme"s as required
if (/\.keyedtheme$/.test(path))
requiredFiles[path] = true;
@@ -203,14 +205,14 @@ function pressEnvironment(rootPath, outputFiles, environment, options) {
if (requiredFiles[path]) {
stream.print("Included: \0green(" + rootPath.relative(path) + "\0)");
included++;
includedBytes += allFiles[path].code().length
includedBytes += aFileExecutable.code().length
}
else {
stream.print("Excluded: \0red(" + rootPath.relative(path) + "\0)");
}
total++;
totalBytes += allFiles[path].code().length
}
totalBytes += aFileExecutable.code().length
}, this);
stream.print(sprintf(
"Saved \0green(%f%%\0) (\0blue(%s\0)); Total required files: \0magenta(%d\0) (\0blue(%s\0)) of \0magenta(%d\0) (\0blue(%s\0));",
Math.round(((includedBytes - totalBytes) / totalBytes) * -100),