Skip to content

Commit 2fd48bf

Browse files
author
Fabrice Bellard
committed
fixed module async evaluation logic - added DUMP_MODULE_EXEC
1 parent f1b1c00 commit 2fd48bf

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

TODO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,5 @@ Optimization ideas:
6262
Test262o: 0/11262 errors, 463 excluded
6363
Test262o commit: 7da91bceb9ce7613f87db47ddd1292a2dda58b42 (es5-tests branch)
6464

65-
Result: 48/79398 errors, 1637 excluded, 6771 skipped
65+
Result: 47/79398 errors, 1637 excluded, 6771 skipped
6666
Test262 commit: 1e38cbeb1c878a352b55c3ebe03ee8eda74a33ed

quickjs.c

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
//#define DUMP_ATOMS /* dump atoms in JS_FreeContext */
104104
//#define DUMP_SHAPES /* dump shapes in JS_FreeContext */
105105
//#define DUMP_MODULE_RESOLVE
106+
//#define DUMP_MODULE_EXEC
106107
//#define DUMP_PROMISE
107108
//#define DUMP_READ_OBJECT
108109
//#define DUMP_ROPE_REBALANCE
@@ -839,7 +840,8 @@ struct JSModuleDef {
839840
int async_parent_modules_count;
840841
int async_parent_modules_size;
841842
int pending_async_dependencies;
842-
BOOL async_evaluation;
843+
BOOL async_evaluation; /* true: async_evaluation_timestamp corresponds to [[AsyncEvaluationOrder]]
844+
false: [[AsyncEvaluationOrder]] is UNSET or DONE */
843845
int64_t async_evaluation_timestamp;
844846
JSModuleDef *cycle_root;
845847
JSValue promise; /* corresponds to spec field: capability */
@@ -29833,6 +29835,14 @@ static int exec_module_list_cmp(const void *p1, const void *p2, void *opaque)
2983329835
static int js_execute_async_module(JSContext *ctx, JSModuleDef *m);
2983429836
static int js_execute_sync_module(JSContext *ctx, JSModuleDef *m,
2983529837
JSValue *pvalue);
29838+
#ifdef DUMP_MODULE_EXEC
29839+
static void js_dump_module(JSContext *ctx, const char *str, JSModuleDef *m)
29840+
{
29841+
char buf1[ATOM_GET_STR_BUF_SIZE];
29842+
static const char *module_status_str[] = { "unlinked", "linking", "linked", "evaluating", "evaluating_async", "evaluated" };
29843+
printf("%s: %s status=%s\n", str, JS_AtomGetStr(ctx, buf1, sizeof(buf1), m->module_name), module_status_str[m->status]);
29844+
}
29845+
#endif
2983629846

2983729847
static JSValue js_async_module_execution_rejected(JSContext *ctx, JSValueConst this_val,
2983829848
int argc, JSValueConst *argv, int magic, JSValue *func_data)
@@ -29841,6 +29851,9 @@ static JSValue js_async_module_execution_rejected(JSContext *ctx, JSValueConst t
2984129851
JSValueConst error = argv[0];
2984229852
int i;
2984329853

29854+
#ifdef DUMP_MODULE_EXEC
29855+
js_dump_module(ctx, __func__, module);
29856+
#endif
2984429857
if (js_check_stack_overflow(ctx->rt, 0))
2984529858
return JS_ThrowStackOverflow(ctx);
2984629859

@@ -29856,6 +29869,7 @@ static JSValue js_async_module_execution_rejected(JSContext *ctx, JSValueConst t
2985629869
module->eval_has_exception = TRUE;
2985729870
module->eval_exception = JS_DupValue(ctx, error);
2985829871
module->status = JS_MODULE_STATUS_EVALUATED;
29872+
module->async_evaluation = FALSE;
2985929873

2986029874
for(i = 0; i < module->async_parent_modules_count; i++) {
2986129875
JSModuleDef *m = module->async_parent_modules[i];
@@ -29882,6 +29896,9 @@ static JSValue js_async_module_execution_fulfilled(JSContext *ctx, JSValueConst
2988229896
ExecModuleList exec_list_s, *exec_list = &exec_list_s;
2988329897
int i;
2988429898

29899+
#ifdef DUMP_MODULE_EXEC
29900+
js_dump_module(ctx, __func__, module);
29901+
#endif
2988529902
if (module->status == JS_MODULE_STATUS_EVALUATED) {
2988629903
assert(module->eval_has_exception);
2988729904
return JS_UNDEFINED;
@@ -29907,6 +29924,9 @@ static JSValue js_async_module_execution_fulfilled(JSContext *ctx, JSValueConst
2990729924

2990829925
for(i = 0; i < exec_list->count; i++) {
2990929926
JSModuleDef *m = exec_list->tab[i];
29927+
#ifdef DUMP_MODULE_EXEC
29928+
printf(" %d/%d", i, exec_list->count); js_dump_module(ctx, "", m);
29929+
#endif
2991029930
if (m->status == JS_MODULE_STATUS_EVALUATED) {
2991129931
assert(m->eval_has_exception);
2991229932
} else if (m->has_tla) {
@@ -29921,6 +29941,7 @@ static JSValue js_async_module_execution_fulfilled(JSContext *ctx, JSValueConst
2992129941
JS_FreeValue(ctx, m_obj);
2992229942
JS_FreeValue(ctx, error);
2992329943
} else {
29944+
m->async_evaluation = FALSE;
2992429945
js_set_module_evaluated(ctx, m);
2992529946
}
2992629947
}
@@ -29933,6 +29954,9 @@ static int js_execute_async_module(JSContext *ctx, JSModuleDef *m)
2993329954
{
2993429955
JSValue promise, m_obj;
2993529956
JSValue resolve_funcs[2], ret_val;
29957+
#ifdef DUMP_MODULE_EXEC
29958+
js_dump_module(ctx, __func__, m);
29959+
#endif
2993629960
promise = js_async_function_call(ctx, m->func_obj, JS_UNDEFINED, 0, NULL, 0);
2993729961
if (JS_IsException(promise))
2993829962
return -1;
@@ -29952,6 +29976,9 @@ static int js_execute_async_module(JSContext *ctx, JSModuleDef *m)
2995229976
static int js_execute_sync_module(JSContext *ctx, JSModuleDef *m,
2995329977
JSValue *pvalue)
2995429978
{
29979+
#ifdef DUMP_MODULE_EXEC
29980+
js_dump_module(ctx, __func__, m);
29981+
#endif
2995529982
if (m->init_func) {
2995629983
/* C module init : no asynchronous execution */
2995729984
if (m->init_func(ctx, m) < 0)
@@ -29991,19 +30018,16 @@ static int js_inner_module_evaluation(JSContext *ctx, JSModuleDef *m,
2999130018
JSModuleDef *m1;
2999230019
int i;
2999330020

30021+
#ifdef DUMP_MODULE_EXEC
30022+
js_dump_module(ctx, __func__, m);
30023+
#endif
30024+
2999430025
if (js_check_stack_overflow(ctx->rt, 0)) {
2999530026
JS_ThrowStackOverflow(ctx);
2999630027
*pvalue = JS_GetException(ctx);
2999730028
return -1;
2999830029
}
2999930030

30000-
#ifdef DUMP_MODULE_RESOLVE
30001-
{
30002-
char buf1[ATOM_GET_STR_BUF_SIZE];
30003-
printf("js_inner_module_evaluation '%s':\n", JS_AtomGetStr(ctx, buf1, sizeof(buf1), m->module_name));
30004-
}
30005-
#endif
30006-
3000730031
if (m->status == JS_MODULE_STATUS_EVALUATING_ASYNC ||
3000830032
m->status == JS_MODULE_STATUS_EVALUATED) {
3000930033
if (m->eval_has_exception) {
@@ -30104,6 +30128,9 @@ static JSValue js_evaluate_module(JSContext *ctx, JSModuleDef *m)
3010430128
JSModuleDef *m1, *stack_top;
3010530129
JSValue ret_val, result;
3010630130

30131+
#ifdef DUMP_MODULE_EXEC
30132+
js_dump_module(ctx, __func__, m);
30133+
#endif
3010730134
assert(m->status == JS_MODULE_STATUS_LINKED ||
3010830135
m->status == JS_MODULE_STATUS_EVALUATING_ASYNC ||
3010930136
m->status == JS_MODULE_STATUS_EVALUATED);
@@ -30136,6 +30163,9 @@ static JSValue js_evaluate_module(JSContext *ctx, JSModuleDef *m)
3013630163
1, (JSValueConst *)&m->eval_exception);
3013730164
JS_FreeValue(ctx, ret_val);
3013830165
} else {
30166+
#ifdef DUMP_MODULE_EXEC
30167+
js_dump_module(ctx, " done", m);
30168+
#endif
3013930169
assert(m->status == JS_MODULE_STATUS_EVALUATING_ASYNC ||
3014030170
m->status == JS_MODULE_STATUS_EVALUATED);
3014130171
assert(!m->eval_has_exception);

test262_errors.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
test262/test/built-ins/Atomics/notify/retrieve-length-before-index-coercion-non-shared-detached.js:34: TypeError: ArrayBuffer is detached
22
test262/test/built-ins/Atomics/notify/retrieve-length-before-index-coercion-non-shared-detached.js:34: strict mode: TypeError: ArrayBuffer is detached
3-
test262/test/language/module-code/top-level-await/module-graphs-does-not-hang.js:10: TypeError: $DONE() not called
43
test262/test/staging/sm/Date/UTC-convert-all-arguments.js:75: Test262Error: index 1: expected 42, got Error: didn't throw Expected SameValue(«Error: didn't throw», «42») to be true
54
test262/test/staging/sm/Date/constructor-convert-all-arguments.js:75: Test262Error: index undefined: expected 42, got Error: didn't throw Expected SameValue(«Error: didn't throw», «42») to be true
65
test262/test/staging/sm/Date/non-iso.js:76: Test262Error: Expected SameValue(«NaN», «-40071559730000») to be true

0 commit comments

Comments
 (0)