Skip to content

Commit b5e6289

Browse files
committed
2021-03-27 release
1 parent 204682f commit b5e6289

19 files changed

+583
-266
lines changed

Changelog

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2021-03-27:
2+
3+
- faster Array.prototype.push and Array.prototype.unshift
4+
- added JS_UpdateStackTop()
5+
- fixed Windows console
6+
- misc bug fixes
7+
18
2020-11-08:
29

310
- improved function parameter initializers

LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
QuickJS Javascript Engine
2+
3+
Copyright (c) 2017-2021 Fabrice Bellard
4+
Copyright (c) 2017-2021 Charlie Gordon
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.

Makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#
22
# QuickJS Javascript Engine
33
#
4-
# Copyright (c) 2017-2020 Fabrice Bellard
5-
# Copyright (c) 2017-2020 Charlie Gordon
4+
# Copyright (c) 2017-2021 Fabrice Bellard
5+
# Copyright (c) 2017-2021 Charlie Gordon
66
#
77
# Permission is hereby granted, free of charge, to any person obtaining a copy
88
# of this software and associated documentation files (the "Software"), to deal
@@ -179,6 +179,7 @@ LIBS=-lm
179179
ifndef CONFIG_WIN32
180180
LIBS+=-ldl -lpthread
181181
endif
182+
LIBS+=$(EXTRA_LIBS)
182183

183184
$(OBJDIR):
184185
mkdir -p $(OBJDIR) $(OBJDIR)/examples $(OBJDIR)/tests

TODO

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,5 @@ Optimization ideas:
6666
Test262o: 0/11262 errors, 463 excluded
6767
Test262o commit: 7da91bceb9ce7613f87db47ddd1292a2dda58b42 (es5-tests branch)
6868

69-
Result: 51/75119 errors, 899 excluded, 570 skipped
70-
Test262 commit: 1c33fdb0ca60fb9d7392403be769ed0d26209132
69+
Result: 35/75280 errors, 909 excluded, 585 skipped
70+
Test262 commit: 31126581e7290f9233c29cefd93f66c6ac78f1c9

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2020-11-08
1+
2021-03-27

doc/quickjs.texi

+5-4
Original file line numberDiff line numberDiff line change
@@ -896,10 +896,11 @@ set the C opaque point with
896896
@code{JS_GetOpaque()}/@code{JS_SetOpaque()}.
897897

898898
When defining a new JS class, it is possible to declare a finalizer
899-
which is called when the object is destroyed. A @code{gc_mark} method
900-
can be provided so that the cycle removal algorithm can find the other
901-
objects referenced by this object. Other methods are available to
902-
define exotic object behaviors.
899+
which is called when the object is destroyed. The finalizer should be
900+
used to release C resources. It is invalid to execute JS code from
901+
it. A @code{gc_mark} method can be provided so that the cycle removal
902+
algorithm can find the other objects referenced by this object. Other
903+
methods are available to define exotic object behaviors.
903904

904905
The Class ID are globally allocated (i.e. for all runtimes). The
905906
JSClass are allocated per @code{JSRuntime}. @code{JS_SetClassProto()}

libbf.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Tiny arbitrary precision floating point library
33
*
4-
* Copyright (c) 2017-2020 Fabrice Bellard
4+
* Copyright (c) 2017-2021 Fabrice Bellard
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal

libbf.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Tiny arbitrary precision floating point library
33
*
4-
* Copyright (c) 2017-2020 Fabrice Bellard
4+
* Copyright (c) 2017-2021 Fabrice Bellard
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal

qjs.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
22
* QuickJS stand alone interpreter
33
*
4-
* Copyright (c) 2017-2020 Fabrice Bellard
5-
* Copyright (c) 2017-2020 Charlie Gordon
4+
* Copyright (c) 2017-2021 Fabrice Bellard
5+
* Copyright (c) 2017-2021 Charlie Gordon
66
*
77
* Permission is hereby granted, free of charge, to any person obtaining a copy
88
* of this software and associated documentation files (the "Software"), to deal
@@ -156,7 +156,13 @@ static inline size_t js_trace_malloc_usable_size(void *ptr)
156156
#endif
157157
}
158158

159-
static void __attribute__((format(printf, 2, 3)))
159+
static void
160+
#ifdef _WIN32
161+
/* mingw printf is used */
162+
__attribute__((format(gnu_printf, 2, 3)))
163+
#else
164+
__attribute__((format(printf, 2, 3)))
165+
#endif
160166
js_trace_malloc_printf(JSMallocState *s, const char *fmt, ...)
161167
{
162168
va_list ap;

qjsc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* QuickJS command line compiler
33
*
4-
* Copyright (c) 2018-2020 Fabrice Bellard
4+
* Copyright (c) 2018-2021 Fabrice Bellard
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal

qjscalc.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -2299,8 +2299,13 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
22992299
function array_div(a, b) {
23002300
return array_mul(a, b.inverse());
23012301
}
2302-
function array_scalar_div(a, b) {
2303-
return a * b.inverse();
2302+
function array_element_wise_inverse(a) {
2303+
var r, i, n;
2304+
n = a.length;
2305+
r = [];
2306+
for(i = 0; i < n; i++)
2307+
r[i] = a[i].inverse();
2308+
return r;
23042309
}
23052310
function array_eq(a, b) {
23062311
var n, i;
@@ -2337,14 +2342,14 @@ var Integer, Float, Fraction, Complex, Mod, Polynomial, PolyMod, RationalFunctio
23372342
right: [Number, BigInt, Float, Fraction, Complex, Mod,
23382343
Polynomial, PolyMod, RationalFunction, Series],
23392344
"*": array_scalar_mul,
2340-
"/": array_scalar_div,
2345+
"/"(a, b) { return a * b.inverse(); },
23412346
"**": generic_pow, /* XXX: only for integer */
23422347
},
23432348
{
23442349
left: [Number, BigInt, Float, Fraction, Complex, Mod,
23452350
Polynomial, PolyMod, RationalFunction, Series],
23462351
"*"(a, b) { return array_scalar_mul(b, a); },
2347-
"/"(a, b) { return array_scalar_div(b, a); },
2352+
"/"(a, b) { return a * array_element_wise_inverse(b); },
23482353
});
23492354

23502355
add_props(Array.prototype, {

quickjs-libc.c

+70-25
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
22
* QuickJS C library
33
*
4-
* Copyright (c) 2017-2020 Fabrice Bellard
5-
* Copyright (c) 2017-2020 Charlie Gordon
4+
* Copyright (c) 2017-2021 Fabrice Bellard
5+
* Copyright (c) 2017-2021 Charlie Gordon
66
*
77
* Permission is hereby granted, free of charge, to any person obtaining a copy
88
* of this software and associated documentation files (the "Software"), to deal
@@ -1663,7 +1663,7 @@ static JSValue js_os_isatty(JSContext *ctx, JSValueConst this_val,
16631663
int fd;
16641664
if (JS_ToInt32(ctx, &fd, argv[0]))
16651665
return JS_EXCEPTION;
1666-
return JS_NewBool(ctx, isatty(fd) == 1);
1666+
return JS_NewBool(ctx, (isatty(fd) != 0));
16671667
}
16681668

16691669
#if defined(_WIN32)
@@ -1689,6 +1689,10 @@ static JSValue js_os_ttyGetWinSize(JSContext *ctx, JSValueConst this_val,
16891689
return obj;
16901690
}
16911691

1692+
/* Windows 10 built-in VT100 emulation */
1693+
#define __ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
1694+
#define __ENABLE_VIRTUAL_TERMINAL_INPUT 0x0200
1695+
16921696
static JSValue js_os_ttySetRaw(JSContext *ctx, JSValueConst this_val,
16931697
int argc, JSValueConst *argv)
16941698
{
@@ -1698,8 +1702,12 @@ static JSValue js_os_ttySetRaw(JSContext *ctx, JSValueConst this_val,
16981702
if (JS_ToInt32(ctx, &fd, argv[0]))
16991703
return JS_EXCEPTION;
17001704
handle = (HANDLE)_get_osfhandle(fd);
1701-
1702-
SetConsoleMode(handle, ENABLE_WINDOW_INPUT);
1705+
SetConsoleMode(handle, ENABLE_WINDOW_INPUT | __ENABLE_VIRTUAL_TERMINAL_INPUT);
1706+
_setmode(fd, _O_BINARY);
1707+
if (fd == 0) {
1708+
handle = (HANDLE)_get_osfhandle(1); /* corresponding output */
1709+
SetConsoleMode(handle, ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT | __ENABLE_VIRTUAL_TERMINAL_PROCESSING);
1710+
}
17031711
return JS_UNDEFINED;
17041712
}
17051713
#else
@@ -1772,7 +1780,19 @@ static JSValue js_os_remove(JSContext *ctx, JSValueConst this_val,
17721780
filename = JS_ToCString(ctx, argv[0]);
17731781
if (!filename)
17741782
return JS_EXCEPTION;
1775-
ret = js_get_errno(remove(filename));
1783+
#if defined(_WIN32)
1784+
{
1785+
struct stat st;
1786+
if (stat(filename, &st) == 0 && S_ISDIR(st.st_mode)) {
1787+
ret = rmdir(filename);
1788+
} else {
1789+
ret = unlink(filename);
1790+
}
1791+
}
1792+
#else
1793+
ret = remove(filename);
1794+
#endif
1795+
ret = js_get_errno(ret);
17761796
JS_FreeCString(ctx, filename);
17771797
return JS_NewInt32(ctx, ret);
17781798
}
@@ -2588,7 +2608,47 @@ static JSValue js_os_utimes(JSContext *ctx, JSValueConst this_val,
25882608
return JS_NewInt32(ctx, ret);
25892609
}
25902610

2591-
#if !defined(_WIN32)
2611+
/* sleep(delay_ms) */
2612+
static JSValue js_os_sleep(JSContext *ctx, JSValueConst this_val,
2613+
int argc, JSValueConst *argv)
2614+
{
2615+
int64_t delay;
2616+
int ret;
2617+
2618+
if (JS_ToInt64(ctx, &delay, argv[0]))
2619+
return JS_EXCEPTION;
2620+
if (delay < 0)
2621+
delay = 0;
2622+
#if defined(_WIN32)
2623+
{
2624+
if (delay > INT32_MAX)
2625+
delay = INT32_MAX;
2626+
Sleep(delay);
2627+
ret = 0;
2628+
}
2629+
#else
2630+
{
2631+
struct timespec ts;
2632+
2633+
ts.tv_sec = delay / 1000;
2634+
ts.tv_nsec = (delay % 1000) * 1000000;
2635+
ret = js_get_errno(nanosleep(&ts, NULL));
2636+
}
2637+
#endif
2638+
return JS_NewInt32(ctx, ret);
2639+
}
2640+
2641+
#if defined(_WIN32)
2642+
static char *realpath(const char *path, char *buf)
2643+
{
2644+
if (!_fullpath(buf, path, PATH_MAX)) {
2645+
errno = ENOENT;
2646+
return NULL;
2647+
} else {
2648+
return buf;
2649+
}
2650+
}
2651+
#endif
25922652

25932653
/* return [path, errorcode] */
25942654
static JSValue js_os_realpath(JSContext *ctx, JSValueConst this_val,
@@ -2612,6 +2672,7 @@ static JSValue js_os_realpath(JSContext *ctx, JSValueConst this_val,
26122672
return make_string_error(ctx, buf, err);
26132673
}
26142674

2675+
#if !defined(_WIN32)
26152676
static JSValue js_os_symlink(JSContext *ctx, JSValueConst this_val,
26162677
int argc, JSValueConst *argv)
26172678
{
@@ -3031,22 +3092,6 @@ static JSValue js_os_kill(JSContext *ctx, JSValueConst this_val,
30313092
return JS_NewInt32(ctx, ret);
30323093
}
30333094

3034-
/* sleep(delay_ms) */
3035-
static JSValue js_os_sleep(JSContext *ctx, JSValueConst this_val,
3036-
int argc, JSValueConst *argv)
3037-
{
3038-
int64_t delay;
3039-
struct timespec ts;
3040-
int ret;
3041-
3042-
if (JS_ToInt64(ctx, &delay, argv[0]))
3043-
return JS_EXCEPTION;
3044-
ts.tv_sec = delay / 1000;
3045-
ts.tv_nsec = (delay % 1000) * 1000000;
3046-
ret = js_get_errno(nanosleep(&ts, NULL));
3047-
return JS_NewInt32(ctx, ret);
3048-
}
3049-
30503095
/* dup(fd) */
30513096
static JSValue js_os_dup(JSContext *ctx, JSValueConst this_val,
30523097
int argc, JSValueConst *argv)
@@ -3598,17 +3643,17 @@ static const JSCFunctionListEntry js_os_funcs[] = {
35983643
#endif
35993644
JS_CFUNC_MAGIC_DEF("stat", 1, js_os_stat, 0 ),
36003645
JS_CFUNC_DEF("utimes", 3, js_os_utimes ),
3646+
JS_CFUNC_DEF("sleep", 1, js_os_sleep ),
3647+
JS_CFUNC_DEF("realpath", 1, js_os_realpath ),
36013648
#if !defined(_WIN32)
36023649
JS_CFUNC_MAGIC_DEF("lstat", 1, js_os_stat, 1 ),
3603-
JS_CFUNC_DEF("realpath", 1, js_os_realpath ),
36043650
JS_CFUNC_DEF("symlink", 2, js_os_symlink ),
36053651
JS_CFUNC_DEF("readlink", 1, js_os_readlink ),
36063652
JS_CFUNC_DEF("exec", 1, js_os_exec ),
36073653
JS_CFUNC_DEF("waitpid", 2, js_os_waitpid ),
36083654
OS_FLAG(WNOHANG),
36093655
JS_CFUNC_DEF("pipe", 0, js_os_pipe ),
36103656
JS_CFUNC_DEF("kill", 2, js_os_kill ),
3611-
JS_CFUNC_DEF("sleep", 1, js_os_sleep ),
36123657
JS_CFUNC_DEF("dup", 1, js_os_dup ),
36133658
JS_CFUNC_DEF("dup2", 2, js_os_dup2 ),
36143659
#endif

0 commit comments

Comments
 (0)