1#ifndef mujs_h
2#define mujs_h
3
4#include <setjmp.h> /* required for setjmp in fz_try macro */
5
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10/* noreturn is a GCC extension */
11#ifdef __GNUC__
12#define JS_NORETURN __attribute__((noreturn))
13#else
14#ifdef _MSC_VER
15#define JS_NORETURN __declspec(noreturn)
16#else
17#define JS_NORETURN
18#endif
19#endif
20
21/* GCC can do type checking of printf strings */
22#ifdef __printflike
23#define JS_PRINTFLIKE __printflike
24#else
25#if __GNUC__ > 2 || __GNUC__ == 2 && __GNUC_MINOR__ >= 7
26#define JS_PRINTFLIKE(fmtarg, firstvararg) \
27 __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
28#else
29#define JS_PRINTFLIKE(fmtarg, firstvararg)
30#endif
31#endif
32
33typedef struct js_State js_State;
34
35typedef void *(*js_Alloc)(void *memctx, void *ptr, int size);
36typedef void (*js_Panic)(js_State *J);
37typedef void (*js_CFunction)(js_State *J);
38typedef void (*js_Finalize)(js_State *J, void *p);
39typedef int (*js_HasProperty)(js_State *J, void *p, const char *name);
40typedef int (*js_Put)(js_State *J, void *p, const char *name);
41typedef int (*js_Delete)(js_State *J, void *p, const char *name);
42typedef void (*js_Report)(js_State *J, const char *message);
43
44/* Basic functions */
45js_State *js_newstate(js_Alloc alloc, void *actx, int flags);
46void js_setcontext(js_State *J, void *uctx);
47void *js_getcontext(js_State *J);
48void js_setreport(js_State *J, js_Report report);
49js_Panic js_atpanic(js_State *J, js_Panic panic);
50void js_freestate(js_State *J);
51void js_gc(js_State *J, int report);
52
53int js_dostring(js_State *J, const char *source);
54int js_dofile(js_State *J, const char *filename);
55int js_ploadstring(js_State *J, const char *filename, const char *source);
56int js_ploadfile(js_State *J, const char *filename);
57int js_pcall(js_State *J, int n);
58int js_pconstruct(js_State *J, int n);
59
60/* Exception handling */
61
62void *js_savetry(js_State *J); /* returns a jmp_buf */
63
64#define js_try(J) \
65 setjmp(js_savetry(J))
66
67void js_endtry(js_State *J);
68
69/* State constructor flags */
70enum {
71 JS_STRICT = 1,
72};
73
74/* RegExp flags */
75enum {
76 JS_REGEXP_G = 1,
77 JS_REGEXP_I = 2,
78 JS_REGEXP_M = 4,
79};
80
81/* Property attribute flags */
82enum {
83 JS_READONLY = 1,
84 JS_DONTENUM = 2,
85 JS_DONTCONF = 4,
86};
87
88void js_report(js_State *J, const char *message);
89
90void js_newerror(js_State *J, const char *message);
91void js_newevalerror(js_State *J, const char *message);
92void js_newrangeerror(js_State *J, const char *message);
93void js_newreferenceerror(js_State *J, const char *message);
94void js_newsyntaxerror(js_State *J, const char *message);
95void js_newtypeerror(js_State *J, const char *message);
96void js_newurierror(js_State *J, const char *message);
97
98JS_NORETURN void js_error(js_State *J, const char *fmt, ...) JS_PRINTFLIKE(2,3);
99JS_NORETURN void js_evalerror(js_State *J, const char *fmt, ...) JS_PRINTFLIKE(2,3);
100JS_NORETURN void js_rangeerror(js_State *J, const char *fmt, ...) JS_PRINTFLIKE(2,3);
101JS_NORETURN void js_referenceerror(js_State *J, const char *fmt, ...) JS_PRINTFLIKE(2,3);
102JS_NORETURN void js_syntaxerror(js_State *J, const char *fmt, ...) JS_PRINTFLIKE(2,3);
103JS_NORETURN void js_typeerror(js_State *J, const char *fmt, ...) JS_PRINTFLIKE(2,3);
104JS_NORETURN void js_urierror(js_State *J, const char *fmt, ...) JS_PRINTFLIKE(2,3);
105JS_NORETURN void js_throw(js_State *J);
106
107void js_loadstring(js_State *J, const char *filename, const char *source);
108void js_loadfile(js_State *J, const char *filename);
109
110void js_eval(js_State *J);
111void js_call(js_State *J, int n);
112void js_construct(js_State *J, int n);
113
114const char *js_ref(js_State *J);
115void js_unref(js_State *J, const char *ref);
116
117void js_getregistry(js_State *J, const char *name);
118void js_setregistry(js_State *J, const char *name);
119void js_delregistry(js_State *J, const char *name);
120
121void js_getglobal(js_State *J, const char *name);
122void js_setglobal(js_State *J, const char *name);
123void js_defglobal(js_State *J, const char *name, int atts);
124
125int js_hasproperty(js_State *J, int idx, const char *name);
126void js_getproperty(js_State *J, int idx, const char *name);
127void js_setproperty(js_State *J, int idx, const char *name);
128void js_defproperty(js_State *J, int idx, const char *name, int atts);
129void js_delproperty(js_State *J, int idx, const char *name);
130void js_defaccessor(js_State *J, int idx, const char *name, int atts);
131
132int js_getlength(js_State *J, int idx);
133void js_setlength(js_State *J, int idx, int len);
134int js_hasindex(js_State *J, int idx, int i);
135void js_getindex(js_State *J, int idx, int i);
136void js_setindex(js_State *J, int idx, int i);
137void js_delindex(js_State *J, int idx, int i);
138
139void js_currentfunction(js_State *J);
140void js_pushglobal(js_State *J);
141void js_pushundefined(js_State *J);
142void js_pushnull(js_State *J);
143void js_pushboolean(js_State *J, int v);
144void js_pushnumber(js_State *J, double v);
145void js_pushstring(js_State *J, const char *v);
146void js_pushlstring(js_State *J, const char *v, int n);
147void js_pushliteral(js_State *J, const char *v);
148
149void js_newobjectx(js_State *J);
150void js_newobject(js_State *J);
151void js_newarray(js_State *J);
152void js_newboolean(js_State *J, int v);
153void js_newnumber(js_State *J, double v);
154void js_newstring(js_State *J, const char *v);
155void js_newcfunction(js_State *J, js_CFunction fun, const char *name, int length);
156void js_newcconstructor(js_State *J, js_CFunction fun, js_CFunction con, const char *name, int length);
157void js_newuserdata(js_State *J, const char *tag, void *data, js_Finalize finalize);
158void js_newuserdatax(js_State *J, const char *tag, void *data, js_HasProperty has, js_Put put, js_Delete del, js_Finalize finalize);
159void js_newregexp(js_State *J, const char *pattern, int flags);
160
161void js_pushiterator(js_State *J, int idx, int own);
162const char *js_nextiterator(js_State *J, int idx);
163
164int js_isdefined(js_State *J, int idx);
165int js_isundefined(js_State *J, int idx);
166int js_isnull(js_State *J, int idx);
167int js_isboolean(js_State *J, int idx);
168int js_isnumber(js_State *J, int idx);
169int js_isstring(js_State *J, int idx);
170int js_isprimitive(js_State *J, int idx);
171int js_isobject(js_State *J, int idx);
172int js_isarray(js_State *J, int idx);
173int js_isregexp(js_State *J, int idx);
174int js_iscoercible(js_State *J, int idx);
175int js_iscallable(js_State *J, int idx);
176int js_isuserdata(js_State *J, int idx, const char *tag);
177int js_iserror(js_State *J, int idx);
178
179int js_toboolean(js_State *J, int idx);
180double js_tonumber(js_State *J, int idx);
181const char *js_tostring(js_State *J, int idx);
182void *js_touserdata(js_State *J, int idx, const char *tag);
183
184const char *js_trystring(js_State *J, int idx, const char *error);
185double js_trynumber(js_State *J, int idx, double error);
186int js_tryinteger(js_State *J, int idx, int error);
187int js_tryboolean(js_State *J, int idx, int error);
188
189int js_tointeger(js_State *J, int idx);
190int js_toint32(js_State *J, int idx);
191unsigned int js_touint32(js_State *J, int idx);
192short js_toint16(js_State *J, int idx);
193unsigned short js_touint16(js_State *J, int idx);
194
195int js_gettop(js_State *J);
196void js_pop(js_State *J, int n);
197void js_rot(js_State *J, int n);
198void js_copy(js_State *J, int idx);
199void js_remove(js_State *J, int idx);
200void js_insert(js_State *J, int idx);
201void js_replace(js_State* J, int idx);
202
203void js_dup(js_State *J);
204void js_dup2(js_State *J);
205void js_rot2(js_State *J);
206void js_rot3(js_State *J);
207void js_rot4(js_State *J);
208void js_rot2pop1(js_State *J);
209void js_rot3pop2(js_State *J);
210
211void js_concat(js_State *J);
212int js_compare(js_State *J, int *okay);
213int js_equal(js_State *J);
214int js_strictequal(js_State *J);
215int js_instanceof(js_State *J);
216const char *js_typeof(js_State *J, int idx);
217
218void js_repr(js_State *J, int idx);
219const char *js_torepr(js_State *J, int idx);
220const char *js_tryrepr(js_State *J, int idx, const char *error);
221
222#ifdef __cplusplus
223}
224#endif
225
226#endif
227