Skip to content

Commit 5e05c55

Browse files
committed
更新到2024-01-13版本
1 parent e3dd446 commit 5e05c55

32 files changed

+3720
-1423
lines changed

Changelog

+19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
2024-01-13:
2+
3+
- top-level-await support in modules
4+
- allow 'await' in the REPL
5+
- added Array.prototype.{with,toReversed,toSpliced,toSorted} and
6+
TypedArray.prototype.{with,toReversed,toSorted}
7+
- added String.prototype.isWellFormed and String.prototype.toWellFormed
8+
- added Object.groupBy and Map.groupBy
9+
- added Promise.withResolvers
10+
- class static block
11+
- 'in' operator support for private fields
12+
- optional chaining fixes
13+
- added RegExp 'd' flag
14+
- fixed RegExp zero length match logic
15+
- fixed RegExp case insensitive flag
16+
- added os.getpid() and os.now()
17+
- added cosmopolitan build
18+
- misc bug fixes
19+
120
2023-12-09:
221

322
- added Object.hasOwn, {String|Array|TypedArray}.prototype.at,

Makefile

+52-31
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,11 @@ CONFIG_LTO=y
3333
#CONFIG_WERROR=y
3434
# force 32 bit build for some utilities
3535
#CONFIG_M32=y
36-
37-
ifdef CONFIG_DARWIN
38-
# use clang instead of gcc
39-
CONFIG_CLANG=y
40-
CONFIG_DEFAULT_AR=y
41-
endif
36+
# cosmopolitan build (see https://github.com/jart/cosmopolitan)
37+
#CONFIG_COSMO=y
4238

4339
# installation directory
44-
prefix=/usr/local
40+
PREFIX?=/usr/local
4541

4642
# use the gprof profiler
4743
#CONFIG_PROFILE=y
@@ -52,21 +48,28 @@ CONFIG_BIGNUM=y
5248

5349
OBJDIR=.obj
5450

51+
ifdef CONFIG_DARWIN
52+
# use clang instead of gcc
53+
CONFIG_CLANG=y
54+
CONFIG_DEFAULT_AR=y
55+
endif
56+
5557
ifdef CONFIG_WIN32
5658
ifdef CONFIG_M32
57-
CROSS_PREFIX=i686-w64-mingw32-
59+
CROSS_PREFIX?=i686-w64-mingw32-
5860
else
59-
CROSS_PREFIX=x86_64-w64-mingw32-
61+
CROSS_PREFIX?=x86_64-w64-mingw32-
6062
endif
6163
EXE=.exe
6264
else
63-
CROSS_PREFIX=
65+
CROSS_PREFIX?=
6466
EXE=
6567
endif
68+
6669
ifdef CONFIG_CLANG
6770
HOST_CC=clang
6871
CC=$(CROSS_PREFIX)clang
69-
CFLAGS=-g -Wall -MMD -MF $(OBJDIR)/$(@F).d
72+
CFLAGS+=-g -Wall -MMD -MF $(OBJDIR)/$(@F).d
7073
CFLAGS += -Wextra
7174
CFLAGS += -Wno-sign-compare
7275
CFLAGS += -Wno-missing-field-initializers
@@ -84,10 +87,18 @@ ifdef CONFIG_CLANG
8487
AR=$(CROSS_PREFIX)ar
8588
endif
8689
endif
90+
else ifdef CONFIG_COSMO
91+
CONFIG_LTO=
92+
HOST_CC=gcc
93+
CC=cosmocc
94+
# cosmocc does not correct support -MF
95+
CFLAGS=-g -Wall #-MMD -MF $(OBJDIR)/$(@F).d
96+
CFLAGS += -Wno-array-bounds -Wno-format-truncation
97+
AR=cosmoar
8798
else
8899
HOST_CC=gcc
89100
CC=$(CROSS_PREFIX)gcc
90-
CFLAGS=-g -Wall -MMD -MF $(OBJDIR)/$(@F).d
101+
CFLAGS+=-g -Wall -MMD -MF $(OBJDIR)/$(@F).d
91102
CFLAGS += -Wno-array-bounds -Wno-format-truncation
92103
ifdef CONFIG_LTO
93104
AR=$(CROSS_PREFIX)gcc-ar
@@ -96,6 +107,7 @@ else
96107
endif
97108
endif
98109
STRIP=$(CROSS_PREFIX)strip
110+
CFLAGS+=-fwrapv # ensure that signed overflows behave as expected
99111
ifdef CONFIG_WERROR
100112
CFLAGS+=-Werror
101113
endif
@@ -112,7 +124,11 @@ CFLAGS_DEBUG=$(CFLAGS) -O0
112124
CFLAGS_SMALL=$(CFLAGS) -Os
113125
CFLAGS_OPT=$(CFLAGS) -O2
114126
CFLAGS_NOLTO:=$(CFLAGS_OPT)
115-
LDFLAGS=-g
127+
ifdef CONFIG_COSMO
128+
LDFLAGS+=-s # better to strip by default
129+
else
130+
LDFLAGS+=-g
131+
endif
116132
ifdef CONFIG_LTO
117133
CFLAGS_SMALL+=-flto
118134
CFLAGS_OPT+=-flto
@@ -132,6 +148,12 @@ else
132148
LDEXPORT=-rdynamic
133149
endif
134150

151+
ifndef CONFIG_COSMO
152+
ifndef CONFIG_DARWIN
153+
CONFIG_SHARED_LIBS=y # building shared libraries is supported
154+
endif
155+
endif
156+
135157
PROGS=qjs$(EXE) qjsc$(EXE) run-test262
136158
ifneq ($(CROSS_PREFIX),)
137159
QJSC_CC=gcc
@@ -154,13 +176,12 @@ endif
154176

155177
# examples
156178
ifeq ($(CROSS_PREFIX),)
157-
ifdef CONFIG_ASAN
158-
PROGS+=
159-
else
160-
PROGS+=examples/hello examples/hello_module examples/test_fib
161-
ifndef CONFIG_DARWIN
162-
PROGS+=examples/fib.so examples/point.so
179+
PROGS+=examples/hello
180+
ifndef CONFIG_ASAN
181+
PROGS+=examples/hello_module
163182
endif
183+
ifdef CONFIG_SHARED_LIBS
184+
PROGS+=examples/test_fib examples/fib.so examples/point.so
164185
endif
165186
endif
166187

@@ -200,11 +221,11 @@ $(QJSC): $(OBJDIR)/qjsc.host.o \
200221

201222
endif #CROSS_PREFIX
202223

203-
QJSC_DEFINES:=-DCONFIG_CC=\"$(QJSC_CC)\" -DCONFIG_PREFIX=\"$(prefix)\"
224+
QJSC_DEFINES:=-DCONFIG_CC=\"$(QJSC_CC)\" -DCONFIG_PREFIX=\"$(PREFIX)\"
204225
ifdef CONFIG_LTO
205226
QJSC_DEFINES+=-DCONFIG_LTO
206227
endif
207-
QJSC_HOST_DEFINES:=-DCONFIG_CC=\"$(HOST_CC)\" -DCONFIG_PREFIX=\"$(prefix)\"
228+
QJSC_HOST_DEFINES:=-DCONFIG_CC=\"$(HOST_CC)\" -DCONFIG_PREFIX=\"$(PREFIX)\"
208229

209230
$(OBJDIR)/qjsc.o: CFLAGS+=$(QJSC_DEFINES)
210231
$(OBJDIR)/qjsc.host.o: CFLAGS+=$(QJSC_HOST_DEFINES)
@@ -297,17 +318,17 @@ clean:
297318
rm -rf run-test262-debug run-test262-32
298319

299320
install: all
300-
mkdir -p "$(DESTDIR)$(prefix)/bin"
321+
mkdir -p "$(DESTDIR)$(PREFIX)/bin"
301322
$(STRIP) qjs qjsc
302-
install -m755 qjs qjsc "$(DESTDIR)$(prefix)/bin"
303-
ln -sf qjs "$(DESTDIR)$(prefix)/bin/qjscalc"
304-
mkdir -p "$(DESTDIR)$(prefix)/lib/quickjs"
305-
install -m644 libquickjs.a "$(DESTDIR)$(prefix)/lib/quickjs"
323+
install -m755 qjs qjsc "$(DESTDIR)$(PREFIX)/bin"
324+
ln -sf qjs "$(DESTDIR)$(PREFIX)/bin/qjscalc"
325+
mkdir -p "$(DESTDIR)$(PREFIX)/lib/quickjs"
326+
install -m644 libquickjs.a "$(DESTDIR)$(PREFIX)/lib/quickjs"
306327
ifdef CONFIG_LTO
307-
install -m644 libquickjs.lto.a "$(DESTDIR)$(prefix)/lib/quickjs"
328+
install -m644 libquickjs.lto.a "$(DESTDIR)$(PREFIX)/lib/quickjs"
308329
endif
309-
mkdir -p "$(DESTDIR)$(prefix)/include/quickjs"
310-
install -m644 quickjs.h quickjs-libc.h "$(DESTDIR)$(prefix)/include/quickjs"
330+
mkdir -p "$(DESTDIR)$(PREFIX)/include/quickjs"
331+
install -m644 quickjs.h quickjs-libc.h "$(DESTDIR)$(PREFIX)/include/quickjs"
311332

312333
###############################################################################
313334
# examples
@@ -373,7 +394,7 @@ doc/%.html: doc/%.html.pre
373394
###############################################################################
374395
# tests
375396

376-
ifndef CONFIG_DARWIN
397+
ifdef CONFIG_SHARED_LIBS
377398
test: tests/bjson.so examples/point.so
378399
endif
379400
ifdef CONFIG_M32
@@ -387,7 +408,7 @@ test: qjs
387408
./qjs tests/test_loop.js
388409
./qjs tests/test_std.js
389410
./qjs tests/test_worker.js
390-
ifndef CONFIG_DARWIN
411+
ifdef CONFIG_SHARED_LIBS
391412
ifdef CONFIG_BIGNUM
392413
./qjs --bignum tests/test_bjson.js
393414
else

TODO

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
Bugs:
2-
- modules: better error handling with cyclic module references
3-
41
Misc ideas:
52
- use custom printf to avoid compatibility issues with floating point numbers
63
- consistent naming for preprocessor defines
@@ -66,5 +63,5 @@ Optimization ideas:
6663
Test262o: 0/11262 errors, 463 excluded
6764
Test262o commit: 7da91bceb9ce7613f87db47ddd1292a2dda58b42 (es5-tests branch)
6865

69-
Result: 35/75280 errors, 909 excluded, 585 skipped
70-
Test262 commit: 31126581e7290f9233c29cefd93f66c6ac78f1c9
66+
Result: 10/76947 errors, 1497 excluded, 8117 skipped
67+
Test262 commit: 6cbb6da9473c56d95358d8e679c5a6d2b4574efb

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2023-12-09
1+
2024-01-13

cutils.h

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
#define countof(x) (sizeof(x) / sizeof((x)[0]))
5050
#endif
5151

52+
/* return the pointer of type 'type *' containing 'ptr' as field 'member' */
53+
#define container_of(ptr, type, member) ((type *)((uint8_t *)(ptr) - offsetof(type, member)))
54+
5255
typedef int BOOL;
5356

5457
#ifndef FALSE

doc/quickjs.texi

+38-15
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
@chapter Introduction
2121

22-
QuickJS is a small and embeddable Javascript engine. It supports the
23-
ES2020 specification
24-
@footnote{@url{https://tc39.es/ecma262/}}
22+
QuickJS is a small and embeddable Javascript engine. It supports most of the
23+
ES2023 specification
24+
@footnote{@url{https://tc39.es/ecma262/2023 }}
2525
including modules, asynchronous generators, proxies and BigInt.
2626

2727
It supports mathematical extensions such as big decimal float float
@@ -34,14 +34,14 @@ and operator overloading.
3434

3535
@item Small and easily embeddable: just a few C files, no external dependency, 210 KiB of x86 code for a simple ``hello world'' program.
3636

37-
@item Fast interpreter with very low startup time: runs the 69000 tests of the ECMAScript Test Suite@footnote{@url{https://github.com/tc39/test262}} in about 95 seconds on a single core of a desktop PC. The complete life cycle of a runtime instance completes in less than 300 microseconds.
37+
@item Fast interpreter with very low startup time: runs the 77000 tests of the ECMAScript Test Suite@footnote{@url{https://github.com/tc39/test262}} in less than 2 minutes on a single core of a desktop PC. The complete life cycle of a runtime instance completes in less than 300 microseconds.
3838

39-
@item Almost complete ES2020 support including modules, asynchronous
40-
generators and full Annex B support (legacy web compatibility). Many
41-
features from the upcoming ES2021 specification
42-
@footnote{@url{https://tc39.github.io/ecma262/}} are also supported.
39+
@item Almost complete ES2023 support including modules, asynchronous
40+
generators and full Annex B support (legacy web compatibility). Some
41+
features from the upcoming ES2024 specification
42+
@footnote{@url{https://tc39.es/ecma262/}} are also supported.
4343

44-
@item Passes nearly 100% of the ECMAScript Test Suite tests when selecting the ES2020 features.
44+
@item Passes nearly 100% of the ECMAScript Test Suite tests when selecting the ES2023 features.
4545

4646
@item Compile Javascript sources to executables with no external dependency.
4747

@@ -69,6 +69,11 @@ options then run @code{make}.
6969
You can type @code{make install} as root if you wish to install the binaries and support files to
7070
@code{/usr/local} (this is not necessary to use QuickJS).
7171

72+
Note: On some OSes atomic operations are not available or need a
73+
specific library. If you get related errors, you should either add
74+
@code{-latomics} in the Makefile @code{LIBS} variable or disable
75+
@code{CONFIG_ATOMICS} in @file{quickjs.c}.
76+
7277
@section Quick start
7378

7479
@code{qjs} is the command line interpreter (Read-Eval-Print Loop). You can pass
@@ -265,9 +270,9 @@ about 100 seconds).
265270

266271
@section Language support
267272

268-
@subsection ES2020 support
273+
@subsection ES2023 support
269274

270-
The ES2020 specification is almost fully supported including the Annex
275+
The ES2023 specification is almost fully supported including the Annex
271276
B (legacy web compatibility) and the Unicode related features.
272277

273278
The following features are not supported yet:
@@ -276,6 +281,10 @@ The following features are not supported yet:
276281

277282
@item Tail calls@footnote{We believe the current specification of tails calls is too complicated and presents limited practical interests.}
278283

284+
@item WeakRef and FinalizationRegistry objects
285+
286+
@item Symbols as WeakMap keys
287+
279288
@end itemize
280289

281290
@subsection ECMA402
@@ -368,6 +377,9 @@ optional properties:
368377
@item backtrace_barrier
369378
Boolean (default = false). If true, error backtraces do not list the
370379
stack frames below the evalScript.
380+
@item async
381+
Boolean (default = false). If true, @code{await} is accepted in the
382+
script and a promise is returned.
371383
@end table
372384

373385
@item loadScript(filename)
@@ -749,6 +761,9 @@ object containing optional parameters:
749761

750762
@end table
751763

764+
@item getpid()
765+
Return the current process ID.
766+
752767
@item waitpid(pid, options)
753768
@code{waitpid} Unix system call. Return the array @code{[ret,
754769
status]}. @code{ret} contains @code{-errno} in case of error.
@@ -769,6 +784,17 @@ write_fd]} or null in case of error.
769784
@item sleep(delay_ms)
770785
Sleep during @code{delay_ms} milliseconds.
771786

787+
@item sleepAsync(delay_ms)
788+
Asynchronouse sleep during @code{delay_ms} milliseconds. Returns a promise. Example:
789+
@example
790+
await os.sleepAsync(500);
791+
@end example
792+
793+
@item now()
794+
Return a timestamp in milliseconds with more precision than
795+
@code{Date.now()}. The time origin is unspecified and is normally not
796+
impacted by system clock adjustments.
797+
772798
@item setTimeout(func, delay)
773799
Call the function @code{func} after @code{delay} ms. Return a handle
774800
to the timer.
@@ -1053,17 +1079,14 @@ stack holds the Javascript parameters and local variables.
10531079
@section RegExp
10541080

10551081
A specific regular expression engine was developed. It is both small
1056-
and efficient and supports all the ES2020 features including the
1082+
and efficient and supports all the ES2023 features including the
10571083
Unicode properties. As the Javascript compiler, it directly generates
10581084
bytecode without a parse tree.
10591085

10601086
Backtracking with an explicit stack is used so that there is no
10611087
recursion on the system stack. Simple quantifiers are specifically
10621088
optimized to avoid recursions.
10631089

1064-
Infinite recursions coming from quantifiers with empty terms are
1065-
avoided.
1066-
10671090
The full regexp library weights about 15 KiB (x86 code), excluding the
10681091
Unicode library.
10691092

libbf.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <stddef.h>
2828
#include <stdint.h>
2929

30-
#if INTPTR_MAX >= INT64_MAX
30+
#if defined(__SIZEOF_INT128__) && (INTPTR_MAX >= INT64_MAX)
3131
#define LIMB_LOG2_BITS 6
3232
#else
3333
#define LIMB_LOG2_BITS 5

libregexp-opcode.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ DEF(range32, 3) /* variable length */
5050
DEF(lookahead, 5)
5151
DEF(negative_lookahead, 5)
5252
DEF(push_char_pos, 1) /* push the character position on the stack */
53-
DEF(bne_char_pos, 5) /* pop one stack element and jump if equal to the character
54-
position */
53+
DEF(check_advance, 1) /* pop one stack element and check that it is different from the character position */
5554
DEF(prev, 1) /* go to the previous char */
5655
DEF(simple_greedy_quant, 17)
5756

0 commit comments

Comments
 (0)