Skip to content

Commit

Permalink
更新到2019-08-18版本
Browse files Browse the repository at this point in the history
  • Loading branch information
llgoer committed Aug 18, 2019
1 parent 9d5243b commit a703cc1
Show file tree
Hide file tree
Showing 25 changed files with 1,472 additions and 494 deletions.
8 changes: 8 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2019-08-18:

- added os.realpath, os.getcwd, os.mkdir, os.stat, os.lstat,
os.readlink, os.readdir, os.utimes, std.popen
- module autodetection
- added import.meta
- misc bug fixes

2019-08-10:

- added public class fields and private class fields, methods and
Expand Down
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -382,39 +382,39 @@ test: qjs qjsbn
./qjs tests/test_op.js
./qjs tests/test_builtin.js
./qjs tests/test_loop.js
./qjs -m tests/test_std.js
./qjs tests/test_std.js
ifndef CONFIG_DARWIN
./qjs -m tests/test_bjson.js
./qjs tests/test_bjson.js
endif
./qjsbn tests/test_closure.js
./qjsbn tests/test_op.js
./qjsbn tests/test_builtin.js
./qjsbn tests/test_loop.js
./qjsbn -m tests/test_std.js
./qjsbn tests/test_std.js
./qjsbn --qjscalc tests/test_bignum.js

test-32: qjs32 qjsbn32
./qjs32 tests/test_closure.js
./qjs32 tests/test_op.js
./qjs32 tests/test_builtin.js
./qjs32 tests/test_loop.js
./qjs32 -m tests/test_std.js
./qjs32 tests/test_std.js
./qjsbn32 tests/test_closure.js
./qjsbn32 tests/test_op.js
./qjsbn32 tests/test_builtin.js
./qjsbn32 tests/test_loop.js
./qjsbn32 -m tests/test_std.js
./qjsbn32 tests/test_std.js
./qjsbn32 --qjscalc tests/test_bignum.js

stats: qjs qjs32
./qjs -qd
./qjs32 -qd

microbench: qjs
./qjs tests/microbench.js
./qjs --std tests/microbench.js

microbench-32: qjs32
./qjs32 tests/microbench.js
./qjs32 --std tests/microbench.js

# ES5 tests (obsolete)
test2o: run-test262
Expand Down
7 changes: 3 additions & 4 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
- fix regexp skip in js_parse_skip_parens_token()
- 64-bit atoms in 64-bit mode?
- rename CONFIG_ALL_UNICODE, CONFIG_BIGNUM, CONFIG_ATOMICS, CONFIG_CHECK_JSVALUE ?
- unify coding style and naming conventions
Expand Down Expand Up @@ -76,6 +75,6 @@ REPL:
Test262o: 0/11262 errors, 463 excluded
Test262o commit: 7da91bceb9ce7613f87db47ddd1292a2dda58b42 (es5-tests branch)

Test262: 27/66629 errors, 784 excluded, 1406 skipped
Test262bn: 27/68730 errors, 717 excluded, 419 skipped
test262 commit: 8f5f6a1aa1a99640483d067f84fcf7719d9e6c38
Test262: 2/67090 errors, 842 excluded, 1386 skipped
Test262bn: 2/69191 errors, 775 excluded, 399 skipped
test262 commit: 59a1a016b7cf5cf43f66b274c7d1db4ec6066935
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2019-08-10
2019-08-18
74 changes: 72 additions & 2 deletions doc/quickjs.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified doc/quickjs.pdf
Binary file not shown.
63 changes: 61 additions & 2 deletions doc/quickjs.texi
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ Go to interactive mode (it is not the default when files are provided on the com

@item -m
@item --module
Load as ES6 module (default if .mjs file extension).
Load as ES6 module (default=autodetect).

@item --script
Load as ES6 script (default=autodetect).

@end table

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

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

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

@item popen(command, flags)
Open a process by creating a pipe (wrapper to the libc @code{popen()}). Throws
@code{std.Error} in case of I/O error.

@item tmpfile()
Open a temporary file. Throws @code{std.Error} in case of I/O error.

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

@item realpath(path)
Return @code{[str, err]} where @code{str} is the canonicalized absolute
pathname of @code{path} and @code{err} the error code.

@item getcwd()
Return @code{[str, err]} where @code{str} is the current working directory
and @code{err} the error code.

@item mkdir(path, mode = 0o777)
Create a directory at @code{path}. Return the error code.

@item stat(path)
@item lstat(path)

Return @code{[obj, err]} where @code{obj} is an object containing the
file status of @code{path}. @code{err} is the error code. The
following fields are defined in @code{obj}: dev, ino, mode, nlink,
uid, gid, rdev, size, blocks, atime, mtime, ctime. The times are
specified in milliseconds since 1970. @code{lstat()} is the same as
@code{stat()} excepts that it returns information about the link
itself.

@item S_IFMT
@item S_IFIFO
@item S_IFCHR
@item S_IFDIR
@item S_IFBLK
@item S_IFREG
@item S_IFSOCK
@item S_IFLNK
@item S_ISGID
@item S_ISUID
Constants to interpret the @code{mode} property returned by
@code{stat()}. They have the same value as in the C system header
@file{sys/stat.h}.

@item utimes(path, atime, mtime)
Change the access and modification times of the file @code{path}. The
times are specified in milliseconds since 1970.

@item symlink(target, linkpath)
Create a link at @code{linkpath} containing the string @code{target}.

@item readlink(path)
Return @code{[str, err]} where @code{str} is the link target and @code{err}
the error code.

@item readdir(path)
Return @code{[array, err]} where @code{array} is an array of strings
containing the filenames of the directory @code{path}. @code{err} is
the error code.

@item setReadHandler(fd, func)
Add a read handler to the file handle @code{fd}. @code{func} is called
each time there is data pending for @code{fd}. A single read handler
Expand Down
38 changes: 23 additions & 15 deletions qjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,25 @@ static int eval_buf(JSContext *ctx, const void *buf, int buf_len,
return ret;
}

static int eval_file(JSContext *ctx, const char *filename, int eval_flags)
static int eval_file(JSContext *ctx, const char *filename, int module)
{
uint8_t *buf;
int ret;
int ret, eval_flags;
size_t buf_len;

buf = js_load_file(ctx, &buf_len, filename);
if (!buf) {
perror(filename);
exit(1);
}

if (module < 0) {
module = JS_DetectModule((const char *)buf, buf_len);
}
if (module)
eval_flags = JS_EVAL_TYPE_MODULE;
else
eval_flags = JS_EVAL_TYPE_GLOBAL;
ret = eval_buf(ctx, buf, buf_len, filename, eval_flags);
js_free(ctx, buf);
return ret;
Expand Down Expand Up @@ -239,11 +247,13 @@ static const JSMallocFunctions trace_mf = {
void help(void)
{
printf("QuickJS version " CONFIG_VERSION "\n"
"usage: " PROG_NAME " [options] [files]\n"
"usage: " PROG_NAME " [options] [file]\n"
"-h --help list options\n"
"-e --eval EXPR evaluate EXPR\n"
"-i --interactive go to interactive mode\n"
"-m --module load as ES6 module (default if .mjs file extension)\n"
"-m --module load as ES6 module (default=autodetect)\n"
" --script load as ES6 script (default=autodetect)\n"
" --std make 'std' and 'os' available to the loaded script\n"
#ifdef CONFIG_BIGNUM
" --qjscalc load the QJSCalc runtime (default if invoked as qjscalc)\n"
#endif
Expand All @@ -264,8 +274,8 @@ int main(int argc, char **argv)
int dump_memory = 0;
int trace_memory = 0;
int empty_run = 0;
int module = 0;
int load_std = 1;
int module = -1;
int load_std = 0;
#ifdef CONFIG_BIGNUM
int load_jscalc;
#endif
Expand Down Expand Up @@ -327,6 +337,10 @@ int main(int argc, char **argv)
module = 1;
continue;
}
if (!strcmp(longopt, "script")) {
module = 0;
continue;
}
if (opt == 'd' || !strcmp(longopt, "dump")) {
dump_memory++;
continue;
Expand All @@ -335,8 +349,8 @@ int main(int argc, char **argv)
trace_memory++;
continue;
}
if (!strcmp(longopt, "nostd")) {
load_std = 0;
if (!strcmp(longopt, "std")) {
load_std = 1;
continue;
}
#ifdef CONFIG_BIGNUM
Expand Down Expand Up @@ -406,15 +420,9 @@ int main(int argc, char **argv)
/* interactive mode */
interactive = 1;
} else {
int eval_flags;
const char *filename;
filename = argv[optind];

if (module || has_suffix(filename, ".mjs"))
eval_flags = JS_EVAL_TYPE_MODULE;
else
eval_flags = JS_EVAL_TYPE_GLOBAL;
if (eval_file(ctx, filename, eval_flags))
if (eval_file(ctx, filename, module))
goto fail;
}
if (interactive) {
Expand Down
Loading

0 comments on commit a703cc1

Please sign in to comment.