JS: Move ownership of jsthread from browser to htmlc

Since it makes more sense for the htmlc to be responsible for
when the JS thread gets destroyed, move its lifetime from the
responsibility of the browser window to the html content.

Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
This commit is contained in:
Daniel Silverstone 2020-03-22 10:00:29 +00:00
parent 98e461a3b3
commit efbfaa0cb1
No known key found for this signature in database
GPG Key ID: C30DF439F2987D74
5 changed files with 25 additions and 71 deletions

View File

@ -1637,12 +1637,6 @@ static void html_stop(struct content *c)
{
html_content *htmlc = (html_content *) c;
/* invalidate the html content reference to the javascript context
* as it is about to become invalid and must not be used any
* more.
*/
html_script_invalidate_ctx(htmlc);
switch (c->status) {
case CONTENT_STATUS_LOADING:
/* Still loading; simply flag that we've been aborted
@ -1853,6 +1847,14 @@ static void html_destroy(struct content *c)
if (html->base_url)
nsurl_unref(html->base_url);
/* At this point we can be moderately confident the JS is offline
* so we destroy the JS thread.
*/
if (html->jsthread != NULL) {
js_destroythread(html->jsthread);
html->jsthread = NULL;
}
if (html->parser != NULL) {
dom_hubbub_parser_destroy(html->parser);
html->parser = NULL;
@ -1977,12 +1979,6 @@ static nserror html_close(struct content *c)
/* clear the html content reference to the browser window */
htmlc->bw = NULL;
/* invalidate the html content reference to the javascript context
* as it is about to become invalid and must not be used any
* more.
*/
html_script_invalidate_ctx(htmlc);
/* remove all object references from the html content */
html_object_close_objects(htmlc);

View File

@ -320,14 +320,6 @@ nserror html_script_exec(html_content *htmlc, bool allow_defer);
*/
nserror html_script_free(html_content *htmlc);
/**
* Ensure the html content javascript context is invalidated.
*
* \param htmlc html content.
* \return NSERROR_OK or error code.
*/
nserror html_script_invalidate_ctx(html_content *htmlc);
/**
* Check if any of the scripts loaded were insecure
*/

View File

@ -664,10 +664,3 @@ nserror html_script_free(html_content *html)
return NSERROR_OK;
}
/* exported internal interface documented in html/html_internal.h */
nserror html_script_invalidate_ctx(html_content *htmlc)
{
htmlc->jsthread = NULL;
return NSERROR_OK;
}

View File

@ -265,12 +265,6 @@ struct browser_window {
/** current javascript context */
struct jsheap *jsheap;
/** 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 {
char *text; /**< Current status bar text. */

View File

@ -701,11 +701,6 @@ 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);
}
@ -723,15 +718,10 @@ 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 */
@ -1289,10 +1279,6 @@ 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);
@ -1499,16 +1485,23 @@ 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 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;
{
/* only the content object created by the browser
* window requires a new javascript thread object
*/
jsthread *thread;
assert(bw->loading_content == c);
if (js_newthread(bw->jsheap,
bw,
hlcache_handle_get_content(c),
&thread) == NSERROR_OK) {
/* The content which is requesting the thread
* is required to keep hold of it and
* to destroy it when it is finished with it.
*/
*(event->data.jsthread) = thread;
}
}
break;
@ -1752,22 +1745,12 @@ 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);
@ -4091,10 +4074,6 @@ 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 &&