Fixed a number of subtle bugs introduced with the last keyed archiver change.

Reviewed by me.
This commit is contained in:
Francisco Ryan Tolmasky I committed 2009-01-08 18:26:12 -08:00
1 parent 33cd18e109
commit 4a24923edb
9 files changed
+133 -67

No files matched your search

+3
View File
@@ -718,6 +718,9 @@ var CPPopUpButtonMenuKey = @"CPPopUpButtonMenuKey",
if (self)
{
// Nothing is currently selected
_selectedIndex = -1;
[self setMenu:[aCoder decodeObjectForKey:CPPopUpButtonMenuKey]];
[self selectItemAtIndex:[aCoder decodeObjectForKey:CPPopUpButtonSelectedIndexKey]];
[self setPullsDown:[aCoder decodeBoolForKey:CPPopUpButtonPullsDownKey]];
+5 -3
View File
@@ -385,10 +385,12 @@ var CPSplitViewHorizontalImage = nil,
- (float)minPossiblePositionOfDividerAtIndex:(int)dividerIndex
{
var frame = [_subviews[dividerIndex - 1] frame];
if (dividerIndex > 0)
{
var frame = [_subviews[dividerIndex - 1] frame];
return frame.origin[_originComponent] + frame.size[_sizeComponent] + [self dividerThickness];
}
else
return 0;
}
@@ -415,7 +417,7 @@ var CPSplitViewHorizontalImage = nil,
var frame = [self frame],
viewA = _subviews[dividerIndex],
frameA = [viewA frame],
viewB = _subviews[dividerIndex+1],
viewB = _subviews[dividerIndex + 1],
frameB = [viewB frame];
var realPosition = MAX(MIN(position, actualMax), actualMin);
+3 -3
View File
@@ -661,7 +661,7 @@ var CTRL_KEY_CODE = 17;
{
_pasteboardKeyDownEvent = event;
window.setTimeout(function () { [self _checkPasteboardElement] }, 0);
window.setNativeTimeout(function () { [self _checkPasteboardElement] }, 0);
return;
}
@@ -706,7 +706,7 @@ var CTRL_KEY_CODE = 17;
_DOMPasteboardElement.select();
window.setTimeout(function() { [self _clearPasteboardElement]; }, 0);
window.setNativeTimeout(function() { [self _clearPasteboardElement]; }, 0);
}
return;
@@ -862,7 +862,7 @@ var CTRL_KEY_CODE = 17;
try
{
var value = _DOMPasteboardElement.value;
if ([value length])
{
var pasteboard = [CPPasteboard generalPasteboard];
+55 -2
View File
@@ -23,10 +23,11 @@
@import "CPObject.j"
@import "CPDictionary.j"
@import "CPURLRequest.j"
@implementation CPBundle : CPObject
{
Class _principalClass;
}
+ (id)alloc
@@ -49,6 +50,20 @@
return [CPBundle bundleWithPath:"Info.plist"];
}
- (id)initWithPath:(CPString)aPath
{
self = [super init];
if (self)
{
path = aPath;
objj_setBundleForPath(path, self);
}
return self;
}
- (Class)classNamed:(CPString)aString
{
// ???
@@ -71,7 +86,7 @@
- (Class)principalClass
{
var className = [[self infoDictionary] objectForKey:@"CPPrincipalClass"];
var className = [self objectForInfoDictionaryKey:@"CPPrincipalClass"];
//[self load];
@@ -88,6 +103,44 @@
return [info objectForKey:aKey];
}
//
- (void)loadWithDelegate:(id)aDelegate
{
self._delegate = aDelegate;
self._infoConnection = [CPURLConnection connectionWithRequest:[CPURLRequest requestWithURL:[self bundlePath] + "/Info.plist"] delegate:self];
}
- (void)connection:(CPURLConnection)aConnection didReceiveData:(CPString)data
{
if (aConnection === self._infoConnection)
{
info = CPPropertyListCreateFromData([CPData dataWithString:data]);
[CPURLConnection connectionWithRequest:[CPURLRequest requestWithURL:[self bundlePath] + "/" + [self objectForInfoDictionaryKey:"CPBundleExecutable"]] delegate:self];
}
else
{
objj_decompile([data string], self);
var files = [self objectForInfoDictionaryKey:@"CPBundleReplacedFiles"];
importCallback = function()
{
// FIXME: Should we share a common context across all these loads?
if (files.length > 0)
objj_import([self bundlePath] + '/' + files.pop(), YES, importCallback);
else if ([_delegate respondsToSelector:@selector(bundleDidFinishLoading:)])
[_delegate bundleDidFinishLoading:self];
}
objj_import([self bundlePath] + '/' + files.pop(), YES, importCallback);
}
}
- (void)connectionDidFinishLoading:(CPURLConnection)aConnection
{
}
@end
objj_bundle.prototype.isa = CPBundle;
+8 -8
View File
@@ -472,7 +472,7 @@ var _CPKeyedArchiverEncodeObject = function(self, anObject, isConditional)
// We wrap primitive JavaScript objects in a unique subclass of CPValue.
// This way, when we unarchive, we know to unwrap it, since
// _CPKeyedArchiverValue should not be used anywhere else.
if (anObject != nil && !anObject.isa)
if (anObject !== nil && !anObject.isa)
anObject = [_CPKeyedArchiverValue valueWithJSObject:anObject];
// Get the proper replacement object
@@ -481,21 +481,21 @@ var _CPKeyedArchiverEncodeObject = function(self, anObject, isConditional)
// If a replacement object doesn't exist, then actually ask for one.
// Explicitly compare to nil because object could be === 0.
if (object == nil)
if (object === nil)
{
object = [anObject replacementObjectForKeyedArchiver:self];
// Notify our delegate of this replacement.
if (self._delegate)
{
if (object != anObject && self._delegateSelectors & _CPKeyedArchiverWillReplaceObjectWithObjectSelector)
if (object !== anObject && self._delegateSelectors & _CPKeyedArchiverWillReplaceObjectWithObjectSelector)
[self._delegate archiver:self willReplaceObject:anObject withObject:object];
if (self._delegateSelectors & _CPKeyedArchiverWillEncodeObjectSelector)
{
anObject = [self._delegate archiver:self willEncodeObject:object];
if (anObject != object && self._delegateSelectors & _CPKeyedArchiverWillReplaceObjectWithObjectSelector)
if (anObject !== object && self._delegateSelectors & _CPKeyedArchiverWillReplaceObjectWithObjectSelector)
[self._delegate archiver:self willReplaceObject:object withObject:anObject];
object = anObject;
@@ -508,7 +508,7 @@ var _CPKeyedArchiverEncodeObject = function(self, anObject, isConditional)
// If we still don't have an object by this point, then return a
// reference to the null object.
// Explicitly compare to nil because object could be === 0.
if (object == nil)
if (object === nil)
return _CPKeyedArchiverNullReference;
// If not, then grab the object's UID
@@ -517,7 +517,7 @@ var _CPKeyedArchiverEncodeObject = function(self, anObject, isConditional)
// If this object doesn't have a unique index in the object table yet,
// then it also hasn't been properly encoded. We explicitly compare
// index to nil since it could be 0, which would also evaluate to false.
if (UID == nil)
if (UID === nil)
{
// If it is being conditionally encoded, then
if (isConditional)
@@ -535,7 +535,7 @@ var _CPKeyedArchiverEncodeObject = function(self, anObject, isConditional)
var theClass = [anObject classForKeyedArchiver],
plistObject = nil;
if (theClass === _CPKeyedArchiverStringClass || theClass === _CPKeyedArchiverNumberClass)// || theClass == _CPKeyedArchiverBooleanClass)
if ((theClass === _CPKeyedArchiverStringClass) || (theClass === _CPKeyedArchiverNumberClass))// || theClass == _CPKeyedArchiverBooleanClass)
plistObject = object;
else
{
@@ -581,7 +581,7 @@ var _CPKeyedArchiverEncodeObject = function(self, anObject, isConditional)
UID = [self._conditionalUIDs objectForKey:hash];
// If this object WAS previously encoded conditionally...
if (UID != nil)
if (UID !== nil)
{
[self._UIDs setObject:UID forKey:hash];
[self._plistObjects replaceObjectAtIndex:UID withObject:plistObject];
+2 -2
View File
@@ -419,7 +419,7 @@ var _CPKeyedUnarchiverDecodeObjectAtIndex = function(self, anIndex)
var savedPlistObject = self._plistObject;
self._plistObject = plistObject;
var string = className;
var processedObject = [object initWithCoder:self];
self._plistObject = savedPlistObject;
@@ -432,7 +432,7 @@ var _CPKeyedUnarchiverDecodeObjectAtIndex = function(self, anIndex)
object = processedObject;
self._objects[anIndex] = processedObject;
}
processedObject = [object awakeAfterUsingCoder:self];
if (processedObject != object)
-1
View File
@@ -17,7 +17,6 @@
<file name = "exception.js" />
<file name = "preprocess.js" />
<file name = "evaluate.js" />
<file name = "static.js" />
<file name = "debug.js" />
<file name = "bootstrap.js" />
+57
View File
@@ -77,6 +77,11 @@ function objj_getBundleWithPath(aPath)
return objj_bundles[aPath];
}
function objj_setBundleForPath(aPath, aBundle)
{
objj_bundles[aPath] = aBundle;
}
function objj_bundleForClass(aClass)
{
return objj_bundlesForClass[aClass.name];
@@ -533,3 +538,55 @@ objj_request_xmlhttp = function()
}
ENDIF
OBJJUnrecognizedFormatException = "OBJJUnrecognizedFormatException";
var STATIC_MAGIC_NUMBER = "@STATIC",
MARKER_PATH = "p",
MARKER_CODE = "c",
MARKER_IMPORT_STD = 'I',
MARKER_IMPORT_LOCAL = 'i';
var STATIC_EXTENSION = "sj";
function objj_decompile(aString, bundle)
{
var stream = new objj_markedStream(aString);
if (stream.magicNumber() != STATIC_MAGIC_NUMBER)
objj_exception_throw(new objj_exception(OBJJUnrecognizedFormatException, "*** Could not recognize executable code format."));
if (stream.version() != 1.0)
objj_exception_throw(new objj_exception(OBJJUnrecognizedFormatException, "*** Could not recognize executable code format."));
var file = NULL,
files = [];
while (marker = stream.getMarker())
{
var text = stream.getString();
switch (marker)
{
case MARKER_PATH: file = new objj_file();
file.path = DIRECTORY(bundle.path) + text;
file.bundle = bundle;
file.fragments = [];
files.push(file);
objj_files[file.path] = file;
break;
case MARKER_CODE: file.fragments.push(fragment_create_code(text, bundle, file));
break;
case MARKER_IMPORT_STD: file.fragments.push(fragment_create_file(text, bundle, NO, file));
break;
case MARKER_IMPORT_LOCAL: file.fragments.push(fragment_create_file(text, bundle, YES, file));
break;
}
}
return files;
}
-48
View File
@@ -1,48 +0,0 @@
OBJJUnrecognizedFormatException = "OBJJUnrecognizedFormatException";
var STATIC_MAGIC_NUMBER = "@STATIC",
MARKER_PATH = "p",
MARKER_CODE = "c",
MARKER_IMPORT_STD = 'I',
MARKER_IMPORT_LOCAL = 'i';
var STATIC_EXTENSION = "sj";
function objj_decompile(aString, bundle)
{
var stream = new objj_markedStream(aString);
if (stream.magicNumber() != STATIC_MAGIC_NUMBER)
objj_exception_throw(new objj_exception(OBJJUnrecognizedFormatException, "*** Could not recognize executable code format."));
if (stream.version() != 1.0)
objj_exception_throw(new objj_exception(OBJJUnrecognizedFormatException, "*** Could not recognize executable code format."));
var file = NULL,
files = [];
while (marker = stream.getMarker())
{
var text = stream.getString();
switch (marker)
{
case MARKER_PATH: file = new objj_file();
file.path = DIRECTORY(bundle.path) + text;
file.bundle = bundle;
file.fragments = [];
files.push(file);
break;
case MARKER_CODE: file.fragments.push(fragment_create_code(text, bundle, file));
break;
case MARKER_IMPORT_STD: file.fragments.push(fragment_create_file(text, bundle, NO, file));
break;
case MARKER_IMPORT_LOCAL: file.fragments.push(fragment_create_file(text, bundle, YES, file));
break;
}
}
return files;
}