Skip to content

update to upstream 2024-01-13 #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 82 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
95a3f5a
fixed invalid Array.prototype.push/unshift optimization
bellard Mar 6, 2022
7cd468f
added Object.hasOwn()
bellard Mar 6, 2022
aef044a
updated test262.conf
bellard Mar 6, 2022
f0cc4d2
updated to Unicode 14.0.0
bellard Mar 6, 2022
bd8cc5a
bf_set_ui() fix (github issue #133)
bellard Dec 1, 2023
971c2b4
fixed js_proxy_isArray stack overflow (github issue #178)
bellard Dec 1, 2023
99f8768
the BigInt support is now always included
bellard Dec 4, 2023
4c7e911
updated to unicode 15.0.0
Dec 5, 2023
53a78a1
keep LTO
Dec 5, 2023
307a28d
added String.prototype.at, Array.prototype.at and TypedArray.prototyp…
Dec 5, 2023
6e96270
added missing bignum error tests (github issue #159)
Dec 5, 2023
3ff80a9
fixed private field setters (github issue #194)
Dec 7, 2023
3a2ae64
fixed negative zero date
Dec 9, 2023
e28b001
Make Date methods argument coercion spec compliant (bnoordhuis)
Dec 9, 2023
86fbaf4
fixed lexical scope of 'this' with eval (github issue #192)
Dec 9, 2023
3c4f6a4
Retrieve RegExp 'g' flag in spec conformant way (original patch by bn…
Dec 9, 2023
21feed5
Implement extended named capture group identifiers (bnoordhuis)
Dec 9, 2023
fbc5a7f
reworked set property and fixed corner cases of typed array set property
Dec 9, 2023
1b1fefd
fixed delete super.x error
Dec 9, 2023
afaf2bc
Symbol.species is no longer used in TypedArray constructor from a Typ…
Dec 9, 2023
6f6c8b6
fixed duplicate static private setter/getter test
Dec 9, 2023
8243215
added Array.prototype.findLast{Index} and TypeArray.prototype.findLas…
Dec 9, 2023
f921bae
new release
Dec 9, 2023
299c3d1
raise an error if a private method is added twice to an object
Dec 13, 2023
aa2a8b6
added -fwrapv to CFLAGS to ensure that signed overflows have a well d…
Dec 13, 2023
da2f279
Fix AsyncGenerator.prototype.return error handling (bnoordhuis)
Dec 13, 2023
c172a02
fixed async generator in case of exception in the implicit await in t…
Dec 13, 2023
4af4b40
fixed 'return' handling with 'yield' in 'for of' or with finally bloc…
Dec 13, 2023
93be733
test 128 bit integer support (github issue #125)
Dec 22, 2023
512bfd5
fixed js_strtod with large integers (github issue #206)
Dec 22, 2023
d552447
safer typed array finalizer
Dec 22, 2023
7210077
added container_of macro
Dec 22, 2023
9f5137d
fixed define own property with writable=false on module namespace
Dec 22, 2023
e81ad30
removed incorrect await in async yield*
Dec 22, 2023
86bb3f5
'for of' expression cannot start with 'async'
Dec 22, 2023
89d21bd
use Unicode normalization in String.prototype.localeCompare
Dec 22, 2023
ec2e70f
removed unused JSContext field
Dec 22, 2023
d076a42
reduced JS_MAX_LOCAL_VARS (github issue #123)
Dec 22, 2023
3a859e1
call js_std_free_handlers() in the code generated by qjsc (github iss…
Dec 22, 2023
92f7fa1
top-level-await support - follow the spec in the implementation of th…
Dec 27, 2023
d536aa5
typos
Dec 27, 2023
9dc39a9
fixed detached TypedArray in sort()
Dec 27, 2023
23b4dbe
added String.prototype.isWellFormed and String.prototype.toWellFormed
Dec 27, 2023
47ec1a2
added Object.groupBy and Map.groupBy (initial patch by bnoordhuis)
Dec 27, 2023
ddfd9ae
added Array.prototype.{with,toReversed,toSpliced,toSorted} and TypedA…
Dec 27, 2023
264d410
added Promise.withResolvers
Dec 27, 2023
8c10866
added RegExp 'd' flag (bnoordhuis)
Dec 27, 2023
962db35
removed memory leak
Dec 27, 2023
d6b72a5
fixed the garbage collection of async functions with closures (github…
Dec 27, 2023
d6eebde
fixed crash when resizing property shapes in case of OOM (github issu…
Dec 27, 2023
dc0226a
fixed JS module autodetection with shebang (github issue #91)
Dec 27, 2023
57c0417
define the same atoms with or without CONFIG_ATOMICS (github issue #76)
Dec 27, 2023
3fcc200
added os.now()
Dec 27, 2023
2e7b26c
added Error cause
Jan 2, 2024
9c1814b
make JS_NewClassID thread safe
Jan 2, 2024
f71310d
allow 'await' in the REPL and added os.sleepAsync()
Jan 2, 2024
1b3178c
fixed crash in JS_DumpMemoryUsage (github issue #65)
Jan 2, 2024
76dd42a
added note about atomic operations
Jan 2, 2024
311c111
class static block (initial patch by bnoordhuis)
Jan 2, 2024
5e8a5f4
added 'in' operator for private fields
Jan 2, 2024
499cff7
added a comment for non-initialized warning in Valgrind (github issue…
Jan 6, 2024
ec8ca77
fixed test262: derived-this-uninitialized-realm.js
Jan 6, 2024
53e00f9
make for in faster and spec compliant (github issue #137)
Jan 6, 2024
dfb47ad
fixed run_test262_harness_test() with modules
Jan 6, 2024
e468b2b
avoid potentially undefined behavior and make valgrind happy (bnoordh…
Jan 8, 2024
65e8a03
fixed class name init in static initializers
Jan 8, 2024
10d3942
fixed next token parsing after a function definition (github issue #77)
Jan 8, 2024
a0a699e
fix worker termination in example (github issue #98)
Jan 8, 2024
63f9f67
fixed regexp case insensitive flag
Jan 8, 2024
bfebd3d
fixed Date.toLocaleString() (kuzmas)
Jan 8, 2024
ededcce
optional chaining fixes (github issue #103)
Jan 9, 2024
4b4313f
regexp: fixed the zero advance logic in quantifiers (github issue #158)
Jan 10, 2024
27b3cbb
added os.getpid()
Jan 11, 2024
9359ac2
more portable and Windows version for getTimezoneOffset() (github iss…
Jan 11, 2024
43a6d7a
update test results
Jan 11, 2024
8327812
fixed uninitialized harnessbuf
Jan 11, 2024
06b6144
native cosmopolitan build
Jan 11, 2024
512388b
fixed JS_GetScriptOrModuleName() in direct or indirect eval code
Jan 13, 2024
692814d
allow override of PREFIX, CROSS_PREFIX, CFLAGS and LDFLAGS in Makefil…
Jan 13, 2024
f16f546
new release
Jan 13, 2024
0cfb98b
getTimezoneOffset ifdef fix
1000TurquoisePogs May 14, 2025
5a8c5b9
Remove cases for missing OP "OP_iterator_close_return"
1000TurquoisePogs May 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
2024-01-13:

- top-level-await support in modules
- allow 'await' in the REPL
- added Array.prototype.{with,toReversed,toSpliced,toSorted} and
TypedArray.prototype.{with,toReversed,toSorted}
- added String.prototype.isWellFormed and String.prototype.toWellFormed
- added Object.groupBy and Map.groupBy
- added Promise.withResolvers
- class static block
- 'in' operator support for private fields
- optional chaining fixes
- added RegExp 'd' flag
- fixed RegExp zero length match logic
- fixed RegExp case insensitive flag
- added os.getpid() and os.now()
- added cosmopolitan build
- misc bug fixes

2023-12-09:

- added Object.hasOwn, {String|Array|TypedArray}.prototype.at,
{Array|TypedArray}.prototype.findLast{Index}
- BigInt support is enabled even if CONFIG_BIGNUM disabled
- updated to Unicode 15.0.0
- misc bug fixes

2021-03-27:

- faster Array.prototype.push and Array.prototype.unshift
Expand Down
93 changes: 55 additions & 38 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,40 +33,43 @@ CONFIG_LTO=y
#CONFIG_WERROR=y
# force 32 bit build for some utilities
#CONFIG_M32=y

ifdef CONFIG_DARWIN
# use clang instead of gcc
CONFIG_CLANG=y
CONFIG_DEFAULT_AR=y
endif
# cosmopolitan build (see https://github.com/jart/cosmopolitan)
#CONFIG_COSMO=y

# installation directory
prefix=/usr/local
PREFIX?=/usr/local

# use the gprof profiler
#CONFIG_PROFILE=y
# use address sanitizer
#CONFIG_ASAN=y
# include the code for BigInt/BigFloat/BigDecimal and math mode
# include the code for BigFloat/BigDecimal, math mode and faster large integers
CONFIG_BIGNUM=y

OBJDIR=.obj

ifdef CONFIG_DARWIN
# use clang instead of gcc
CONFIG_CLANG=y
CONFIG_DEFAULT_AR=y
endif

ifdef CONFIG_WIN32
ifdef CONFIG_M32
CROSS_PREFIX=i686-w64-mingw32-
CROSS_PREFIX?=i686-w64-mingw32-
else
CROSS_PREFIX=x86_64-w64-mingw32-
CROSS_PREFIX?=x86_64-w64-mingw32-
endif
EXE=.exe
else
CROSS_PREFIX=
CROSS_PREFIX?=
EXE=
endif

ifdef CONFIG_CLANG
HOST_CC=clang
CC=$(CROSS_PREFIX)clang
CFLAGS=-g -Wall -MMD -MF $(OBJDIR)/$(@F).d
CFLAGS+=-g -Wall -MMD -MF $(OBJDIR)/$(@F).d
CFLAGS += -Wextra
CFLAGS += -Wno-sign-compare
CFLAGS += -Wno-missing-field-initializers
Expand All @@ -84,10 +87,18 @@ ifdef CONFIG_CLANG
AR=$(CROSS_PREFIX)ar
endif
endif
else ifdef CONFIG_COSMO
CONFIG_LTO=
HOST_CC=gcc
CC=cosmocc
# cosmocc does not correct support -MF
CFLAGS=-g -Wall #-MMD -MF $(OBJDIR)/$(@F).d
CFLAGS += -Wno-array-bounds -Wno-format-truncation
AR=cosmoar
else
HOST_CC=gcc
CC=$(CROSS_PREFIX)gcc
CFLAGS=-g -Wall -MMD -MF $(OBJDIR)/$(@F).d
CFLAGS+=-g -Wall -MMD -MF $(OBJDIR)/$(@F).d
CFLAGS += -Wno-array-bounds -Wno-format-truncation
ifdef CONFIG_LTO
AR=$(CROSS_PREFIX)gcc-ar
Expand All @@ -96,6 +107,7 @@ else
endif
endif
STRIP=$(CROSS_PREFIX)strip
CFLAGS+=-fwrapv # ensure that signed overflows behave as expected
ifdef CONFIG_WERROR
CFLAGS+=-Werror
endif
Expand All @@ -112,7 +124,11 @@ CFLAGS_DEBUG=$(CFLAGS) -O0
CFLAGS_SMALL=$(CFLAGS) -Os
CFLAGS_OPT=$(CFLAGS) -O2
CFLAGS_NOLTO:=$(CFLAGS_OPT)
LDFLAGS=-g
ifdef CONFIG_COSMO
LDFLAGS+=-s # better to strip by default
else
LDFLAGS+=-g
endif
ifdef CONFIG_LTO
CFLAGS_SMALL+=-flto
CFLAGS_OPT+=-flto
Expand All @@ -132,6 +148,12 @@ else
LDEXPORT=-rdynamic
endif

ifndef CONFIG_COSMO
ifndef CONFIG_DARWIN
CONFIG_SHARED_LIBS=y # building shared libraries is supported
endif
endif

PROGS=qjs$(EXE) qjsc$(EXE) run-test262
ifneq ($(CROSS_PREFIX),)
QJSC_CC=gcc
Expand All @@ -154,23 +176,21 @@ endif

# examples
ifeq ($(CROSS_PREFIX),)
ifdef CONFIG_ASAN
PROGS+=
else
PROGS+=examples/hello examples/hello_module examples/test_fib
ifndef CONFIG_DARWIN
PROGS+=examples/fib.so examples/point.so
PROGS+=examples/hello
ifndef CONFIG_ASAN
PROGS+=examples/hello_module
endif
ifdef CONFIG_SHARED_LIBS
PROGS+=examples/test_fib examples/fib.so examples/point.so
endif
endif

all: $(OBJDIR) $(OBJDIR)/quickjs.check.o $(OBJDIR)/qjs.check.o $(PROGS)

QJS_LIB_OBJS=$(OBJDIR)/quickjs.o $(OBJDIR)/libregexp.o $(OBJDIR)/libunicode.o $(OBJDIR)/cutils.o $(OBJDIR)/quickjs-libc.o
QJS_LIB_OBJS=$(OBJDIR)/quickjs.o $(OBJDIR)/libregexp.o $(OBJDIR)/libunicode.o $(OBJDIR)/cutils.o $(OBJDIR)/quickjs-libc.o $(OBJDIR)/libbf.o

QJS_OBJS=$(OBJDIR)/qjs.o $(OBJDIR)/repl.o $(QJS_LIB_OBJS)
ifdef CONFIG_BIGNUM
QJS_LIB_OBJS+=$(OBJDIR)/libbf.o
QJS_OBJS+=$(OBJDIR)/qjscalc.o
endif

Expand Down Expand Up @@ -201,11 +221,11 @@ $(QJSC): $(OBJDIR)/qjsc.host.o \

endif #CROSS_PREFIX

QJSC_DEFINES:=-DCONFIG_CC=\"$(QJSC_CC)\" -DCONFIG_PREFIX=\"$(prefix)\"
QJSC_DEFINES:=-DCONFIG_CC=\"$(QJSC_CC)\" -DCONFIG_PREFIX=\"$(PREFIX)\"
ifdef CONFIG_LTO
QJSC_DEFINES+=-DCONFIG_LTO
endif
QJSC_HOST_DEFINES:=-DCONFIG_CC=\"$(HOST_CC)\" -DCONFIG_PREFIX=\"$(prefix)\"
QJSC_HOST_DEFINES:=-DCONFIG_CC=\"$(HOST_CC)\" -DCONFIG_PREFIX=\"$(PREFIX)\"

$(OBJDIR)/qjsc.o: CFLAGS+=$(QJSC_DEFINES)
$(OBJDIR)/qjsc.host.o: CFLAGS+=$(QJSC_HOST_DEFINES)
Expand Down Expand Up @@ -298,17 +318,17 @@ clean:
rm -rf run-test262-debug run-test262-32

install: all
mkdir -p "$(DESTDIR)$(prefix)/bin"
mkdir -p "$(DESTDIR)$(PREFIX)/bin"
$(STRIP) qjs qjsc
install -m755 qjs qjsc "$(DESTDIR)$(prefix)/bin"
ln -sf qjs "$(DESTDIR)$(prefix)/bin/qjscalc"
mkdir -p "$(DESTDIR)$(prefix)/lib/quickjs"
install -m644 libquickjs.a "$(DESTDIR)$(prefix)/lib/quickjs"
install -m755 qjs qjsc "$(DESTDIR)$(PREFIX)/bin"
ln -sf qjs "$(DESTDIR)$(PREFIX)/bin/qjscalc"
mkdir -p "$(DESTDIR)$(PREFIX)/lib/quickjs"
install -m644 libquickjs.a "$(DESTDIR)$(PREFIX)/lib/quickjs"
ifdef CONFIG_LTO
install -m644 libquickjs.lto.a "$(DESTDIR)$(prefix)/lib/quickjs"
install -m644 libquickjs.lto.a "$(DESTDIR)$(PREFIX)/lib/quickjs"
endif
mkdir -p "$(DESTDIR)$(prefix)/include/quickjs"
install -m644 quickjs.h quickjs-libc.h "$(DESTDIR)$(prefix)/include/quickjs"
mkdir -p "$(DESTDIR)$(PREFIX)/include/quickjs"
install -m644 quickjs.h quickjs-libc.h "$(DESTDIR)$(PREFIX)/include/quickjs"

###############################################################################
# examples
Expand All @@ -317,10 +337,7 @@ endif
HELLO_SRCS=examples/hello.js
HELLO_OPTS=-fno-string-normalize -fno-map -fno-promise -fno-typedarray \
-fno-typedarray -fno-regexp -fno-json -fno-eval -fno-proxy \
-fno-date -fno-module-loader
ifdef CONFIG_BIGNUM
HELLO_OPTS+=-fno-bigint
endif
-fno-date -fno-module-loader -fno-bigint

hello.c: $(QJSC) $(HELLO_SRCS)
$(QJSC) -e $(HELLO_OPTS) -o $@ $(HELLO_SRCS)
Expand Down Expand Up @@ -377,7 +394,7 @@ doc/%.html: doc/%.html.pre
###############################################################################
# tests

ifndef CONFIG_DARWIN
ifdef CONFIG_SHARED_LIBS
test: tests/bjson.so examples/point.so
endif
ifdef CONFIG_M32
Expand All @@ -391,7 +408,7 @@ test: qjs
./qjs tests/test_loop.js
./qjs tests/test_std.js
./qjs tests/test_worker.js
ifndef CONFIG_DARWIN
ifdef CONFIG_SHARED_LIBS
ifdef CONFIG_BIGNUM
./qjs --bignum tests/test_bjson.js
else
Expand Down
7 changes: 2 additions & 5 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
Bugs:
- modules: better error handling with cyclic module references

Misc ideas:
- use custom printf to avoid compatibility issues with floating point numbers
- consistent naming for preprocessor defines
Expand Down Expand Up @@ -66,5 +63,5 @@ Optimization ideas:
Test262o: 0/11262 errors, 463 excluded
Test262o commit: 7da91bceb9ce7613f87db47ddd1292a2dda58b42 (es5-tests branch)

Result: 35/75280 errors, 909 excluded, 585 skipped
Test262 commit: 31126581e7290f9233c29cefd93f66c6ac78f1c9
Result: 10/76947 errors, 1497 excluded, 8117 skipped
Test262 commit: 6cbb6da9473c56d95358d8e679c5a6d2b4574efb
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2021-03-27
2024-01-13
3 changes: 3 additions & 0 deletions cutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
#define countof(x) (sizeof(x) / sizeof((x)[0]))
#endif

/* return the pointer of type 'type *' containing 'ptr' as field 'member' */
#define container_of(ptr, type, member) ((type *)((uint8_t *)(ptr) - offsetof(type, member)))

typedef int BOOL;

#ifndef FALSE
Expand Down
53 changes: 38 additions & 15 deletions doc/quickjs.texi
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

@chapter Introduction

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

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

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

@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.
@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.

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

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

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

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

Note: On some OSes atomic operations are not available or need a
specific library. If you get related errors, you should either add
@code{-latomics} in the Makefile @code{LIBS} variable or disable
@code{CONFIG_ATOMICS} in @file{quickjs.c}.

@section Quick start

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

@section Language support

@subsection ES2020 support
@subsection ES2023 support

The ES2020 specification is almost fully supported including the Annex
The ES2023 specification is almost fully supported including the Annex
B (legacy web compatibility) and the Unicode related features.

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

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

@item WeakRef and FinalizationRegistry objects

@item Symbols as WeakMap keys

@end itemize

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

@item loadScript(filename)
Expand Down Expand Up @@ -749,6 +761,9 @@ object containing optional parameters:

@end table

@item getpid()
Return the current process ID.

@item waitpid(pid, options)
@code{waitpid} Unix system call. Return the array @code{[ret,
status]}. @code{ret} contains @code{-errno} in case of error.
Expand All @@ -769,6 +784,17 @@ write_fd]} or null in case of error.
@item sleep(delay_ms)
Sleep during @code{delay_ms} milliseconds.

@item sleepAsync(delay_ms)
Asynchronouse sleep during @code{delay_ms} milliseconds. Returns a promise. Example:
@example
await os.sleepAsync(500);
@end example

@item now()
Return a timestamp in milliseconds with more precision than
@code{Date.now()}. The time origin is unspecified and is normally not
impacted by system clock adjustments.

@item setTimeout(func, delay)
Call the function @code{func} after @code{delay} ms. Return a handle
to the timer.
Expand Down Expand Up @@ -1053,17 +1079,14 @@ stack holds the Javascript parameters and local variables.
@section RegExp

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

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

Infinite recursions coming from quantifiers with empty terms are
avoided.

The full regexp library weights about 15 KiB (x86 code), excluding the
Unicode library.

Expand Down
Loading