FreeWRL / FreeX3D 4.3.0
jsUtils_sm.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);
92void JS_ECMA_TO_X3D(JSContext *cx, void *Data, unsigned datalen, int dataType, jsval *newval);
93void X3D_MF_TO_JS_B(JSContext *cx, union anyVrml* Data, int dataType, int *valueChanged, jsval *newval);
94void X3D_SF_TO_JS_BNode(JSContext *cx, void *Data, unsigned datalen, int dataType, int *valueChanged, jsval *newval);
95JSBool setSFNodeField (JSContext *cx, JS::Handle<JSObject*> hobj, JS::Handle<jsid> hiid, JSBool strict, JS::MutableHandle<JS::Value> hvp);
96void JS_SF_TO_X3D_BNode(JSContext *cx, void *Data, int dataType, int *valueChanged, jsval *newval);
97JSBool JS_NewNumberValue(JSContext *cx, jsdouble d, jsval *rval);
98
99const char *classToString(JSClass *myClass);
100#define CHECK_CLASS(cx,obj,argv,fnString,expClass) \
101/* printf ("CHECK_CLASS, obj %u, argv %u\n",obj,argv);*/ \
102 if (!JS_InstanceOf(cx, obj, &expClass, argv)) { \
103 printf ("Javascript Instance problem in '%s' - expected a '%s', got a ", fnString, classToString(&expClass)); \
104 printJSNodeType (cx,obj); \
105 return JS_FALSE; \
106 }
107int JS_SetPrivateFw(JSContext *cx, JSObject* obj, void *data);
108JSObject* JS_NewGlobalObjectFw(JSContext *cx, JSClass *clasp); //, JSPrincipals *princ);
109void * JS_GetPrivateFw(JSContext *cx,JSObject*_obj);
110JSObject* JS_GetParentFw(JSContext *cx, JSObject *me);
111JSObject * JS_ConstructObjectWithArgumentsFw(JSContext *cx, JSClass *clasp, JSObject *parent, unsigned argc, jsval *argv);
112JSObject * JS_ConstructObjectFw(JSContext *cx, JSClass *clasp, void *whatever, JSObject *parent);
113JSObject * JS_GetPrototypeFw(JSContext *cx, JSObject * obj);
114JSClass * JS_GetClassFw(JSContext *cx, JSObject * obj);
115
116#define JSSCRIPT JSScript
117
118
119
120#define JS_GET_PROPERTY_STUB JS_PropertyStub
121/* #define JS_GET_PROPERTY_STUB js_GetPropertyDebug */
122
123#define JS_SET_PROPERTY_STUB1 js_SetPropertyDebug1
124
125/* #define JS_SET_PROPERTY_STUB2 js_SetPropertyDebug2 */
126#if JS_VERSION < 185
127# define JS_SET_PROPERTY_STUB2 JS_PropertyStub
128#else
129# define JS_SET_PROPERTY_STUB2 JS_StrictPropertyStub
130#endif
131
132#define JS_SET_PROPERTY_STUB3 js_SetPropertyDebug3
133#define JS_SET_PROPERTY_STUB4 js_SetPropertyDebug4
134#define JS_SET_PROPERTY_STUB5 js_SetPropertyDebug5
135#define JS_SET_PROPERTY_STUB6 js_SetPropertyDebug6
136#define JS_SET_PROPERTY_STUB7 js_SetPropertyDebug7
137#define JS_SET_PROPERTY_STUB8 js_SetPropertyDebug8
138#define JS_SET_PROPERTY_CHECK js_SetPropertyCheck
139
140
141#endif /* __FREEWRL_JS_UTILS_H__ */