Oolite
Loading...
Searching...
No Matches
OOJSVector.h File Reference
import "OOMaths.h"
import <Foundation/Foundation.h>
#include <quickjs.h>
Include dependency graph for OOJSVector.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void InitOOJSVector (JSContext *context, JSValueConst global)
JSValue JSVectorWithVector (JSContext *context, Vector vector) NONNULL_FUNC
JSValue JSVectorWithHPVector (JSContext *context, HPVector vector) NONNULL_FUNC
BOOL VectorToJSValue (JSContext *context, Vector vector, JSValue *outValue) NONNULL_FUNC
BOOL HPVectorToJSValue (JSContext *context, HPVector vector, JSValue *outValue) NONNULL_FUNC
BOOL NSPointToVectorJSValue (JSContext *context, NSPoint point, JSValue *outValue) NONNULL_FUNC
BOOL JSValueToVector (JSContext *context, JSValueConst value, Vector *outVector) NONNULL_FUNC
BOOL JSValueToHPVector (JSContext *context, JSValueConst value, HPVector *outVector) NONNULL_FUNC
BOOL JSObjectGetVector (JSContext *context, JSValueConst vectorObj, HPVector *outVector) GCC_ATTR((nonnull(1
BOOL BOOL JSVectorSetVector (JSContext *context, JSValueConst vectorObj, Vector vector) GCC_ATTR((nonnull(1)))
BOOL JSVectorSetHPVector (JSContext *context, JSValueConst vectorObj, HPVector vector) GCC_ATTR((nonnull(1)))
BOOL VectorFromArgumentList (JSContext *context, NSString *scriptClass, NSString *function, int argc, JSValueConst *argv, HPVector *outVector, int *outConsumed) GCC_ATTR((nonnull(1
BOOL BOOL VectorFromArgumentListNoError (JSContext *context, int argc, JSValueConst *argv, HPVector *outVector, int *outConsumed) GCC_ATTR((nonnull(1

Function Documentation

◆ HPVectorToJSValue()

BOOL HPVectorToJSValue ( JSContext * context,
HPVector vector,
JSValue * outValue )

Definition at line 183 of file OOJSVector.m.

184{
186
187 assert(outValue != NULL);
188
189 JSValue object = JSVectorWithHPVector(context, vector);
190 if (EXPECT_NOT(JS_IsException(object))) {
191 *outValue = JS_UNDEFINED;
192 return NO;
193 }
194
195 *outValue = object;
196 return YES;
197
199}
#define EXPECT_NOT(x)
#define OOJS_PROFILE_EXIT
#define OOJS_PROFILE_ENTER
JSObject * JSVectorWithHPVector(JSContext *context, HPVector vector)
Definition OOJSVector.m:282

References EXPECT_NOT, JSVectorWithHPVector(), OOJS_PROFILE_ENTER, and OOJS_PROFILE_EXIT.

Here is the call graph for this function:

◆ InitOOJSVector()

void InitOOJSVector ( JSContext * context,
JSValueConst global )

Definition at line 129 of file OOJSVector.m.

130{
132
133 // As in SpiderMonkey, the prototype is itself an instance with no private data, treated as zero.
134 OOJSInitClass(context, global, sVectorClassID, JS_UNDEFINED, VectorConstruct, 0,
136}
static JSPropertySpec sVectorProperties[]
Definition OOJSVector.m:96
static JSFunctionSpec sVectorMethods[]
Definition OOJSVector.m:104
static JSFunctionSpec sVectorStaticMethods[]
Definition OOJSVector.m:204
static JSBool VectorConstruct(JSContext *context, uintN argc, jsval *vp)
Definition OOJSVector.m:683
static JSClass sVectorClass
Definition OOJSVector.m:74
static JSClassID sVectorClassID
Definition OOJSVector.m:35
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, OOJSInitClass(), OOJSRegisterClass(), sVectorClass, sVectorClassID, sVectorMethods, sVectorProperties, sVectorStaticMethods, and VectorConstruct().

Here is the call graph for this function:

◆ JSObjectGetVector()

BOOL JSObjectGetVector ( JSContext * context,
JSValueConst vectorObj,
HPVector * outVector )

◆ JSValueToHPVector()

BOOL JSValueToHPVector ( JSContext * context,
JSValueConst value,
HPVector * outVector )

Definition at line 206 of file OOJSVector.m.

207{
208 if (EXPECT_NOT(!JS_IsObject(value)))
209 return NO;
210
211 return JSObjectGetVector(context, value, outVector);
212}
BOOL JSObjectGetVector(JSContext *context, JSObject *vectorObj, HPVector *outVector)
Definition OOJSVector.m:415

References EXPECT_NOT, and JSObjectGetVector().

Here is the call graph for this function:

◆ JSValueToVector()

BOOL JSValueToVector ( JSContext * context,
JSValueConst value,
Vector * outVector )

Definition at line 214 of file OOJSVector.m.

215{
216 if (EXPECT_NOT(!JS_IsObject(value)))
217 return NO;
219 BOOL result = JSObjectGetVector(context, value, &tmp);
220 *outVector = HPVectorToVector(tmp);
221 return result;
222}
const HPVector kZeroHPVector
Definition OOHPVector.m:27
OOINLINE Vector HPVectorToVector(HPVector v) INLINE_CONST_FUNC
Definition OOHPVector.h:175

References EXPECT_NOT, HPVectorToVector(), JSObjectGetVector(), and kZeroHPVector.

Here is the call graph for this function:

◆ JSVectorSetHPVector()

BOOL JSVectorSetHPVector ( JSContext * context,
JSValueConst vectorObj,
HPVector vector )

Definition at line 309 of file OOJSVector.m.

310{
312
313 HPVector* private = NULL;
314
315 if (EXPECT_NOT(!JS_IsObject(vectorObj)))
316 return NO;
317
318private
319 = JS_GetOpaque(vectorObj, sVectorClassID);
320 if (private != NULL) // If this is a (JS) Vector...
321 {
322 *private = vector;
323 return YES;
324 }
325
326 if (JS_GetClassID(vectorObj) == sVectorClassID) {
327 // Silently fail for the prototype.
328 return YES;
329 }
330
331 return NO;
332
334}

References EXPECT_NOT, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and sVectorClassID.

Referenced by JSVectorSetVector(), and VectorSetProperty().

Here is the caller graph for this function:

◆ JSVectorSetVector()

BOOL BOOL JSVectorSetVector ( JSContext * context,
JSValueConst vectorObj,
Vector vector )

Definition at line 304 of file OOJSVector.m.

305{
306 return JSVectorSetHPVector(context, vectorObj, vectorToHPVector(vector));
307}
OOINLINE HPVector vectorToHPVector(Vector v) INLINE_CONST_FUNC
Definition OOHPVector.h:166
BOOL JSVectorSetHPVector(JSContext *context, JSValueConst vectorObj, HPVector vector)
Definition OOJSVector.m:309

References JSVectorSetHPVector(), and vectorToHPVector().

Here is the call graph for this function:

◆ JSVectorWithHPVector()

JSValue JSVectorWithHPVector ( JSContext * context,
HPVector vector )

Definition at line 282 of file OOJSVector.m.

283{
285
286 JSObject* result = NULL;
287 HPVector* private = NULL;
288
289private
290 = malloc(sizeof *private);
291 if (EXPECT_NOT(private == NULL))
292 return NULL;
293
294 *private = vector;
295
296 result = JS_NewObject(context, &sVectorClass, sVectorPrototype, NULL);
297 if (result != NULL) {
298 if (EXPECT_NOT(!JS_SetPrivate(context, result, private)))
299 result = NULL;
300 }
301
302 if (EXPECT_NOT(result == NULL))
303 free(private);
304
305 return result;
306
308}
static JSObject * sVectorPrototype
Definition OOJSVector.m:38

References EXPECT_NOT, OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and sVectorClassID.

Referenced by HPVectorToJSValue(), HPVectorToJSValue(), JSVectorWithVector(), and VectorConstruct().

Here is the caller graph for this function:

◆ JSVectorWithVector()

JSValue JSVectorWithVector ( JSContext * context,
Vector vector )

Definition at line 236 of file OOJSVector.m.

237{
239
240 JSObject* result = NULL;
241 HPVector* private = NULL;
242
243private
244 = malloc(sizeof *private);
245 if (EXPECT_NOT(private == NULL))
246 return NULL;
247
248 *private = vectorToHPVector(vector);
249
250 result = JS_NewObject(context, &sVectorClass, sVectorPrototype, NULL);
251 if (result != NULL) {
252 if (EXPECT_NOT(!JS_SetPrivate(context, result, private)))
253 result = NULL;
254 }
255
256 if (EXPECT_NOT(result == NULL))
257 free(private);
258
259 return result;
260
262}

References JSVectorWithHPVector(), OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and vectorToHPVector().

Referenced by VectorToJSValue().

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

◆ NSPointToVectorJSValue()

BOOL NSPointToVectorJSValue ( JSContext * context,
NSPoint point,
JSValue * outValue )

Definition at line 201 of file OOJSVector.m.

202{
203 return VectorToJSValue(context, make_vector(point.x, point.y, 0), outValue);
204}
BOOL VectorToJSValue(JSContext *context, Vector vector, jsval *outValue)
Definition OOJSVector.m:264
OOINLINE Vector make_vector(OOScalar vx, OOScalar vy, OOScalar vz) INLINE_CONST_FUNC
Definition OOVector.h:149

References make_vector(), and VectorToJSValue().

Here is the call graph for this function:

◆ VectorFromArgumentList()

BOOL VectorFromArgumentList ( JSContext * context,
NSString * scriptClass,
NSString * function,
int argc,
JSValueConst * argv,
HPVector * outVector,
int * outConsumed )

◆ VectorFromArgumentListNoError()

BOOL BOOL VectorFromArgumentListNoError ( JSContext * context,
int argc,
JSValueConst * argv,
HPVector * outVector,
int * outConsumed )

◆ VectorToJSValue()

BOOL VectorToJSValue ( JSContext * context,
Vector vector,
JSValue * outValue )

Definition at line 147 of file OOJSVector.m.

148{
150
151 assert(outValue != NULL);
152
153 return HPVectorToJSValue(context, vectorToHPVector(vector), outValue);
154
156}
BOOL HPVectorToJSValue(JSContext *context, HPVector vector, jsval *outValue)
Definition OOJSVector.m:310

References HPVectorToJSValue(), OOJS_PROFILE_ENTER, OOJS_PROFILE_EXIT, and vectorToHPVector().

Here is the call graph for this function: