103
103
//#define DUMP_ATOMS /* dump atoms in JS_FreeContext */
104
104
//#define DUMP_SHAPES /* dump shapes in JS_FreeContext */
105
105
//#define DUMP_MODULE_RESOLVE
106
+ //#define DUMP_MODULE_EXEC
106
107
//#define DUMP_PROMISE
107
108
//#define DUMP_READ_OBJECT
108
109
//#define DUMP_ROPE_REBALANCE
@@ -839,7 +840,8 @@ struct JSModuleDef {
839
840
int async_parent_modules_count;
840
841
int async_parent_modules_size;
841
842
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 */
843
845
int64_t async_evaluation_timestamp;
844
846
JSModuleDef *cycle_root;
845
847
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)
29833
29835
static int js_execute_async_module(JSContext *ctx, JSModuleDef *m);
29834
29836
static int js_execute_sync_module(JSContext *ctx, JSModuleDef *m,
29835
29837
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
29836
29846
29837
29847
static JSValue js_async_module_execution_rejected(JSContext *ctx, JSValueConst this_val,
29838
29848
int argc, JSValueConst *argv, int magic, JSValue *func_data)
@@ -29841,6 +29851,9 @@ static JSValue js_async_module_execution_rejected(JSContext *ctx, JSValueConst t
29841
29851
JSValueConst error = argv[0];
29842
29852
int i;
29843
29853
29854
+ #ifdef DUMP_MODULE_EXEC
29855
+ js_dump_module(ctx, __func__, module);
29856
+ #endif
29844
29857
if (js_check_stack_overflow(ctx->rt, 0))
29845
29858
return JS_ThrowStackOverflow(ctx);
29846
29859
@@ -29856,6 +29869,7 @@ static JSValue js_async_module_execution_rejected(JSContext *ctx, JSValueConst t
29856
29869
module->eval_has_exception = TRUE;
29857
29870
module->eval_exception = JS_DupValue(ctx, error);
29858
29871
module->status = JS_MODULE_STATUS_EVALUATED;
29872
+ module->async_evaluation = FALSE;
29859
29873
29860
29874
for(i = 0; i < module->async_parent_modules_count; i++) {
29861
29875
JSModuleDef *m = module->async_parent_modules[i];
@@ -29882,6 +29896,9 @@ static JSValue js_async_module_execution_fulfilled(JSContext *ctx, JSValueConst
29882
29896
ExecModuleList exec_list_s, *exec_list = &exec_list_s;
29883
29897
int i;
29884
29898
29899
+ #ifdef DUMP_MODULE_EXEC
29900
+ js_dump_module(ctx, __func__, module);
29901
+ #endif
29885
29902
if (module->status == JS_MODULE_STATUS_EVALUATED) {
29886
29903
assert(module->eval_has_exception);
29887
29904
return JS_UNDEFINED;
@@ -29907,6 +29924,9 @@ static JSValue js_async_module_execution_fulfilled(JSContext *ctx, JSValueConst
29907
29924
29908
29925
for(i = 0; i < exec_list->count; i++) {
29909
29926
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
29910
29930
if (m->status == JS_MODULE_STATUS_EVALUATED) {
29911
29931
assert(m->eval_has_exception);
29912
29932
} else if (m->has_tla) {
@@ -29921,6 +29941,7 @@ static JSValue js_async_module_execution_fulfilled(JSContext *ctx, JSValueConst
29921
29941
JS_FreeValue(ctx, m_obj);
29922
29942
JS_FreeValue(ctx, error);
29923
29943
} else {
29944
+ m->async_evaluation = FALSE;
29924
29945
js_set_module_evaluated(ctx, m);
29925
29946
}
29926
29947
}
@@ -29933,6 +29954,9 @@ static int js_execute_async_module(JSContext *ctx, JSModuleDef *m)
29933
29954
{
29934
29955
JSValue promise, m_obj;
29935
29956
JSValue resolve_funcs[2], ret_val;
29957
+ #ifdef DUMP_MODULE_EXEC
29958
+ js_dump_module(ctx, __func__, m);
29959
+ #endif
29936
29960
promise = js_async_function_call(ctx, m->func_obj, JS_UNDEFINED, 0, NULL, 0);
29937
29961
if (JS_IsException(promise))
29938
29962
return -1;
@@ -29952,6 +29976,9 @@ static int js_execute_async_module(JSContext *ctx, JSModuleDef *m)
29952
29976
static int js_execute_sync_module(JSContext *ctx, JSModuleDef *m,
29953
29977
JSValue *pvalue)
29954
29978
{
29979
+ #ifdef DUMP_MODULE_EXEC
29980
+ js_dump_module(ctx, __func__, m);
29981
+ #endif
29955
29982
if (m->init_func) {
29956
29983
/* C module init : no asynchronous execution */
29957
29984
if (m->init_func(ctx, m) < 0)
@@ -29991,19 +30018,16 @@ static int js_inner_module_evaluation(JSContext *ctx, JSModuleDef *m,
29991
30018
JSModuleDef *m1;
29992
30019
int i;
29993
30020
30021
+ #ifdef DUMP_MODULE_EXEC
30022
+ js_dump_module(ctx, __func__, m);
30023
+ #endif
30024
+
29994
30025
if (js_check_stack_overflow(ctx->rt, 0)) {
29995
30026
JS_ThrowStackOverflow(ctx);
29996
30027
*pvalue = JS_GetException(ctx);
29997
30028
return -1;
29998
30029
}
29999
30030
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
-
30007
30031
if (m->status == JS_MODULE_STATUS_EVALUATING_ASYNC ||
30008
30032
m->status == JS_MODULE_STATUS_EVALUATED) {
30009
30033
if (m->eval_has_exception) {
@@ -30104,6 +30128,9 @@ static JSValue js_evaluate_module(JSContext *ctx, JSModuleDef *m)
30104
30128
JSModuleDef *m1, *stack_top;
30105
30129
JSValue ret_val, result;
30106
30130
30131
+ #ifdef DUMP_MODULE_EXEC
30132
+ js_dump_module(ctx, __func__, m);
30133
+ #endif
30107
30134
assert(m->status == JS_MODULE_STATUS_LINKED ||
30108
30135
m->status == JS_MODULE_STATUS_EVALUATING_ASYNC ||
30109
30136
m->status == JS_MODULE_STATUS_EVALUATED);
@@ -30136,6 +30163,9 @@ static JSValue js_evaluate_module(JSContext *ctx, JSModuleDef *m)
30136
30163
1, (JSValueConst *)&m->eval_exception);
30137
30164
JS_FreeValue(ctx, ret_val);
30138
30165
} else {
30166
+ #ifdef DUMP_MODULE_EXEC
30167
+ js_dump_module(ctx, " done", m);
30168
+ #endif
30139
30169
assert(m->status == JS_MODULE_STATUS_EVALUATING_ASYNC ||
30140
30170
m->status == JS_MODULE_STATUS_EVALUATED);
30141
30171
assert(!m->eval_has_exception);
0 commit comments