struct Instance :
CYValue<Instance, id>
{
- enum Flags {
- None = 0,
- Permanent = (1 << 0),
- Uninitialized = (1 << 1),
- };
+ typedef unsigned Flags;
+ static const Flags None = 0;
+ static const Flags Permanent = 1 << 0;
+ static const Flags Uninitialized = 1 << 1;
Flags flags_;
static JSClassRef GetClass(id value, Flags flags);
+ _finline bool IsPermanent() const {
+ return (flags_ & Permanent) != 0;
+ }
+
_finline bool IsUninitialized() const {
return (flags_ & Uninitialized) != 0;
}
CYValue(value),
flags_(flags)
{
- if ((flags & Instance::Permanent) == 0)
+ if (IsPermanent());
+ /*else if ([value retainCount] == NSUInteger(-1))
+ flags_ |= Instance::Permanent;*/
+ else
value_ = [value_ retain];
}
Instance::~Instance() {
- if ((flags_ & Permanent) == 0)
+ if (!IsPermanent())
[value_ release];
}
if (initialize) {
Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(object)));
- if ((internal->flags_ & Instance::Uninitialized) != 0) {
- internal->flags_ = static_cast<Instance::Flags>(internal->flags_ & ~Instance::Uninitialized);
- _assert(internal->value_ == nil);
- internal->value_ = value;
+ if (internal->IsUninitialized()) {
+ internal->flags_ &= ~Instance::Uninitialized;
+ if (internal->value_ == nil)
+ internal->value_ = value;
+ else
+ _assert(internal->value_ == value);
}
[value release];
self = internal->value_;
_class = nil;
uninitialized = internal->IsUninitialized();
- if (uninitialized)
+ if (uninitialized && [internal->value_ retainCount] != NSUInteger(-1))
internal->value_ = nil;
} else {
self = CYCastNSObject(&pool, context, arguments[0]);