mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 13:52:28 +00:00
Revert whitespace fixes to third_party (#501)
This commit is contained in:
parent
d4000bb8f7
commit
9de3d8f1e6
365 changed files with 39190 additions and 39211 deletions
196
third_party/quickjs/quickjs-libc.c
vendored
196
third_party/quickjs/quickjs-libc.c
vendored
|
@ -170,7 +170,7 @@ static JSValue js_printf_internal(JSContext *ctx,
|
|||
break;
|
||||
q = fmtbuf;
|
||||
*q++ = *fmt++; /* copy '%' */
|
||||
|
||||
|
||||
/* flags */
|
||||
for(;;) {
|
||||
c = *fmt;
|
||||
|
@ -224,14 +224,14 @@ static JSValue js_printf_internal(JSContext *ctx,
|
|||
if (*fmt == 'l') {
|
||||
mod = *fmt++;
|
||||
}
|
||||
|
||||
|
||||
/* type */
|
||||
c = *fmt++;
|
||||
if (q >= fmtbuf + sizeof(fmtbuf) - 1)
|
||||
goto invalid;
|
||||
*q++ = c;
|
||||
*q = '\0';
|
||||
|
||||
|
||||
switch (c) {
|
||||
case 'c':
|
||||
if (i >= argc)
|
||||
|
@ -253,7 +253,7 @@ static JSValue js_printf_internal(JSContext *ctx,
|
|||
len = unicode_to_utf8(cbuf, int32_arg);
|
||||
dbuf_put(&dbuf, cbuf, len);
|
||||
break;
|
||||
|
||||
|
||||
case 'd':
|
||||
case 'i':
|
||||
case 'o':
|
||||
|
@ -298,7 +298,7 @@ static JSValue js_printf_internal(JSContext *ctx,
|
|||
dbuf_printf_fun(&dbuf, fmtbuf, string_arg);
|
||||
JS_FreeCString(ctx, string_arg);
|
||||
break;
|
||||
|
||||
|
||||
case 'e':
|
||||
case 'f':
|
||||
case 'g':
|
||||
|
@ -313,11 +313,11 @@ static JSValue js_printf_internal(JSContext *ctx,
|
|||
goto fail;
|
||||
dbuf_printf_fun(&dbuf, fmtbuf, double_arg);
|
||||
break;
|
||||
|
||||
|
||||
case '%':
|
||||
dbuf_putc(&dbuf, '%');
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
/* XXX: should support an extension mechanism */
|
||||
invalid:
|
||||
|
@ -354,7 +354,7 @@ uint8_t *js_load_file(JSContext *ctx, size_t *pbuf_len, const char *filename)
|
|||
uint8_t *buf;
|
||||
size_t buf_len;
|
||||
long lret;
|
||||
|
||||
|
||||
f = fopen(filename, "rb");
|
||||
if (!f)
|
||||
return NULL;
|
||||
|
@ -401,7 +401,7 @@ static JSValue js_loadScript(JSContext *ctx, JSValueConst this_val,
|
|||
const char *filename;
|
||||
JSValue ret;
|
||||
size_t buf_len;
|
||||
|
||||
|
||||
filename = JS_ToCString(ctx, argv[0]);
|
||||
if (!filename)
|
||||
return JS_EXCEPTION;
|
||||
|
@ -426,7 +426,7 @@ static JSValue js_std_loadFile(JSContext *ctx, JSValueConst this_val,
|
|||
const char *filename;
|
||||
JSValue ret;
|
||||
size_t buf_len;
|
||||
|
||||
|
||||
filename = JS_ToCString(ctx, argv[0]);
|
||||
if (!filename)
|
||||
return JS_EXCEPTION;
|
||||
|
@ -458,7 +458,7 @@ static JSModuleDef *js_module_loader_so(JSContext *ctx,
|
|||
void *hd;
|
||||
JSInitModuleFunc *init;
|
||||
char *filename;
|
||||
|
||||
|
||||
if (!strchr(module_name, '/')) {
|
||||
/* must add a '/' so that the DLL is not searched in the
|
||||
system library paths */
|
||||
|
@ -470,7 +470,7 @@ static JSModuleDef *js_module_loader_so(JSContext *ctx,
|
|||
} else {
|
||||
filename = (char *)module_name;
|
||||
}
|
||||
|
||||
|
||||
/* C module */
|
||||
hd = dlopen(filename, RTLD_NOW | RTLD_LOCAL);
|
||||
if (filename != module_name)
|
||||
|
@ -509,7 +509,7 @@ int js_module_set_import_meta(JSContext *ctx, JSValueConst func_val,
|
|||
JSValue meta_obj;
|
||||
JSAtom module_name_atom;
|
||||
const char *module_name;
|
||||
|
||||
|
||||
assert(JS_VALUE_GET_TAG(func_val) == JS_TAG_MODULE);
|
||||
m = JS_VALUE_GET_PTR(func_val);
|
||||
|
||||
|
@ -540,7 +540,7 @@ int js_module_set_import_meta(JSContext *ctx, JSValueConst func_val,
|
|||
pstrcpy(buf, sizeof(buf), module_name);
|
||||
}
|
||||
JS_FreeCString(ctx, module_name);
|
||||
|
||||
|
||||
meta_obj = JS_GetImportMeta(ctx, m);
|
||||
if (JS_IsException(meta_obj))
|
||||
return -1;
|
||||
|
@ -565,14 +565,14 @@ JSModuleDef *js_module_loader(JSContext *ctx,
|
|||
size_t buf_len;
|
||||
uint8_t *buf;
|
||||
JSValue func_val;
|
||||
|
||||
|
||||
buf = js_load_file(ctx, &buf_len, module_name);
|
||||
if (!buf) {
|
||||
JS_ThrowReferenceError(ctx, "could not load module filename '%s'",
|
||||
module_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* compile the module */
|
||||
func_val = JS_Eval(ctx, (char *)buf, buf_len, module_name,
|
||||
JS_EVAL_TYPE_MODULE | JS_EVAL_FLAG_COMPILE_ONLY);
|
||||
|
@ -738,7 +738,7 @@ static JSValue js_evalScript(JSContext *ctx, JSValueConst this_val,
|
|||
JSValueConst options_obj;
|
||||
BOOL backtrace_barrier = FALSE;
|
||||
int flags;
|
||||
|
||||
|
||||
if (argc >= 2) {
|
||||
options_obj = argv[1];
|
||||
if (get_bool_option(ctx, &backtrace_barrier, options_obj,
|
||||
|
@ -753,7 +753,7 @@ static JSValue js_evalScript(JSContext *ctx, JSValueConst this_val,
|
|||
/* install the interrupt handler */
|
||||
JS_SetInterruptHandler(JS_GetRuntime(ctx), interrupt_handler, NULL);
|
||||
}
|
||||
flags = JS_EVAL_TYPE_GLOBAL;
|
||||
flags = JS_EVAL_TYPE_GLOBAL;
|
||||
if (backtrace_barrier)
|
||||
flags |= JS_EVAL_FLAG_BACKTRACE_BARRIER;
|
||||
ret = JS_Eval(ctx, str, len, "<evalScript>", flags);
|
||||
|
@ -857,7 +857,7 @@ static JSValue js_std_open(JSContext *ctx, JSValueConst this_val,
|
|||
const char *filename, *mode = NULL;
|
||||
FILE *f;
|
||||
int err;
|
||||
|
||||
|
||||
filename = JS_ToCString(ctx, argv[0]);
|
||||
if (!filename)
|
||||
goto fail;
|
||||
|
@ -893,7 +893,7 @@ static JSValue js_std_popen(JSContext *ctx, JSValueConst this_val,
|
|||
const char *filename, *mode = NULL;
|
||||
FILE *f;
|
||||
int err;
|
||||
|
||||
|
||||
filename = JS_ToCString(ctx, argv[0]);
|
||||
if (!filename)
|
||||
goto fail;
|
||||
|
@ -1007,7 +1007,7 @@ static JSValue js_std_file_puts(JSContext *ctx, JSValueConst this_val,
|
|||
if (!f)
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
|
||||
|
||||
for(i = 0; i < argc; i++) {
|
||||
str = JS_ToCStringLen(ctx, &len, argv[i]);
|
||||
if (!str)
|
||||
|
@ -1138,7 +1138,7 @@ static JSValue js_std_file_read_write(JSContext *ctx, JSValueConst this_val,
|
|||
uint64_t pos, len;
|
||||
size_t size, ret;
|
||||
uint8_t *buf;
|
||||
|
||||
|
||||
if (!f)
|
||||
return JS_EXCEPTION;
|
||||
if (JS_ToIndex(ctx, &pos, argv[1]))
|
||||
|
@ -1165,7 +1165,7 @@ static JSValue js_std_file_getline(JSContext *ctx, JSValueConst this_val,
|
|||
int c;
|
||||
DynBuf dbuf;
|
||||
JSValue obj;
|
||||
|
||||
|
||||
if (!f)
|
||||
return JS_EXCEPTION;
|
||||
|
||||
|
@ -1204,7 +1204,7 @@ static JSValue js_std_file_readAsString(JSContext *ctx, JSValueConst this_val,
|
|||
uint64_t max_size64;
|
||||
size_t max_size;
|
||||
JSValueConst max_size_val;
|
||||
|
||||
|
||||
if (!f)
|
||||
return JS_EXCEPTION;
|
||||
|
||||
|
@ -1268,7 +1268,7 @@ static int http_get_header_line(FILE *f, char *buf, size_t buf_size,
|
|||
{
|
||||
int c;
|
||||
char *p;
|
||||
|
||||
|
||||
p = buf;
|
||||
for(;;) {
|
||||
c = fgetc(f);
|
||||
|
@ -1304,21 +1304,21 @@ static JSValue js_std_urlGet(JSContext *ctx, JSValueConst this_val,
|
|||
DynBuf cmd_buf;
|
||||
DynBuf data_buf_s, *data_buf = &data_buf_s;
|
||||
DynBuf header_buf_s, *header_buf = &header_buf_s;
|
||||
char *buf;
|
||||
char *buf;
|
||||
size_t i, len;
|
||||
int c, status;
|
||||
JSValue response = JS_UNDEFINED, ret_obj;
|
||||
JSValueConst options_obj;
|
||||
FILE *f;
|
||||
BOOL binary_flag, full_flag;
|
||||
|
||||
|
||||
url = JS_ToCString(ctx, argv[0]);
|
||||
if (!url)
|
||||
return JS_EXCEPTION;
|
||||
|
||||
|
||||
binary_flag = FALSE;
|
||||
full_flag = FALSE;
|
||||
|
||||
|
||||
if (argc >= 2) {
|
||||
options_obj = argv[1];
|
||||
|
||||
|
@ -1331,7 +1331,7 @@ static JSValue js_std_urlGet(JSContext *ctx, JSValueConst this_val,
|
|||
return JS_EXCEPTION;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
js_std_dbuf_init(ctx, &cmd_buf);
|
||||
dbuf_printf(&cmd_buf, "%s ''", URL_GET_PROGRAM);
|
||||
len = strlen(url);
|
||||
|
@ -1357,7 +1357,7 @@ static JSValue js_std_urlGet(JSContext *ctx, JSValueConst this_val,
|
|||
|
||||
js_std_dbuf_init(ctx, data_buf);
|
||||
js_std_dbuf_init(ctx, header_buf);
|
||||
|
||||
|
||||
buf = js_malloc(ctx, URL_GET_BUF_SIZE);
|
||||
if (!buf)
|
||||
goto fail;
|
||||
|
@ -1371,7 +1371,7 @@ static JSValue js_std_urlGet(JSContext *ctx, JSValueConst this_val,
|
|||
if (!full_flag && !(status >= 200 && status <= 299)) {
|
||||
goto bad_header;
|
||||
}
|
||||
|
||||
|
||||
/* wait until there is an empty line */
|
||||
for(;;) {
|
||||
if (http_get_header_line(f, buf, URL_GET_BUF_SIZE, header_buf) < 0) {
|
||||
|
@ -1447,7 +1447,7 @@ static JSValue js_std_urlGet(JSContext *ctx, JSValueConst this_val,
|
|||
static JSClassDef js_std_file_class = {
|
||||
"FILE",
|
||||
.finalizer = js_std_file_finalizer,
|
||||
};
|
||||
};
|
||||
|
||||
static JSCFunctionListEntry js_std_error_props[11];
|
||||
static textstartup void js_std_error_props_init() {
|
||||
|
@ -1485,7 +1485,7 @@ static const JSCFunctionListEntry js_std_funcs[] = {
|
|||
JS_CFUNC_DEF("loadFile", 1, js_std_loadFile ),
|
||||
JS_CFUNC_DEF("strerror", 1, js_std_strerror ),
|
||||
JS_CFUNC_DEF("parseExtJSON", 1, js_std_parseExtJSON ),
|
||||
|
||||
|
||||
/* FILE I/O */
|
||||
JS_CFUNC_DEF("open", 2, js_std_open ),
|
||||
JS_CFUNC_DEF("popen", 2, js_std_popen ),
|
||||
|
@ -1499,7 +1499,7 @@ static const JSCFunctionListEntry js_std_funcs[] = {
|
|||
JS_PROP_INT32_DEF("SEEK_END", SEEK_END, JS_PROP_CONFIGURABLE ),
|
||||
JS_OBJECT_DEF("Error", js_std_error_props, countof(js_std_error_props), JS_PROP_CONFIGURABLE),
|
||||
};
|
||||
|
||||
|
||||
static const JSCFunctionListEntry js_std_file_proto_funcs[] = {
|
||||
JS_CFUNC_DEF("close", 0, js_std_file_close ),
|
||||
JS_CFUNC_MAGIC_DEF("puts", 1, js_std_file_puts, 1 ),
|
||||
|
@ -1524,7 +1524,7 @@ static const JSCFunctionListEntry js_std_file_proto_funcs[] = {
|
|||
static int js_std_init(JSContext *ctx, JSModuleDef *m)
|
||||
{
|
||||
JSValue proto;
|
||||
|
||||
|
||||
/* FILE class */
|
||||
/* the class ID is created once */
|
||||
JS_NewClassID(&js_std_file_class_id);
|
||||
|
@ -1605,7 +1605,7 @@ static JSValue js_os_seek(JSContext *ctx, JSValueConst this_val,
|
|||
int fd, whence;
|
||||
int64_t pos, ret;
|
||||
BOOL is_bigint;
|
||||
|
||||
|
||||
if (JS_ToInt32(ctx, &fd, argv[0]))
|
||||
return JS_EXCEPTION;
|
||||
is_bigint = JS_IsBigInt(ctx, argv[1]);
|
||||
|
@ -1630,7 +1630,7 @@ static JSValue js_os_read_write(JSContext *ctx, JSValueConst this_val,
|
|||
size_t size;
|
||||
ssize_t ret;
|
||||
uint8_t *buf;
|
||||
|
||||
|
||||
if (JS_ToInt32(ctx, &fd, argv[0]))
|
||||
return JS_EXCEPTION;
|
||||
if (JS_ToIndex(ctx, &pos, argv[2]))
|
||||
|
@ -1670,7 +1670,7 @@ static JSValue js_os_ttyGetWinSize(JSContext *ctx, JSValueConst this_val,
|
|||
if (JS_ToInt32(ctx, &fd, argv[0]))
|
||||
return JS_EXCEPTION;
|
||||
handle = (HANDLE)_get_osfhandle(fd);
|
||||
|
||||
|
||||
if (!GetConsoleScreenBufferInfo(handle, &info))
|
||||
return JS_NULL;
|
||||
obj = JS_NewArray(ctx);
|
||||
|
@ -1709,7 +1709,7 @@ static JSValue js_os_ttyGetWinSize(JSContext *ctx, JSValueConst this_val,
|
|||
int fd;
|
||||
struct winsize ws;
|
||||
JSValue obj;
|
||||
|
||||
|
||||
if (JS_ToInt32(ctx, &fd, argv[0]))
|
||||
return JS_EXCEPTION;
|
||||
if (ioctl(fd, TIOCGWINSZ, &ws) == 0 &&
|
||||
|
@ -1738,7 +1738,7 @@ static JSValue js_os_ttySetRaw(JSContext *ctx, JSValueConst this_val,
|
|||
{
|
||||
struct termios tty;
|
||||
int fd;
|
||||
|
||||
|
||||
if (JS_ToInt32(ctx, &fd, argv[0]))
|
||||
return JS_EXCEPTION;
|
||||
bzero(&tty, sizeof(tty));
|
||||
|
@ -1767,7 +1767,7 @@ static JSValue js_os_remove(JSContext *ctx, JSValueConst this_val,
|
|||
{
|
||||
const char *filename;
|
||||
int ret;
|
||||
|
||||
|
||||
filename = JS_ToCString(ctx, argv[0]);
|
||||
if (!filename)
|
||||
return JS_EXCEPTION;
|
||||
|
@ -1793,7 +1793,7 @@ static JSValue js_os_rename(JSContext *ctx, JSValueConst this_val,
|
|||
{
|
||||
const char *oldpath, *newpath;
|
||||
int ret;
|
||||
|
||||
|
||||
oldpath = JS_ToCString(ctx, argv[0]);
|
||||
if (!oldpath)
|
||||
return JS_EXCEPTION;
|
||||
|
@ -1845,7 +1845,7 @@ static JSValue js_os_setReadHandler(JSContext *ctx, JSValueConst this_val,
|
|||
JSOSRWHandler *rh;
|
||||
int fd;
|
||||
JSValueConst func;
|
||||
|
||||
|
||||
if (JS_ToInt32(ctx, &fd, argv[0]))
|
||||
return JS_EXCEPTION;
|
||||
func = argv[1];
|
||||
|
@ -1919,7 +1919,7 @@ static JSValue js_os_signal(JSContext *ctx, JSValueConst this_val,
|
|||
|
||||
if (!is_main_thread(rt))
|
||||
return JS_ThrowTypeError(ctx, "signal handler can only be set in the main thread");
|
||||
|
||||
|
||||
if (JS_ToUint32(ctx, &sig_num, argv[0]))
|
||||
return JS_EXCEPTION;
|
||||
if (sig_num >= 64)
|
||||
|
@ -2051,7 +2051,7 @@ static JSClassDef js_os_timer_class = {
|
|||
"OSTimer",
|
||||
.finalizer = js_os_timer_finalizer,
|
||||
.gc_mark = js_os_timer_mark,
|
||||
};
|
||||
};
|
||||
|
||||
static void call_handler(JSContext *ctx, JSValueConst func)
|
||||
{
|
||||
|
@ -2081,12 +2081,12 @@ static int js_os_poll_nt(JSContext *ctx)
|
|||
int64_t cur_time, delay;
|
||||
JSOSRWHandler *rh;
|
||||
struct list_head *el;
|
||||
|
||||
|
||||
/* XXX: handle signals if useful */
|
||||
|
||||
if (list_empty(&ts->os_rw_handlers) && list_empty(&ts->os_timers))
|
||||
return -1; /* no more events */
|
||||
|
||||
|
||||
/* XXX: only timers and basic console input are supported */
|
||||
if (!list_empty(&ts->os_timers)) {
|
||||
cur_time = get_time_ms();
|
||||
|
@ -2160,7 +2160,7 @@ static int handle_posted_message(JSRuntime *rt, JSContext *ctx,
|
|||
struct list_head *el;
|
||||
JSWorkerMessage *msg;
|
||||
JSValue obj, data_obj, func, retval;
|
||||
|
||||
|
||||
pthread_mutex_lock(&ps->mutex);
|
||||
if (!list_empty(&ps->msg_queue)) {
|
||||
el = ps->msg_queue.next;
|
||||
|
@ -2187,7 +2187,7 @@ static int handle_posted_message(JSRuntime *rt, JSContext *ctx,
|
|||
JS_READ_OBJ_SAB | JS_READ_OBJ_REFERENCE);
|
||||
|
||||
js_free_message(msg);
|
||||
|
||||
|
||||
if (JS_IsException(data_obj))
|
||||
goto fail;
|
||||
obj = JS_NewObject(ctx);
|
||||
|
@ -2242,7 +2242,7 @@ static int js_os_poll(JSContext *ctx)
|
|||
if (!ts->recv_pipe && UNLIKELY(os_pending_signals != 0)) {
|
||||
JSOSSignalHandler *sh;
|
||||
uint64_t mask;
|
||||
|
||||
|
||||
list_for_each(el, &ts->os_signal_handlers) {
|
||||
sh = list_entry(el, JSOSSignalHandler, link);
|
||||
mask = (uint64_t)1 << sh->sig_num;
|
||||
|
@ -2257,7 +2257,7 @@ static int js_os_poll(JSContext *ctx)
|
|||
if (list_empty(&ts->os_rw_handlers) && list_empty(&ts->os_timers) &&
|
||||
list_empty(&ts->port_list))
|
||||
return -1; /* no more events */
|
||||
|
||||
|
||||
if (!list_empty(&ts->os_timers)) {
|
||||
cur_time = get_time_ms();
|
||||
min_delay = 10000;
|
||||
|
@ -2285,7 +2285,7 @@ static int js_os_poll(JSContext *ctx)
|
|||
} else {
|
||||
tvp = NULL;
|
||||
}
|
||||
|
||||
|
||||
FD_ZERO(&rfds);
|
||||
FD_ZERO(&wfds);
|
||||
fd_max = -1;
|
||||
|
@ -2371,7 +2371,7 @@ static JSValue js_os_getcwd(JSContext *ctx, JSValueConst this_val,
|
|||
{
|
||||
char buf[MAXPATH];
|
||||
int err;
|
||||
|
||||
|
||||
if (!getcwd(buf, sizeof(buf))) {
|
||||
buf[0] = '\0';
|
||||
err = errno;
|
||||
|
@ -2400,7 +2400,7 @@ static JSValue js_os_mkdir(JSContext *ctx, JSValueConst this_val,
|
|||
{
|
||||
int mode, ret;
|
||||
const char *path;
|
||||
|
||||
|
||||
if (argc >= 2) {
|
||||
if (JS_ToInt32(ctx, &mode, argv[1]))
|
||||
return JS_EXCEPTION;
|
||||
|
@ -2430,7 +2430,7 @@ static JSValue js_os_readdir(JSContext *ctx, JSValueConst this_val,
|
|||
JSValue obj;
|
||||
int err;
|
||||
uint32_t len;
|
||||
|
||||
|
||||
path = JS_ToCString(ctx, argv[0]);
|
||||
if (!path)
|
||||
return JS_EXCEPTION;
|
||||
|
@ -2578,7 +2578,7 @@ static JSValue js_os_utimes(JSContext *ctx, JSValueConst this_val,
|
|||
const char *path;
|
||||
int64_t atime, mtime;
|
||||
int ret;
|
||||
|
||||
|
||||
if (JS_ToInt64(ctx, &atime, argv[1]))
|
||||
return JS_EXCEPTION;
|
||||
if (JS_ToInt64(ctx, &mtime, argv[2]))
|
||||
|
@ -2611,7 +2611,7 @@ static JSValue js_os_sleep(JSContext *ctx, JSValueConst this_val,
|
|||
{
|
||||
int64_t delay;
|
||||
int ret;
|
||||
|
||||
|
||||
if (JS_ToInt64(ctx, &delay, argv[0]))
|
||||
return JS_EXCEPTION;
|
||||
if (delay < 0)
|
||||
|
@ -2663,7 +2663,7 @@ static JSValue js_os_symlink(JSContext *ctx, JSValueConst this_val,
|
|||
{
|
||||
const char *target, *linkpath;
|
||||
int err;
|
||||
|
||||
|
||||
target = JS_ToCString(ctx, argv[0]);
|
||||
if (!target)
|
||||
return JS_EXCEPTION;
|
||||
|
@ -2686,7 +2686,7 @@ static JSValue js_os_readlink(JSContext *ctx, JSValueConst this_val,
|
|||
char buf[MAXPATH];
|
||||
int err;
|
||||
ssize_t res;
|
||||
|
||||
|
||||
path = JS_ToCString(ctx, argv[0]);
|
||||
if (!path)
|
||||
return JS_EXCEPTION;
|
||||
|
@ -2710,7 +2710,7 @@ static char **build_envp(JSContext *ctx, JSValueConst obj)
|
|||
const char *key, *str;
|
||||
JSValue val;
|
||||
size_t key_len, str_len;
|
||||
|
||||
|
||||
if (JS_GetOwnPropertyNames(ctx, &tab, &len, obj,
|
||||
JS_GPN_STRING_MASK | JS_GPN_ENUM_ONLY) < 0)
|
||||
return NULL;
|
||||
|
@ -2775,7 +2775,7 @@ static JSValue js_os_exec(JSContext *ctx, JSValueConst this_val,
|
|||
static const char *std_name[3] = { "stdin", "stdout", "stderr" };
|
||||
int std_fds[3];
|
||||
uint32_t uid = -1, gid = -1;
|
||||
|
||||
|
||||
val = JS_GetPropertyStr(ctx, args, "length");
|
||||
if (JS_IsException(val))
|
||||
return JS_EXCEPTION;
|
||||
|
@ -2804,7 +2804,7 @@ static JSValue js_os_exec(JSContext *ctx, JSValueConst this_val,
|
|||
|
||||
for(i = 0; i < 3; i++)
|
||||
std_fds[i] = i;
|
||||
|
||||
|
||||
/* get the options, if any */
|
||||
if (argc >= 2) {
|
||||
options = argv[1];
|
||||
|
@ -2813,7 +2813,7 @@ static JSValue js_os_exec(JSContext *ctx, JSValueConst this_val,
|
|||
goto exception;
|
||||
if (get_bool_option(ctx, &use_path, options, "usePath"))
|
||||
goto exception;
|
||||
|
||||
|
||||
val = JS_GetPropertyStr(ctx, options, "file");
|
||||
if (JS_IsException(val))
|
||||
goto exception;
|
||||
|
@ -2858,7 +2858,7 @@ static JSValue js_os_exec(JSContext *ctx, JSValueConst this_val,
|
|||
if (!envp)
|
||||
goto exception;
|
||||
}
|
||||
|
||||
|
||||
val = JS_GetPropertyStr(ctx, options, "uid");
|
||||
if (JS_IsException(val))
|
||||
goto exception;
|
||||
|
@ -2965,7 +2965,7 @@ static JSValue js_os_waitpid(JSContext *ctx, JSValueConst this_val,
|
|||
{
|
||||
int pid, status, options, ret;
|
||||
JSValue obj;
|
||||
|
||||
|
||||
if (JS_ToInt32(ctx, &pid, argv[0]))
|
||||
return JS_EXCEPTION;
|
||||
if (JS_ToInt32(ctx, &options, argv[1]))
|
||||
|
@ -2985,7 +2985,7 @@ static JSValue js_os_waitpid(JSContext *ctx, JSValueConst this_val,
|
|||
JS_DefinePropertyValueUint32(ctx, obj, 1, JS_NewInt32(ctx, status),
|
||||
JS_PROP_C_W_E);
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
/* pipe() -> [read_fd, write_fd] or null if error */
|
||||
static JSValue js_os_pipe(JSContext *ctx, JSValueConst this_val,
|
||||
|
@ -2993,7 +2993,7 @@ static JSValue js_os_pipe(JSContext *ctx, JSValueConst this_val,
|
|||
{
|
||||
int pipe_fds[2], ret;
|
||||
JSValue obj;
|
||||
|
||||
|
||||
ret = pipe(pipe_fds);
|
||||
if (ret < 0)
|
||||
return JS_NULL;
|
||||
|
@ -3012,7 +3012,7 @@ static JSValue js_os_kill(JSContext *ctx, JSValueConst this_val,
|
|||
int argc, JSValueConst *argv)
|
||||
{
|
||||
int pid, sig, ret;
|
||||
|
||||
|
||||
if (JS_ToInt32(ctx, &pid, argv[0]))
|
||||
return JS_EXCEPTION;
|
||||
if (JS_ToInt32(ctx, &sig, argv[1]))
|
||||
|
@ -3026,7 +3026,7 @@ static JSValue js_os_dup(JSContext *ctx, JSValueConst this_val,
|
|||
int argc, JSValueConst *argv)
|
||||
{
|
||||
int fd, ret;
|
||||
|
||||
|
||||
if (JS_ToInt32(ctx, &fd, argv[0]))
|
||||
return JS_EXCEPTION;
|
||||
ret = js_get_errno(dup(fd));
|
||||
|
@ -3038,7 +3038,7 @@ static JSValue js_os_dup2(JSContext *ctx, JSValueConst this_val,
|
|||
int argc, JSValueConst *argv)
|
||||
{
|
||||
int fd, fd2, ret;
|
||||
|
||||
|
||||
if (JS_ToInt32(ctx, &fd, argv[0]))
|
||||
return JS_EXCEPTION;
|
||||
if (JS_ToInt32(ctx, &fd2, argv[1]))
|
||||
|
@ -3112,7 +3112,7 @@ static JSWorkerMessagePipe *js_new_message_pipe(void)
|
|||
{
|
||||
JSWorkerMessagePipe *ps;
|
||||
int pipe_fds[2];
|
||||
|
||||
|
||||
if (pipe(pipe_fds) < 0)
|
||||
return NULL;
|
||||
|
||||
|
@ -3153,10 +3153,10 @@ static void js_free_message_pipe(JSWorkerMessagePipe *ps)
|
|||
struct list_head *el, *el1;
|
||||
JSWorkerMessage *msg;
|
||||
int ref_count;
|
||||
|
||||
|
||||
if (!ps)
|
||||
return;
|
||||
|
||||
|
||||
ref_count = atomic_add_int(&ps->ref_count, -1);
|
||||
assert(ref_count >= 0);
|
||||
if (ref_count == 0) {
|
||||
|
@ -3195,7 +3195,7 @@ static void js_worker_finalizer(JSRuntime *rt, JSValue val)
|
|||
static JSClassDef js_worker_class = {
|
||||
"Worker",
|
||||
.finalizer = js_worker_finalizer,
|
||||
};
|
||||
};
|
||||
|
||||
static void *worker_func(void *opaque)
|
||||
{
|
||||
|
@ -3203,12 +3203,12 @@ static void *worker_func(void *opaque)
|
|||
JSRuntime *rt;
|
||||
JSThreadState *ts;
|
||||
JSContext *ctx;
|
||||
|
||||
|
||||
rt = JS_NewRuntime();
|
||||
if (rt == NULL) {
|
||||
fprintf(stderr, "JS_NewRuntime failure");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
js_std_init_handlers(rt);
|
||||
|
||||
JS_SetModuleLoaderFunc(rt, NULL, js_module_loader, NULL);
|
||||
|
@ -3217,7 +3217,7 @@ static void *worker_func(void *opaque)
|
|||
ts = JS_GetRuntimeOpaque(rt);
|
||||
ts->recv_pipe = args->recv_pipe;
|
||||
ts->send_pipe = args->send_pipe;
|
||||
|
||||
|
||||
/* function pointer to avoid linking the whole JS_NewContext() if
|
||||
not needed */
|
||||
ctx = js_worker_new_context_func(rt);
|
||||
|
@ -3249,7 +3249,7 @@ static JSValue js_worker_ctor_internal(JSContext *ctx, JSValueConst new_target,
|
|||
{
|
||||
JSValue obj = JS_UNDEFINED, proto;
|
||||
JSWorkerData *s;
|
||||
|
||||
|
||||
/* create the object */
|
||||
if (JS_IsUndefined(new_target)) {
|
||||
proto = JS_GetClassProto(ctx, js_worker_class_id);
|
||||
|
@ -3286,7 +3286,7 @@ static JSValue js_worker_ctor(JSContext *ctx, JSValueConst new_target,
|
|||
int ret;
|
||||
const char *filename = NULL, *basename;
|
||||
JSAtom basename_atom;
|
||||
|
||||
|
||||
/* XXX: in order to avoid problems with resource liberation, we
|
||||
don't support creating workers inside workers */
|
||||
if (!is_main_thread(rt))
|
||||
|
@ -3302,7 +3302,7 @@ static JSValue js_worker_ctor(JSContext *ctx, JSValueConst new_target,
|
|||
JS_FreeAtom(ctx, basename_atom);
|
||||
if (!basename)
|
||||
goto fail;
|
||||
|
||||
|
||||
/* module name */
|
||||
filename = JS_ToCString(ctx, argv[0]);
|
||||
if (!filename)
|
||||
|
@ -3327,7 +3327,7 @@ static JSValue js_worker_ctor(JSContext *ctx, JSValueConst new_target,
|
|||
args->send_pipe, args->recv_pipe);
|
||||
if (JS_IsException(obj))
|
||||
goto fail;
|
||||
|
||||
|
||||
pthread_attr_init(&attr);
|
||||
/* no join at the end */
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||
|
@ -3365,10 +3365,10 @@ static JSValue js_worker_postMessage(JSContext *ctx, JSValueConst this_val,
|
|||
uint8_t *data;
|
||||
JSWorkerMessage *msg;
|
||||
uint8_t **sab_tab;
|
||||
|
||||
|
||||
if (!worker)
|
||||
return JS_EXCEPTION;
|
||||
|
||||
|
||||
data = JS_WriteObject2(ctx, &data_len, argv[0],
|
||||
JS_WRITE_OBJ_SAB | JS_WRITE_OBJ_REFERENCE,
|
||||
&sab_tab, &sab_tab_len);
|
||||
|
@ -3396,7 +3396,7 @@ static JSValue js_worker_postMessage(JSContext *ctx, JSValueConst this_val,
|
|||
|
||||
js_free(ctx, data);
|
||||
js_free(ctx, sab_tab);
|
||||
|
||||
|
||||
/* increment the SAB reference counts */
|
||||
for(i = 0; i < msg->sab_tab_len; i++) {
|
||||
js_sab_dup(NULL, msg->sab_tab[i]);
|
||||
|
@ -3428,7 +3428,7 @@ static JSValue js_worker_postMessage(JSContext *ctx, JSValueConst this_val,
|
|||
js_free(ctx, data);
|
||||
js_free(ctx, sab_tab);
|
||||
return JS_EXCEPTION;
|
||||
|
||||
|
||||
}
|
||||
|
||||
static JSValue js_worker_set_onmessage(JSContext *ctx, JSValueConst this_val,
|
||||
|
@ -3438,7 +3438,7 @@ static JSValue js_worker_set_onmessage(JSContext *ctx, JSValueConst this_val,
|
|||
JSThreadState *ts = JS_GetRuntimeOpaque(rt);
|
||||
JSWorkerData *worker = JS_GetOpaque2(ctx, this_val, js_worker_class_id);
|
||||
JSWorkerMessageHandler *port;
|
||||
|
||||
|
||||
if (!worker)
|
||||
return JS_EXCEPTION;
|
||||
|
||||
|
@ -3597,7 +3597,7 @@ const void *const js_os_funcs_ctor[] initarray = {js_os_funcs_init};
|
|||
static int js_os_init(JSContext *ctx, JSModuleDef *m)
|
||||
{
|
||||
os_poll_func = js_os_poll;
|
||||
|
||||
|
||||
/* OSTimer class */
|
||||
JS_NewClassID(&js_os_timer_class_id);
|
||||
JS_NewClass(JS_GetRuntime(ctx), js_os_timer_class_id, &js_os_timer_class);
|
||||
|
@ -3612,20 +3612,20 @@ static int js_os_init(JSContext *ctx, JSModuleDef *m)
|
|||
JS_NewClass(JS_GetRuntime(ctx), js_worker_class_id, &js_worker_class);
|
||||
proto = JS_NewObject(ctx);
|
||||
JS_SetPropertyFunctionList(ctx, proto, js_worker_proto_funcs, countof(js_worker_proto_funcs));
|
||||
|
||||
|
||||
obj = JS_NewCFunction2(ctx, js_worker_ctor, "Worker", 1,
|
||||
JS_CFUNC_constructor, 0);
|
||||
JS_SetConstructor(ctx, obj, proto);
|
||||
|
||||
|
||||
JS_SetClassProto(ctx, js_worker_class_id, proto);
|
||||
|
||||
|
||||
/* set 'Worker.parent' if necessary */
|
||||
if (ts->recv_pipe && ts->send_pipe) {
|
||||
JS_DefinePropertyValueStr(ctx, obj, "parent",
|
||||
js_worker_ctor_internal(ctx, JS_UNDEFINED, ts->recv_pipe, ts->send_pipe),
|
||||
JS_PROP_C_W_E);
|
||||
}
|
||||
|
||||
|
||||
JS_SetModuleExport(ctx, m, "Worker", obj);
|
||||
}
|
||||
#endif /* USE_WORKER */
|
||||
|
@ -3690,12 +3690,12 @@ void js_std_add_helpers(JSContext *ctx, int argc, char **argv)
|
|||
}
|
||||
JS_SetPropertyStr(ctx, global_obj, "scriptArgs", args);
|
||||
}
|
||||
|
||||
|
||||
JS_SetPropertyStr(ctx, global_obj, "print",
|
||||
JS_NewCFunction(ctx, js_print, "print", 1));
|
||||
JS_SetPropertyStr(ctx, global_obj, "__loadScript",
|
||||
JS_NewCFunction(ctx, js_loadScript, "__loadScript", 1));
|
||||
|
||||
|
||||
JS_FreeValue(ctx, global_obj);
|
||||
}
|
||||
|
||||
|
@ -3743,7 +3743,7 @@ void js_std_free_handlers(JSRuntime *rt)
|
|||
JSOSSignalHandler *sh = list_entry(el, JSOSSignalHandler, link);
|
||||
free_sh(rt, sh);
|
||||
}
|
||||
|
||||
|
||||
list_for_each_safe(el, el1, &ts->os_timers) {
|
||||
JSOSTimer *th = list_entry(el, JSOSTimer, link);
|
||||
unlink_timer(rt, th);
|
||||
|
@ -3764,7 +3764,7 @@ void js_std_free_handlers(JSRuntime *rt)
|
|||
static void js_dump_obj(JSContext *ctx, FILE *f, JSValueConst val)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
|
||||
str = JS_ToCString(ctx, val);
|
||||
if (str) {
|
||||
fprintf(f, "%s\n", str);
|
||||
|
@ -3778,7 +3778,7 @@ static void js_std_dump_error1(JSContext *ctx, JSValueConst exception_val)
|
|||
{
|
||||
JSValue val;
|
||||
BOOL is_error;
|
||||
|
||||
|
||||
is_error = JS_IsError(ctx, exception_val);
|
||||
js_dump_obj(ctx, stderr, exception_val);
|
||||
if (is_error) {
|
||||
|
@ -3793,7 +3793,7 @@ static void js_std_dump_error1(JSContext *ctx, JSValueConst exception_val)
|
|||
void js_std_dump_error(JSContext *ctx)
|
||||
{
|
||||
JSValue exception_val;
|
||||
|
||||
|
||||
exception_val = JS_GetException(ctx);
|
||||
js_std_dump_error1(ctx, exception_val);
|
||||
JS_FreeValue(ctx, exception_val);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue