Files
cappuccino/Tests/Foundation/CPKeyedArchiverTest.j
T
Alexander Ljungberg 27211db0cc Fixed: JS objects 'randomly' failed to unarchive.
The problem was that if the same JS object was decoded twice as part of a more complex object, the first decoded version was cached in its unwrapped state and not properly unwrapped the second time. This caused very hard to debug theming errors where e.g. a CPTextField's custom inset would decode fine, but a subclass of a CPTextField otherwise exactly the same would fail to decode the inset.
2011-04-21 18:59:30 -04:00

45 lines
1015 B
Plaintext

@import <Foundation/CPKeyedArchiver.j>
@import <Foundation/CPKeyedUnarchiver.j>
@implementation CPKeyedArchiverTest : OJTestCase
{
}
- (void)testJavaScriptObject
{
var original = [Archivable new];
[original setAJsObject:{ 'top': 5 }];
var decoded = [CPKeyedUnarchiver unarchiveObjectWithData:[CPKeyedArchiver archivedDataWithRootObject:original]]
[self assert:5 equals:[decoded aJsObject].top message:"JS object encoded and decoded right"];
}
@end
@implementation Archivable : CPObject
{
JSObject aJsObject @accessors;
}
- (id)initWithCoder:(CPCoder)aCoder
{
if (self = [super init])
{
// Note we decode this twice to expose a bug where the cached decoded
// values did not properly unwrap JS objects.
aJsObject = [aCoder decodeObjectForKey:@"aJsObject"];
aJsObject = [aCoder decodeObjectForKey:@"aJsObject"];
}
return self;
}
- (void)encodeWithCoder:(CPCoder)aCoder
{
[aCoder encodeObject:aJsObject forKey:@"aJsObject"];
}
@end