mirror of
https://github.com/bellard/quickjs.git
synced 2025-09-30 23:07:42 +03:00
Strip trailing spaces
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* ECMA Test 262 Runner for QuickJS
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2017-2021 Fabrice Bellard
|
||||
* Copyright (c) 2017-2021 Charlie Gordon
|
||||
*
|
||||
@@ -321,7 +321,7 @@ void namelist_load(namelist_t *lp, const char *filename)
|
||||
char *p = str_strip(buf);
|
||||
if (*p == '#' || *p == ';' || *p == '\0')
|
||||
continue; /* line comment */
|
||||
|
||||
|
||||
namelist_add(lp, base_name, p);
|
||||
}
|
||||
free(base_name);
|
||||
@@ -457,11 +457,11 @@ static void *agent_start(void *arg)
|
||||
JSContext *ctx;
|
||||
JSValue ret_val;
|
||||
int ret;
|
||||
|
||||
|
||||
rt = JS_NewRuntime();
|
||||
if (rt == NULL) {
|
||||
fatal(1, "JS_NewRuntime failure");
|
||||
}
|
||||
}
|
||||
ctx = JS_NewContext(rt);
|
||||
if (ctx == NULL) {
|
||||
JS_FreeRuntime(rt);
|
||||
@@ -470,7 +470,7 @@ static void *agent_start(void *arg)
|
||||
JS_SetContextOpaque(ctx, agent);
|
||||
JS_SetRuntimeInfo(rt, "agent");
|
||||
JS_SetCanBlock(rt, TRUE);
|
||||
|
||||
|
||||
add_helpers(ctx);
|
||||
ret_val = JS_Eval(ctx, agent->script, strlen(agent->script),
|
||||
"<evalScript>", JS_EVAL_TYPE_GLOBAL);
|
||||
@@ -479,7 +479,7 @@ static void *agent_start(void *arg)
|
||||
if (JS_IsException(ret_val))
|
||||
js_std_dump_error(ctx);
|
||||
JS_FreeValue(ctx, ret_val);
|
||||
|
||||
|
||||
for(;;) {
|
||||
JSContext *ctx1;
|
||||
ret = JS_ExecutePendingJob(JS_GetRuntime(ctx), &ctx1);
|
||||
@@ -491,12 +491,12 @@ static void *agent_start(void *arg)
|
||||
break;
|
||||
} else {
|
||||
JSValue args[2];
|
||||
|
||||
|
||||
pthread_mutex_lock(&agent_mutex);
|
||||
while (!agent->broadcast_pending) {
|
||||
pthread_cond_wait(&agent_cond, &agent_mutex);
|
||||
}
|
||||
|
||||
|
||||
agent->broadcast_pending = FALSE;
|
||||
pthread_cond_signal(&agent_cond);
|
||||
|
||||
@@ -533,7 +533,7 @@ static JSValue js_agent_start(JSContext *ctx, JSValue this_val,
|
||||
|
||||
if (JS_GetContextOpaque(ctx) != NULL)
|
||||
return JS_ThrowTypeError(ctx, "cannot be called inside an agent");
|
||||
|
||||
|
||||
script = JS_ToCString(ctx, argv[0]);
|
||||
if (!script)
|
||||
return JS_EXCEPTION;
|
||||
@@ -552,7 +552,7 @@ static void js_agent_free(JSContext *ctx)
|
||||
{
|
||||
struct list_head *el, *el1;
|
||||
Test262Agent *agent;
|
||||
|
||||
|
||||
list_for_each_safe(el, el1, &agent_list) {
|
||||
agent = list_entry(el, Test262Agent, link);
|
||||
pthread_join(agent->tid, NULL);
|
||||
@@ -561,7 +561,7 @@ static void js_agent_free(JSContext *ctx)
|
||||
free(agent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static JSValue js_agent_leaving(JSContext *ctx, JSValue this_val,
|
||||
int argc, JSValue *argv)
|
||||
{
|
||||
@@ -593,16 +593,16 @@ static JSValue js_agent_broadcast(JSContext *ctx, JSValue this_val,
|
||||
uint8_t *buf;
|
||||
size_t buf_size;
|
||||
int32_t val;
|
||||
|
||||
|
||||
if (JS_GetContextOpaque(ctx) != NULL)
|
||||
return JS_ThrowTypeError(ctx, "cannot be called inside an agent");
|
||||
|
||||
|
||||
buf = JS_GetArrayBuffer(ctx, &buf_size, sab);
|
||||
if (!buf)
|
||||
return JS_EXCEPTION;
|
||||
if (JS_ToInt32(ctx, &val, argv[1]))
|
||||
return JS_EXCEPTION;
|
||||
|
||||
|
||||
/* broadcast the values and wait until all agents have started
|
||||
calling their callbacks */
|
||||
pthread_mutex_lock(&agent_mutex);
|
||||
@@ -697,7 +697,7 @@ static JSValue js_agent_report(JSContext *ctx, JSValue this_val,
|
||||
rep = malloc(sizeof(*rep));
|
||||
rep->str = strdup(str);
|
||||
JS_FreeCString(ctx, str);
|
||||
|
||||
|
||||
pthread_mutex_lock(&report_mutex);
|
||||
list_add_tail(&rep->link, &report_list);
|
||||
pthread_mutex_unlock(&report_mutex);
|
||||
@@ -717,7 +717,7 @@ static const JSCFunctionListEntry js_agent_funcs[] = {
|
||||
JS_CFUNC_DEF("sleep", 1, js_agent_sleep ),
|
||||
JS_CFUNC_DEF("monotonicNow", 0, js_agent_monotonicNow ),
|
||||
};
|
||||
|
||||
|
||||
static JSValue js_new_agent(JSContext *ctx)
|
||||
{
|
||||
JSValue agent;
|
||||
@@ -733,7 +733,7 @@ static JSValue js_createRealm(JSContext *ctx, JSValue this_val,
|
||||
{
|
||||
JSContext *ctx1;
|
||||
JSValue ret;
|
||||
|
||||
|
||||
ctx1 = JS_NewContext(JS_GetRuntime(ctx));
|
||||
if (!ctx1)
|
||||
return JS_ThrowOutOfMemory(ctx);
|
||||
@@ -753,7 +753,7 @@ static JSValue add_helpers1(JSContext *ctx)
|
||||
{
|
||||
JSValue global_obj;
|
||||
JSValue obj262, obj;
|
||||
|
||||
|
||||
global_obj = JS_GetGlobalObject(ctx);
|
||||
|
||||
JS_SetPropertyStr(ctx, global_obj, "print",
|
||||
@@ -784,7 +784,7 @@ static JSValue add_helpers1(JSContext *ctx)
|
||||
JS_SetPropertyStr(ctx, obj262, "IsHTMLDDA", obj);
|
||||
|
||||
JS_SetPropertyStr(ctx, global_obj, "$262", JS_DupValue(ctx, obj262));
|
||||
|
||||
|
||||
JS_FreeValue(ctx, global_obj);
|
||||
return obj262;
|
||||
}
|
||||
@@ -813,14 +813,14 @@ static JSModuleDef *js_module_loader_test(JSContext *ctx,
|
||||
uint8_t *buf;
|
||||
JSModuleDef *m;
|
||||
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);
|
||||
@@ -929,14 +929,14 @@ void load_config(const char *filename)
|
||||
perror_exit(1, filename);
|
||||
}
|
||||
base_name = get_basename(filename);
|
||||
|
||||
|
||||
while (fgets(buf, sizeof(buf), f) != NULL) {
|
||||
char *p, *q;
|
||||
lineno++;
|
||||
p = str_strip(buf);
|
||||
if (*p == '#' || *p == ';' || *p == '\0')
|
||||
continue; /* line comment */
|
||||
|
||||
|
||||
if (*p == "[]"[0]) {
|
||||
/* new section */
|
||||
p++;
|
||||
@@ -1002,7 +1002,7 @@ void load_config(const char *filename)
|
||||
test_mode = TEST_STRICT;
|
||||
else if (str_equal(q, "all") || str_equal(q, "both"))
|
||||
test_mode = TEST_ALL;
|
||||
else
|
||||
else
|
||||
fatal(2, "unknown test mode: %s", q);
|
||||
continue;
|
||||
}
|
||||
@@ -1143,7 +1143,7 @@ int longest_match(const char *str, const char *find, int pos, int *ppos, int lin
|
||||
int len, maxlen;
|
||||
|
||||
maxlen = 0;
|
||||
|
||||
|
||||
if (*find) {
|
||||
const char *p;
|
||||
for (p = str + pos; *p; p++) {
|
||||
@@ -1176,7 +1176,7 @@ static int eval_buf(JSContext *ctx, const char *buf, size_t buf_len,
|
||||
int ret, error_line, pos, pos_line;
|
||||
BOOL is_error, has_error_line, ret_promise;
|
||||
const char *error_name;
|
||||
|
||||
|
||||
pos = skip_comments(buf, 1, &pos_line);
|
||||
error_line = pos_line;
|
||||
has_error_line = FALSE;
|
||||
@@ -1186,7 +1186,7 @@ static int eval_buf(JSContext *ctx, const char *buf, size_t buf_len,
|
||||
/* a module evaluation returns a promise */
|
||||
ret_promise = ((eval_flags & JS_EVAL_TYPE_MODULE) != 0);
|
||||
async_done = 0; /* counter of "Test262:AsyncTestComplete" messages */
|
||||
|
||||
|
||||
res_val = JS_Eval(ctx, buf, buf_len, filename, eval_flags);
|
||||
|
||||
if ((is_async || ret_promise) && !JS_IsException(res_val)) {
|
||||
@@ -1239,7 +1239,7 @@ static int eval_buf(JSContext *ctx, const char *buf, size_t buf_len,
|
||||
if (is_error) {
|
||||
JSValue name, stack;
|
||||
const char *stack_str;
|
||||
|
||||
|
||||
name = JS_GetPropertyStr(ctx, exception_val, "name");
|
||||
error_name = JS_ToCString(ctx, name);
|
||||
stack = JS_GetPropertyStr(ctx, exception_val, "stack");
|
||||
@@ -1248,10 +1248,10 @@ static int eval_buf(JSContext *ctx, const char *buf, size_t buf_len,
|
||||
if (stack_str) {
|
||||
const char *p;
|
||||
int len;
|
||||
|
||||
|
||||
if (outfile)
|
||||
fprintf(outfile, "%s", stack_str);
|
||||
|
||||
|
||||
len = strlen(filename);
|
||||
p = strstr(stack_str, filename);
|
||||
if (p != NULL && p[len] == ':') {
|
||||
@@ -1269,7 +1269,7 @@ static int eval_buf(JSContext *ctx, const char *buf, size_t buf_len,
|
||||
if (error_type) {
|
||||
char *error_class;
|
||||
const char *msg;
|
||||
|
||||
|
||||
msg = JS_ToCString(ctx, exception_val);
|
||||
error_class = strdup_len(msg, strcspn(msg, ":"));
|
||||
if (!str_equal(error_class, error_type))
|
||||
@@ -1393,7 +1393,7 @@ char *extract_desc(const char *buf, char style)
|
||||
const char *p, *desc_start;
|
||||
char *desc;
|
||||
int len;
|
||||
|
||||
|
||||
p = buf;
|
||||
while (*p != '\0') {
|
||||
if (p[0] == '/' && p[1] == '*' && p[2] == style && p[3] != '/') {
|
||||
@@ -1525,11 +1525,11 @@ int run_test_buf(const char *filename, const char *harness, namelist_t *ip,
|
||||
JSRuntime *rt;
|
||||
JSContext *ctx;
|
||||
int i, ret;
|
||||
|
||||
|
||||
rt = JS_NewRuntime();
|
||||
if (rt == NULL) {
|
||||
fatal(1, "JS_NewRuntime failure");
|
||||
}
|
||||
}
|
||||
ctx = JS_NewContext(rt);
|
||||
if (ctx == NULL) {
|
||||
JS_FreeRuntime(rt);
|
||||
@@ -1538,10 +1538,10 @@ int run_test_buf(const char *filename, const char *harness, namelist_t *ip,
|
||||
JS_SetRuntimeInfo(rt, filename);
|
||||
|
||||
JS_SetCanBlock(rt, can_block);
|
||||
|
||||
|
||||
/* loader for ES6 modules */
|
||||
JS_SetModuleLoaderFunc(rt, NULL, js_module_loader_test, NULL);
|
||||
|
||||
|
||||
add_helpers(ctx);
|
||||
|
||||
for (i = 0; i < ip->count; i++) {
|
||||
@@ -1554,7 +1554,7 @@ int run_test_buf(const char *filename, const char *harness, namelist_t *ip,
|
||||
ret = eval_buf(ctx, buf, buf_len, filename, TRUE, is_negative,
|
||||
error_type, outfile, eval_flags, is_async);
|
||||
ret = (ret != 0);
|
||||
|
||||
|
||||
if (dump_memory) {
|
||||
update_stats(rt, filename);
|
||||
}
|
||||
@@ -1587,7 +1587,7 @@ int run_test(const char *filename, int index)
|
||||
BOOL is_negative, is_nostrict, is_onlystrict, is_async, is_module, skip;
|
||||
BOOL can_block;
|
||||
namelist_t include_list = { 0 }, *ip = &include_list;
|
||||
|
||||
|
||||
is_nostrict = is_onlystrict = is_negative = is_async = is_module = skip = FALSE;
|
||||
can_block = TRUE;
|
||||
error_type = NULL;
|
||||
@@ -1823,13 +1823,13 @@ int run_test262_harness_test(const char *filename, BOOL is_module)
|
||||
int eval_flags, ret_code, ret;
|
||||
JSValue res_val;
|
||||
BOOL can_block;
|
||||
|
||||
|
||||
outfile = stdout; /* for js_print */
|
||||
|
||||
rt = JS_NewRuntime();
|
||||
if (rt == NULL) {
|
||||
fatal(1, "JS_NewRuntime failure");
|
||||
}
|
||||
}
|
||||
ctx = JS_NewContext(rt);
|
||||
if (ctx == NULL) {
|
||||
JS_FreeRuntime(rt);
|
||||
@@ -1839,10 +1839,10 @@ int run_test262_harness_test(const char *filename, BOOL is_module)
|
||||
|
||||
can_block = TRUE;
|
||||
JS_SetCanBlock(rt, can_block);
|
||||
|
||||
|
||||
/* loader for ES6 modules */
|
||||
JS_SetModuleLoaderFunc(rt, NULL, js_module_loader_test, NULL);
|
||||
|
||||
|
||||
add_helpers(ctx);
|
||||
|
||||
buf = load_file(filename, &buf_len);
|
||||
@@ -2035,14 +2035,14 @@ int main(int argc, char **argv)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (optind >= argc && !test_list.count)
|
||||
help();
|
||||
|
||||
if (is_test262_harness) {
|
||||
return run_test262_harness_test(argv[optind], is_module);
|
||||
}
|
||||
|
||||
|
||||
error_out = stdout;
|
||||
if (error_filename) {
|
||||
error_file = load_file(error_filename, NULL);
|
||||
|
Reference in New Issue
Block a user