00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 @import "CPObject.j"
00024 @import "CPCoder.j"
00025
00026
00034 @implementation CPValue : CPObject
00035 {
00036 JSObject _JSObject;
00037 }
00038
00044 + (id)valueWithJSObject:(JSObject)aJSObject
00045 {
00046 return [[self alloc] initWithJSObject:aJSObject];
00047 }
00048
00054 - (id)initWithJSObject:(JSObject)aJSObject
00055 {
00056 self = [super init];
00057
00058 if (self)
00059 _JSObject = aJSObject;
00060
00061 return self;
00062 }
00063
00067 - (JSObject)JSObject
00068 {
00069 return _JSObject;
00070 }
00071
00072 @end
00073
00074 var CPValueValueKey = @"CPValueValueKey";
00075
00076 @implementation CPValue (CPCoding)
00077
00083 - (id)initWithCoder:(CPCoder)aCoder
00084 {
00085 self = [super init];
00086
00087 if (self)
00088 _JSObject = JSON.parse([aCoder decodeObjectForKey:CPValueValueKey]);
00089
00090 return self;
00091 }
00092
00097 - (void)encodeWithCoder:(CPCoder)aCoder
00098 {
00099 [aCoder encodeObject:JSON.stringify(_JSObject) forKey:CPValueValueKey];
00100 }
00101
00102 @end
00103
00104 function CPJSObjectCreateJSON(aJSObject)
00105 {
00106 CPLog.warn("CPJSObjectCreateJSON deprecated, use JSON.stringify() or CPString's objectFromJSON");
00107 return JSON.stringify(aJSObject);
00108 }
00109
00110 function CPJSObjectCreateWithJSON(aString)
00111 {
00112 CPLog.warn("CPJSObjectCreateWithJSON deprecated, use JSON.parse() or CPString's JSONFromObject");
00113 return JSON.parse(aString);
00114 }