From 66a23c25605c9c7eca7b5c9b420a079ce1203faf Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 21 Mar 2020 19:08:21 +0000 Subject: Browser: Split JS threads between current and loading Signed-off-by: Daniel Silverstone --- desktop/browser_private.h | 7 ++++++- desktop/browser_window.c | 50 +++++++++++++++++++++++++++++++++++------------ 2 files changed, 44 insertions(+), 13 deletions(-) (limited to 'desktop') diff --git a/desktop/browser_private.h b/desktop/browser_private.h index 562abf131..89dc5cca4 100644 --- a/desktop/browser_private.h +++ b/desktop/browser_private.h @@ -264,7 +264,12 @@ struct browser_window { /** current javascript context */ struct jsheap *jsheap; - struct jsthread *jsthread; + + /** The JS thread (if any) for the current content */ + struct jsthread *current_jsthread; + + /** The JS thread (if any) for the loading content */ + struct jsthread *loading_jsthread; /** cache of the currently displayed status text. */ struct { diff --git a/desktop/browser_window.c b/desktop/browser_window.c index bd446a072..c98eca832 100644 --- a/desktop/browser_window.c +++ b/desktop/browser_window.c @@ -702,6 +702,10 @@ browser_window_convert_to_download(struct browser_window *bw, /* remove content from browser window */ hlcache_handle_release(bw->loading_content); bw->loading_content = NULL; + if (bw->loading_jsthread != NULL) { + js_destroythread(bw->loading_jsthread); + bw->loading_jsthread = NULL; + } browser_window_stop_throbber(bw); } @@ -719,10 +723,15 @@ static nserror browser_window_content_ready(struct browser_window *bw) if (bw->current_content != NULL) { content_close(bw->current_content); hlcache_handle_release(bw->current_content); + if (bw->current_jsthread != NULL) { + js_destroythread(bw->current_jsthread); + } } bw->current_content = bw->loading_content; + bw->current_jsthread = bw->loading_jsthread; bw->loading_content = NULL; + bw->loading_jsthread = NULL; if (!bw->internal_nav) { /* Transfer the fetch parameters */ @@ -1280,6 +1289,10 @@ browser_window__handle_error(struct browser_window *bw, if (c == bw->loading_content) { bw->loading_content = NULL; + if (bw->loading_jsthread != NULL) { + js_destroythread(bw->loading_jsthread); + bw->loading_jsthread = NULL; + } } else if (c == bw->current_content) { bw->current_content = NULL; browser_window_remove_caret(bw, false); @@ -1486,18 +1499,16 @@ browser_window_callback(hlcache_handle *c, const hlcache_event *event, void *pw) break; case CONTENT_MSG_GETTHREAD: - { - /* only the content object created by the browser - * window requires a new global compartment object - */ - jsthread *thread; - assert(bw->loading_content == c); - if (js_newthread(bw->jsheap, - bw, - hlcache_handle_get_content(c), - &thread) == NSERROR_OK) { - *(event->data.jsthread) = thread; - } + /* only the content object created by the browser + * window requires a new javascript thread object + */ + assert(bw->loading_content == c); + assert(bw->loading_jsthread == NULL); + if (js_newthread(bw->jsheap, + bw, + hlcache_handle_get_content(c), + &bw->loading_jsthread) == NSERROR_OK) { + *(event->data.jsthread) = bw->loading_jsthread; } break; @@ -1741,12 +1752,22 @@ static void browser_window_destroy_internal(struct browser_window *bw) bw->loading_content = NULL; } + if (bw->loading_jsthread != NULL) { + js_destroythread(bw->loading_jsthread); + bw->loading_jsthread = NULL; + } + if (bw->current_content != NULL) { content_close(bw->current_content); hlcache_handle_release(bw->current_content); bw->current_content = NULL; } + if (bw->current_jsthread != NULL) { + js_destroythread(bw->current_jsthread); + bw->current_jsthread = NULL; + } + if (bw->favicon.loading != NULL) { hlcache_handle_abort(bw->favicon.loading); hlcache_handle_release(bw->favicon.loading); @@ -1766,6 +1787,7 @@ static void browser_window_destroy_internal(struct browser_window *bw) if (bw->jsheap != NULL) { js_destroyheap(bw->jsheap); + bw->jsheap = NULL; } /* These simply free memory, so are safe here */ @@ -4069,6 +4091,10 @@ void browser_window_stop(struct browser_window *bw) hlcache_handle_abort(bw->loading_content); hlcache_handle_release(bw->loading_content); bw->loading_content = NULL; + if (bw->loading_jsthread != NULL) { + js_destroythread(bw->loading_jsthread); + bw->loading_jsthread = NULL; + } } if (bw->current_content != NULL && -- cgit v1.2.3