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:
Justine Tunney 2021-04-10 16:22:35 -07:00
parent 8f52c0d773
commit 8a91518633
38 changed files with 395 additions and 184 deletions

View file

@ -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);