FreeWRL / FreeX3D 4.3.0
jsUtils.h
1/*
2
3
4CProto.h - this is the object representing a PROTO definition and being
5capable of instantiating it.
6
7We keep a vector of pointers to all that pointers which point to "inner
8memory" and need therefore be updated when copying. Such pointers include
9field-destinations and parts of ROUTEs. Those pointers are then simply
10copied, their new positions put in the new vector, and afterwards are all
11pointers there updated.
12
13*/
14
15/****************************************************************************
16 This file is part of the FreeWRL/FreeX3D Distribution.
17
18 Copyright 2009 CRC Canada. (http://www.crc.gc.ca)
19
20 FreeWRL/FreeX3D is free software: you can redistribute it and/or modify
21 it under the terms of the GNU Lesser Public License as published by
22 the Free Software Foundation, either version 3 of the License, or
23 (at your option) any later version.
24
25 FreeWRL/FreeX3D is distributed in the hope that it will be useful,
26 but WITHOUT ANY WARRANTY; without even the implied warranty of
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 GNU General Public License for more details.
29
30 You should have received a copy of the GNU General Public License
31 along with FreeWRL/FreeX3D. If not, see <http://www.gnu.org/licenses/>.
32****************************************************************************/
33
34
35#ifndef __FREEWRL_JS_UTILS_H__
36#define __FREEWRL_JS_UTILS_H__
37
38
39#include <system_js.h>
40
41#ifndef FALSE
42#define FALSE 0
43#endif /* FALSE */
44
45#define CLEANUP_JAVASCRIPT(cx) \
46 /* printf ("calling JS_GC at %s:%d cx %u thread %u\n",__FILE__,__LINE__,cx,pthread_self()); */ \
47 JS_GC(cx);
48
49#define LARGESTRING 2048
50#define STRING 512
51#define SMALLSTRING 128
52
53#define FNAME_STUB "file"
54#define LINENO_STUB 0
55
56
57
58//extern struct ECMAValueStruct ECMAValues[];
59//extern int maxECMAVal;
60int findInECMATable(JSContext *context, jsval toFind);
61int findNameInECMATable(JSContext *context, char *toFind);
62void resetNameInECMATable(JSContext *context, char *toFind);
63
64/* We keep around the results of script routing, or just script running... */
65//extern jsval JSCreate_global_return_val;
66//extern jsval JSglobal_return_val;
67//extern void *JSSFpointer;
68
69int jsrrunScript(JSContext *_context, JSObject *_globalObj, char *script, jsval *rval);
70int JS_DefineSFNodeSpecificProperties (JSContext *context, JSObject *object, struct X3D_Node * ptr);
71
72#ifdef JAVASCRIPTVERBOSE
73# define ACTUALRUNSCRIPT(a,b,c) ActualrunScript(a,b,c,__FILE__,__LINE__)
74/* now in JScript.h -- int ActualrunScript(intptr_t num, char *script, jsval *rval, char *fn, int line); */
75#else
76# define ACTUALRUNSCRIPT(a,b,c) ActualrunScript(a,b,c)
77/* now in JScript.h -- int ActualrunScript(intptr_t num, char *script, jsval *rval); */
78#endif
79
80void
81reportWarningsOn(void);
82
83void
84reportWarningsOff(void);
85
86void
87errorReporter(JSContext *cx,
88 const char *message,
89 JSErrorReport *report);
90
91void X3D_ECMA_TO_JS(JSContext *cx, void *Data, int datalen, int dataType, jsval *ret);
92#if JS_VERSION < 185
93JSBool setSFNodeField (JSContext *context, JSObject *obj, jsid id, jsval *vp);
94#elif JS_VERSION == 185
95JSBool setSFNodeField (JSContext *context, JSObject *obj, jsid id, JSBool strict, jsval *vp);
96#else
97JSBool setSFNodeField (JSContext *cx, JSHandleObject hobj, JSHandleId hiid, JSBool strict, JSMutableHandleValue hvp);
98#endif
99
100const char *classToString(JSClass *myClass);
101#define CHECK_CLASS(cx,obj,argv,fnString,expClass) \
102/* printf ("CHECK_CLASS, obj %u, argv %u\n",obj,argv);*/ \
103 if (!JS_InstanceOf(cx, obj, &expClass, argv)) { \
104 printf ("Javascript Instance problem in '%s' - expected a '%s', got a ", fnString, classToString(&expClass)); \
105 printJSNodeType (cx,obj); \
106 return JS_FALSE; \
107 }
108
109#endif /* __FREEWRL_JS_UTILS_H__ */