FreeWRL/FreeX3D  3.0.0
jsUtils.h
1 /*
2 
3 
4 CProto.h - this is the object representing a PROTO definition and being
5 capable of instantiating it.
6 
7 We keep a vector of pointers to all that pointers which point to "inner
8 memory" and need therefore be updated when copying. Such pointers include
9 field-destinations and parts of ROUTEs. Those pointers are then simply
10 copied, their new positions put in the new vector, and afterwards are all
11 pointers 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;
60 int findInECMATable(JSContext *context, jsval toFind);
61 int findNameInECMATable(JSContext *context, char *toFind);
62 void 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 
69 int jsrrunScript(JSContext *_context, JSObject *_globalObj, char *script, jsval *rval);
70 int 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 
80 void
81 reportWarningsOn(void);
82 
83 void
84 reportWarningsOff(void);
85 
86 void
87 errorReporter(JSContext *cx,
88  const char *message,
89  JSErrorReport *report);
90 
91 void X3D_ECMA_TO_JS(JSContext *cx, void *Data, int datalen, int dataType, jsval *ret);
92 #if JS_VERSION < 185
93 JSBool setSFNodeField (JSContext *context, JSObject *obj, jsid id, jsval *vp);
94 #else
95 JSBool setSFNodeField (JSContext *context, JSObject *obj, jsid id, JSBool strict, jsval *vp);
96 #endif
97 
98 const char *classToString(JSClass *myClass);
99 #define CHECK_CLASS(cx,obj,argv,fnString,expClass) \
100 /* printf ("CHECK_CLASS, obj %u, argv %u\n",obj,argv);*/ \
101  if (!JS_InstanceOf(cx, obj, &expClass, argv)) { \
102  printf ("Javascript Instance problem in '%s' - expected a '%s', got a ", fnString, classToString(&expClass)); \
103  printJSNodeType (cx,obj); \
104  return JS_FALSE; \
105  }
106 
107 #endif /* __FREEWRL_JS_UTILS_H__ */