zig-pug 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +346 -0
- package/binding.c +375 -0
- package/binding.gyp +28 -0
- package/common.gypi +5 -0
- package/include/zigpug.h +135 -0
- package/index.js +205 -0
- package/package.json +87 -0
- package/vendor/mujs/COPYING +16 -0
- package/vendor/mujs/README +50 -0
- package/vendor/mujs/astnames.h +92 -0
- package/vendor/mujs/jsarray.c +832 -0
- package/vendor/mujs/jsboolean.c +38 -0
- package/vendor/mujs/jsbuiltin.c +249 -0
- package/vendor/mujs/jscompile.c +1428 -0
- package/vendor/mujs/jsdate.c +861 -0
- package/vendor/mujs/jsdtoa.c +749 -0
- package/vendor/mujs/jserror.c +139 -0
- package/vendor/mujs/jsfunction.c +231 -0
- package/vendor/mujs/jsgc.c +284 -0
- package/vendor/mujs/jsi.h +870 -0
- package/vendor/mujs/jsintern.c +137 -0
- package/vendor/mujs/jslex.c +878 -0
- package/vendor/mujs/jsmath.c +194 -0
- package/vendor/mujs/jsnumber.c +198 -0
- package/vendor/mujs/jsobject.c +560 -0
- package/vendor/mujs/json.c +422 -0
- package/vendor/mujs/jsparse.c +1065 -0
- package/vendor/mujs/jsproperty.c +341 -0
- package/vendor/mujs/jsregexp.c +232 -0
- package/vendor/mujs/jsrepr.c +285 -0
- package/vendor/mujs/jsrun.c +2096 -0
- package/vendor/mujs/jsstate.c +334 -0
- package/vendor/mujs/jsstring.c +852 -0
- package/vendor/mujs/jsvalue.c +708 -0
- package/vendor/mujs/libmujs.a +0 -0
- package/vendor/mujs/main.c +396 -0
- package/vendor/mujs/mujs.h +253 -0
- package/vendor/mujs/one.c +25 -0
- package/vendor/mujs/opnames.h +85 -0
- package/vendor/mujs/pp.c +980 -0
- package/vendor/mujs/regexp.c +1277 -0
- package/vendor/mujs/regexp.h +46 -0
- package/vendor/mujs/utf.c +305 -0
- package/vendor/mujs/utf.h +52 -0
- package/vendor/mujs/utfdata.h +2209 -0
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
#include <stdio.h>
|
|
2
|
+
#include <stdlib.h>
|
|
3
|
+
#include <string.h>
|
|
4
|
+
#ifdef _MSC_VER
|
|
5
|
+
#include <io.h>
|
|
6
|
+
#else
|
|
7
|
+
#include <unistd.h>
|
|
8
|
+
#endif
|
|
9
|
+
#include <errno.h>
|
|
10
|
+
|
|
11
|
+
#include "mujs.h"
|
|
12
|
+
|
|
13
|
+
static char *xoptarg; /* Global argument pointer. */
|
|
14
|
+
static int xoptind = 0; /* Global argv index. */
|
|
15
|
+
static int xgetopt(int argc, char *argv[], char *optstring)
|
|
16
|
+
{
|
|
17
|
+
static char *scan = NULL; /* Private scan pointer. */
|
|
18
|
+
|
|
19
|
+
char c;
|
|
20
|
+
char *place;
|
|
21
|
+
|
|
22
|
+
xoptarg = NULL;
|
|
23
|
+
|
|
24
|
+
if (!scan || *scan == '\0') {
|
|
25
|
+
if (xoptind == 0)
|
|
26
|
+
xoptind++;
|
|
27
|
+
|
|
28
|
+
if (xoptind >= argc || argv[xoptind][0] != '-' || argv[xoptind][1] == '\0')
|
|
29
|
+
return EOF;
|
|
30
|
+
if (argv[xoptind][1] == '-' && argv[xoptind][2] == '\0') {
|
|
31
|
+
xoptind++;
|
|
32
|
+
return EOF;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
scan = argv[xoptind]+1;
|
|
36
|
+
xoptind++;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
c = *scan++;
|
|
40
|
+
place = strchr(optstring, c);
|
|
41
|
+
|
|
42
|
+
if (!place || c == ':') {
|
|
43
|
+
fprintf(stderr, "%s: unknown option -%c\n", argv[0], c);
|
|
44
|
+
return '?';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
place++;
|
|
48
|
+
if (*place == ':') {
|
|
49
|
+
if (*scan != '\0') {
|
|
50
|
+
xoptarg = scan;
|
|
51
|
+
scan = NULL;
|
|
52
|
+
} else if (xoptind < argc) {
|
|
53
|
+
xoptarg = argv[xoptind];
|
|
54
|
+
xoptind++;
|
|
55
|
+
} else {
|
|
56
|
+
fprintf(stderr, "%s: option requires argument -%c\n", argv[0], c);
|
|
57
|
+
return ':';
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return c;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
#ifdef HAVE_READLINE
|
|
65
|
+
#include <readline/readline.h>
|
|
66
|
+
#include <readline/history.h>
|
|
67
|
+
#else
|
|
68
|
+
void using_history(void) { }
|
|
69
|
+
void add_history(const char *string) { }
|
|
70
|
+
void rl_bind_key(int key, void (*fun)(void)) { }
|
|
71
|
+
void rl_insert(void) { }
|
|
72
|
+
char *readline(const char *prompt)
|
|
73
|
+
{
|
|
74
|
+
static char line[500], *p;
|
|
75
|
+
int n;
|
|
76
|
+
fputs(prompt, stdout);
|
|
77
|
+
p = fgets(line, sizeof line, stdin);
|
|
78
|
+
if (p) {
|
|
79
|
+
n = strlen(line);
|
|
80
|
+
if (n > 0 && line[n-1] == '\n')
|
|
81
|
+
line[--n] = 0;
|
|
82
|
+
p = malloc(n+1);
|
|
83
|
+
memcpy(p, line, n+1);
|
|
84
|
+
return p;
|
|
85
|
+
}
|
|
86
|
+
return NULL;
|
|
87
|
+
}
|
|
88
|
+
#endif
|
|
89
|
+
|
|
90
|
+
#define PS1 "> "
|
|
91
|
+
|
|
92
|
+
static void jsB_gc(js_State *J)
|
|
93
|
+
{
|
|
94
|
+
int report = js_toboolean(J, 1);
|
|
95
|
+
js_gc(J, report);
|
|
96
|
+
js_pushundefined(J);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static void jsB_load(js_State *J)
|
|
100
|
+
{
|
|
101
|
+
int i, n = js_gettop(J);
|
|
102
|
+
for (i = 1; i < n; ++i) {
|
|
103
|
+
js_loadfile(J, js_tostring(J, i));
|
|
104
|
+
js_pushundefined(J);
|
|
105
|
+
js_call(J, 0);
|
|
106
|
+
js_pop(J, 1);
|
|
107
|
+
}
|
|
108
|
+
js_pushundefined(J);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
static void jsB_compile(js_State *J)
|
|
112
|
+
{
|
|
113
|
+
const char *source = js_tostring(J, 1);
|
|
114
|
+
const char *filename = js_isdefined(J, 2) ? js_tostring(J, 2) : "[string]";
|
|
115
|
+
js_loadstring(J, filename, source);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
static void jsB_print(js_State *J)
|
|
119
|
+
{
|
|
120
|
+
int i, top = js_gettop(J);
|
|
121
|
+
for (i = 1; i < top; ++i) {
|
|
122
|
+
const char *s = js_tostring(J, i);
|
|
123
|
+
if (i > 1) putchar(' ');
|
|
124
|
+
fputs(s, stdout);
|
|
125
|
+
}
|
|
126
|
+
putchar('\n');
|
|
127
|
+
js_pushundefined(J);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
static void jsB_write(js_State *J)
|
|
131
|
+
{
|
|
132
|
+
int i, top = js_gettop(J);
|
|
133
|
+
for (i = 1; i < top; ++i) {
|
|
134
|
+
const char *s = js_tostring(J, i);
|
|
135
|
+
if (i > 1) putchar(' ');
|
|
136
|
+
fputs(s, stdout);
|
|
137
|
+
}
|
|
138
|
+
js_pushundefined(J);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
static void jsB_read(js_State *J)
|
|
142
|
+
{
|
|
143
|
+
const char *filename = js_tostring(J, 1);
|
|
144
|
+
FILE *f;
|
|
145
|
+
char *s;
|
|
146
|
+
int n, t;
|
|
147
|
+
|
|
148
|
+
f = fopen(filename, "rb");
|
|
149
|
+
if (!f) {
|
|
150
|
+
js_error(J, "cannot open file '%s': %s", filename, strerror(errno));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (fseek(f, 0, SEEK_END) < 0) {
|
|
154
|
+
fclose(f);
|
|
155
|
+
js_error(J, "cannot seek in file '%s': %s", filename, strerror(errno));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
n = ftell(f);
|
|
159
|
+
if (n < 0) {
|
|
160
|
+
fclose(f);
|
|
161
|
+
js_error(J, "cannot tell in file '%s': %s", filename, strerror(errno));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (fseek(f, 0, SEEK_SET) < 0) {
|
|
165
|
+
fclose(f);
|
|
166
|
+
js_error(J, "cannot seek in file '%s': %s", filename, strerror(errno));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
s = malloc(n + 1);
|
|
170
|
+
if (!s) {
|
|
171
|
+
fclose(f);
|
|
172
|
+
js_error(J, "out of memory");
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
t = fread(s, 1, n, f);
|
|
176
|
+
if (t != n) {
|
|
177
|
+
free(s);
|
|
178
|
+
fclose(f);
|
|
179
|
+
js_error(J, "cannot read data from file '%s': %s", filename, strerror(errno));
|
|
180
|
+
}
|
|
181
|
+
s[n] = 0;
|
|
182
|
+
|
|
183
|
+
js_pushstring(J, s);
|
|
184
|
+
free(s);
|
|
185
|
+
fclose(f);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
static void jsB_readline(js_State *J)
|
|
189
|
+
{
|
|
190
|
+
char *line = readline("");
|
|
191
|
+
if (!line) {
|
|
192
|
+
js_pushnull(J);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
js_pushstring(J, line);
|
|
196
|
+
if (*line)
|
|
197
|
+
add_history(line);
|
|
198
|
+
free(line);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
static void jsB_quit(js_State *J)
|
|
202
|
+
{
|
|
203
|
+
exit(js_tonumber(J, 1));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
static void jsB_repr(js_State *J)
|
|
207
|
+
{
|
|
208
|
+
js_repr(J, 1);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
static const char *require_js =
|
|
212
|
+
"function require(name) {\n"
|
|
213
|
+
"var cache = require.cache;\n"
|
|
214
|
+
"if (name in cache) return cache[name];\n"
|
|
215
|
+
"var exports = {};\n"
|
|
216
|
+
"cache[name] = exports;\n"
|
|
217
|
+
"Function('exports', read(name+'.js'))(exports);\n"
|
|
218
|
+
"return exports;\n"
|
|
219
|
+
"}\n"
|
|
220
|
+
"require.cache = Object.create(null);\n"
|
|
221
|
+
;
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
static const char *stacktrace_js =
|
|
225
|
+
"Error.prototype.toString = function() { return this.stack }\n"
|
|
226
|
+
;
|
|
227
|
+
|
|
228
|
+
static const char *console_js =
|
|
229
|
+
"var console = { log: print, debug: print, warn: print, error: print };"
|
|
230
|
+
;
|
|
231
|
+
|
|
232
|
+
static int eval_print(js_State *J, const char *source)
|
|
233
|
+
{
|
|
234
|
+
if (js_ploadstring(J, "[stdin]", source)) {
|
|
235
|
+
fprintf(stderr, "%s\n", js_trystring(J, -1, "Error"));
|
|
236
|
+
js_pop(J, 1);
|
|
237
|
+
return 1;
|
|
238
|
+
}
|
|
239
|
+
js_pushundefined(J);
|
|
240
|
+
if (js_pcall(J, 0)) {
|
|
241
|
+
fprintf(stderr, "%s\n", js_trystring(J, -1, "Error"));
|
|
242
|
+
js_pop(J, 1);
|
|
243
|
+
return 1;
|
|
244
|
+
}
|
|
245
|
+
if (js_isdefined(J, -1)) {
|
|
246
|
+
printf("%s\n", js_tryrepr(J, -1, "can't convert to string"));
|
|
247
|
+
}
|
|
248
|
+
js_pop(J, 1);
|
|
249
|
+
return 0;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
static char *read_stdin(void)
|
|
253
|
+
{
|
|
254
|
+
int n = 0;
|
|
255
|
+
int t = 512;
|
|
256
|
+
char *s = NULL;
|
|
257
|
+
|
|
258
|
+
for (;;) {
|
|
259
|
+
char *ss = realloc(s, t);
|
|
260
|
+
if (!ss) {
|
|
261
|
+
free(s);
|
|
262
|
+
fprintf(stderr, "cannot allocate storage for stdin contents\n");
|
|
263
|
+
return NULL;
|
|
264
|
+
}
|
|
265
|
+
s = ss;
|
|
266
|
+
n += fread(s + n, 1, t - n - 1, stdin);
|
|
267
|
+
if (n < t - 1)
|
|
268
|
+
break;
|
|
269
|
+
t *= 2;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (ferror(stdin)) {
|
|
273
|
+
free(s);
|
|
274
|
+
fprintf(stderr, "error reading stdin\n");
|
|
275
|
+
return NULL;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
s[n] = 0;
|
|
279
|
+
return s;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
static void usage(void)
|
|
283
|
+
{
|
|
284
|
+
fprintf(stderr, "Usage: mujs [options] [script [scriptArgs*]]\n");
|
|
285
|
+
fprintf(stderr, "\t-i: Enter interactive prompt after running code.\n");
|
|
286
|
+
fprintf(stderr, "\t-s: Check strictness.\n");
|
|
287
|
+
exit(1);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
int
|
|
291
|
+
main(int argc, char **argv)
|
|
292
|
+
{
|
|
293
|
+
char *input;
|
|
294
|
+
js_State *J;
|
|
295
|
+
int status = 0;
|
|
296
|
+
int strict = 0;
|
|
297
|
+
int interactive = 0;
|
|
298
|
+
int runlimit = 0;
|
|
299
|
+
int memlimit = 0;
|
|
300
|
+
int i, c;
|
|
301
|
+
|
|
302
|
+
while ((c = xgetopt(argc, argv, "isR:M:")) != -1) {
|
|
303
|
+
switch (c) {
|
|
304
|
+
default: usage(); break;
|
|
305
|
+
case 'i': interactive = 1; break;
|
|
306
|
+
case 's': strict = 1; break;
|
|
307
|
+
case 'R': runlimit = atoi(xoptarg); break;
|
|
308
|
+
case 'M': memlimit = atoi(xoptarg); break;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
J = js_newstate(NULL, NULL, strict ? JS_STRICT : 0);
|
|
313
|
+
if (!J) {
|
|
314
|
+
fprintf(stderr, "Could not initialize MuJS.\n");
|
|
315
|
+
exit(1);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
js_newcfunction(J, jsB_gc, "gc", 0);
|
|
319
|
+
js_setglobal(J, "gc");
|
|
320
|
+
|
|
321
|
+
js_newcfunction(J, jsB_load, "load", 1);
|
|
322
|
+
js_setglobal(J, "load");
|
|
323
|
+
|
|
324
|
+
js_newcfunction(J, jsB_compile, "compile", 2);
|
|
325
|
+
js_setglobal(J, "compile");
|
|
326
|
+
|
|
327
|
+
js_newcfunction(J, jsB_print, "print", 0);
|
|
328
|
+
js_setglobal(J, "print");
|
|
329
|
+
|
|
330
|
+
js_newcfunction(J, jsB_write, "write", 0);
|
|
331
|
+
js_setglobal(J, "write");
|
|
332
|
+
|
|
333
|
+
js_newcfunction(J, jsB_read, "read", 1);
|
|
334
|
+
js_setglobal(J, "read");
|
|
335
|
+
|
|
336
|
+
js_newcfunction(J, jsB_readline, "readline", 0);
|
|
337
|
+
js_setglobal(J, "readline");
|
|
338
|
+
|
|
339
|
+
js_newcfunction(J, jsB_repr, "repr", 0);
|
|
340
|
+
js_setglobal(J, "repr");
|
|
341
|
+
|
|
342
|
+
js_newcfunction(J, jsB_quit, "quit", 1);
|
|
343
|
+
js_setglobal(J, "quit");
|
|
344
|
+
|
|
345
|
+
js_dostring(J, require_js);
|
|
346
|
+
js_dostring(J, stacktrace_js);
|
|
347
|
+
js_dostring(J, console_js);
|
|
348
|
+
|
|
349
|
+
if (xoptind == argc) {
|
|
350
|
+
interactive = 1;
|
|
351
|
+
} else {
|
|
352
|
+
c = xoptind++;
|
|
353
|
+
|
|
354
|
+
js_newarray(J);
|
|
355
|
+
i = 0;
|
|
356
|
+
while (xoptind < argc) {
|
|
357
|
+
js_pushstring(J, argv[xoptind++]);
|
|
358
|
+
js_setindex(J, -2, i++);
|
|
359
|
+
}
|
|
360
|
+
js_setglobal(J, "scriptArgs");
|
|
361
|
+
|
|
362
|
+
js_setlimit(J, runlimit, memlimit);
|
|
363
|
+
if (js_dofile(J, argv[c]))
|
|
364
|
+
status = 1;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
if (interactive) {
|
|
368
|
+
printf("Welcome to MuJS %d.%d.%d.\n",
|
|
369
|
+
JS_VERSION_MAJOR, JS_VERSION_MINOR, JS_VERSION_PATCH);
|
|
370
|
+
if (isatty(0)) {
|
|
371
|
+
using_history();
|
|
372
|
+
rl_bind_key('\t', rl_insert);
|
|
373
|
+
input = readline(PS1);
|
|
374
|
+
while (input) {
|
|
375
|
+
js_setlimit(J, runlimit, memlimit);
|
|
376
|
+
eval_print(J, input);
|
|
377
|
+
if (*input)
|
|
378
|
+
add_history(input);
|
|
379
|
+
free(input);
|
|
380
|
+
input = readline(PS1);
|
|
381
|
+
}
|
|
382
|
+
putchar('\n');
|
|
383
|
+
} else {
|
|
384
|
+
input = read_stdin();
|
|
385
|
+
js_setlimit(J, runlimit, memlimit);
|
|
386
|
+
if (!input || !js_dostring(J, input))
|
|
387
|
+
status = 1;
|
|
388
|
+
free(input);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
js_gc(J, 0);
|
|
393
|
+
js_freestate(J);
|
|
394
|
+
|
|
395
|
+
return status;
|
|
396
|
+
}
|
|
@@ -0,0 +1,253 @@
|
|
|
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
|
+
#define JS_VERSION_MAJOR 1
|
|
11
|
+
#define JS_VERSION_MINOR 3
|
|
12
|
+
#define JS_VERSION_PATCH 8
|
|
13
|
+
|
|
14
|
+
#define JS_VERSION (JS_VERSION_MAJOR * 10000 + JS_VERSION_MINOR * 100 + JS_VERSION_PATCH)
|
|
15
|
+
#define JS_CHECKVERSION(x,y,z) (JS_VERSION >= ((x) * 10000 + (y) * 100 + (z)))
|
|
16
|
+
|
|
17
|
+
/* noreturn is a GCC extension */
|
|
18
|
+
#ifdef __GNUC__
|
|
19
|
+
#define JS_NORETURN __attribute__((noreturn))
|
|
20
|
+
#else
|
|
21
|
+
#ifdef _MSC_VER
|
|
22
|
+
#define JS_NORETURN __declspec(noreturn)
|
|
23
|
+
#else
|
|
24
|
+
#define JS_NORETURN
|
|
25
|
+
#endif
|
|
26
|
+
#endif
|
|
27
|
+
|
|
28
|
+
/* GCC can do type checking of printf strings */
|
|
29
|
+
#ifdef __printflike
|
|
30
|
+
#define JS_PRINTFLIKE __printflike
|
|
31
|
+
#else
|
|
32
|
+
#if __GNUC__ > 2 || __GNUC__ == 2 && __GNUC_MINOR__ >= 7
|
|
33
|
+
#define JS_PRINTFLIKE(fmtarg, firstvararg) \
|
|
34
|
+
__attribute__((__format__ (__printf__, fmtarg, firstvararg)))
|
|
35
|
+
#else
|
|
36
|
+
#define JS_PRINTFLIKE(fmtarg, firstvararg)
|
|
37
|
+
#endif
|
|
38
|
+
#endif
|
|
39
|
+
|
|
40
|
+
typedef struct js_State js_State;
|
|
41
|
+
|
|
42
|
+
typedef void *(*js_Alloc)(void *memctx, void *ptr, int size);
|
|
43
|
+
typedef void (*js_Panic)(js_State *J);
|
|
44
|
+
typedef void (*js_CFunction)(js_State *J);
|
|
45
|
+
typedef void (*js_Finalize)(js_State *J, void *p);
|
|
46
|
+
typedef int (*js_HasProperty)(js_State *J, void *p, const char *name);
|
|
47
|
+
typedef int (*js_Put)(js_State *J, void *p, const char *name);
|
|
48
|
+
typedef int (*js_Delete)(js_State *J, void *p, const char *name);
|
|
49
|
+
typedef void (*js_Report)(js_State *J, const char *message);
|
|
50
|
+
|
|
51
|
+
/* Basic functions */
|
|
52
|
+
js_State *js_newstate(js_Alloc alloc, void *actx, int flags);
|
|
53
|
+
void js_setcontext(js_State *J, void *uctx);
|
|
54
|
+
void *js_getcontext(js_State *J);
|
|
55
|
+
void js_setreport(js_State *J, js_Report report);
|
|
56
|
+
js_Panic js_atpanic(js_State *J, js_Panic panic);
|
|
57
|
+
void js_freestate(js_State *J);
|
|
58
|
+
void js_gc(js_State *J, int report);
|
|
59
|
+
void js_setlimit(js_State *J, int runlimit, int memlimit);
|
|
60
|
+
|
|
61
|
+
int js_dostring(js_State *J, const char *source);
|
|
62
|
+
int js_dofile(js_State *J, const char *filename);
|
|
63
|
+
int js_ploadstring(js_State *J, const char *filename, const char *source);
|
|
64
|
+
int js_ploadfile(js_State *J, const char *filename);
|
|
65
|
+
int js_pcall(js_State *J, int n);
|
|
66
|
+
int js_pconstruct(js_State *J, int n);
|
|
67
|
+
|
|
68
|
+
/* Exception handling */
|
|
69
|
+
|
|
70
|
+
void *js_savetry(js_State *J); /* returns a jmp_buf */
|
|
71
|
+
|
|
72
|
+
#define js_try(J) \
|
|
73
|
+
setjmp(js_savetry(J))
|
|
74
|
+
|
|
75
|
+
void js_endtry(js_State *J);
|
|
76
|
+
|
|
77
|
+
/* State constructor flags */
|
|
78
|
+
enum {
|
|
79
|
+
JS_STRICT = 1,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/* RegExp flags */
|
|
83
|
+
enum {
|
|
84
|
+
JS_REGEXP_G = 1,
|
|
85
|
+
JS_REGEXP_I = 2,
|
|
86
|
+
JS_REGEXP_M = 4,
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/* Property attribute flags */
|
|
90
|
+
enum {
|
|
91
|
+
JS_READONLY = 1,
|
|
92
|
+
JS_DONTENUM = 2,
|
|
93
|
+
JS_DONTCONF = 4,
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/* enum for js_type() */
|
|
97
|
+
enum {
|
|
98
|
+
JS_ISUNDEFINED,
|
|
99
|
+
JS_ISNULL,
|
|
100
|
+
JS_ISBOOLEAN,
|
|
101
|
+
JS_ISNUMBER,
|
|
102
|
+
JS_ISSTRING,
|
|
103
|
+
JS_ISFUNCTION,
|
|
104
|
+
JS_ISOBJECT
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
void js_report(js_State *J, const char *message);
|
|
108
|
+
|
|
109
|
+
void js_newerror(js_State *J, const char *message);
|
|
110
|
+
void js_newevalerror(js_State *J, const char *message);
|
|
111
|
+
void js_newrangeerror(js_State *J, const char *message);
|
|
112
|
+
void js_newreferenceerror(js_State *J, const char *message);
|
|
113
|
+
void js_newsyntaxerror(js_State *J, const char *message);
|
|
114
|
+
void js_newtypeerror(js_State *J, const char *message);
|
|
115
|
+
void js_newurierror(js_State *J, const char *message);
|
|
116
|
+
|
|
117
|
+
JS_NORETURN void js_error(js_State *J, const char *fmt, ...) JS_PRINTFLIKE(2,3);
|
|
118
|
+
JS_NORETURN void js_evalerror(js_State *J, const char *fmt, ...) JS_PRINTFLIKE(2,3);
|
|
119
|
+
JS_NORETURN void js_rangeerror(js_State *J, const char *fmt, ...) JS_PRINTFLIKE(2,3);
|
|
120
|
+
JS_NORETURN void js_referenceerror(js_State *J, const char *fmt, ...) JS_PRINTFLIKE(2,3);
|
|
121
|
+
JS_NORETURN void js_syntaxerror(js_State *J, const char *fmt, ...) JS_PRINTFLIKE(2,3);
|
|
122
|
+
JS_NORETURN void js_typeerror(js_State *J, const char *fmt, ...) JS_PRINTFLIKE(2,3);
|
|
123
|
+
JS_NORETURN void js_urierror(js_State *J, const char *fmt, ...) JS_PRINTFLIKE(2,3);
|
|
124
|
+
JS_NORETURN void js_throw(js_State *J);
|
|
125
|
+
|
|
126
|
+
void js_loadstring(js_State *J, const char *filename, const char *source);
|
|
127
|
+
void js_loadfile(js_State *J, const char *filename);
|
|
128
|
+
|
|
129
|
+
void js_eval(js_State *J);
|
|
130
|
+
void js_call(js_State *J, int n);
|
|
131
|
+
void js_construct(js_State *J, int n);
|
|
132
|
+
|
|
133
|
+
const char *js_ref(js_State *J);
|
|
134
|
+
void js_unref(js_State *J, const char *ref);
|
|
135
|
+
|
|
136
|
+
void js_getregistry(js_State *J, const char *name);
|
|
137
|
+
void js_setregistry(js_State *J, const char *name);
|
|
138
|
+
void js_delregistry(js_State *J, const char *name);
|
|
139
|
+
|
|
140
|
+
void js_getglobal(js_State *J, const char *name);
|
|
141
|
+
void js_setglobal(js_State *J, const char *name);
|
|
142
|
+
void js_defglobal(js_State *J, const char *name, int atts);
|
|
143
|
+
void js_delglobal(js_State *J, const char *name);
|
|
144
|
+
|
|
145
|
+
int js_hasproperty(js_State *J, int idx, const char *name);
|
|
146
|
+
void js_getproperty(js_State *J, int idx, const char *name);
|
|
147
|
+
void js_setproperty(js_State *J, int idx, const char *name);
|
|
148
|
+
void js_defproperty(js_State *J, int idx, const char *name, int atts);
|
|
149
|
+
void js_delproperty(js_State *J, int idx, const char *name);
|
|
150
|
+
void js_defaccessor(js_State *J, int idx, const char *name, int atts);
|
|
151
|
+
|
|
152
|
+
int js_getlength(js_State *J, int idx);
|
|
153
|
+
void js_setlength(js_State *J, int idx, int len);
|
|
154
|
+
int js_hasindex(js_State *J, int idx, int i);
|
|
155
|
+
void js_getindex(js_State *J, int idx, int i);
|
|
156
|
+
void js_setindex(js_State *J, int idx, int i);
|
|
157
|
+
void js_delindex(js_State *J, int idx, int i);
|
|
158
|
+
|
|
159
|
+
void js_currentfunction(js_State *J);
|
|
160
|
+
void *js_currentfunctiondata(js_State *J);
|
|
161
|
+
void js_pushglobal(js_State *J);
|
|
162
|
+
void js_pushundefined(js_State *J);
|
|
163
|
+
void js_pushnull(js_State *J);
|
|
164
|
+
void js_pushboolean(js_State *J, int v);
|
|
165
|
+
void js_pushnumber(js_State *J, double v);
|
|
166
|
+
void js_pushstring(js_State *J, const char *v);
|
|
167
|
+
void js_pushlstring(js_State *J, const char *v, int n);
|
|
168
|
+
void js_pushliteral(js_State *J, const char *v);
|
|
169
|
+
|
|
170
|
+
void js_newobjectx(js_State *J);
|
|
171
|
+
void js_newobject(js_State *J);
|
|
172
|
+
void js_newarray(js_State *J);
|
|
173
|
+
void js_newboolean(js_State *J, int v);
|
|
174
|
+
void js_newnumber(js_State *J, double v);
|
|
175
|
+
void js_newstring(js_State *J, const char *v);
|
|
176
|
+
void js_newcfunction(js_State *J, js_CFunction fun, const char *name, int length);
|
|
177
|
+
void js_newcfunctionx(js_State *J, js_CFunction fun, const char *name, int length, void *data, js_Finalize finalize);
|
|
178
|
+
void js_newcconstructor(js_State *J, js_CFunction fun, js_CFunction con, const char *name, int length);
|
|
179
|
+
void js_newuserdata(js_State *J, const char *tag, void *data, js_Finalize finalize);
|
|
180
|
+
void js_newuserdatax(js_State *J, const char *tag, void *data, js_HasProperty has, js_Put put, js_Delete del, js_Finalize finalize);
|
|
181
|
+
void js_newregexp(js_State *J, const char *pattern, int flags);
|
|
182
|
+
|
|
183
|
+
void js_pushiterator(js_State *J, int idx, int own);
|
|
184
|
+
const char *js_nextiterator(js_State *J, int idx);
|
|
185
|
+
|
|
186
|
+
int js_isdefined(js_State *J, int idx);
|
|
187
|
+
int js_isundefined(js_State *J, int idx);
|
|
188
|
+
int js_isnull(js_State *J, int idx);
|
|
189
|
+
int js_isboolean(js_State *J, int idx);
|
|
190
|
+
int js_isnumber(js_State *J, int idx);
|
|
191
|
+
int js_isstring(js_State *J, int idx);
|
|
192
|
+
int js_isprimitive(js_State *J, int idx);
|
|
193
|
+
int js_isobject(js_State *J, int idx);
|
|
194
|
+
int js_isarray(js_State *J, int idx);
|
|
195
|
+
int js_isregexp(js_State *J, int idx);
|
|
196
|
+
int js_iscoercible(js_State *J, int idx);
|
|
197
|
+
int js_iscallable(js_State *J, int idx);
|
|
198
|
+
int js_isuserdata(js_State *J, int idx, const char *tag);
|
|
199
|
+
int js_iserror(js_State *J, int idx);
|
|
200
|
+
int js_isnumberobject(js_State *J, int idx);
|
|
201
|
+
int js_isstringobject(js_State *J, int idx);
|
|
202
|
+
int js_isbooleanobject(js_State *J, int idx);
|
|
203
|
+
int js_isdateobject(js_State *J, int idx);
|
|
204
|
+
|
|
205
|
+
int js_toboolean(js_State *J, int idx);
|
|
206
|
+
double js_tonumber(js_State *J, int idx);
|
|
207
|
+
const char *js_tostring(js_State *J, int idx);
|
|
208
|
+
void *js_touserdata(js_State *J, int idx, const char *tag);
|
|
209
|
+
|
|
210
|
+
const char *js_trystring(js_State *J, int idx, const char *error);
|
|
211
|
+
double js_trynumber(js_State *J, int idx, double error);
|
|
212
|
+
int js_tryinteger(js_State *J, int idx, int error);
|
|
213
|
+
int js_tryboolean(js_State *J, int idx, int error);
|
|
214
|
+
|
|
215
|
+
int js_tointeger(js_State *J, int idx);
|
|
216
|
+
int js_toint32(js_State *J, int idx);
|
|
217
|
+
unsigned int js_touint32(js_State *J, int idx);
|
|
218
|
+
short js_toint16(js_State *J, int idx);
|
|
219
|
+
unsigned short js_touint16(js_State *J, int idx);
|
|
220
|
+
|
|
221
|
+
int js_gettop(js_State *J);
|
|
222
|
+
void js_pop(js_State *J, int n);
|
|
223
|
+
void js_rot(js_State *J, int n);
|
|
224
|
+
void js_copy(js_State *J, int idx);
|
|
225
|
+
void js_remove(js_State *J, int idx);
|
|
226
|
+
void js_insert(js_State *J, int idx);
|
|
227
|
+
void js_replace(js_State* J, int idx);
|
|
228
|
+
|
|
229
|
+
void js_dup(js_State *J);
|
|
230
|
+
void js_dup2(js_State *J);
|
|
231
|
+
void js_rot2(js_State *J);
|
|
232
|
+
void js_rot3(js_State *J);
|
|
233
|
+
void js_rot4(js_State *J);
|
|
234
|
+
void js_rot2pop1(js_State *J);
|
|
235
|
+
void js_rot3pop2(js_State *J);
|
|
236
|
+
|
|
237
|
+
void js_concat(js_State *J);
|
|
238
|
+
int js_compare(js_State *J, int *okay);
|
|
239
|
+
int js_equal(js_State *J);
|
|
240
|
+
int js_strictequal(js_State *J);
|
|
241
|
+
int js_instanceof(js_State *J);
|
|
242
|
+
const char *js_typeof(js_State *J, int idx);
|
|
243
|
+
int js_type(js_State *J, int idx);
|
|
244
|
+
|
|
245
|
+
void js_repr(js_State *J, int idx);
|
|
246
|
+
const char *js_torepr(js_State *J, int idx);
|
|
247
|
+
const char *js_tryrepr(js_State *J, int idx, const char *error);
|
|
248
|
+
|
|
249
|
+
#ifdef __cplusplus
|
|
250
|
+
}
|
|
251
|
+
#endif
|
|
252
|
+
|
|
253
|
+
#endif
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#include "jsarray.c"
|
|
2
|
+
#include "jsboolean.c"
|
|
3
|
+
#include "jsbuiltin.c"
|
|
4
|
+
#include "jscompile.c"
|
|
5
|
+
#include "jsdate.c"
|
|
6
|
+
#include "jsdtoa.c"
|
|
7
|
+
#include "jserror.c"
|
|
8
|
+
#include "jsfunction.c"
|
|
9
|
+
#include "jsgc.c"
|
|
10
|
+
#include "jsintern.c"
|
|
11
|
+
#include "jslex.c"
|
|
12
|
+
#include "jsmath.c"
|
|
13
|
+
#include "jsnumber.c"
|
|
14
|
+
#include "jsobject.c"
|
|
15
|
+
#include "json.c"
|
|
16
|
+
#include "jsparse.c"
|
|
17
|
+
#include "jsproperty.c"
|
|
18
|
+
#include "jsregexp.c"
|
|
19
|
+
#include "jsrepr.c"
|
|
20
|
+
#include "jsrun.c"
|
|
21
|
+
#include "jsstate.c"
|
|
22
|
+
#include "jsstring.c"
|
|
23
|
+
#include "jsvalue.c"
|
|
24
|
+
#include "regexp.c"
|
|
25
|
+
#include "utf.c"
|