Work on JavaScript API update.
git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@3853 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
parent
ec9b9f10f5
commit
295c921403
@ -118,7 +118,7 @@ static OODebugMonitor *sSingleton = nil;
|
||||
if (_script == nil)
|
||||
{
|
||||
JSObject *global = [jsEng globalObject];
|
||||
JS_DefineProperty(context, global, "debugConsole", OBJECT_TO_JSVAL([self javaScriptValueInContext:context]), NULL, NULL, JSPROP_ENUMERATE);
|
||||
JS_DefineProperty(context, global, "debugConsole", [self javaScriptValueInContext:context], NULL, NULL, JSPROP_ENUMERATE);
|
||||
}
|
||||
|
||||
[jsEng releaseContext:context];
|
||||
|
@ -118,7 +118,11 @@ static OORegExpMatcher *sActiveInstance;
|
||||
[regExp getCharacters:buffer];
|
||||
|
||||
_cachedRegExpString = [regExp retain];
|
||||
#if OO_NEW_JS
|
||||
JSObject *regExpObj = JS_NewUCRegExpObjectNoStatics(context, buffer, expLength, flags);
|
||||
#else
|
||||
JSObject *regExpObj = JS_NewUCRegExpObject(context, buffer, expLength, flags);
|
||||
#endif
|
||||
_cachedRegExpObject = [[OOJSValue alloc] initWithJSObject:regExpObj inContext:context];
|
||||
_cachedFlags = flags;
|
||||
|
||||
|
@ -177,7 +177,7 @@ MA 02110-1301, USA.
|
||||
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
JS_RemoveRoot(context, &argv[i]);
|
||||
JS_RemoveValueRoot(context, &argv[i]);
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
@ -42,8 +42,6 @@ static JSBool ManifestDeleteProperty(OOJS_PROP_ARGS);
|
||||
static JSBool ManifestGetProperty(OOJS_PROP_ARGS);
|
||||
static JSBool ManifestSetProperty(OOJS_PROP_ARGS);
|
||||
|
||||
static JSBool ManifestToString(OOJS_NATIVE_ARGS);
|
||||
|
||||
|
||||
static JSClass sManifestClass =
|
||||
{
|
||||
@ -137,14 +135,6 @@ static JSPropertySpec sManifestProperties[] =
|
||||
static const unsigned kManifestCaseInsensitiveLimit = kManifest_gemstones + 1;
|
||||
|
||||
|
||||
static JSFunctionSpec sManifestMethods[] =
|
||||
{
|
||||
// JS name Function min args
|
||||
{ "toString", ManifestToString, 0 },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
|
||||
static NSDictionary *sManifestNameMap;
|
||||
|
||||
|
||||
@ -191,7 +181,7 @@ static NSDictionary *sManifestNameMap;
|
||||
|
||||
void InitOOJSManifest(JSContext *context, JSObject *global)
|
||||
{
|
||||
sManifestPrototype = JS_InitClass(context, global, NULL, &sManifestClass, NULL, 0, sManifestProperties, sManifestMethods, NULL, NULL);
|
||||
sManifestPrototype = JS_InitClass(context, global, NULL, &sManifestClass, NULL, 0, sManifestProperties, NULL, NULL, NULL);
|
||||
JSRegisterObjectConverter(&sManifestClass, JSBasicPrivateObjectConverter);
|
||||
|
||||
// Create manifest object as a property of the player.ship object.
|
||||
@ -215,10 +205,10 @@ void InitOOJSManifest(JSContext *context, JSObject *global)
|
||||
}
|
||||
|
||||
|
||||
static JSBool ManifestDeleteProperty(JSContext *context, JSObject *this, jsval name, jsval *value)
|
||||
static JSBool ManifestDeleteProperty(OOJS_PROP_ARGS)
|
||||
{
|
||||
jsval v = JSVAL_VOID;
|
||||
return ManifestSetProperty(context, this, name, &v);
|
||||
return ManifestSetProperty(context, this, propID, &v);
|
||||
}
|
||||
|
||||
|
||||
@ -566,19 +556,3 @@ static JSBool ManifestSetProperty(OOJS_PROP_ARGS)
|
||||
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
||||
|
||||
// *** Methods ***
|
||||
|
||||
// toString() : String
|
||||
static JSBool ManifestToString(OOJS_NATIVE_ARGS)
|
||||
{
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
NSString *ret = @"[Manifest Object]";
|
||||
|
||||
*outResult = [ret javaScriptValueInContext:context];
|
||||
return YES;
|
||||
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ static NSString *KeyForPropertyID(JSContext *context, PropertyID propID)
|
||||
}
|
||||
|
||||
|
||||
static JSBool MissionVariablesDeleteProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool MissionVariablesDeleteProperty(OOJS_PROP_ARGS);
|
||||
static JSBool MissionVariablesGetProperty(OOJS_PROP_ARGS);
|
||||
static JSBool MissionVariablesSetProperty(OOJS_PROP_ARGS);
|
||||
static JSBool MissionVariablesEnumerate(JSContext *cx, JSObject *obj, JSIterateOp enum_op, jsval *statep, jsid *idp);
|
||||
@ -176,6 +176,9 @@ static JSBool MissionVariablesEnumerate(JSContext *context, JSObject *object, JS
|
||||
switch (enumOp)
|
||||
{
|
||||
case JSENUMERATE_INIT:
|
||||
#if OO_NEW_JS
|
||||
case JSENUMERATE_INIT_ALL: // For ES5 Object.getOwnPropertyNames(). Since we have no non-enumerable properties, this is the same as _INIT.
|
||||
#endif
|
||||
{
|
||||
// -allKeys implicitly makes a copy, which is good since the enumerating code might mutate.
|
||||
NSArray *mvars = [[[PlayerEntity sharedPlayer] missionVariables] allKeys];
|
||||
@ -183,7 +186,11 @@ static JSBool MissionVariablesEnumerate(JSContext *context, JSObject *object, JS
|
||||
*state = PRIVATE_TO_JSVAL(mvarEnumerator);
|
||||
if (idp != NULL)
|
||||
{
|
||||
#if OO_NEW_JS
|
||||
*idp = INT_TO_JSID([mvars count]);
|
||||
#else
|
||||
*idp = INT_TO_JSVAL([mvars count]);
|
||||
#endif
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
@ -207,7 +214,14 @@ static JSBool MissionVariablesEnumerate(JSContext *context, JSObject *object, JS
|
||||
case JSENUMERATE_DESTROY:
|
||||
{
|
||||
[mvarEnumerator release];
|
||||
if (idp != NULL) return JS_ValueToId(context, JSVAL_VOID, idp);
|
||||
if (idp != NULL)
|
||||
{
|
||||
#if OO_NEW_JS
|
||||
*idp = JSID_VOID;
|
||||
#else
|
||||
return JS_ValueToId(context, JSVAL_VOID, idp);
|
||||
#endif
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ static JSBool OoliteCompareVersion(OOJS_NATIVE_ARGS)
|
||||
NSEnumerator *componentEnum = nil;
|
||||
id component = nil;
|
||||
|
||||
components = JSValueToObject(context, argv[0]);
|
||||
components = JSValueToObject(context, OOJS_ARG(0));
|
||||
if ([components isKindOfClass:[NSArray class]])
|
||||
{
|
||||
// Require each element to be a number
|
||||
@ -186,9 +186,13 @@ static JSBool OoliteCompareVersion(OOJS_NATIVE_ARGS)
|
||||
|
||||
if (components != nil)
|
||||
{
|
||||
*outResult = INT_TO_JSVAL(CompareVersions(components, VersionComponents()));
|
||||
OOJS_RETURN_INT(CompareVersions(components, VersionComponents()));
|
||||
}
|
||||
// Else leave as JSVAL_VOID
|
||||
else
|
||||
{
|
||||
OOJS_RETURN_VOID;
|
||||
}
|
||||
|
||||
|
||||
return YES;
|
||||
|
||||
|
@ -338,11 +338,11 @@ static JSBool PlayerCommsMessage(OOJS_NATIVE_ARGS)
|
||||
double time = 4.5;
|
||||
BOOL gotTime = YES;
|
||||
|
||||
message = JSValToNSString(context, argv[0]);
|
||||
if (argc > 1) gotTime = JS_ValueToNumber(context, argv[1], &time);
|
||||
message = JSValToNSString(context, OOJS_ARG(0));
|
||||
if (argc > 1) gotTime = JS_ValueToNumber(context, OOJS_ARG(1), &time);
|
||||
if (message == nil || !gotTime)
|
||||
{
|
||||
OOReportJSBadArguments(context, @"Player", @"commsMessage", argc, argv, nil, @"message and optional duration");
|
||||
OOReportJSBadArguments(context, @"Player", @"commsMessage", argc, OOJS_ARGV, nil, @"message and optional duration");
|
||||
return NO;
|
||||
}
|
||||
|
||||
@ -362,11 +362,11 @@ static JSBool PlayerConsoleMessage(OOJS_NATIVE_ARGS)
|
||||
double time = 3.0;
|
||||
BOOL gotTime = YES;
|
||||
|
||||
message = JSValToNSString(context, argv[0]);
|
||||
if (argc > 1) gotTime = JS_ValueToNumber(context, argv[1], &time);
|
||||
message = JSValToNSString(context, OOJS_ARG(0));
|
||||
if (argc > 1) gotTime = JS_ValueToNumber(context, OOJS_ARG(1), &time);
|
||||
if (message == nil || !gotTime)
|
||||
{
|
||||
OOReportJSBadArguments(context, @"Player", @"consoleMessage", argc, argv, nil, @"message and optional duration");
|
||||
OOReportJSBadArguments(context, @"Player", @"consoleMessage", argc, OOJS_ARGV, nil, @"message and optional duration");
|
||||
return NO;
|
||||
}
|
||||
|
||||
@ -431,10 +431,10 @@ static JSBool PlayerAddMessageToArrivalReport(OOJS_NATIVE_ARGS)
|
||||
|
||||
NSString *report = nil;
|
||||
|
||||
report = JSValToNSString(context, argv[0]);
|
||||
report = JSValToNSString(context, OOJS_ARG(0));
|
||||
if (report == nil)
|
||||
{
|
||||
OOReportJSBadArguments(context, @"Player", @"addMessageToArrivalReport", argc, argv, nil, @"arrival message");
|
||||
OOReportJSBadArguments(context, @"Player", @"addMessageToArrivalReport", argc, OOJS_ARGV, nil, @"arrival message");
|
||||
return NO;
|
||||
}
|
||||
|
||||
@ -461,7 +461,7 @@ static JSBool PlayerSetEscapePodDestination(OOJS_NATIVE_ARGS)
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
destValue = JSValueToObject(context, argv[0]);
|
||||
destValue = JSValueToObject(context, OOJS_ARG(0));
|
||||
|
||||
if (!destValue || [destValue isKindOfClass:[ShipEntity class]])
|
||||
{
|
||||
@ -494,10 +494,15 @@ static JSBool PlayerSetEscapePodDestination(OOJS_NATIVE_ARGS)
|
||||
// 4.70 fuel to get there, 2.35 to fly back = 7ly fuel, plus rounding error.
|
||||
rescueRange = [UNIVERSE strict] ? 2.35 : 3.5;
|
||||
}
|
||||
NSMutableArray *sDests = (NSMutableArray *)[UNIVERSE nearbyDestinationsWithinRange: rescueRange];
|
||||
NSMutableArray *sDests = (NSMutableArray *)[UNIVERSE nearbyDestinationsWithinRange:rescueRange];
|
||||
int i = 0, nDests = [sDests count];
|
||||
if (nDests > 0) for (i = --nDests; i > 0; i--)
|
||||
if ([(NSDictionary*)[sDests objectAtIndex:i] oo_boolForKey:@"nova"]) [sDests removeObjectAtIndex:i];
|
||||
{
|
||||
if ([(NSDictionary*)[sDests objectAtIndex:i] oo_boolForKey:@"nova"])
|
||||
{
|
||||
[sDests removeObjectAtIndex:i];
|
||||
}
|
||||
}
|
||||
|
||||
// i is back to 0, nDests could have changed...
|
||||
nDests = [sDests count];
|
||||
@ -518,7 +523,7 @@ static JSBool PlayerSetEscapePodDestination(OOJS_NATIVE_ARGS)
|
||||
else
|
||||
{
|
||||
JSBool bValue;
|
||||
if (JS_ValueToBoolean(context, argv[0], &bValue) && bValue == NO)
|
||||
if (JS_ValueToBoolean(context, OOJS_ARG(0), &bValue) && bValue == NO)
|
||||
{
|
||||
[player setDockTarget:NULL];
|
||||
OK = YES;
|
||||
@ -529,7 +534,7 @@ static JSBool PlayerSetEscapePodDestination(OOJS_NATIVE_ARGS)
|
||||
|
||||
if (OK == NO)
|
||||
{
|
||||
OOReportJSBadArguments(context, @"Player", @"setEscapePodDestination", argc, argv, nil, @"a valid station, null, or 'NEARBY_SYSTEM'");
|
||||
OOReportJSBadArguments(context, @"Player", @"setEscapePodDestination", argc, OOJS_ARGV, nil, @"a valid station, null, or 'NEARBY_SYSTEM'");
|
||||
}
|
||||
return OK;
|
||||
|
||||
|
@ -466,24 +466,27 @@ static JSBool QuaternionConstruct(OOJS_NATIVE_ARGS)
|
||||
|
||||
Quaternion quaternion = kZeroQuaternion;
|
||||
Quaternion *private = NULL;
|
||||
#if OO_NEW_JS
|
||||
JSObject *this = OOJS_THIS;
|
||||
#endif
|
||||
|
||||
private = malloc(sizeof *private);
|
||||
if (EXPECT_NOT(private == NULL)) return NO;
|
||||
|
||||
// If called without new, replace this with a new Vector object.
|
||||
if (!JS_IsConstructing(context))
|
||||
if (!OOJS_IS_CONSTRUCTING)
|
||||
{
|
||||
this = JS_NewObject(context, &sQuaternionClass, NULL, NULL);
|
||||
if (this == NULL) return NO;
|
||||
*outResult = OBJECT_TO_JSVAL(this);
|
||||
OOJS_SET_RVAL(OBJECT_TO_JSVAL(this));
|
||||
}
|
||||
|
||||
if (argc != 0)
|
||||
{
|
||||
if (EXPECT_NOT(!QuaternionFromArgumentListNoErrorInternal(context, argc, argv, &quaternion, NULL, YES)))
|
||||
if (EXPECT_NOT(!QuaternionFromArgumentListNoErrorInternal(context, argc, OOJS_ARGV, &quaternion, NULL, YES)))
|
||||
{
|
||||
free(private);
|
||||
OOReportJSBadArguments(context, NULL, NULL, argc, argv,
|
||||
OOReportJSBadArguments(context, NULL, NULL, argc, OOJS_ARGV,
|
||||
@"Could not construct quaternion from parameters",
|
||||
@"Vector, Entity or array of four numbers");
|
||||
return NO;
|
||||
@ -513,9 +516,9 @@ static JSBool QuaternionToString(OOJS_NATIVE_ARGS)
|
||||
|
||||
Quaternion thisq;
|
||||
|
||||
if (EXPECT_NOT(!GetThisQuaternion(context, this, &thisq, @"toString"))) return NO;
|
||||
if (EXPECT_NOT(!GetThisQuaternion(context, OOJS_THIS, &thisq, @"toString"))) return NO;
|
||||
|
||||
*outResult = [QuaternionDescription(thisq) javaScriptValueInContext:context];
|
||||
OOJS_SET_RVAL([QuaternionDescription(thisq) javaScriptValueInContext:context]);
|
||||
return YES;
|
||||
|
||||
OOJS_NATIVE_EXIT
|
||||
@ -529,10 +532,10 @@ static JSBool QuaternionToSource(OOJS_NATIVE_ARGS)
|
||||
|
||||
Quaternion thisq;
|
||||
|
||||
if (EXPECT_NOT(!GetThisQuaternion(context, this, &thisq, @"toSource"))) return NO;
|
||||
if (EXPECT_NOT(!GetThisQuaternion(context, OOJS_THIS, &thisq, @"toSource"))) return NO;
|
||||
|
||||
*outResult = [[NSString stringWithFormat:@"Quaternion(%g, %g, %g, %g)", thisq.w, thisq.x, thisq.y, thisq.z]
|
||||
javaScriptValueInContext:context];
|
||||
NSString *str = [NSString stringWithFormat:@"Quaternion(%g, %g, %g, %g)", thisq.w, thisq.x, thisq.y, thisq.z];
|
||||
OOJS_SET_RVAL([str javaScriptValueInContext:context]);
|
||||
return YES;
|
||||
|
||||
OOJS_NATIVE_EXIT
|
||||
@ -546,12 +549,12 @@ static JSBool QuaternionMultiply(OOJS_NATIVE_ARGS)
|
||||
|
||||
Quaternion thisq, thatq, result;
|
||||
|
||||
if (EXPECT_NOT(!GetThisQuaternion(context, this, &thisq, @"multiply"))) return NO;
|
||||
if (EXPECT_NOT(!QuaternionFromArgumentList(context, @"Quaternion", @"multiply", argc, argv, &thatq, NULL))) return NO;
|
||||
if (EXPECT_NOT(!GetThisQuaternion(context, OOJS_THIS, &thisq, @"multiply"))) return NO;
|
||||
if (EXPECT_NOT(!QuaternionFromArgumentList(context, @"Quaternion", @"multiply", argc, OOJS_ARGV, &thatq, NULL))) return NO;
|
||||
|
||||
result = quaternion_multiply(thisq, thatq);
|
||||
|
||||
return QuaternionToJSValue(context, result, outResult);
|
||||
OOJS_RETURN_QUATERNION(result);
|
||||
|
||||
OOJS_PROFILE_EXIT
|
||||
}
|
||||
@ -565,12 +568,12 @@ static JSBool QuaternionDot(OOJS_NATIVE_ARGS)
|
||||
Quaternion thisq, thatq;
|
||||
double result;
|
||||
|
||||
if (EXPECT_NOT(!GetThisQuaternion(context, this, &thisq, @"dot"))) return NO;
|
||||
if (EXPECT_NOT(!QuaternionFromArgumentList(context, @"Quaternion", @"dot", argc, argv, &thatq, NULL))) return NO;
|
||||
if (EXPECT_NOT(!GetThisQuaternion(context, OOJS_THIS, &thisq, @"dot"))) return NO;
|
||||
if (EXPECT_NOT(!QuaternionFromArgumentList(context, @"Quaternion", @"dot", argc, OOJS_ARGV, &thatq, NULL))) return NO;
|
||||
|
||||
result = quaternion_dot_product(thisq, thatq);
|
||||
|
||||
return JS_NewDoubleValue(context, result, outResult);
|
||||
OOJS_RETURN_DOUBLE(result);
|
||||
|
||||
OOJS_PROFILE_EXIT
|
||||
}
|
||||
@ -585,8 +588,11 @@ static JSBool QuaternionRotate(OOJS_NATIVE_ARGS)
|
||||
Vector axis;
|
||||
double angle;
|
||||
uintN consumed;
|
||||
#if OO_NEW_JS
|
||||
jsval *argv = OOJS_ARGV;
|
||||
#endif
|
||||
|
||||
if (EXPECT_NOT(!GetThisQuaternion(context, this, &thisq, @"rotate"))) return NO;
|
||||
if (EXPECT_NOT(!GetThisQuaternion(context, OOJS_THIS, &thisq, @"rotate"))) return NO;
|
||||
if (EXPECT_NOT(!VectorFromArgumentList(context, @"Quaternion", @"rotate", argc, argv, &axis, &consumed))) return NO;
|
||||
argv += consumed;
|
||||
argc -= consumed;
|
||||
@ -597,7 +603,7 @@ static JSBool QuaternionRotate(OOJS_NATIVE_ARGS)
|
||||
}
|
||||
// Else no angle specified, so don't rotate and pass value through unchanged.
|
||||
|
||||
return QuaternionToJSValue(context, thisq, outResult);
|
||||
OOJS_RETURN_QUATERNION(thisq);
|
||||
|
||||
OOJS_PROFILE_EXIT
|
||||
}
|
||||
@ -611,12 +617,12 @@ static JSBool QuaternionRotateX(OOJS_NATIVE_ARGS)
|
||||
Quaternion quat;
|
||||
double angle;
|
||||
|
||||
if (EXPECT_NOT(!GetThisQuaternion(context, this, &quat, @"rotateX"))) return NO;
|
||||
if (EXPECT_NOT(!NumberFromArgumentList(context, @"Quaternion", @"rotateX", argc, argv, &angle, NULL))) return NO;
|
||||
if (EXPECT_NOT(!GetThisQuaternion(context, OOJS_THIS, &quat, @"rotateX"))) return NO;
|
||||
if (EXPECT_NOT(!NumberFromArgumentList(context, @"Quaternion", @"rotateX", argc, OOJS_ARGV, &angle, NULL))) return NO;
|
||||
|
||||
quaternion_rotate_about_x(&quat, angle);
|
||||
|
||||
return QuaternionToJSValue(context, quat, outResult);
|
||||
OOJS_RETURN_QUATERNION(quat);
|
||||
|
||||
OOJS_PROFILE_EXIT
|
||||
}
|
||||
@ -630,12 +636,12 @@ static JSBool QuaternionRotateY(OOJS_NATIVE_ARGS)
|
||||
Quaternion quat;
|
||||
double angle;
|
||||
|
||||
if (EXPECT_NOT(!GetThisQuaternion(context, this, &quat, @"rotateY"))) return NO;
|
||||
if (EXPECT_NOT(!NumberFromArgumentList(context, @"Quaternion", @"rotateY", argc, argv, &angle, NULL))) return NO;
|
||||
if (EXPECT_NOT(!GetThisQuaternion(context, OOJS_THIS, &quat, @"rotateY"))) return NO;
|
||||
if (EXPECT_NOT(!NumberFromArgumentList(context, @"Quaternion", @"rotateY", argc, OOJS_ARGV, &angle, NULL))) return NO;
|
||||
|
||||
quaternion_rotate_about_y(&quat, angle);
|
||||
|
||||
return QuaternionToJSValue(context, quat, outResult);
|
||||
OOJS_RETURN_QUATERNION(quat);
|
||||
|
||||
OOJS_PROFILE_EXIT
|
||||
}
|
||||
@ -649,12 +655,12 @@ static JSBool QuaternionRotateZ(OOJS_NATIVE_ARGS)
|
||||
Quaternion quat;
|
||||
double angle;
|
||||
|
||||
if (EXPECT_NOT(!GetThisQuaternion(context, this, &quat, @"rotateZ"))) return NO;
|
||||
if (EXPECT_NOT(!NumberFromArgumentList(context, @"Quaternion", @"rotateZ", argc, argv, &angle, NULL))) return NO;
|
||||
if (EXPECT_NOT(!GetThisQuaternion(context, OOJS_THIS, &quat, @"rotateZ"))) return NO;
|
||||
if (EXPECT_NOT(!NumberFromArgumentList(context, @"Quaternion", @"rotateZ", argc, OOJS_ARGV, &angle, NULL))) return NO;
|
||||
|
||||
quaternion_rotate_about_z(&quat, angle);
|
||||
|
||||
return QuaternionToJSValue(context, quat, outResult);
|
||||
OOJS_RETURN_QUATERNION(quat);
|
||||
|
||||
OOJS_PROFILE_EXIT
|
||||
}
|
||||
@ -667,11 +673,11 @@ static JSBool QuaternionNormalize(OOJS_NATIVE_ARGS)
|
||||
|
||||
Quaternion quat;
|
||||
|
||||
if (EXPECT_NOT(!GetThisQuaternion(context, this, &quat, @"normalize"))) return NO;
|
||||
if (EXPECT_NOT(!GetThisQuaternion(context, OOJS_THIS, &quat, @"normalize"))) return NO;
|
||||
|
||||
quaternion_normalize(&quat);
|
||||
|
||||
return QuaternionToJSValue(context, quat, outResult);
|
||||
OOJS_RETURN_QUATERNION(quat);
|
||||
|
||||
OOJS_PROFILE_EXIT
|
||||
}
|
||||
@ -685,11 +691,11 @@ static JSBool QuaternionVectorForward(OOJS_NATIVE_ARGS)
|
||||
Quaternion thisq;
|
||||
Vector result;
|
||||
|
||||
if (EXPECT_NOT(!GetThisQuaternion(context, this, &thisq, @"vectorForward()"))) return NO;
|
||||
if (EXPECT_NOT(!GetThisQuaternion(context, OOJS_THIS, &thisq, @"vectorForward()"))) return NO;
|
||||
|
||||
result = vector_forward_from_quaternion(thisq);
|
||||
|
||||
return VectorToJSValue(context, result, outResult);
|
||||
OOJS_RETURN_VECTOR(result);
|
||||
|
||||
OOJS_PROFILE_EXIT
|
||||
}
|
||||
@ -703,11 +709,11 @@ static JSBool QuaternionVectorUp(OOJS_NATIVE_ARGS)
|
||||
Quaternion thisq;
|
||||
Vector result;
|
||||
|
||||
if (EXPECT_NOT(!GetThisQuaternion(context, this, &thisq, @"vectorUp"))) return NO;
|
||||
if (EXPECT_NOT(!GetThisQuaternion(context, OOJS_THIS, &thisq, @"vectorUp"))) return NO;
|
||||
|
||||
result = vector_up_from_quaternion(thisq);
|
||||
|
||||
return VectorToJSValue(context, result, outResult);
|
||||
OOJS_RETURN_VECTOR(result);
|
||||
|
||||
OOJS_PROFILE_EXIT
|
||||
}
|
||||
@ -721,11 +727,11 @@ static JSBool QuaternionVectorRight(OOJS_NATIVE_ARGS)
|
||||
Quaternion thisq;
|
||||
Vector result;
|
||||
|
||||
if (EXPECT_NOT(!GetThisQuaternion(context, this, &thisq, @"vectorRight"))) return NO;
|
||||
if (EXPECT_NOT(!GetThisQuaternion(context, OOJS_THIS, &thisq, @"vectorRight"))) return NO;
|
||||
|
||||
result = vector_right_from_quaternion(thisq);
|
||||
|
||||
return VectorToJSValue(context, result, outResult);
|
||||
OOJS_RETURN_VECTOR(result);
|
||||
|
||||
OOJS_PROFILE_EXIT
|
||||
}
|
||||
@ -741,13 +747,13 @@ static JSBool QuaternionToArray(OOJS_NATIVE_ARGS)
|
||||
BOOL OK = YES;
|
||||
jsval nVal;
|
||||
|
||||
if (EXPECT_NOT(!GetThisQuaternion(context, this, &thisq, @"toArray"))) return NO;
|
||||
if (EXPECT_NOT(!GetThisQuaternion(context, OOJS_THIS, &thisq, @"toArray"))) return NO;
|
||||
|
||||
result = JS_NewArrayObject(context, 0, NULL);
|
||||
if (result != NULL)
|
||||
{
|
||||
// We do this at the top because *outResult is a GC root.
|
||||
*outResult = OBJECT_TO_JSVAL(result);
|
||||
OOJS_SET_RVAL(OBJECT_TO_JSVAL(result));
|
||||
|
||||
if (JS_NewNumberValue(context, thisq.w, &nVal)) JS_SetElement(context, result, 0, &nVal);
|
||||
else OK = NO;
|
||||
@ -759,7 +765,7 @@ static JSBool QuaternionToArray(OOJS_NATIVE_ARGS)
|
||||
else OK = NO;
|
||||
}
|
||||
|
||||
if (!OK) *outResult = JSVAL_VOID;
|
||||
if (!OK) OOJS_SET_RVAL(JSVAL_VOID);
|
||||
return YES;
|
||||
|
||||
OOJS_PROFILE_EXIT
|
||||
@ -773,7 +779,7 @@ static JSBool QuaternionStaticRandom(OOJS_NATIVE_ARGS)
|
||||
{
|
||||
OOJS_PROFILE_ENTER
|
||||
|
||||
return QuaternionToJSValue(context, OORandomQuaternion(), outResult);
|
||||
OOJS_RETURN_QUATERNION(OORandomQuaternion());
|
||||
|
||||
OOJS_PROFILE_EXIT
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -29,14 +29,12 @@ MA 02110-1301, USA.
|
||||
static JSObject *sSpecialFunctionsObject;
|
||||
|
||||
|
||||
static JSBool SpecialToString(OOJS_NATIVE_ARGS);
|
||||
static JSBool SpecialJSWarning(OOJS_NATIVE_ARGS);
|
||||
|
||||
|
||||
static JSFunctionSpec sSpecialFunctionsMethods[] =
|
||||
{
|
||||
// JS name Function min args
|
||||
{ "toString", SpecialToString, 0 },
|
||||
{ "jsWarning", SpecialJSWarning, 1 },
|
||||
{ 0 }
|
||||
};
|
||||
@ -47,7 +45,11 @@ void InitOOJSSpecialFunctions(JSContext *context, JSObject *global)
|
||||
sSpecialFunctionsObject = JS_NewObject(context, NULL, NULL, NULL);
|
||||
OOJS_AddGCObjectRoot(context, &sSpecialFunctionsObject, "OOJSSpecialFunctions");
|
||||
JS_DefineFunctions(context, sSpecialFunctionsObject, sSpecialFunctionsMethods);
|
||||
#if OO_NEW_JS
|
||||
JS_FreezeObject(context, sSpecialFunctionsObject);
|
||||
#else
|
||||
JS_SealObject(context, sSpecialFunctionsObject, NO);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -63,23 +65,12 @@ OOJSValue *JSSpecialFunctionsObjectWrapper(JSContext *context)
|
||||
}
|
||||
|
||||
|
||||
static JSBool SpecialToString(OOJS_NATIVE_ARGS)
|
||||
{
|
||||
OOJS_PROFILE_ENTER
|
||||
|
||||
*outResult = STRING_TO_JSVAL(JS_NewStringCopyZ(context, "[object OoliteSpecialFunctions]"));
|
||||
return YES;
|
||||
|
||||
OOJS_PROFILE_EXIT
|
||||
}
|
||||
|
||||
|
||||
static JSBool SpecialJSWarning(OOJS_NATIVE_ARGS)
|
||||
{
|
||||
OOJS_PROFILE_ENTER // These functions are exception-safe
|
||||
|
||||
OOSetJSWarningOrErrorStackSkip(1);
|
||||
OOReportJSWarning(context, @"%@", [NSString stringWithJavaScriptValue:argv[0] inContext:context]);
|
||||
OOReportJSWarning(context, @"%@", [NSString stringWithJavaScriptValue:OOJS_ARG(0) inContext:context]);
|
||||
OOSetJSWarningOrErrorStackSkip(0);
|
||||
return YES;
|
||||
|
||||
|
@ -332,7 +332,7 @@ static JSBool StationDockPlayer(OOJS_NATIVE_ARGS)
|
||||
}
|
||||
|
||||
StationEntity *stationForDockingPlayer = nil;
|
||||
JSStationGetStationEntity(context, this, &stationForDockingPlayer);
|
||||
JSStationGetStationEntity(context, OOJS_THIS, &stationForDockingPlayer);
|
||||
|
||||
#if DOCKING_CLEARANCE_ENABLED
|
||||
[player setDockingClearanceStatus:DOCKING_CLEARANCE_STATUS_GRANTED];
|
||||
@ -356,23 +356,21 @@ static JSBool StationLaunchShipWithRole(OOJS_NATIVE_ARGS)
|
||||
ShipEntity *result = nil;
|
||||
JSBool abortAllDockings = NO;
|
||||
|
||||
if (!JSStationGetStationEntity(context, this, &station)) return YES; // stale reference, no-op
|
||||
if (!JSStationGetStationEntity(context, OOJS_THIS, &station)) return YES; // stale reference, no-op
|
||||
|
||||
if (argc > 1) JS_ValueToBoolean(context, argv[1], &abortAllDockings);
|
||||
if (argc > 1) JS_ValueToBoolean(context, OOJS_ARG(1), &abortAllDockings);
|
||||
|
||||
NSString *shipRole = JSValToNSString(context, argv[0]);
|
||||
NSString *shipRole = JSValToNSString(context, OOJS_ARG(1));
|
||||
if (EXPECT_NOT(shipRole == nil))
|
||||
{
|
||||
OOReportJSBadArguments(context, @"Station", @"launchShipWithRole", argc, argv, nil, @"shipRole");
|
||||
OOReportJSBadArguments(context, @"Station", @"launchShipWithRole", argc, OOJS_ARGV, nil, @"shipRole");
|
||||
return NO;
|
||||
}
|
||||
|
||||
result = [station launchIndependentShip:shipRole];
|
||||
if (abortAllDockings) [station abortAllDockings];
|
||||
*outResult = [result javaScriptValueInContext:context];
|
||||
|
||||
return YES;
|
||||
|
||||
OOJS_RETURN_OBJECT(result);
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
||||
@ -382,14 +380,9 @@ static JSBool StationLaunchDefenseShip(OOJS_NATIVE_ARGS)
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
StationEntity *station = nil;
|
||||
ShipEntity *result = nil;
|
||||
if (!JSStationGetStationEntity(context, this, &station)) return YES; // stale reference, no-op
|
||||
|
||||
result = [station launchDefenseShip];
|
||||
*outResult = [result javaScriptValueInContext:context];
|
||||
|
||||
return YES;
|
||||
if (!JSStationGetStationEntity(context, OOJS_THIS, &station)) return YES; // stale reference, no-op
|
||||
|
||||
OOJS_RETURN_OBJECT([station launchDefenseShip]);
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
||||
@ -399,14 +392,9 @@ static JSBool StationLaunchScavenger(OOJS_NATIVE_ARGS)
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
StationEntity *station = nil;
|
||||
ShipEntity *result = nil;
|
||||
if (!JSStationGetStationEntity(context, this, &station)) return YES; // stale reference, no-op
|
||||
|
||||
result = [station launchScavenger];
|
||||
*outResult = [result javaScriptValueInContext:context];
|
||||
|
||||
return YES;
|
||||
if (!JSStationGetStationEntity(context, OOJS_THIS, &station)) return YES; // stale reference, no-op
|
||||
|
||||
OOJS_RETURN_OBJECT([station launchScavenger]);
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
||||
@ -416,14 +404,9 @@ static JSBool StationLaunchMiner(OOJS_NATIVE_ARGS)
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
StationEntity *station = nil;
|
||||
ShipEntity *result = nil;
|
||||
if (!JSStationGetStationEntity(context, this, &station)) return YES; // stale reference, no-op
|
||||
|
||||
result = [station launchMiner];
|
||||
*outResult = [result javaScriptValueInContext:context];
|
||||
|
||||
return YES;
|
||||
if (!JSStationGetStationEntity(context, OOJS_THIS, &station)) return YES; // stale reference, no-op
|
||||
|
||||
OOJS_RETURN_OBJECT([station launchMiner]);
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
||||
@ -433,14 +416,9 @@ static JSBool StationLaunchPirateShip(OOJS_NATIVE_ARGS)
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
StationEntity *station = nil;
|
||||
ShipEntity *result = nil;
|
||||
if (!JSStationGetStationEntity(context, this, &station)) return YES; // stale reference, no-op
|
||||
|
||||
result = [station launchPirateShip];
|
||||
*outResult = [result javaScriptValueInContext:context];
|
||||
|
||||
return YES;
|
||||
if (!JSStationGetStationEntity(context, OOJS_THIS, &station)) return YES; // stale reference, no-op
|
||||
|
||||
OOJS_RETURN_OBJECT([station launchPirateShip]);
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
||||
@ -450,14 +428,9 @@ static JSBool StationLaunchShuttle(OOJS_NATIVE_ARGS)
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
StationEntity *station = nil;
|
||||
ShipEntity *result = nil;
|
||||
if (!JSStationGetStationEntity(context, this, &station)) return YES; // stale reference, no-op
|
||||
|
||||
result = [station launchShuttle];
|
||||
*outResult = [result javaScriptValueInContext:context];
|
||||
|
||||
return YES;
|
||||
if (!JSStationGetStationEntity(context, OOJS_THIS, &station)) return YES; // stale reference, no-op
|
||||
|
||||
OOJS_RETURN_OBJECT([station launchShuttle]);
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
||||
@ -467,14 +440,9 @@ static JSBool StationLaunchPatrol(OOJS_NATIVE_ARGS)
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
StationEntity *station = nil;
|
||||
ShipEntity *result = nil;
|
||||
if (!JSStationGetStationEntity(context, this, &station)) return YES; // stale reference, no-op
|
||||
|
||||
result = [station launchPatrol];
|
||||
*outResult = [result javaScriptValueInContext:context];
|
||||
|
||||
return YES;
|
||||
if (!JSStationGetStationEntity(context, OOJS_THIS, &station)) return YES; // stale reference, no-op
|
||||
|
||||
OOJS_RETURN_OBJECT([station launchPatrol]);
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
||||
@ -484,13 +452,8 @@ static JSBool StationLaunchPolice(OOJS_NATIVE_ARGS)
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
StationEntity *station = nil;
|
||||
NSArray *result = nil;
|
||||
if (!JSStationGetStationEntity(context, this, &station)) return YES; // stale reference, no-op
|
||||
|
||||
result = [station launchPolice];
|
||||
*outResult = [result javaScriptValueInContext:context];
|
||||
|
||||
return YES;
|
||||
if (!JSStationGetStationEntity(context, OOJS_THIS, &station)) return YES; // stale reference, no-op
|
||||
|
||||
OOJS_RETURN_OBJECT([station launchPolice]);
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
@ -350,17 +350,21 @@ static void TimerFinalize(JSContext *context, JSObject *this)
|
||||
|
||||
|
||||
// new Timer(this : Object, function : Function, delay : Number [, interval : Number]) : Timer
|
||||
static JSBool TimerConstruct(JSContext *context, JSObject *inThis, uintN argc, jsval *argv, jsval *outResult)
|
||||
static JSBool TimerConstruct(OOJS_NATIVE_ARGS)
|
||||
{
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
JSObject *this = NULL;
|
||||
jsval function = JSVAL_VOID;
|
||||
double delay;
|
||||
double interval = -1.0;
|
||||
OOJSTimer *timer = nil;
|
||||
#if OO_NEW_JS
|
||||
JSObject *this = NULL;
|
||||
#else
|
||||
this = NULL;
|
||||
#endif
|
||||
|
||||
if (!JS_IsConstructing(context))
|
||||
if (!OOJS_IS_CONSTRUCTING)
|
||||
{
|
||||
OOReportJSError(context, @"Timer() cannot be called as a function, it must be used as a constructor (as in new Timer(...)).");
|
||||
return NO;
|
||||
@ -368,34 +372,34 @@ static JSBool TimerConstruct(JSContext *context, JSObject *inThis, uintN argc, j
|
||||
|
||||
if (argc < 3)
|
||||
{
|
||||
OOReportJSBadArguments(context, nil, @"Timer", argc, argv, @"Invalid arguments in constructor", @"(object, function, number [, number])");
|
||||
OOReportJSBadArguments(context, nil, @"Timer", argc, OOJS_ARGV, @"Invalid arguments in constructor", @"(object, function, number [, number])");
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (!JSVAL_IS_NULL(argv[0]) && !JSVAL_IS_VOID(argv[0]))
|
||||
if (!JSVAL_IS_NULL(OOJS_ARG(0)) && !JSVAL_IS_VOID(OOJS_ARG(0)))
|
||||
{
|
||||
if (!JS_ValueToObject(context, argv[0], &this))
|
||||
if (!JS_ValueToObject(context, OOJS_ARG(0), &this))
|
||||
{
|
||||
OOReportJSBadArguments(context, nil, @"Timer", 1, argv, @"Invalid argument in constructor", @"object");
|
||||
OOReportJSBadArguments(context, nil, @"Timer", 1, OOJS_ARGV, @"Invalid argument in constructor", @"object");
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
function = argv[1];
|
||||
function = OOJS_ARG(1);
|
||||
if (JS_ValueToFunction(context, function) == NULL)
|
||||
{
|
||||
OOReportJSBadArguments(context, nil, @"Timer", 1, argv + 1, @"Invalid argument in constructor", @"function");
|
||||
OOReportJSBadArguments(context, nil, @"Timer", 1, OOJS_ARGV + 1, @"Invalid argument in constructor", @"function");
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (!JS_ValueToNumber(context, argv[2], &delay) || isnan(delay))
|
||||
if (!JS_ValueToNumber(context, OOJS_ARG(2), &delay) || isnan(delay))
|
||||
{
|
||||
OOReportJSBadArguments(context, nil, @"Timer", 1, argv + 2, @"Invalid argument in constructor", @"number");
|
||||
OOReportJSBadArguments(context, nil, @"Timer", 1, OOJS_ARGV + 2, @"Invalid argument in constructor", @"number");
|
||||
return NO;
|
||||
}
|
||||
|
||||
// Fourth argument is optional.
|
||||
if (3 < argc && !JS_ValueToNumber(context, argv[3], &interval)) interval = -1;
|
||||
if (3 < argc && !JS_ValueToNumber(context, OOJS_ARG(3), &interval)) interval = -1;
|
||||
|
||||
// Ensure interval is not too small.
|
||||
if (0.0 < interval && interval < kMinInterval) interval = kMinInterval;
|
||||
@ -404,7 +408,7 @@ static JSBool TimerConstruct(JSContext *context, JSObject *inThis, uintN argc, j
|
||||
interval:interval
|
||||
function:function
|
||||
this:this
|
||||
jsSelf:JSVAL_TO_OBJECT(*outResult)];
|
||||
jsSelf:JSVAL_TO_OBJECT(OOJS_RVAL)];
|
||||
if (timer != nil)
|
||||
{
|
||||
if (delay >= 0) // Leave in stopped state if delay is negative
|
||||
@ -415,7 +419,7 @@ static JSBool TimerConstruct(JSContext *context, JSObject *inThis, uintN argc, j
|
||||
}
|
||||
else
|
||||
{
|
||||
*outResult = JSVAL_NULL;
|
||||
OOJS_SET_RVAL(JSVAL_NULL);
|
||||
}
|
||||
|
||||
return YES;
|
||||
@ -433,11 +437,9 @@ static JSBool TimerStart(OOJS_NATIVE_ARGS)
|
||||
|
||||
OOJSTimer *thisTimer = nil;
|
||||
|
||||
if (EXPECT_NOT(!JSTimerGetTimer(context, this, &thisTimer))) return NO;
|
||||
|
||||
*outResult = BOOLToJSVal([thisTimer scheduleTimer]);
|
||||
return YES;
|
||||
if (EXPECT_NOT(!JSTimerGetTimer(context, OOJS_THIS, &thisTimer))) return NO;
|
||||
|
||||
OOJS_RETURN_BOOL([thisTimer scheduleTimer]);
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
||||
@ -449,7 +451,7 @@ static JSBool TimerStop(OOJS_NATIVE_ARGS)
|
||||
|
||||
OOJSTimer *thisTimer = nil;
|
||||
|
||||
if (EXPECT_NOT(!JSTimerGetTimer(context, this, &thisTimer))) return NO;
|
||||
if (EXPECT_NOT(!JSTimerGetTimer(context, OOJS_THIS, &thisTimer))) return NO;
|
||||
|
||||
[thisTimer unscheduleTimer];
|
||||
return YES;
|
||||
|
@ -32,7 +32,7 @@ MA 02110-1301, USA.
|
||||
static JSBool WorldScriptsGetProperty(OOJS_PROP_ARGS);
|
||||
static JSBool WorldScriptsEnumerate(JSContext *cx, JSObject *obj);
|
||||
|
||||
static JSBool GetWorldScriptNames(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool GetWorldScriptNames(OOJS_PROP_ARGS);
|
||||
|
||||
|
||||
static JSClass sWorldScriptsClass =
|
||||
@ -119,14 +119,12 @@ static JSBool WorldScriptsEnumerate(JSContext *context, JSObject *object)
|
||||
}
|
||||
|
||||
|
||||
static JSBool GetWorldScriptNames(JSContext *context, JSObject *this, jsval name, jsval *outValue)
|
||||
static JSBool GetWorldScriptNames(OOJS_PROP_ARGS)
|
||||
{
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
NSArray *names = nil;
|
||||
|
||||
names = [OOPlayerForScripting() worldScriptNames];
|
||||
*outValue = [names javaScriptValueInContext:context];
|
||||
NSArray *names = [OOPlayerForScripting() worldScriptNames];
|
||||
*value = [names javaScriptValueInContext:context];
|
||||
|
||||
return YES;
|
||||
|
||||
|
@ -448,6 +448,7 @@ void OOJSDumpStack(NSString *logMessageClass, JSContext *context);
|
||||
#if OO_NEW_JS
|
||||
// Native callback conventions have changed.
|
||||
#define OOJS_NATIVE_ARGS JSContext *context, uintN argc, jsval *vp
|
||||
#define OOJS_NATIVE_CALLTHROUGH context, argc, vp
|
||||
#define OOJS_CALLEE JS_CALLEE(context, vp)
|
||||
#define OOJS_THIS_VAL JS_THIS(context, vp)
|
||||
#define OOJS_THIS JS_THIS_OBJECT(context, vp)
|
||||
@ -469,6 +470,7 @@ void OOJSDumpStack(NSString *logMessageClass, JSContext *context);
|
||||
|
||||
#else
|
||||
#define OOJS_NATIVE_ARGS JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult
|
||||
#define OOJS_NATIVE_CALLTHROUGH context, this, argc, argv, outResult
|
||||
#define OOJS_CALLEE argv[-2]
|
||||
#define OOJS_THIS_VAL OBJECT_TO_JSVAL(this)
|
||||
#define OOJS_THIS this
|
||||
@ -490,6 +492,10 @@ void OOJSDumpStack(NSString *logMessageClass, JSContext *context);
|
||||
#endif
|
||||
|
||||
#define OOJS_ARG(n) (OOJS_ARGV[(n)])
|
||||
#define OOJS_RETURN_VOID do { OOJS_SET_RVAL(JSVAL_VOID); return YES; } while (0)
|
||||
#define OOJS_RETURN_BOOL(v) do { OOJS_SET_RVAL(BOOLToJSVal(v)); return YES; } while (0)
|
||||
#define OOJS_RETURN_INT(v) do { OOJS_SET_RVAL(INT_TO_JSVAL(v)); return YES; } while (0)
|
||||
#define OOJS_RETURN_OBJECT(o) do { OOJS_SET_RVAL([o javaScriptValueInContext:context]); return YES; } while (0)
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user