From 17aa5bcf29fb46daea23fcde45f9bc2a636cffc3 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Mon, 17 Oct 2022 18:22:33 +0200 Subject: [PATCH] [xhr] onloadend --- src/ecmascript/spidermonkey/xhr.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/ecmascript/spidermonkey/xhr.cpp b/src/ecmascript/spidermonkey/xhr.cpp index 8887656e..ecade426 100644 --- a/src/ecmascript/spidermonkey/xhr.cpp +++ b/src/ecmascript/spidermonkey/xhr.cpp @@ -143,6 +143,7 @@ struct xhr { }; static void onload_run(void *data); +static void onloadend_run(void *data); static void onreadystatechange_run(void *data); static void ontimeout_run(void *data); @@ -534,6 +535,25 @@ onload_run(void *data) } } +static void +onloadend_run(void *data) +{ + struct xhr *xhr = (struct xhr *)data; + + if (xhr) { + struct ecmascript_interpreter *interpreter = xhr->interpreter; + JSContext *ctx = (JSContext *)interpreter->backend_data; + JS::Realm *comp = JS::EnterRealm(ctx, (JSObject *)interpreter->ac); + JS::RootedValue r_val(ctx); + interpreter->heartbeat = add_heartbeat(interpreter); + JS_CallFunctionValue(ctx, xhr->thisval, xhr->onloadend, JS::HandleValueArray::empty(), &r_val); + done_heartbeat(interpreter->heartbeat); + JS::LeaveRealm(ctx, comp); + + check_for_rerender(interpreter, "xhr_onloadend"); + } +} + static void onreadystatechange_run(void *data) { @@ -612,6 +632,7 @@ xhr_loading_callback(struct download *download, struct xhr *xhr) if (is_in_state(download->state, S_TIMEOUT)) { xhr->readyState = DONE; register_bottom_half(ontimeout_run, xhr); + register_bottom_half(onloadend_run, xhr); } else if (is_in_result_state(download->state)) { struct cache_entry *cached = download->cached; @@ -680,6 +701,7 @@ xhr_loading_callback(struct download *download, struct xhr *xhr) mem_free_set(&xhr->responseType, stracpy("")); xhr->readyState = DONE; register_bottom_half(onload_run, xhr); + register_bottom_half(onloadend_run, xhr); } }