diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2020-03-22 10:14:00 +0000 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2020-03-22 10:14:00 +0000 |
commit | d1e2eef18b25e97c7c06068aa519003605202853 (patch) | |
tree | 8044c7984e413c8bb8e370b4031578801042e3fb /content/handlers/javascript/duktape | |
parent | efbfaa0cb1808a3953f1595b9c5e1be9d7994469 (diff) | |
download | netsurf-d1e2eef18b25e97c7c06068aa519003605202853.tar.gz netsurf-d1e2eef18b25e97c7c06068aa519003605202853.tar.bz2 |
JS: Add concept of js_closethread
In order to better model content close vs destroy, add the concept
of closing a thread to the JS interface.
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'content/handlers/javascript/duktape')
-rw-r--r-- | content/handlers/javascript/duktape/dukky.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/content/handlers/javascript/duktape/dukky.c b/content/handlers/javascript/duktape/dukky.c index bb227d44d..7357863cd 100644 --- a/content/handlers/javascript/duktape/dukky.c +++ b/content/handlers/javascript/duktape/dukky.c @@ -754,6 +754,26 @@ nserror js_newthread(jsheap *heap, void *win_priv, void *doc_priv, jsthread **th #undef CTX #define CTX (thread->ctx) +/* exported interface documented in js.h */ +nserror js_closethread(jsthread *thread) +{ + /* We can always close down a thread, it might just confuse + * the code running, though we don't mind since we're in the + * process of destruction at this point + */ + duk_int_t top = duk_get_top(CTX); + + /* Closing down the extant thread */ + NSLOG(dukky, DEBUG, "Closing down extant thread %p in heap %p", thread, thread->heap); + duk_get_global_string(CTX, MAGIC(closedownThread)); + dukky_pcall(CTX, 0, true); + + /* Restore whatever stack we had */ + duk_set_top(CTX, top); + + return NSERROR_OK; +} + /** * Destroy a Duktape thread */ |