Skip to content

Commit

Permalink
Merge pull request #5 from L-jasmine/bump/quickjs_2024
Browse files Browse the repository at this point in the history
Bump/quickjs 2024
  • Loading branch information
L-jasmine authored Jan 29, 2024
2 parents 210721f + 5b11512 commit 84589b6
Show file tree
Hide file tree
Showing 41 changed files with 7,127 additions and 5,774 deletions.
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.sleepAsync(), 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 @@ endif
#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 @@ -115,7 +127,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 @@ -135,6 +151,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 @@ -157,23 +179,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 @@ -204,11 +224,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 @@ -301,17 +321,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 @@ -320,10 +340,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 @@ -380,7 +397,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 @@ -394,7 +411,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: 8/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 @@ -49,6 +49,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

0 comments on commit 84589b6

Please sign in to comment.