35static JSBool
ShipGroupGetProperty(JSContext *context, JSObject *
this, jsid propID, jsval *value);
36static JSBool
ShipGroupSetProperty(JSContext *context, JSObject *
this, jsid propID, JSBool strict, jsval *value);
58 JSCLASS_NO_OPTIONAL_MEMBERS
106 if (!JSID_IS_INT(propID))
return YES;
113 if (
EXPECT_NOT(!JSShipGroupGetShipGroup(context,
this, &group)))
return NO;
115 switch (JSID_TO_INT(propID))
119 if (result ==
nil) result = [NSArray array];
127 result = [group
name];
128 if (result ==
nil) result = [NSNull null];
132 return JS_NewNumberValue(context, [group
count], value);
146static JSBool
ShipGroupSetProperty(JSContext *context, JSObject *
this, jsid propID, JSBool strict, jsval *value)
148 if (!JSID_IS_INT(propID))
return YES;
155 if (
EXPECT_NOT(!JSShipGroupGetShipGroup(context,
this, &group)))
return NO;
157 switch (JSID_TO_INT(propID))
161 if (shipValue !=
nil || JSVAL_IS_NULL(*value))
169 [group
setName:OOStringFromJSValueEvenIfNull(context, *value)];
190 if (
EXPECT_NOT(!JS_IsConstructing(context, vp)))
192 OOJSReportError(context,
@"ShipGroup() cannot be called as a function, it must be used as a constructor (as in new ShipGroup(...)).");
196 NSString *name =
nil;
225@implementation OOShipGroup (OOJavaScriptExtensions)
227- (jsval) oo_jsValueInContext:(JSContext *)context
229 jsval result = JSVAL_NULL;
236 if (!JS_SetPrivate(context, _jsSelf, [
self retain])) _jsSelf = NULL;
240 if (_jsSelf != NULL) result = OBJECT_TO_JSVAL(_jsSelf);
246- (void) oo_clearJSSelf:(JSObject *)selfVal
248 if (_jsSelf == selfVal) _jsSelf = NULL;
277 if ([thisGroup containsShip:ship])
286 if ([thisGroupLeader escortGroup] == thisGroup)
288 if ([thisGroup
count] > 1)
291 if ([thatGroup
count] > 1 && [[thatGroup leader] escortGroup] == thatGroup)
293 OOJSReportWarningForCaller(context,
@"ShipGroup",
@"addShip",
@"Ship %@ cannot be assigned to two escort groups, ignoring.", ship);
303 if ([thisGroupLeader escortGroup] == [thisGroupLeader group])
307 thisGroup = [thisGroupLeader
group];
#define OOJS_NATIVE_ENTER(cx)
static JSPropertySpec sShipGroupProperties[]
static JSObject * sShipGroupPrototype
static JSBool ShipGroupAddShip(JSContext *context, uintN argc, jsval *vp)
static JSBool ShipGroupGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSBool ShipGroupContainsShip(JSContext *context, uintN argc, jsval *vp)
static JSBool ShipGroupConstruct(JSContext *context, uintN argc, jsval *vp)
static JSBool ShipGroupSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
static JSBool ShipGroupRemoveShip(JSContext *context, uintN argc, jsval *vp)
void InitOOJSShipGroup(JSContext *context, JSObject *global)
static JSFunctionSpec sShipGroupMethods[]
static JSClass sShipGroupClass
JSBool OOJSObjectWrapperToString(JSContext *context, uintN argc, jsval *vp)
#define OOJS_PROP_READWRITE_CB
void OOJSRegisterObjectConverter(JSClass *theClass, OOJSClassConverterCallback converter)
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
#define DEFINE_JS_OBJECT_GETTER(NAME, JSCLASS, JSPROTO, OBJCCLASSNAME)
void OOJSObjectWrapperFinalize(JSContext *context, JSObject *this)
#define OOJS_RETURN_OBJECT(o)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
void OOJSReportWarningForCaller(JSContext *context, NSString *scriptClass, NSString *function, NSString *format,...)
#define OOJS_RETURN_BOOL(v)
id OOJSNativeObjectOfClassFromJSValue(JSContext *context, jsval value, Class requiredClass)
NSString * OOStringFromJSValue(JSContext *context, jsval value)
void OOJSReportError(JSContext *context, NSString *format,...)
void OOJSReportBadPropertyValue(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec, jsval value)
id OOJSBasicPrivateObjectConverter(JSContext *context, JSObject *object)
void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)
#define OOJS_PROP_READONLY_CB
void setName:(NSString *name)
void setLeader:(ShipEntity *leader)
BOOL acceptAsEscort:(ShipEntity *other_ship)
void setGroup:(OOShipGroup *group)