4 /* noreturn is a GCC extension */
6 #define JS_NORETURN __attribute__((noreturn))
9 #define JS_NORETURN __declspec(noreturn)
15 /* GCC can do type checking of printf strings */
17 #define JS_PRINTFLIKE __printflike
19 #if __GNUC__ > 2 || __GNUC__ == 2 && __GNUC_MINOR__ >= 7
20 #define JS_PRINTFLIKE(fmtarg, firstvararg) \
21 __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
23 #define JS_PRINTFLIKE(fmtarg, firstvararg)
27 typedef struct js_State js_State;
29 typedef void *(*js_Alloc)(void *memctx, void *ptr, unsigned int size);
30 typedef void (*js_Panic)(js_State *J);
31 typedef void (*js_CFunction)(js_State *J);
32 typedef void (*js_Finalize)(js_State *J, void *p);
35 js_State *js_newstate(js_Alloc alloc, void *actx, int flags);
36 void js_setcontext(js_State *J, void *uctx);
37 void *js_getcontext(js_State *J);
38 js_Panic js_atpanic(js_State *J, js_Panic panic);
39 void js_freestate(js_State *J);
40 void js_gc(js_State *J, int report);
42 int js_dostring(js_State *J, const char *source, int report);
43 int js_dofile(js_State *J, const char *filename);
44 int js_ploadstring(js_State *J, const char *filename, const char *source);
45 int js_ploadfile(js_State *J, const char *filename);
46 int js_pcall(js_State *J, int n);
47 int js_pconstruct(js_State *J, int n);
49 /* State constructor flags */
61 /* Property attribute flags */
68 void js_newerror(js_State *J, const char *message);
69 void js_newevalerror(js_State *J, const char *message);
70 void js_newrangeerror(js_State *J, const char *message);
71 void js_newreferenceerror(js_State *J, const char *message);
72 void js_newsyntaxerror(js_State *J, const char *message);
73 void js_newtypeerror(js_State *J, const char *message);
74 void js_newurierror(js_State *J, const char *message);
76 JS_NORETURN void js_error(js_State *J, const char *fmt, ...) JS_PRINTFLIKE(2,3);
77 JS_NORETURN void js_evalerror(js_State *J, const char *fmt, ...) JS_PRINTFLIKE(2,3);
78 JS_NORETURN void js_rangeerror(js_State *J, const char *fmt, ...) JS_PRINTFLIKE(2,3);
79 JS_NORETURN void js_referenceerror(js_State *J, const char *fmt, ...) JS_PRINTFLIKE(2,3);
80 JS_NORETURN void js_syntaxerror(js_State *J, const char *fmt, ...) JS_PRINTFLIKE(2,3);
81 JS_NORETURN void js_typeerror(js_State *J, const char *fmt, ...) JS_PRINTFLIKE(2,3);
82 JS_NORETURN void js_urierror(js_State *J, const char *fmt, ...) JS_PRINTFLIKE(2,3);
83 JS_NORETURN void js_throw(js_State *J);
85 void js_loadstring(js_State *J, const char *filename, const char *source);
86 void js_loadfile(js_State *J, const char *filename);
88 void js_eval(js_State *J);
89 void js_call(js_State *J, int n);
90 void js_construct(js_State *J, int n);
92 const char *js_ref(js_State *J);
93 void js_unref(js_State *J, const char *ref);
95 void js_getregistry(js_State *J, const char *name);
96 void js_setregistry(js_State *J, const char *name);
97 void js_delregistry(js_State *J, const char *name);
99 void js_getglobal(js_State *J, const char *name);
100 void js_setglobal(js_State *J, const char *name);
101 void js_defglobal(js_State *J, const char *name, int atts);
103 int js_hasproperty(js_State *J, int idx, const char *name);
104 void js_getproperty(js_State *J, int idx, const char *name);
105 void js_setproperty(js_State *J, int idx, const char *name);
106 void js_defproperty(js_State *J, int idx, const char *name, int atts);
107 void js_delproperty(js_State *J, int idx, const char *name);
108 void js_defaccessor(js_State *J, int idx, const char *name, int atts);
110 unsigned int js_getlength(js_State *J, int idx);
111 void js_setlength(js_State *J, int idx, unsigned int len);
112 int js_hasindex(js_State *J, int idx, unsigned int i);
113 void js_getindex(js_State *J, int idx, unsigned int i);
114 void js_setindex(js_State *J, int idx, unsigned int i);
115 void js_delindex(js_State *J, int idx, unsigned int i);
117 void js_currentfunction(js_State *J);
118 void js_pushglobal(js_State *J);
119 void js_pushundefined(js_State *J);
120 void js_pushnull(js_State *J);
121 void js_pushboolean(js_State *J, int v);
122 void js_pushnumber(js_State *J, double v);
123 void js_pushstring(js_State *J, const char *v);
124 void js_pushlstring(js_State *J, const char *v, unsigned int n);
125 void js_pushliteral(js_State *J, const char *v);
127 void js_newobject(js_State *J);
128 void js_newarray(js_State *J);
129 void js_newboolean(js_State *J, int v);
130 void js_newnumber(js_State *J, double v);
131 void js_newstring(js_State *J, const char *v);
132 void js_newcfunction(js_State *J, js_CFunction fun, const char *name, unsigned int length);
133 void js_newcconstructor(js_State *J, js_CFunction fun, js_CFunction con, const char *name, unsigned int length);
134 void js_newuserdata(js_State *J, const char *tag, void *data, js_Finalize finalize);
135 void js_newregexp(js_State *J, const char *pattern, int flags);
137 void js_pushiterator(js_State *J, int idx, int own);
138 const char *js_nextiterator(js_State *J, int idx);
140 int js_isdefined(js_State *J, int idx);
141 int js_isundefined(js_State *J, int idx);
142 int js_isnull(js_State *J, int idx);
143 int js_isboolean(js_State *J, int idx);
144 int js_isnumber(js_State *J, int idx);
145 int js_isstring(js_State *J, int idx);
146 int js_isprimitive(js_State *J, int idx);
147 int js_isobject(js_State *J, int idx);
148 int js_isarray(js_State *J, int idx);
149 int js_isregexp(js_State *J, int idx);
150 int js_iscallable(js_State *J, int idx);
151 int js_isuserdata(js_State *J, int idx, const char *tag);
153 int js_toboolean(js_State *J, int idx);
154 double js_tonumber(js_State *J, int idx);
155 const char *js_tostring(js_State *J, int idx);
156 void *js_touserdata(js_State *J, int idx, const char *tag);
158 double js_tointeger(js_State *J, int idx);
159 int js_toint32(js_State *J, int idx);
160 unsigned int js_touint32(js_State *J, int idx);
161 short js_toint16(js_State *J, int idx);
162 unsigned short js_touint16(js_State *J, int idx);
164 int js_gettop(js_State *J);
165 void js_settop(js_State *J, int idx);
166 void js_pop(js_State *J, int n);
167 void js_rot(js_State *J, int n);
168 void js_copy(js_State *J, int idx);
169 void js_remove(js_State *J, int idx);
170 void js_insert(js_State *J, int idx);
171 void js_replace(js_State* J, int idx);
173 void js_concat(js_State *J);
174 int js_compare(js_State *J, int *okay);
175 int js_equal(js_State *J);
176 int js_strictequal(js_State *J);
177 int js_instanceof(js_State *J);