Oolite
Loading...
Searching...
No Matches
OOJSSystemInfo.m File Reference
Include dependency graph for OOJSSystemInfo.m:

Go to the source code of this file.

Classes

class  OOSystemInfo

Macros

#define OOJS_EXOTIC_ENTER    @try {
#define OOJS_EXOTIC_EXIT(context, failure)

Enumerations

enum  { kSystemInfo_coordinates , kSystemInfo_internalCoordinates , kSystemInfo_galaxyID , kSystemInfo_systemID }

Functions

static JSValue SystemInfoGetProperty (OOJS_GETTER_ARGS)
static void SystemInfoFinalize (JSRuntime *runtime, JSValueConst this)
static int SystemInfoExoticGetOwnProperty (JSContext *context, JSPropertyDescriptor *desc, JSValueConst obj, JSAtom prop)
static int SystemInfoExoticGetOwnPropertyNames (JSContext *context, JSPropertyEnum **ptab, uint32_t *plen, JSValueConst obj)
static int SystemInfoExoticDeleteProperty (JSContext *context, JSValueConst obj, JSAtom prop)
static JSValue SystemInfoExoticGetProperty (JSContext *context, JSValueConst obj, JSAtom prop, JSValueConst receiver)
static int SystemInfoExoticSetProperty (JSContext *context, JSValueConst obj, JSAtom prop, JSValueConst value, JSValueConst receiver, int flags)
static JSValue SystemInfoDistanceToSystem (OOJS_NATIVE_ARGS)
static JSValue SystemInfoRouteToSystem (OOJS_NATIVE_ARGS)
static JSValue SystemInfoSamplePrice (OOJS_NATIVE_ARGS)
static JSValue SystemInfoSetPropertyMethod (OOJS_NATIVE_ARGS)
static JSValue SystemInfoStaticSetInterstellarProperty (OOJS_NATIVE_ARGS)
static JSValue SystemInfoStaticFilteredSystems (OOJS_NATIVE_ARGS)
void InitOOJSSystemInfo (JSContext *context, JSValueConst global)
JSValue GetJSSystemInfoForSystem (JSContext *context, OOGalaxyID galaxy, OOSystemID system)
static OOSystemInfo * SystemInfoForObject (JSValueConst obj)
static NSString * SystemInfoKeyForAtom (JSContext *context, JSAtom prop)
static BOOL SystemInfoGetSystemDataValue (JSContext *context, OOSystemInfo *info, NSString *key, JSValue *outValue)
static int SystemInfoSetOnPrototypeChain (JSContext *context, JSValueConst obj, JSAtom prop, JSValueConst value, JSValueConst receiver, int flags, BOOL *outHandled)

Variables

static JSClassID sSystemInfoClassID
static JSValue sCachedSystemInfo
static OOGalaxyID sCachedGalaxy
static OOSystemID sCachedSystem
static JSClassExoticMethods sSystemInfoExoticMethods
static JSClassDef sSystemInfoClass
static const JSCFunctionListEntry sSystemInfoProperties []
static const JSCFunctionListEntry sSystemInfoMethods []
static const JSCFunctionListEntry sSystemInfoStaticMethods []

Macro Definition Documentation

◆ OOJS_EXOTIC_ENTER

#define OOJS_EXOTIC_ENTER    @try {

◆ OOJS_EXOTIC_EXIT

#define OOJS_EXOTIC_EXIT ( context,
failure )
Value:
} \
@catch (id exception) \
{ \
OOJSReportWrappedException(context, exception); \
return (failure); \
}

Definition at line 387 of file OOJSSystemInfo.m.

387#define OOJS_EXOTIC_EXIT(context, failure) \
388 } \
389 @catch (id exception) \
390 { \
391 OOJSReportWrappedException(context, exception); \
392 return (failure); \
393 }

Referenced by SystemInfoExoticDeleteProperty(), SystemInfoExoticGetOwnProperty(), SystemInfoExoticGetOwnPropertyNames(), SystemInfoExoticGetProperty(), and SystemInfoExoticSetProperty().

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kSystemInfo_coordinates 
kSystemInfo_internalCoordinates 
kSystemInfo_galaxyID 
kSystemInfo_systemID 

Definition at line 107 of file OOJSSystemInfo.m.

107 {
108 // Property IDs
109 kSystemInfo_coordinates, // system coordinates (in LY), Vector3D (with z = 0), read-only
110 kSystemInfo_internalCoordinates, // system coordinates (unscaled), Vector3D (with z = 0), read-only
111 kSystemInfo_galaxyID, // galaxy number, integer, read-only
112 kSystemInfo_systemID // system number, integer, read-only
113};
@ kSystemInfo_systemID
@ kSystemInfo_coordinates
@ kSystemInfo_internalCoordinates
@ kSystemInfo_galaxyID

Function Documentation

◆ GetJSSystemInfoForSystem()

JSValue GetJSSystemInfoForSystem ( JSContext * context,
OOGalaxyID galaxy,
OOSystemID system )

Definition at line 328 of file OOJSSystemInfo.m.

329{
331
332 // Use cached object if possible.
333 if (JS_IsObject(sCachedSystemInfo) && sCachedGalaxy == galaxy && sCachedSystem == system) {
334 return JS_DupValue(context, sCachedSystemInfo);
335 }
336
337 // If not, create a new one.
338 OOSystemInfo* info = nil;
339 JSValue result;
341 info = [[[OOSystemInfo alloc] initWithGalaxy:galaxy system:system] autorelease];
343
344 if (EXPECT_NOT(info == nil)) {
345 OOJSReportWarning(context, @"Could not create system info object for galaxy %u, system %i.", galaxy, system);
346 }
347
348 result = OOJSValueFromNativeObject(context, info);
349
350 // Replace the cached object. (Freeing it may run SystemInfoFinalize(), which clears the cache.)
351 JSValue oldCache = sCachedSystemInfo;
352 sCachedSystemInfo = JS_UNDEFINED;
353 if (JS_IsObject(oldCache))
354 JS_FreeValue(context, oldCache);
355 sCachedSystemInfo = JS_IsObject(result) ? JS_DupValue(context, result) : JS_UNDEFINED;
356 sCachedGalaxy = galaxy;
357 sCachedSystem = system;
358
359 return result;
360
362}
#define EXPECT_NOT(x)
#define OOJS_PROFILE_EXIT
#define OOJS_END_FULL_NATIVE
#define OOJS_BEGIN_FULL_NATIVE(context)
#define OOJS_PROFILE_ENTER
static OOSystemID sCachedSystem
static JSObject * sCachedSystemInfo
static OOGalaxyID sCachedGalaxy
void OOJSReportWarning(JSContext *context, NSString *format,...)
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
return nil

References EXPECT_NOT, OOSystemInfo::galaxy, nil, OOJS_BEGIN_FULL_NATIVE, OOJS_END_FULL_NATIVE, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJS_PROFILE_EXIT_JSVAL, OOJSReportWarning(), OOJSValueFromNativeObject(), sCachedGalaxy, sCachedSystem, sCachedSystemInfo, and OOSystemInfo::system.

Referenced by SystemGetProperty(), SystemGetProperty(), SystemStaticInfoForSystem(), and SystemStaticInfoForSystem().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitOOJSSystemInfo()

void InitOOJSSystemInfo ( JSContext * context,
JSValueConst global )

Definition at line 309 of file OOJSSystemInfo.m.

310{
311 static BOOL observing = NO;
312 if (!observing) {
313 [[NSNotificationCenter defaultCenter] addObserver:[OOSystemInfo class]
314 selector:@selector(oo_javaScriptEngineWillReset:)
316 object:nil];
317 observing = YES;
318 }
319 sCachedSystemInfo = JS_UNDEFINED;
320
322 OOJSInitClass(context, global, sSystemInfoClassID, JS_UNDEFINED, OOJSUnconstructableConstruct, 0,
326}
static JSPropertySpec sSystemInfoProperties[]
static JSFunctionSpec sSystemInfoStaticMethods[]
static JSClass sSystemInfoClass
static JSFunctionSpec sSystemInfoMethods[]
NSString *const kOOJavaScriptEngineWillResetNotification
void OOJSRegisterObjectConverter(JSClass *theClass, OOJSClassConverterCallback converter)
JSBool OOJSUnconstructableConstruct(JSContext *context, uintN argc, jsval *vp)
id OOJSBasicPrivateObjectConverter(JSContext *context, JSObject *object)
static JSClassID sSystemInfoClassID
JSClassID OOJSRegisterClass(JSClassID *ioClassID, const JSClassDef *classDef)
Definition OOJSClasses.m:61
JSValueConst OOJSInitClass(JSContext *context, JSValueConst global, JSClassID classID, JSValueConst parentPrototype, JSCFunction *constructor, int constructorArgCount, const JSCFunctionListEntry *properties, size_t propertyCount, const JSCFunctionListEntry *methods, size_t methodCount, const JSCFunctionListEntry *staticMethods, size_t staticMethodCount)
#define OOJS_COUNT(array)

References OOJS_COUNT, OOJSBasicPrivateObjectConverter(), OOJSInitClass(), OOJSRegisterClass(), OOJSRegisterObjectConverter(), OOJSUnconstructableConstruct(), sCachedSystemInfo, sSystemInfoClass, sSystemInfoClassID, sSystemInfoMethods, sSystemInfoProperties, and sSystemInfoStaticMethods.

Here is the call graph for this function:

◆ SystemInfoDistanceToSystem()

JSValue SystemInfoDistanceToSystem ( OOJS_NATIVE_ARGS )
static

Definition at line 777 of file OOJSSystemInfo.m.

778{
779 OOJS_NATIVE_ENTER(context)
780
781 OOSystemInfo* thisInfo = nil;
782 OOSystemInfo* otherInfo = nil;
783
784 if (!JSSystemInfoGetSystemInfo(context, OOJS_THIS, &thisInfo))
785 return OOJSNativeFailure(context);
786 // SpiderMonkey version used JS_ValueToObject(); a primitive can't be a SystemInfo anyway.
787 if (argc < 1 || !JS_IsObject(OOJS_ARGV[0]) || !JSSystemInfoGetSystemInfo(context, OOJS_ARGV[0], &otherInfo)) {
788 OOJSReportBadArguments(context, @"SystemInfo", @"distanceToSystem", MIN(argc, 1), OOJS_ARGV, nil, @"system info");
789 return OOJSNativeFailure(context);
790 }
791
792 BOOL sameGalaxy = ([thisInfo galaxy] == [otherInfo galaxy]);
793 if (!sameGalaxy) {
794 OOJSReportErrorForCaller(context, @"SystemInfo", @"distanceToSystem", @"Cannot calculate distance for systems in other galaxies.");
795 return OOJSNativeFailure(context);
796 }
797
798 NSPoint thisCoord = [thisInfo coordinates];
799 NSPoint otherCoord = [otherInfo coordinates];
800
801 OOJS_RETURN_DOUBLE(distanceBetweenPlanetPositions(thisCoord.x, thisCoord.y, otherCoord.x, otherCoord.y));
802
804}
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
#define OOJS_THIS
#define OOJS_RETURN_DOUBLE(value)
void OOJSReportErrorForCaller(JSContext *context, NSString *scriptClass, NSString *function, NSString *format,...)
#define OOJS_ARGV
void OOJSReportBadArguments(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, NSString *message, NSString *expectedArgsDescription)
#define MIN(A, B)
Definition OOMaths.h:91
JSValue OOJSNativeFailure(JSContext *context)
NSPoint coordinates()
OOGalaxyID galaxy()
OOINLINE double distanceBetweenPlanetPositions(int x1, int y1, int x2, int y2) INLINE_CONST_FUNC

References OOSystemInfo::coordinates, distanceBetweenPlanetPositions(), OOSystemInfo::galaxy, MIN, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_DOUBLE, OOJS_THIS, OOJSNativeFailure(), OOJSReportBadArguments(), and OOJSReportErrorForCaller().

Here is the call graph for this function:

◆ SystemInfoExoticDeleteProperty()

int SystemInfoExoticDeleteProperty ( JSContext * context,
JSValueConst obj,
JSAtom prop )
static

Definition at line 618 of file OOJSSystemInfo.m.

619{
621
623
624 // SpiderMonkey version: set the property to undefined (which removes it).
626 NSString* key = SystemInfoKeyForAtom(context, prop);
627 if (info != nil && key != nil) {
628 [info setValue:nil forKey:key];
629 }
630 return true;
631
632 OOJS_EXOTIC_EXIT(context, -1)
633
635}
#define OOJS_EXOTIC_EXIT(context, failure)
#define OOJS_EXOTIC_ENTER
static NSString * SystemInfoKeyForAtom(JSContext *context, JSAtom prop)
static OOSystemInfo * SystemInfoForObject(JSValueConst obj)

References nil, OOJS_EXOTIC_ENTER, OOJS_EXOTIC_EXIT, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, SystemInfoForObject(), and SystemInfoKeyForAtom().

Here is the call graph for this function:

◆ SystemInfoExoticGetOwnProperty()

int SystemInfoExoticGetOwnProperty ( JSContext * context,
JSPropertyDescriptor * desc,
JSValueConst obj,
JSAtom prop )
static

Definition at line 507 of file OOJSSystemInfo.m.

508{
510
512
514 NSString* key = (info != nil) ? SystemInfoKeyForAtom(context, prop) : nil;
515 JSValue value;
516
517 /* SpiderMonkey reported the fixed (shared permanent) properties as own
518 properties, so they win over system data keys of the same name
519 (notably "coordinates"). They are hidden, but a name that is also a
520 system data key is reported as enumerable, since the SpiderMonkey
521 enumerate hook listed every system data key.
522 */
523 int shared = OOJSGetSharedPermanentOwnProperty(context, desc, obj, prop);
524 if (shared != 0) {
525 if (shared > 0 && desc != NULL && key != nil) {
526 if (SystemInfoGetSystemDataValue(context, info, key, &value)) {
527 if (JS_IsException(value)) {
528 JS_FreeValue(context, desc->getter);
529 JS_FreeValue(context, desc->setter);
530 JS_FreeValue(context, desc->value);
531 return -1;
532 }
533 JS_FreeValue(context, value);
534 desc->flags |= JS_PROP_ENUMERABLE;
535 }
536 }
537 return shared;
538 }
539
540 if (key == nil)
541 return false; // Prototype (no dynamic properties) or symbol.
542
543 /* SpiderMonkey's resolve hook made system data keys enumerable (for..in and
544 Object.keys() list them) but not own properties: hasOwnProperty() and
545 the in operator returned false. QuickJS asks this hook without a
546 descriptor for hasOwnProperty() and in, and with one when collecting
547 enumerable keys, so answer accordingly. (QuickJS-ng 0.17 behaviour;
548 tools/js-parity checks it.)
549 */
550 if (desc == NULL)
551 return false;
552
553 if (!SystemInfoGetSystemDataValue(context, info, key, &value)) {
554 return false;
555 }
556 if (JS_IsException(value))
557 return -1;
558
559 if (desc != NULL) {
560 desc->flags = JS_PROP_C_W_E;
561 desc->value = value;
562 desc->getter = JS_UNDEFINED;
563 desc->setter = JS_UNDEFINED;
564 } else {
565 JS_FreeValue(context, value);
566 }
567 return true;
568
569 OOJS_EXOTIC_EXIT(context, -1)
570
572}
static BOOL SystemInfoGetSystemDataValue(JSContext *context, OOSystemInfo *info, NSString *key, JSValue *outValue)
int OOJSGetSharedPermanentOwnProperty(JSContext *context, JSPropertyDescriptor *desc, JSValueConst object, JSAtom prop)

References nil, OOJS_EXOTIC_ENTER, OOJS_EXOTIC_EXIT, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOJSGetSharedPermanentOwnProperty(), SystemInfoForObject(), SystemInfoGetSystemDataValue(), and SystemInfoKeyForAtom().

Here is the call graph for this function:

◆ SystemInfoExoticGetOwnPropertyNames()

int SystemInfoExoticGetOwnPropertyNames ( JSContext * context,
JSPropertyEnum ** ptab,
uint32_t * plen,
JSValueConst obj )
static

Definition at line 574 of file OOJSSystemInfo.m.

575{
577
579
580 *ptab = NULL;
581 *plen = 0;
582
584 NSArray* keys = [info allKeys];
585 NSUInteger count = [keys count];
586 assert(count <= INT32_MAX);
587
588 JSPropertyEnum* tab = js_mallocz(context, sizeof *tab * (count + 1));
589 if (tab == NULL)
590 return -1;
591
592 // System data keys (all enumerable; the SpiderMonkey enumerate hook listed exactly these).
593 uint32_t i = 0;
594 for (NSString* key in keys) {
595 JSAtom atom = JS_NewAtom(context, [[key description] UTF8String]);
596 if (atom == JS_ATOM_NULL) {
597 JS_FreePropertyEnum(context, tab, i);
598 return -1;
599 }
600 tab[i].atom = atom;
601 tab[i].is_enumerable = true;
602 i++;
603 }
604
605 /* Only the system data keys, as SpiderMonkey's JSCLASS_NEW_ENUMERATE hook
606 listed: the fixed properties (galaxyID...) are not named, although
607 hasOwnProperty() reports them, as before.
608 */
609 *ptab = tab;
610 *plen = i;
611 return 0;
612
613 OOJS_EXOTIC_EXIT(context, -1)
614
616}
unsigned count
NSArray * allKeys()

References OOSystemInfo::allKeys, count, OOJS_EXOTIC_ENTER, OOJS_EXOTIC_EXIT, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and SystemInfoForObject().

Here is the call graph for this function:

◆ SystemInfoExoticGetProperty()

JSValue SystemInfoExoticGetProperty ( JSContext * context,
JSValueConst obj,
JSAtom prop,
JSValueConst receiver )
static

Definition at line 637 of file OOJSSystemInfo.m.

638{
640
642
643 // Prototype chain first: SpiderMonkey only used the hook for otherwise unknown names.
644 JSValue proto = JS_GetPrototype(context, obj);
645 while (JS_IsObject(proto)) {
646 JSPropertyDescriptor desc;
647 int found = JS_GetOwnProperty(context, &desc, proto, prop);
648 if (found < 0) {
649 JS_FreeValue(context, proto);
650 return JS_EXCEPTION;
651 }
652 if (found) {
653 JS_FreeValue(context, proto);
654 if (desc.flags & JS_PROP_GETSET) {
655 JSValue result = JS_UNDEFINED;
656 JS_FreeValue(context, desc.setter);
657 if (JS_IsFunction(context, desc.getter)) {
658 result = JS_Call(context, desc.getter, receiver, 0, NULL);
659 }
660 JS_FreeValue(context, desc.getter);
661 return result;
662 }
663 return desc.value;
664 }
665
666 JSValue next = JS_GetPrototype(context, proto);
667 JS_FreeValue(context, proto);
668 proto = next;
669 }
670 if (JS_IsException(proto))
671 return JS_EXCEPTION;
672 JS_FreeValue(context, proto);
673
675 if (info == nil) {
676 // Let QuickJS behave normally for the prototype object (where info will be nil).
677 return JS_UNDEFINED;
678 }
679
680 NSString* key = SystemInfoKeyForAtom(context, prop);
681 if (key == nil)
682 return JS_UNDEFINED;
683
684 JSValue value;
685 if (!SystemInfoGetSystemDataValue(context, info, key, &value) && [info isNullAssignedForKey:key])
686 return JS_NULL;
687 return value;
688
689 OOJS_EXOTIC_EXIT(context, JS_EXCEPTION)
690
692}

References nil, OOJS_EXOTIC_ENTER, OOJS_EXOTIC_EXIT, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, SystemInfoForObject(), SystemInfoGetSystemDataValue(), and SystemInfoKeyForAtom().

Here is the call graph for this function:

◆ SystemInfoExoticSetProperty()

int SystemInfoExoticSetProperty ( JSContext * context,
JSValueConst obj,
JSAtom prop,
JSValueConst value,
JSValueConst receiver,
int flags )
static

Definition at line 694 of file OOJSSystemInfo.m.

695{
697
699
700 BOOL handled;
701 int result = SystemInfoSetOnPrototypeChain(context, obj, prop, value, receiver, flags, &handled);
702 if (handled)
703 return result;
704
706 NSString* key = SystemInfoKeyForAtom(context, prop);
707 if (info == nil || key == nil || !JS_IsObject(receiver) || JS_VALUE_GET_PTR(receiver) != JS_VALUE_GET_PTR(obj)) {
708 // Ordinary property (prototype object, symbol, or inherited by another object).
709 return JS_DefinePropertyValue(context, receiver, prop, JS_DupValue(context, value), JS_PROP_C_W_E);
710 }
711
712 /* Assigning null removes the system data key. SpiderMonkey also stored the
713 value in the object's own slot, so reading the key back gave null;
714 remember such keys to do the same.
715 */
716 [info setValue:OOStringFromJSValue(context, value) forKey:key];
717 [info setNullAssigned:JS_IsNull(value) forKey:key];
718 return true;
719
720 OOJS_EXOTIC_EXIT(context, -1)
721
723}
static int SystemInfoSetOnPrototypeChain(JSContext *context, JSValueConst obj, JSAtom prop, JSValueConst value, JSValueConst receiver, int flags, BOOL *outHandled)
void setNullAssigned:forKey:(BOOL flag,[forKey] NSString *key)
void setValue:forKey:(id value,[forKey] NSString *key)

References nil, OOJS_EXOTIC_ENTER, OOJS_EXOTIC_EXIT, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, OOSystemInfo::setNullAssigned:forKey:, OOSystemInfo::setValue:forKey:, SystemInfoForObject(), SystemInfoKeyForAtom(), and SystemInfoSetOnPrototypeChain().

Here is the call graph for this function:

◆ SystemInfoFinalize()

void SystemInfoFinalize ( JSRuntime * runtime,
JSValueConst this )
static

Definition at line 364 of file OOJSSystemInfo.m.

365{
367
368 // Clear now-stale cache entry if appropriate.
369 if (JS_IsObject(sCachedSystemInfo) && JS_VALUE_GET_PTR(sCachedSystemInfo) == JS_VALUE_GET_PTR(this)) {
370 sCachedSystemInfo = JS_UNDEFINED;
371 }
372
373 // Releases the OOSystemInfo.
374 OOJSObjectWrapperFinalize(runtime, this);
375
377}
#define OOJS_PROFILE_EXIT_VOID
void OOJSObjectWrapperFinalize(JSContext *context, JSObject *this)

References OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT_VOID, OOJSObjectWrapperFinalize(), and sCachedSystemInfo.

Here is the call graph for this function:

◆ SystemInfoForObject()

OOSystemInfo * SystemInfoForObject ( JSValueConst obj)
static

Definition at line 396 of file OOJSSystemInfo.m.

397{
398 return (OOSystemInfo*)JS_GetOpaque(obj, sSystemInfoClassID);
399}

References sSystemInfoClassID.

Referenced by SystemInfoExoticDeleteProperty(), SystemInfoExoticGetOwnProperty(), SystemInfoExoticGetOwnPropertyNames(), SystemInfoExoticGetProperty(), and SystemInfoExoticSetProperty().

Here is the caller graph for this function:

◆ SystemInfoGetProperty()

JSValue SystemInfoGetProperty ( OOJS_GETTER_ARGS )
static

Definition at line 727 of file OOJSSystemInfo.m.

728{
729 OOJS_NATIVE_ENTER(context)
730
731 OOSystemInfo* info = OOJSNativeObjectOfClassFromJSObject(context, this, [OOSystemInfo class]);
732 if (info == nil) {
733 // Let QuickJS handle access to the prototype object (where info will be nil).
734 return JS_UNDEFINED;
735 }
736
737 // What if we're trying to access a saved witchspace systemInfo object?
738 BOOL savedInterstellarInfo = ![UNIVERSE inInterstellarSpace] && [info system] == -1;
739 BOOL sameGalaxy = [PLAYER currentGalaxyID] == [info galaxy];
740
741 switch (magic) {
743 if (sameGalaxy && !savedInterstellarInfo) {
745 } else {
746 OOJSReportError(context, @"Cannot read systemInfo values for %@.", savedInterstellarInfo ? @"invalid interstellar space reference" : @"other galaxies");
747 return OOJSNativeFailure(context);
748 }
749 break;
750
752 if (sameGalaxy && !savedInterstellarInfo) {
754 } else {
755 OOJSReportError(context, @"Cannot read systemInfo values for %@.", savedInterstellarInfo ? @"invalid interstellar space reference" : @"other galaxies");
756 return OOJSNativeFailure(context);
757 }
758 break;
759
761 return JS_NewInt32(context, [info galaxy]);
762
764 return JS_NewInt32(context, [info system]);
765
766 default:
768 return OOJSNativeFailure(context);
769 }
770
772}
BOOL NSPointToVectorJSValue(JSContext *context, NSPoint point, jsval *outValue) NONNULL_FUNC
Definition OOJSVector.m:328
#define OOJS_RETURN_WITH_HELPER(helper, value)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
void OOJSReportError(JSContext *context, NSString *format,...)
id OOJSNativeObjectOfClassFromJSObject(JSContext *context, JSObject *object, Class requiredClass)
#define OOJS_RETURN_VECTOR(value)
Vector OOGalacticCoordinatesFromInternal(NSPoint internalCoordinates)
OOSystemID system()

References OOSystemInfo::coordinates, OOSystemInfo::galaxy, kSystemInfo_coordinates, kSystemInfo_galaxyID, kSystemInfo_internalCoordinates, kSystemInfo_systemID, nil, NSPointToVectorJSValue(), OOGalacticCoordinatesFromInternal(), OOJS_COUNT, OOJS_GETTER_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VECTOR, OOJS_RETURN_WITH_HELPER, OOJSNativeFailure(), OOJSNativeObjectOfClassFromJSObject(), OOJSReportBadPropertySelector(), OOJSReportError(), sSystemInfoProperties, and OOSystemInfo::system.

Here is the call graph for this function:

◆ SystemInfoGetSystemDataValue()

BOOL SystemInfoGetSystemDataValue ( JSContext * context,
OOSystemInfo * info,
NSString * key,
JSValue * outValue )
static

Definition at line 418 of file OOJSSystemInfo.m.

419{
420 *outValue = JS_UNDEFINED;
421
422 OOSystemDescriptionManager* systemManager = [UNIVERSE systemManager];
423 id propValue = nil;
424 // interstellar space needs more work at this stage
425 if ([info system] != -1) {
426 propValue = [systemManager getProperty:key forSystem:[info system] inGalaxy:[info galaxy]];
427 } else {
428 propValue = [info valueForKey:key];
429 }
430
431 if (propValue == nil)
432 return NO;
433
434 if ([propValue isKindOfClass:[NSNumber class]] || OOIsNumberLiteral([propValue description], YES)) {
435 *outValue = JS_NewNumber(context, [propValue doubleValue]);
436 } else {
437 *outValue = [propValue oo_jsValueInContext:context];
438 }
439 return YES;
440}
BOOL OOIsNumberLiteral(NSString *string, BOOL allowSpaces)
#define UNIVERSE
Definition Universe.h:827

References OOSystemInfo::galaxy, OOSystemDescriptionManager::getProperty:forSystem:inGalaxy:, nil, OOIsNumberLiteral(), OOSystemInfo::system, and OOSystemInfo::valueForKey:.

Referenced by SystemInfoExoticGetOwnProperty(), and SystemInfoExoticGetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SystemInfoKeyForAtom()

NSString * SystemInfoKeyForAtom ( JSContext * context,
JSAtom prop )
static

Definition at line 402 of file OOJSSystemInfo.m.

403{
404 NSString* key = nil;
405 JSValue propValue = JS_AtomToValue(context, prop);
406 if (JS_IsString(propValue)) {
407 key = OOStringFromJSValue(context, propValue);
408 }
409 JS_FreeValue(context, propValue);
410 return key;
411}
NSString * OOStringFromJSValue(JSContext *context, jsval value)

References nil, and OOStringFromJSValue().

Referenced by SystemInfoExoticDeleteProperty(), SystemInfoExoticGetOwnProperty(), SystemInfoExoticGetProperty(), and SystemInfoExoticSetProperty().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SystemInfoRouteToSystem()

JSValue SystemInfoRouteToSystem ( OOJS_NATIVE_ARGS )
static

Definition at line 807 of file OOJSSystemInfo.m.

808{
809 OOJS_NATIVE_ENTER(context)
810
811 OOSystemInfo* thisInfo = nil;
812 OOSystemInfo* otherInfo = nil;
813 NSDictionary* result = nil;
815
816 if (!JSSystemInfoGetSystemInfo(context, OOJS_THIS, &thisInfo))
817 return OOJSNativeFailure(context);
818 if (argc < 1 || !JS_IsObject(OOJS_ARGV[0]) || !JSSystemInfoGetSystemInfo(context, OOJS_ARGV[0], &otherInfo)) {
819 OOJSReportBadArguments(context, @"SystemInfo", @"routeToSystem", MIN(argc, 1), OOJS_ARGV, nil, @"system info");
820 return OOJSNativeFailure(context);
821 }
822
823 BOOL sameGalaxy = ([thisInfo galaxy] == [otherInfo galaxy]);
824 if (!sameGalaxy) {
825 OOJSReportErrorForCaller(context, @"SystemInfo", @"routeToSystem", @"Cannot calculate route for destinations in other galaxies.");
826 return OOJSNativeFailure(context);
827 }
828
829 if (argc >= 2) {
830 routeType = StringToRouteType(OOStringFromJSValue(context, OOJS_ARGV[1]));
831 }
832
834 result = [UNIVERSE routeFromSystem:[thisInfo system] toSystem:[otherInfo system] optimizedBy:routeType];
836
837 OOJS_RETURN_OBJECT(result);
838
840}
OORouteType StringToRouteType(NSString *string)
#define OOJS_RETURN_OBJECT(o)
OORouteType
Definition OOTypes.h:31
@ OPTIMIZED_BY_JUMPS
Definition OOTypes.h:33

References OOSystemInfo::galaxy, MIN, nil, OOJS_ARGV, OOJS_BEGIN_FULL_NATIVE, OOJS_END_FULL_NATIVE, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_OBJECT, OOJS_THIS, OOJSNativeFailure(), OOJSReportBadArguments(), OOJSReportErrorForCaller(), OOStringFromJSValue(), OPTIMIZED_BY_JUMPS, StringToRouteType(), and OOSystemInfo::system.

Here is the call graph for this function:

◆ SystemInfoSamplePrice()

JSValue SystemInfoSamplePrice ( OOJS_NATIVE_ARGS )
static

Definition at line 843 of file OOJSSystemInfo.m.

844{
845 OOJS_NATIVE_ENTER(context)
846
847 OOSystemInfo* thisInfo = nil;
848
849 if (!JSSystemInfoGetSystemInfo(context, OOJS_THIS, &thisInfo))
850 return OOJSNativeFailure(context);
851 OOCommodityType commodity = OOStringFromJSValue(context, OOJS_ARGV[0]);
852 if (EXPECT_NOT(![[UNIVERSE commodities] goodDefined:commodity])) {
853 OOJSReportBadArguments(context, @"SystemInfo", @"samplePrice", MIN(argc, 1), OOJS_ARGV, NULL, @"Unrecognised commodity type");
854 return OOJSNativeFailure(context);
855 }
856
857 BOOL sameGalaxy = ([thisInfo galaxy] == [PLAYER galaxyNumber]);
858 if (!sameGalaxy) {
859 OOJSReportErrorForCaller(context, @"SystemInfo", @"samplePrice", @"Cannot calculate sample price for destinations in other galaxies.");
860 return OOJSNativeFailure(context);
861 }
862
863 OOCreditsQuantity price = [[UNIVERSE commodities] samplePriceForCommodity:commodity inEconomy:[[thisInfo valueForKey:@"economy"] intValue] withScript:[thisInfo valueForKey:@"commodity_script"] inSystem:[thisInfo system]];
864
865 return JS_NewNumber(context, price);
866
868}
NSString * OOCommodityType
Definition OOTypes.h:97
uint64_t OOCreditsQuantity
Definition OOTypes.h:160
OOCreditsQuantity samplePriceForCommodity:inEconomy:withScript:inSystem:(OOCommodityType commodity,[inEconomy] OOEconomyID economy,[withScript] NSString *scriptName,[inSystem] OOSystemID system)
id valueForKey:(NSString *key)

References EXPECT_NOT, OOSystemInfo::galaxy, MIN, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_THIS, OOJSNativeFailure(), OOJSReportBadArguments(), OOJSReportErrorForCaller(), OOStringFromJSValue(), OOCommodities::samplePriceForCommodity:inEconomy:withScript:inSystem:, OOSystemInfo::system, UNIVERSE, and OOSystemInfo::valueForKey:.

Here is the call graph for this function:

◆ SystemInfoSetOnPrototypeChain()

int SystemInfoSetOnPrototypeChain ( JSContext * context,
JSValueConst obj,
JSAtom prop,
JSValueConst value,
JSValueConst receiver,
int flags,
BOOL * outHandled )
static

Definition at line 448 of file OOJSSystemInfo.m.

449{
450 JSValue proto = JS_GetPrototype(context, obj);
451 *outHandled = YES;
452
453 while (JS_IsObject(proto)) {
454 JSPropertyDescriptor desc;
455 int found = JS_GetOwnProperty(context, &desc, proto, prop);
456 if (found < 0) {
457 JS_FreeValue(context, proto);
458 return -1;
459 }
460 if (found) {
461 JS_FreeValue(context, proto);
462 if (desc.flags & JS_PROP_GETSET) {
463 JS_FreeValue(context, desc.getter);
464 if (JS_IsUndefined(desc.setter))
465 goto readOnly;
466 JSValue result = JS_Call(context, desc.setter, receiver, 1, &value);
467 JS_FreeValue(context, desc.setter);
468 if (JS_IsException(result))
469 return -1;
470 JS_FreeValue(context, result);
471 return true;
472 }
473 JS_FreeValue(context, desc.value);
474 if (!(desc.flags & JS_PROP_WRITABLE))
475 goto readOnly;
476 *outHandled = NO;
477 return true;
478 }
479
480 JSValue next = JS_GetPrototype(context, proto);
481 JS_FreeValue(context, proto);
482 proto = next;
483 }
484
485 if (JS_IsException(proto))
486 return -1;
487 JS_FreeValue(context, proto);
488 *outHandled = NO;
489 return true;
490
491readOnly:
492 /* QuickJS does not expose whether the calling code is strict, so
493 assignments to read-only properties are ignored except when the
494 caller explicitly asks for an exception (JS_PROP_THROW).
495 */
496 if (flags & JS_PROP_THROW) {
497 JSValue propName = JS_AtomToString(context, prop);
498 const char* name = JS_ToCString(context, propName);
499 JS_ThrowTypeError(context, "'%s' is read-only", name ? name : "?");
500 JS_FreeCString(context, name);
501 JS_FreeValue(context, propName);
502 return -1;
503 }
504 return false;
505}

Referenced by SystemInfoExoticSetProperty().

Here is the caller graph for this function:

◆ SystemInfoSetPropertyMethod()

JSValue SystemInfoSetPropertyMethod ( OOJS_NATIVE_ARGS )
static

Definition at line 870 of file OOJSSystemInfo.m.

871{
872 OOJS_NATIVE_ENTER(context)
873
874 OOSystemInfo* thisInfo = nil;
875
876 if (!JSSystemInfoGetSystemInfo(context, OOJS_THIS, &thisInfo))
877 return OOJSNativeFailure(context);
878
879 NSString* property = nil;
880 id value = nil;
881 NSString* manifest = nil;
882
883 int32_t iValue;
884
885 if (argc < 3) {
886 OOJSReportBadArguments(context, @"SystemInfo", @"setProperty", MIN(argc, 3), OOJS_ARGV, NULL, @"setProperty(layer, property, value [,manifest])");
887 return OOJSNativeFailure(context);
888 }
889 if (!OOJSValueToInt32(context, OOJS_ARGV[0], &iValue)) {
890 OOJSReportBadArguments(context, @"SystemInfo", @"setProperty", MIN(argc, 3), OOJS_ARGV, NULL, @"setProperty(layer, property, value [,manifest])");
891 return OOJSNativeFailure(context);
892 }
893 if (iValue < 0 || iValue >= OO_SYSTEM_LAYERS) {
894 OOJSReportBadArguments(context, @"SystemInfo", @"setProperty", MIN(argc, 3), OOJS_ARGV, NULL, @"layer must be 0, 1, 2 or 3");
895 return OOJSNativeFailure(context);
896 }
897 OOSystemLayer layer = (OOSystemLayer)iValue;
898
899 property = OOStringFromJSValue(context, OOJS_ARGV[1]);
900 if (!JS_IsNull(OOJS_ARGV[2])) {
901 value = OOJSNativeObjectFromJSValue(context, OOJS_ARGV[2]);
902 }
903 if (argc >= 4) {
904 manifest = OOStringFromJSValue(context, OOJS_ARGV[3]);
905 } else {
906 manifest = [[OOJSScript currentlyRunningScript] propertyNamed:kLocalManifestProperty];
907 }
908
909 [UNIVERSE setSystemDataForGalaxy:[thisInfo galaxy] planet:[thisInfo system] key:property value:value fromManifest:manifest forLayer:layer];
910
912
914}
id OOJSNativeObjectFromJSValue(JSContext *context, jsval value)
OOINLINE BOOL OOJSValueToInt32(JSContext *context, jsval value, int32_t *outValue)
#define OOJS_RETURN_VOID
#define OO_SYSTEM_LAYERS
id propertyNamed:(NSString *name)
Definition OOJSScript.m:431
OOJSScript * currentlyRunningScript()
Definition OOJSScript.m:101

References OOJSScript::currentlyRunningScript, OOSystemInfo::galaxy, MIN, nil, OO_SYSTEM_LAYERS, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJS_THIS, OOJSNativeFailure(), OOJSNativeObjectFromJSValue(), OOJSReportBadArguments(), OOJSValueToInt32(), OOStringFromJSValue(), OOJSScript::propertyNamed:, and OOSystemInfo::system.

Here is the call graph for this function:

◆ SystemInfoStaticFilteredSystems()

JSValue SystemInfoStaticFilteredSystems ( OOJS_NATIVE_ARGS )
static

Definition at line 917 of file OOJSSystemInfo.m.

918{
919 OOJS_NATIVE_ENTER(context)
920
921 /* SpiderMonkey version converted the this argument with
922 JS_ValueToObject(). QuickJS performs the same conversion (and
923 null/undefined -> global object) when calling a non-strict
924 function, so it is passed through unchanged.
925 */
926 // Get this and predicate arguments
927 if (argc < 2 || !OOJSValueIsFunction(context, OOJS_ARGV[1])) {
928 OOJSReportBadArguments(context, @"SystemInfo", @"filteredSystems", argc, OOJS_ARGV, nil, @"this and predicate function");
929 return OOJSNativeFailure(context);
930 }
931 JSValueConst jsThis = OOJS_ARGV[0];
932 JSValueConst predicate = OOJS_ARGV[1];
933
934 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
935 NSMutableArray* result = [NSMutableArray arrayWithCapacity:256];
936 JSValue rval = JS_UNDEFINED;
937
938 // Not OOJS_BEGIN_FULL_NATIVE() - we use JSAPI while paused.
940
941 // Iterate over systems.
942 BOOL OK = result != nil;
943 OOGalaxyID galaxy = [PLAYER currentGalaxyID];
944 OOSystemID system;
945 for (system = 0; system <= kOOMaximumSystemID; system++) {
946 // NOTE: this deliberately bypasses the cache, since iteration is inherently unfriendly to a single-item cache.
947 OOSystemInfo* info = [[[OOSystemInfo alloc] initWithGalaxy:galaxy system:system] autorelease];
948 JSValue args[1] = { OOJSValueFromNativeObject(context, info) };
949
951 JSValue callResult = JS_Call(context, predicate, jsThis, 1, (JSValueConst*)args);
953 JS_FreeValue(context, args[0]);
954
955 // On exception, it is left pending and propagated to our caller, as before.
956 OK = !JS_IsException(callResult);
957
958 if (OK) {
959 int boolVal = JS_ToBool(context, callResult);
960 if (boolVal > 0) {
961 [result addObject:info];
962 } else if (boolVal < 0) {
963 JS_FreeValue(context, JS_GetException(context));
964 }
965 }
966 JS_FreeValue(context, callResult);
967
968 if (!OK)
969 break;
970 }
971
972 if (OK) {
973 rval = [result oo_jsValueInContext:context];
974 } else {
975 rval = OOJSNativeFailure(context);
976 }
977
978 [pool release];
979
981 return rval;
982
984}
void OOJSPauseTimeLimiter(void)
OOINLINE BOOL OOJSValueIsFunction(JSContext *context, jsval value)
void OOJSResumeTimeLimiter(void)
@ kOOMaximumSystemID
Definition OOTypes.h:187
int16_t OOSystemID
Definition OOTypes.h:183
uint8_t OOGalaxyID
Definition OOTypes.h:182

References OOSystemInfo::galaxy, kOOMaximumSystemID, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSNativeFailure(), OOJSPauseTimeLimiter(), OOJSReportBadArguments(), OOJSResumeTimeLimiter(), OOJSValueFromNativeObject(), OOJSValueIsFunction(), and OOSystemInfo::system.

Here is the call graph for this function:

◆ SystemInfoStaticSetInterstellarProperty()

JSValue SystemInfoStaticSetInterstellarProperty ( OOJS_NATIVE_ARGS )
static

Definition at line 986 of file OOJSSystemInfo.m.

987{
988 OOJS_NATIVE_ENTER(context)
989
990 NSString* property = nil;
991 id value = nil;
992 NSString* manifest = nil;
993
994 int32_t iValue;
995 OOGalaxyID g;
996 OOSystemID s1, s2;
997
998 if (argc < 6) {
999 OOJSReportBadArguments(context, @"SystemInfo", @"setInterstellarProperty", MIN(argc, 3), OOJS_ARGV, NULL, @"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
1000 return OOJSNativeFailure(context);
1001 }
1002 if (!OOJSValueToInt32(context, OOJS_ARGV[0], &iValue)) {
1003 OOJSReportBadArguments(context, @"SystemInfo", @"setInterstellarProperty", MIN(argc, 3), OOJS_ARGV, NULL, @"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
1004 return OOJSNativeFailure(context);
1005 }
1006 if (iValue < 0 || iValue > kOOMaximumGalaxyID) {
1007 OOJSReportBadArguments(context, @"SystemInfo", @"setInterstellarProperty", MIN(argc, 3), OOJS_ARGV, NULL, @"galaxy out of range");
1008 return OOJSNativeFailure(context);
1009 } else {
1010 g = (OOGalaxyID)iValue;
1011 }
1012
1013 if (!OOJSValueToInt32(context, OOJS_ARGV[1], &iValue)) {
1014 OOJSReportBadArguments(context, @"SystemInfo", @"setInterstellarProperty", MIN(argc, 3), OOJS_ARGV, NULL, @"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
1015 return OOJSNativeFailure(context);
1016 }
1017 if (iValue < 0 || iValue > kOOMaximumSystemID) {
1018 OOJSReportBadArguments(context, @"SystemInfo", @"setInterstellarProperty", MIN(argc, 3), OOJS_ARGV, NULL, @"fromsystem out of range");
1019 return OOJSNativeFailure(context);
1020 } else {
1021 s1 = (OOSystemID)iValue;
1022 }
1023
1024 if (!OOJSValueToInt32(context, OOJS_ARGV[2], &iValue)) {
1025 OOJSReportBadArguments(context, @"SystemInfo", @"setInterstellarProperty", MIN(argc, 3), OOJS_ARGV, NULL, @"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
1026 return OOJSNativeFailure(context);
1027 }
1028 if (iValue < 0 || iValue > kOOMaximumSystemID) {
1029 OOJSReportBadArguments(context, @"SystemInfo", @"setInterstellarProperty", MIN(argc, 3), OOJS_ARGV, NULL, @"tosystem out of range");
1030 return OOJSNativeFailure(context);
1031 } else {
1032 s2 = (OOSystemID)iValue;
1033 }
1034
1035 if (!OOJSValueToInt32(context, OOJS_ARGV[3], &iValue)) {
1036 OOJSReportBadArguments(context, @"SystemInfo", @"setInterstellarProperty", MIN(argc, 3), OOJS_ARGV, NULL, @"setProperty(galaxy, fromsystem, tosystem, layer, property, value [,manifest])");
1037 return OOJSNativeFailure(context);
1038 }
1039 if (iValue < 0 || iValue >= OO_SYSTEM_LAYERS) {
1040 OOJSReportBadArguments(context, @"SystemInfo", @"setInterstellarProperty", MIN(argc, 3), OOJS_ARGV, NULL, @"layer must be 0, 1, 2 or 3");
1041 return OOJSNativeFailure(context);
1042 }
1043 OOSystemLayer layer = (OOSystemLayer)iValue;
1044
1045 property = OOStringFromJSValue(context, OOJS_ARGV[4]);
1046 if (!JS_IsNull(OOJS_ARGV[5])) {
1047 value = OOJSNativeObjectFromJSValue(context, OOJS_ARGV[5]);
1048 }
1049 if (argc >= 7) {
1050 manifest = OOStringFromJSValue(context, OOJS_ARGV[6]);
1051 } else {
1052 manifest = [[OOJSScript currentlyRunningScript] propertyNamed:kLocalManifestProperty];
1053 }
1054
1055 NSString* key = [NSString stringWithFormat:@"interstellar: %u %u %u", g, s1, s2];
1056
1057 [[UNIVERSE systemManager] setProperty:property forSystemKey:key andLayer:layer toValue:value fromManifest:manifest];
1058
1060
1062}
@ kOOMaximumGalaxyID
Definition OOTypes.h:186

References OOJSScript::currentlyRunningScript, kOOMaximumGalaxyID, kOOMaximumSystemID, MIN, nil, OO_SYSTEM_LAYERS, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJSNativeFailure(), OOJSNativeObjectFromJSValue(), OOJSReportBadArguments(), OOJSValueToInt32(), OOStringFromJSValue(), and OOJSScript::propertyNamed:.

Here is the call graph for this function:

Variable Documentation

◆ sCachedGalaxy

OOGalaxyID sCachedGalaxy
static

Definition at line 73 of file OOJSSystemInfo.m.

◆ sCachedSystem

OOSystemID sCachedSystem
static

Definition at line 74 of file OOJSSystemInfo.m.

◆ sCachedSystemInfo

JSValue sCachedSystemInfo
static

Definition at line 72 of file OOJSSystemInfo.m.

Referenced by OOSystemInfo::oo_javaScriptEngineWillReset:.

◆ sSystemInfoClass

JSClassDef sSystemInfoClass
static
Initial value:
= {
.class_name = "SystemInfo",
.finalizer = SystemInfoFinalize,
}
static void SystemInfoFinalize(JSContext *context, JSObject *this)
static JSClassExoticMethods sSystemInfoExoticMethods

Definition at line 101 of file OOJSSystemInfo.m.

101 {
102 .class_name = "SystemInfo",
103 .finalizer = SystemInfoFinalize,
104 .exotic = &sSystemInfoExoticMethods,
105};

Referenced by OOSystemInfo::oo_jsValueInContext:.

◆ sSystemInfoClassID

JSClassID sSystemInfoClassID
static

Definition at line 62 of file OOJSSystemInfo.m.

Referenced by InitOOJSSystemInfo(), OOSystemInfo::system, and SystemInfoForObject().

◆ sSystemInfoExoticMethods

JSClassExoticMethods sSystemInfoExoticMethods
static
Initial value:
= {
.get_own_property = SystemInfoExoticGetOwnProperty,
.get_own_property_names = SystemInfoExoticGetOwnPropertyNames,
.delete_property = SystemInfoExoticDeleteProperty,
.get_property = SystemInfoExoticGetProperty,
.set_property = SystemInfoExoticSetProperty,
}
static int SystemInfoExoticGetOwnPropertyNames(JSContext *context, JSPropertyEnum **ptab, uint32_t *plen, JSValueConst obj)
static int SystemInfoExoticDeleteProperty(JSContext *context, JSValueConst obj, JSAtom prop)
static JSValue SystemInfoExoticGetProperty(JSContext *context, JSValueConst obj, JSAtom prop, JSValueConst receiver)
static int SystemInfoExoticSetProperty(JSContext *context, JSValueConst obj, JSAtom prop, JSValueConst value, JSValueConst receiver, int flags)
static int SystemInfoExoticGetOwnProperty(JSContext *context, JSPropertyDescriptor *desc, JSValueConst obj, JSAtom prop)

Definition at line 93 of file OOJSSystemInfo.m.

93 {
94 .get_own_property = SystemInfoExoticGetOwnProperty,
95 .get_own_property_names = SystemInfoExoticGetOwnPropertyNames,
96 .delete_property = SystemInfoExoticDeleteProperty,
97 .get_property = SystemInfoExoticGetProperty,
98 .set_property = SystemInfoExoticSetProperty,
99};

◆ sSystemInfoMethods

const JSCFunctionListEntry sSystemInfoMethods[]
static
Initial value:
= {
JS_CFUNC_DEF("toString", 0, OOJSObjectWrapperToString),
JS_CFUNC_DEF("distanceToSystem", 1, SystemInfoDistanceToSystem),
JS_CFUNC_DEF("routeToSystem", 1, SystemInfoRouteToSystem),
JS_CFUNC_DEF("samplePrice", 1, SystemInfoSamplePrice),
JS_CFUNC_DEF("setProperty", 3, SystemInfoSetPropertyMethod),
}
static JSBool SystemInfoDistanceToSystem(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemInfoRouteToSystem(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemInfoSetPropertyMethod(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemInfoSamplePrice(JSContext *context, uintN argc, jsval *vp)
JSBool OOJSObjectWrapperToString(JSContext *context, uintN argc, jsval *vp)

Definition at line 123 of file OOJSSystemInfo.m.

123 {
124 // JS name, min args, function
125 JS_CFUNC_DEF("toString", 0, OOJSObjectWrapperToString),
126 JS_CFUNC_DEF("distanceToSystem", 1, SystemInfoDistanceToSystem),
127 JS_CFUNC_DEF("routeToSystem", 1, SystemInfoRouteToSystem),
128 JS_CFUNC_DEF("samplePrice", 1, SystemInfoSamplePrice),
129 JS_CFUNC_DEF("setProperty", 3, SystemInfoSetPropertyMethod),
130};

◆ sSystemInfoProperties

const JSCFunctionListEntry sSystemInfoProperties[]
static
Initial value:
= {
JS_CGETSET_MAGIC_DEF2("coordinates", SystemInfoGetProperty, NULL, kSystemInfo_coordinates, OOJS_PROP_HIDDEN_READONLY_CB),
JS_CGETSET_MAGIC_DEF2("internalCoordinates", SystemInfoGetProperty, NULL, kSystemInfo_internalCoordinates, OOJS_PROP_HIDDEN_READONLY_CB),
JS_CGETSET_MAGIC_DEF2("galaxyID", SystemInfoGetProperty, NULL, kSystemInfo_galaxyID, OOJS_PROP_HIDDEN_READONLY_CB),
JS_CGETSET_MAGIC_DEF2("systemID", SystemInfoGetProperty, NULL, kSystemInfo_systemID, OOJS_PROP_HIDDEN_READONLY_CB),
}
static JSBool SystemInfoGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
#define OOJS_PROP_HIDDEN_READONLY_CB

Definition at line 115 of file OOJSSystemInfo.m.

115 {
116 // JS name, getter, setter, ID, flags (hidden: see comment at top of file)
117 JS_CGETSET_MAGIC_DEF2("coordinates", SystemInfoGetProperty, NULL, kSystemInfo_coordinates, OOJS_PROP_HIDDEN_READONLY_CB),
118 JS_CGETSET_MAGIC_DEF2("internalCoordinates", SystemInfoGetProperty, NULL, kSystemInfo_internalCoordinates, OOJS_PROP_HIDDEN_READONLY_CB),
119 JS_CGETSET_MAGIC_DEF2("galaxyID", SystemInfoGetProperty, NULL, kSystemInfo_galaxyID, OOJS_PROP_HIDDEN_READONLY_CB),
120 JS_CGETSET_MAGIC_DEF2("systemID", SystemInfoGetProperty, NULL, kSystemInfo_systemID, OOJS_PROP_HIDDEN_READONLY_CB),
121};

◆ sSystemInfoStaticMethods

const JSCFunctionListEntry sSystemInfoStaticMethods[]
static
Initial value:
= {
JS_CFUNC_DEF("filteredSystems", 2, SystemInfoStaticFilteredSystems),
JS_CFUNC_DEF("setInterstellarProperty", 4, SystemInfoStaticSetInterstellarProperty),
}
static JSBool SystemInfoStaticFilteredSystems(JSContext *context, uintN argc, jsval *vp)
static JSBool SystemInfoStaticSetInterstellarProperty(JSContext *context, uintN argc, jsval *vp)

Definition at line 132 of file OOJSSystemInfo.m.

132 {
133 // JS name, min args, function
134 JS_CFUNC_DEF("filteredSystems", 2, SystemInfoStaticFilteredSystems),
135 JS_CFUNC_DEF("setInterstellarProperty", 4, SystemInfoStaticSetInterstellarProperty),
136};