Skip to content

Commit a703cc1

Browse files
author
llgoer
committed
更新到2019-08-18版本
1 parent 9d5243b commit a703cc1

25 files changed

+1472
-494
lines changed

Changelog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2019-08-18:
2+
3+
- added os.realpath, os.getcwd, os.mkdir, os.stat, os.lstat,
4+
os.readlink, os.readdir, os.utimes, std.popen
5+
- module autodetection
6+
- added import.meta
7+
- misc bug fixes
8+
19
2019-08-10:
210

311
- added public class fields and private class fields, methods and

Makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -382,39 +382,39 @@ test: qjs qjsbn
382382
./qjs tests/test_op.js
383383
./qjs tests/test_builtin.js
384384
./qjs tests/test_loop.js
385-
./qjs -m tests/test_std.js
385+
./qjs tests/test_std.js
386386
ifndef CONFIG_DARWIN
387-
./qjs -m tests/test_bjson.js
387+
./qjs tests/test_bjson.js
388388
endif
389389
./qjsbn tests/test_closure.js
390390
./qjsbn tests/test_op.js
391391
./qjsbn tests/test_builtin.js
392392
./qjsbn tests/test_loop.js
393-
./qjsbn -m tests/test_std.js
393+
./qjsbn tests/test_std.js
394394
./qjsbn --qjscalc tests/test_bignum.js
395395

396396
test-32: qjs32 qjsbn32
397397
./qjs32 tests/test_closure.js
398398
./qjs32 tests/test_op.js
399399
./qjs32 tests/test_builtin.js
400400
./qjs32 tests/test_loop.js
401-
./qjs32 -m tests/test_std.js
401+
./qjs32 tests/test_std.js
402402
./qjsbn32 tests/test_closure.js
403403
./qjsbn32 tests/test_op.js
404404
./qjsbn32 tests/test_builtin.js
405405
./qjsbn32 tests/test_loop.js
406-
./qjsbn32 -m tests/test_std.js
406+
./qjsbn32 tests/test_std.js
407407
./qjsbn32 --qjscalc tests/test_bignum.js
408408

409409
stats: qjs qjs32
410410
./qjs -qd
411411
./qjs32 -qd
412412

413413
microbench: qjs
414-
./qjs tests/microbench.js
414+
./qjs --std tests/microbench.js
415415

416416
microbench-32: qjs32
417-
./qjs32 tests/microbench.js
417+
./qjs32 --std tests/microbench.js
418418

419419
# ES5 tests (obsolete)
420420
test2o: run-test262

TODO

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
- fix regexp skip in js_parse_skip_parens_token()
21
- 64-bit atoms in 64-bit mode?
32
- rename CONFIG_ALL_UNICODE, CONFIG_BIGNUM, CONFIG_ATOMICS, CONFIG_CHECK_JSVALUE ?
43
- unify coding style and naming conventions
@@ -76,6 +75,6 @@ REPL:
7675
Test262o: 0/11262 errors, 463 excluded
7776
Test262o commit: 7da91bceb9ce7613f87db47ddd1292a2dda58b42 (es5-tests branch)
7877

79-
Test262: 27/66629 errors, 784 excluded, 1406 skipped
80-
Test262bn: 27/68730 errors, 717 excluded, 419 skipped
81-
test262 commit: 8f5f6a1aa1a99640483d067f84fcf7719d9e6c38
78+
Test262: 2/67090 errors, 842 excluded, 1386 skipped
79+
Test262bn: 2/69191 errors, 775 excluded, 399 skipped
80+
test262 commit: 59a1a016b7cf5cf43f66b274c7d1db4ec6066935

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2019-08-10
1+
2019-08-18

doc/quickjs.html

Lines changed: 72 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/quickjs.pdf

1.52 KB
Binary file not shown.

doc/quickjs.texi

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ Go to interactive mode (it is not the default when files are provided on the com
127127

128128
@item -m
129129
@item --module
130-
Load as ES6 module (default if .mjs file extension).
130+
Load as ES6 module (default=autodetect).
131+
132+
@item --script
133+
Load as ES6 script (default=autodetect).
131134

132135
@end table
133136

@@ -164,7 +167,7 @@ Set the output filename (default = @file{out.c} or @file{a.out}).
164167
Set the C name of the generated data.
165168

166169
@item -m
167-
Compile as Javascript module (default if @file{.mjs} extension).
170+
Compile as Javascript module (default=autodetect).
168171

169172
@item -M module_name[,cname]
170173
Add initialization code for an external C module. See the
@@ -395,6 +398,10 @@ The constructor contains the following fields:
395398
Open a file (wrapper to the libc @code{fopen()}). Throws
396399
@code{std.Error} in case of I/O error.
397400

401+
@item popen(command, flags)
402+
Open a process by creating a pipe (wrapper to the libc @code{popen()}). Throws
403+
@code{std.Error} in case of I/O error.
404+
398405
@item tmpfile()
399406
Open a temporary file. Throws @code{std.Error} in case of I/O error.
400407

@@ -556,6 +563,58 @@ Remove a file. Return 0 if OK or < 0 if error.
556563
@item rename(oldname, newname)
557564
Rename a file. Return 0 if OK or < 0 if error.
558565

566+
@item realpath(path)
567+
Return @code{[str, err]} where @code{str} is the canonicalized absolute
568+
pathname of @code{path} and @code{err} the error code.
569+
570+
@item getcwd()
571+
Return @code{[str, err]} where @code{str} is the current working directory
572+
and @code{err} the error code.
573+
574+
@item mkdir(path, mode = 0o777)
575+
Create a directory at @code{path}. Return the error code.
576+
577+
@item stat(path)
578+
@item lstat(path)
579+
580+
Return @code{[obj, err]} where @code{obj} is an object containing the
581+
file status of @code{path}. @code{err} is the error code. The
582+
following fields are defined in @code{obj}: dev, ino, mode, nlink,
583+
uid, gid, rdev, size, blocks, atime, mtime, ctime. The times are
584+
specified in milliseconds since 1970. @code{lstat()} is the same as
585+
@code{stat()} excepts that it returns information about the link
586+
itself.
587+
588+
@item S_IFMT
589+
@item S_IFIFO
590+
@item S_IFCHR
591+
@item S_IFDIR
592+
@item S_IFBLK
593+
@item S_IFREG
594+
@item S_IFSOCK
595+
@item S_IFLNK
596+
@item S_ISGID
597+
@item S_ISUID
598+
Constants to interpret the @code{mode} property returned by
599+
@code{stat()}. They have the same value as in the C system header
600+
@file{sys/stat.h}.
601+
602+
@item utimes(path, atime, mtime)
603+
Change the access and modification times of the file @code{path}. The
604+
times are specified in milliseconds since 1970.
605+
606+
@item symlink(target, linkpath)
607+
Create a link at @code{linkpath} containing the string @code{target}.
608+
609+
@item readlink(path)
610+
Return @code{[str, err]} where @code{str} is the link target and @code{err}
611+
the error code.
612+
613+
@item readdir(path)
614+
Return @code{[array, err]} where @code{array} is an array of strings
615+
containing the filenames of the directory @code{path}. @code{err} is
616+
the error code.
617+
559618
@item setReadHandler(fd, func)
560619
Add a read handler to the file handle @code{fd}. @code{func} is called
561620
each time there is data pending for @code{fd}. A single read handler

qjs.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,25 @@ static int eval_buf(JSContext *ctx, const void *buf, int buf_len,
6565
return ret;
6666
}
6767

68-
static int eval_file(JSContext *ctx, const char *filename, int eval_flags)
68+
static int eval_file(JSContext *ctx, const char *filename, int module)
6969
{
7070
uint8_t *buf;
71-
int ret;
71+
int ret, eval_flags;
7272
size_t buf_len;
7373

7474
buf = js_load_file(ctx, &buf_len, filename);
7575
if (!buf) {
7676
perror(filename);
7777
exit(1);
7878
}
79+
80+
if (module < 0) {
81+
module = JS_DetectModule((const char *)buf, buf_len);
82+
}
83+
if (module)
84+
eval_flags = JS_EVAL_TYPE_MODULE;
85+
else
86+
eval_flags = JS_EVAL_TYPE_GLOBAL;
7987
ret = eval_buf(ctx, buf, buf_len, filename, eval_flags);
8088
js_free(ctx, buf);
8189
return ret;
@@ -239,11 +247,13 @@ static const JSMallocFunctions trace_mf = {
239247
void help(void)
240248
{
241249
printf("QuickJS version " CONFIG_VERSION "\n"
242-
"usage: " PROG_NAME " [options] [files]\n"
250+
"usage: " PROG_NAME " [options] [file]\n"
243251
"-h --help list options\n"
244252
"-e --eval EXPR evaluate EXPR\n"
245253
"-i --interactive go to interactive mode\n"
246-
"-m --module load as ES6 module (default if .mjs file extension)\n"
254+
"-m --module load as ES6 module (default=autodetect)\n"
255+
" --script load as ES6 script (default=autodetect)\n"
256+
" --std make 'std' and 'os' available to the loaded script\n"
247257
#ifdef CONFIG_BIGNUM
248258
" --qjscalc load the QJSCalc runtime (default if invoked as qjscalc)\n"
249259
#endif
@@ -264,8 +274,8 @@ int main(int argc, char **argv)
264274
int dump_memory = 0;
265275
int trace_memory = 0;
266276
int empty_run = 0;
267-
int module = 0;
268-
int load_std = 1;
277+
int module = -1;
278+
int load_std = 0;
269279
#ifdef CONFIG_BIGNUM
270280
int load_jscalc;
271281
#endif
@@ -327,6 +337,10 @@ int main(int argc, char **argv)
327337
module = 1;
328338
continue;
329339
}
340+
if (!strcmp(longopt, "script")) {
341+
module = 0;
342+
continue;
343+
}
330344
if (opt == 'd' || !strcmp(longopt, "dump")) {
331345
dump_memory++;
332346
continue;
@@ -335,8 +349,8 @@ int main(int argc, char **argv)
335349
trace_memory++;
336350
continue;
337351
}
338-
if (!strcmp(longopt, "nostd")) {
339-
load_std = 0;
352+
if (!strcmp(longopt, "std")) {
353+
load_std = 1;
340354
continue;
341355
}
342356
#ifdef CONFIG_BIGNUM
@@ -406,15 +420,9 @@ int main(int argc, char **argv)
406420
/* interactive mode */
407421
interactive = 1;
408422
} else {
409-
int eval_flags;
410423
const char *filename;
411424
filename = argv[optind];
412-
413-
if (module || has_suffix(filename, ".mjs"))
414-
eval_flags = JS_EVAL_TYPE_MODULE;
415-
else
416-
eval_flags = JS_EVAL_TYPE_GLOBAL;
417-
if (eval_file(ctx, filename, eval_flags))
425+
if (eval_file(ctx, filename, module))
418426
goto fail;
419427
}
420428
if (interactive) {

0 commit comments

Comments
 (0)