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