mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 08:12:28 +00:00
Fix issues revealed by ECMAScript test262
Cosmopolitan's QuickJS is now equally conformant and performant, with the exception of Atomics, which have been disabled since Cosmopolitan currently doesn't support pthreads. QuickJS memory usage -- BigNum 2021-03-27 version, 64-bit, malloc limit: -1 NAME COUNT SIZE memory allocated 937 131764 (140.6 per block) memory used 938 116103 (8 overhead, 16.7 average slack) atoms 513 21408 (41.7 per atom) objects 170 12279 (72.2 per object) properties 864 15531 (5.1 per object) shapes 58 12995 (224.1 per shape) bytecode functions 13 1512 bytecode 13 867 (66.7 per function) C functions 99 arrays 1 fast arrays 1 elements 1 16 (1.0 per fast array) Result: 35/74740 errors, 1279 excluded, 485 skipped, 19 new, 2 fixed real 2m40.828s user 2m29.764s sys 0m10.939s
This commit is contained in:
parent
8f52c0d773
commit
8a91518633
38 changed files with 395 additions and 184 deletions
7
third_party/quickjs/README.cosmo
vendored
7
third_party/quickjs/README.cosmo
vendored
|
@ -1,2 +1,7 @@
|
|||
Source:
|
||||
https://bellard.org/quickjs/quickjs-2021-03-27.tar.xz
|
||||
- https://bellard.org/quickjs/quickjs-2021-03-27.tar.xz
|
||||
|
||||
Local Changes:
|
||||
- Replace snprintf with xasprintf in find_unique_cname
|
||||
- Squash uninitialized read of harnessbuf in run-test262.c
|
||||
- Change run-test262.c to not rebase configured paths
|
||||
|
|
57
third_party/quickjs/quickjs-libc.c
vendored
57
third_party/quickjs/quickjs-libc.c
vendored
|
@ -2764,61 +2764,6 @@ static char **build_envp(JSContext *ctx, JSValueConst obj)
|
|||
goto done;
|
||||
}
|
||||
|
||||
/* execvpe is not available on non GNU systems */
|
||||
static int my_execvpe(const char *filename, char **argv, char **envp)
|
||||
{
|
||||
char *path, *p, *p_next, *p1;
|
||||
char buf[PATH_MAX];
|
||||
size_t filename_len, path_len;
|
||||
BOOL eacces_error;
|
||||
|
||||
filename_len = strlen(filename);
|
||||
if (filename_len == 0) {
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
if (strchr(filename, '/'))
|
||||
return execve(filename, argv, envp);
|
||||
|
||||
path = getenv("PATH");
|
||||
if (!path)
|
||||
path = (char *)"/bin:/usr/bin";
|
||||
eacces_error = FALSE;
|
||||
p = path;
|
||||
for(p = path; p != NULL; p = p_next) {
|
||||
p1 = strchr(p, ':');
|
||||
if (!p1) {
|
||||
p_next = NULL;
|
||||
path_len = strlen(p);
|
||||
} else {
|
||||
p_next = p1 + 1;
|
||||
path_len = p1 - p;
|
||||
}
|
||||
/* path too long */
|
||||
if ((path_len + 1 + filename_len + 1) > PATH_MAX)
|
||||
continue;
|
||||
memcpy(buf, p, path_len);
|
||||
buf[path_len] = '/';
|
||||
memcpy(buf + path_len + 1, filename, filename_len);
|
||||
buf[path_len + 1 + filename_len] = '\0';
|
||||
|
||||
execve(buf, argv, envp);
|
||||
|
||||
if (errno == EACCES) {
|
||||
eacces_error = TRUE;
|
||||
} else if (errno == ENOENT) {
|
||||
/* do nothing */
|
||||
} else if (errno == ENOTDIR) {
|
||||
/* do nothing */
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (eacces_error)
|
||||
errno = EACCES;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* exec(args[, options]) -> exitcode */
|
||||
static JSValue js_os_exec(JSContext *ctx, JSValueConst this_val,
|
||||
int argc, JSValueConst *argv)
|
||||
|
@ -2973,7 +2918,7 @@ static JSValue js_os_exec(JSContext *ctx, JSValueConst this_val,
|
|||
if (!file)
|
||||
file = exec_argv[0];
|
||||
if (use_path)
|
||||
ret = my_execvpe(file, (char **)exec_argv, envp);
|
||||
ret = execvpe(file, (char **)exec_argv, envp);
|
||||
else
|
||||
ret = execve(file, (char **)exec_argv, envp);
|
||||
_exit(127);
|
||||
|
|
20
third_party/quickjs/quickjs.c
vendored
20
third_party/quickjs/quickjs.c
vendored
|
@ -11296,11 +11296,11 @@ static char *i64toa(char *buf_end, int64_t n, unsigned int base)
|
|||
static void js_ecvt1(double d, int n_digits, int *decpt, int *sign, char *buf,
|
||||
int rounding_mode, char *buf1, int buf1_size)
|
||||
{
|
||||
/* if (rounding_mode != FE_TONEAREST) */
|
||||
/* fesetround(rounding_mode); */
|
||||
if (rounding_mode != FE_TONEAREST)
|
||||
fesetround(rounding_mode);
|
||||
snprintf(buf1, buf1_size, "%+.*e", n_digits - 1, d);
|
||||
/* if (rounding_mode != FE_TONEAREST) */
|
||||
/* fesetround(FE_TONEAREST); */
|
||||
if (rounding_mode != FE_TONEAREST)
|
||||
fesetround(FE_TONEAREST);
|
||||
*sign = (buf1[0] == '-');
|
||||
/* mantissa */
|
||||
buf[0] = buf1[1];
|
||||
|
@ -53608,12 +53608,12 @@ static JSValue js_atomics_op(JSContext *ctx,
|
|||
a = func_name((_Atomic(uint32_t) *)ptr, v); \
|
||||
break;
|
||||
#endif
|
||||
/* OP(ADD, atomic_fetch_add) */
|
||||
/* OP(AND, atomic_fetch_and) */
|
||||
/* OP(OR, atomic_fetch_or) */
|
||||
/* OP(SUB, atomic_fetch_sub) */
|
||||
/* OP(XOR, atomic_fetch_xor) */
|
||||
/* OP(EXCHANGE, atomic_exchange) */
|
||||
OP(ADD, atomic_fetch_add)
|
||||
OP(AND, atomic_fetch_and)
|
||||
OP(OR, atomic_fetch_or)
|
||||
OP(SUB, atomic_fetch_sub)
|
||||
OP(XOR, atomic_fetch_xor)
|
||||
OP(EXCHANGE, atomic_exchange)
|
||||
#undef OP
|
||||
|
||||
case ATOMICS_OP_LOAD | (0 << 3):
|
||||
|
|
182
third_party/quickjs/quickjs.mk
vendored
182
third_party/quickjs/quickjs.mk
vendored
|
@ -3,83 +3,151 @@
|
|||
|
||||
PKGS += THIRD_PARTY_QUICKJS
|
||||
|
||||
THIRD_PARTY_QUICKJS_FILES := $(wildcard third_party/quickjs/*)
|
||||
THIRD_PARTY_QUICKJS_SRCS = $(filter %.c,$(THIRD_PARTY_QUICKJS_FILES))
|
||||
THIRD_PARTY_QUICKJS_HDRS = $(filter %.h,$(THIRD_PARTY_QUICKJS_FILES))
|
||||
THIRD_PARTY_QUICKJS_ARTIFACTS += THIRD_PARTY_QUICKJS_A
|
||||
THIRD_PARTY_QUICKJS_BINS = $(THIRD_PARTY_QUICKJS_COMS) $(THIRD_PARTY_QUICKJS_COMS:%=%.dbg)
|
||||
THIRD_PARTY_QUICKJS = $(THIRD_PARTY_QUICKJS_DEPS) $(THIRD_PARTY_QUICKJS_A)
|
||||
THIRD_PARTY_QUICKJS = $(THIRD_PARTY_QUICKJS_A_DEPS) $(THIRD_PARTY_QUICKJS_A)
|
||||
THIRD_PARTY_QUICKJS_A = o/$(MODE)/third_party/quickjs/quickjs.a
|
||||
THIRD_PARTY_QUICKJS_HDRS = $(foreach x,$(THIRD_PARTY_QUICKJS_ARTIFACTS),$($(x)_HDRS))
|
||||
|
||||
THIRD_PARTY_QUICKJS_OBJS = \
|
||||
$(THIRD_PARTY_QUICKJS_SRCS:%.c=o/$(MODE)/%.o)
|
||||
THIRD_PARTY_QUICKJS_A_SRCS = \
|
||||
third_party/quickjs/cutils.c \
|
||||
third_party/quickjs/libbf.c \
|
||||
third_party/quickjs/libregexp.c \
|
||||
third_party/quickjs/libunicode.c \
|
||||
third_party/quickjs/quickjs-libc.c \
|
||||
third_party/quickjs/quickjs.c \
|
||||
third_party/quickjs/wut.c
|
||||
|
||||
THIRD_PARTY_QUICKJS_COMS = \
|
||||
o/$(MODE)/third_party/quickjs/qjs.com
|
||||
THIRD_PARTY_QUICKJS_A_HDRS = \
|
||||
third_party/quickjs/cutils.h \
|
||||
third_party/quickjs/libbf.h \
|
||||
third_party/quickjs/libregexp.h \
|
||||
third_party/quickjs/libunicode.h \
|
||||
third_party/quickjs/list.h \
|
||||
third_party/quickjs/quickjs-libc.h \
|
||||
third_party/quickjs/quickjs.h
|
||||
|
||||
THIRD_PARTY_QUICKJS_CHECKS = \
|
||||
$(THIRD_PARTY_QUICKJS_A).pkg \
|
||||
$(THIRD_PARTY_QUICKJS_HDRS:%=o/$(MODE)/%.ok)
|
||||
THIRD_PARTY_QUICKJS_A_OBJS = \
|
||||
o/$(MODE)/third_party/quickjs/cutils.o \
|
||||
o/$(MODE)/third_party/quickjs/libbf.o \
|
||||
o/$(MODE)/third_party/quickjs/libregexp.o \
|
||||
o/$(MODE)/third_party/quickjs/libunicode.o \
|
||||
o/$(MODE)/third_party/quickjs/quickjs-libc.o \
|
||||
o/$(MODE)/third_party/quickjs/quickjs.o \
|
||||
o/$(MODE)/third_party/quickjs/wut.o
|
||||
|
||||
THIRD_PARTY_QUICKJS_DIRECTDEPS = \
|
||||
LIBC_ALG \
|
||||
LIBC_CALLS \
|
||||
LIBC_FMT \
|
||||
LIBC_INTRIN \
|
||||
LIBC_LOG \
|
||||
LIBC_MEM \
|
||||
LIBC_NEXGEN32E \
|
||||
LIBC_RUNTIME \
|
||||
LIBC_SOCK \
|
||||
LIBC_STDIO \
|
||||
LIBC_STR \
|
||||
LIBC_SYSV \
|
||||
LIBC_SYSV_CALLS \
|
||||
LIBC_TIME \
|
||||
LIBC_TINYMATH \
|
||||
LIBC_UNICODE \
|
||||
LIBC_X \
|
||||
THIRD_PARTY_COMPILER_RT \
|
||||
THIRD_PARTY_GDTOA \
|
||||
THIRD_PARTY_GETOPT \
|
||||
THIRD_PARTY_QUICKJS_A_DIRECTDEPS = \
|
||||
LIBC_ALG \
|
||||
LIBC_CALLS \
|
||||
LIBC_FMT \
|
||||
LIBC_INTRIN \
|
||||
LIBC_LOG \
|
||||
LIBC_MEM \
|
||||
LIBC_NEXGEN32E \
|
||||
LIBC_RUNTIME \
|
||||
LIBC_SOCK \
|
||||
LIBC_STDIO \
|
||||
LIBC_STR \
|
||||
LIBC_SYSV \
|
||||
LIBC_SYSV_CALLS \
|
||||
LIBC_TIME \
|
||||
LIBC_TINYMATH \
|
||||
LIBC_UNICODE \
|
||||
LIBC_X \
|
||||
THIRD_PARTY_COMPILER_RT \
|
||||
THIRD_PARTY_GDTOA \
|
||||
THIRD_PARTY_GETOPT \
|
||||
THIRD_PARTY_MUSL
|
||||
|
||||
THIRD_PARTY_QUICKJS_DEPS := \
|
||||
$(call uniq,$(foreach x,$(THIRD_PARTY_QUICKJS_DIRECTDEPS),$($(x))))
|
||||
THIRD_PARTY_QUICKJS_A_DEPS := \
|
||||
$(call uniq,$(foreach x,$(THIRD_PARTY_QUICKJS_A_DIRECTDEPS),$($(x))))
|
||||
|
||||
$(THIRD_PARTY_QUICKJS_A): \
|
||||
third_party/quickjs/ \
|
||||
$(THIRD_PARTY_QUICKJS_A).pkg \
|
||||
$(filter-out %/quickjs.c,$(THIRD_PARTY_QUICKJS_OBJS))
|
||||
$(THIRD_PARTY_QUICKJS_A): \
|
||||
third_party/quickjs/ \
|
||||
$(THIRD_PARTY_QUICKJS_A).pkg \
|
||||
$(THIRD_PARTY_QUICKJS_A_OBJS)
|
||||
|
||||
$(THIRD_PARTY_QUICKJS_A).pkg: \
|
||||
$(THIRD_PARTY_QUICKJS_OBJS) \
|
||||
$(foreach x,$(THIRD_PARTY_QUICKJS_DIRECTDEPS),$($(x)_A).pkg)
|
||||
$(THIRD_PARTY_QUICKJS_A).pkg: \
|
||||
$(THIRD_PARTY_QUICKJS_A_OBJS) \
|
||||
$(foreach x,$(THIRD_PARTY_QUICKJS_A_DIRECTDEPS),$($(x)_A).pkg)
|
||||
|
||||
o/$(MODE)/third_party/quickjs/qjs.com.dbg: \
|
||||
$(THIRD_PARTY_QUICKJS_DEPS) \
|
||||
$(THIRD_PARTY_QUICKJS_A) \
|
||||
$(THIRD_PARTY_QUICKJS_A).pkg \
|
||||
o/$(MODE)/third_party/quickjs/qjs.o \
|
||||
$(CRT) \
|
||||
THIRD_PARTY_QUICKJS_SRCS = \
|
||||
third_party/quickjs/qjs.c \
|
||||
third_party/quickjs/qjsc.c \
|
||||
third_party/quickjs/run-test262.c \
|
||||
$(foreach x,$(THIRD_PARTY_QUICKJS_ARTIFACTS),$($(x)_SRCS))
|
||||
|
||||
THIRD_PARTY_QUICKJS_OBJS = \
|
||||
o/$(MODE)/third_party/quickjs/qjs.o \
|
||||
o/$(MODE)/third_party/quickjs/qjsc.o \
|
||||
o/$(MODE)/third_party/quickjs/run-test262.o \
|
||||
$(THIRD_PARTY_QUICKJS_A_OBJS)
|
||||
|
||||
THIRD_PARTY_QUICKJS_COMS = \
|
||||
o/$(MODE)/third_party/quickjs/qjs.com \
|
||||
o/$(MODE)/third_party/quickjs/qjsc.com \
|
||||
o/$(MODE)/third_party/quickjs/run-test262.com \
|
||||
o/$(MODE)/third_party/quickjs/unicode_gen.com
|
||||
|
||||
THIRD_PARTY_QUICKJS_CHECKS = \
|
||||
$(THIRD_PARTY_QUICKJS_A).pkg \
|
||||
$(THIRD_PARTY_QUICKJS_A_HDRS:%=o/$(MODE)/%.ok)
|
||||
|
||||
o/$(MODE)/third_party/quickjs/qjs.com.dbg: \
|
||||
$(THIRD_PARTY_QUICKJS_A_DEPS) \
|
||||
$(THIRD_PARTY_QUICKJS_A) \
|
||||
$(THIRD_PARTY_QUICKJS_A).pkg \
|
||||
o/$(MODE)/third_party/quickjs/qjs.o \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
-@$(APELINK)
|
||||
|
||||
$(THIRD_PARTY_QUICKJS_OBJS): \
|
||||
OVERRIDE_CPPFLAGS += \
|
||||
-DCONFIG_BIGNUM \
|
||||
o/$(MODE)/third_party/quickjs/qjsc.com.dbg: \
|
||||
$(THIRD_PARTY_QUICKJS_A_DEPS) \
|
||||
$(THIRD_PARTY_QUICKJS_A) \
|
||||
$(THIRD_PARTY_QUICKJS_A).pkg \
|
||||
o/$(MODE)/third_party/quickjs/qjsc.o \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
-@$(APELINK)
|
||||
|
||||
# git clone git@github.com:tc39/test262 /opt/test262
|
||||
# make -j8 MODE=dbg o/dbg/third_party/quickjs/run-test262.com
|
||||
# o/dbg/third_party/quickjs/run-test262.com -m -c third_party/quickjs/test262.conf -a
|
||||
o/$(MODE)/third_party/quickjs/run-test262.com.dbg: \
|
||||
$(THIRD_PARTY_QUICKJS_A_DEPS) \
|
||||
$(THIRD_PARTY_QUICKJS_A) \
|
||||
$(THIRD_PARTY_QUICKJS_A).pkg \
|
||||
o/$(MODE)/third_party/quickjs/run-test262.o \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
-@$(APELINK)
|
||||
|
||||
o/$(MODE)/third_party/quickjs/unicode_gen.com.dbg: \
|
||||
$(THIRD_PARTY_QUICKJS_A_DEPS) \
|
||||
$(THIRD_PARTY_QUICKJS_A) \
|
||||
$(THIRD_PARTY_QUICKJS_A).pkg \
|
||||
o/$(MODE)/third_party/quickjs/unicode_gen.o \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
-@$(APELINK)
|
||||
|
||||
$(THIRD_PARTY_QUICKJS_OBJS): \
|
||||
OVERRIDE_CPPFLAGS += \
|
||||
-DCONFIG_BIGNUM \
|
||||
-DCONFIG_VERSION=\"$(shell cat third_party/quickjs/VERSION)\"
|
||||
|
||||
o/$(MODE)/third_party/quickjs/unicode_gen.o: \
|
||||
OVERRIDE_CPPFLAGS += \
|
||||
o/$(MODE)/third_party/quickjs/unicode_gen.o: \
|
||||
OVERRIDE_CPPFLAGS += \
|
||||
-DSTACK_FRAME_UNLIMITED
|
||||
|
||||
# TODO(jart): Replace alloca() calls with malloc().
|
||||
o/$(MODE)/third_party/quickjs/libregexp.o \
|
||||
o/$(MODE)/third_party/quickjs/quickjs.o: \
|
||||
OVERRIDE_CPPFLAGS += \
|
||||
o/$(MODE)/third_party/quickjs/libregexp.o \
|
||||
o/$(MODE)/third_party/quickjs/quickjs.o: \
|
||||
OVERRIDE_CPPFLAGS += \
|
||||
-DSTACK_FRAME_UNLIMITED
|
||||
|
||||
.PHONY: o/$(MODE)/third_party/quickjs
|
||||
o/$(MODE)/third_party/quickjs: \
|
||||
$(THIRD_PARTY_QUICKJS_BINS) \
|
||||
o/$(MODE)/third_party/quickjs: \
|
||||
$(THIRD_PARTY_QUICKJS_BINS) \
|
||||
$(THIRD_PARTY_QUICKJS_CHECKS)
|
||||
|
|
7
third_party/quickjs/run-test262.c
vendored
7
third_party/quickjs/run-test262.c
vendored
|
@ -931,7 +931,8 @@ void load_config(const char *filename)
|
|||
if (!f) {
|
||||
perror_exit(1, filename);
|
||||
}
|
||||
base_name = get_basename(filename);
|
||||
/* base_name = get_basename(filename); */
|
||||
base_name = strdup("");
|
||||
|
||||
while (fgets(buf, sizeof(buf), f) != NULL) {
|
||||
char *p, *q;
|
||||
|
@ -1672,6 +1673,8 @@ int run_test(const char *filename, int index)
|
|||
if (p) {
|
||||
snprintf(harnessbuf, sizeof(harnessbuf), "%.*s%s",
|
||||
(int)(p - filename), filename, "test/harness");
|
||||
} else {
|
||||
strcpy(harnessbuf, ""); /* XXX */
|
||||
}
|
||||
harness = harnessbuf;
|
||||
}
|
||||
|
@ -1947,6 +1950,8 @@ int main(int argc, char **argv)
|
|||
BOOL is_test262_harness = FALSE;
|
||||
BOOL is_module = FALSE;
|
||||
|
||||
showcrashreports();
|
||||
|
||||
#if !defined(_WIN32)
|
||||
/* Date tests assume California local time */
|
||||
setenv("TZ", "America/Los_Angeles", 1);
|
||||
|
|
23
third_party/quickjs/test262.conf
vendored
23
third_party/quickjs/test262.conf
vendored
|
@ -26,22 +26,22 @@ module=yes
|
|||
verbose=yes
|
||||
|
||||
# load harness files from this directory
|
||||
harnessdir=test262/harness
|
||||
harnessdir=/opt/test262/harness
|
||||
|
||||
# names of harness include files to skip
|
||||
#harnessexclude=
|
||||
|
||||
# name of the error file for known errors
|
||||
errorfile=test262_errors.txt
|
||||
errorfile=third_party/quickjs/test262_errors.txt
|
||||
|
||||
# exclude tests enumerated in this file (see also [exclude] section)
|
||||
#excludefile=test262_exclude.txt
|
||||
|
||||
# report test results to this file
|
||||
reportfile=test262_report.txt
|
||||
reportfile=o/test262_report.txt
|
||||
|
||||
# enumerate tests from this directory
|
||||
testdir=test262/test
|
||||
testdir=/opt/test262/test
|
||||
|
||||
[features]
|
||||
# Standard language features and proposed extensions
|
||||
|
@ -184,16 +184,19 @@ __setter__
|
|||
# list excluded tests and directories here
|
||||
|
||||
# intl not supported
|
||||
test262/test/intl402/
|
||||
/opt/test262/test/intl402/
|
||||
|
||||
# incompatible with the "caller" feature
|
||||
test262/test/built-ins/Function/prototype/restricted-property-caller.js
|
||||
test262/test/built-ins/Function/prototype/restricted-property-arguments.js
|
||||
test262/test/built-ins/ThrowTypeError/unique-per-realm-function-proto.js
|
||||
/opt/test262/test/built-ins/Function/prototype/restricted-property-caller.js
|
||||
/opt/test262/test/built-ins/Function/prototype/restricted-property-arguments.js
|
||||
/opt/test262/test/built-ins/ThrowTypeError/unique-per-realm-function-proto.js
|
||||
|
||||
# slow tests
|
||||
#test262/test/built-ins/RegExp/CharacterClassEscapes/
|
||||
#test262/test/built-ins/RegExp/property-escapes/
|
||||
#/opt/test262/test/built-ins/RegExp/CharacterClassEscapes/
|
||||
#/opt/test262/test/built-ins/RegExp/property-escapes/
|
||||
|
||||
# No threads in Cosmopolitan ATM
|
||||
/opt/test262/test/built-ins/Atomics/
|
||||
|
||||
[tests]
|
||||
# list test files or use config.testdir
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue