summaryrefslogtreecommitdiff
path: root/content/handlers/javascript/duktape/Window.bnd
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2019-05-05 18:51:25 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2019-05-05 18:51:25 +0100
commitac512958ffb8382b7d7c76748dc69c7ea49baf70 (patch)
tree50bbb256f6040bfbe78361c04e9c18d7e9ef08dc /content/handlers/javascript/duktape/Window.bnd
parente27df0c0b8081f06fec44562b87b35dc0ad434a3 (diff)
downloadnetsurf-ac512958ffb8382b7d7c76748dc69c7ea49baf70.tar.gz
netsurf-ac512958ffb8382b7d7c76748dc69c7ea49baf70.tar.bz2
Ensure we clear the cbt entry after finishing a non-recurring callback
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'content/handlers/javascript/duktape/Window.bnd')
-rw-r--r--content/handlers/javascript/duktape/Window.bnd28
1 files changed, 21 insertions, 7 deletions
diff --git a/content/handlers/javascript/duktape/Window.bnd b/content/handlers/javascript/duktape/Window.bnd
index e19b33670..cfc6f1fdb 100644
--- a/content/handlers/javascript/duktape/Window.bnd
+++ b/content/handlers/javascript/duktape/Window.bnd
@@ -51,17 +51,21 @@ static void window_remove_callback_bits(duk_context *ctx, size_t handle) {
/* ... */
}
-static void window_call_callback(duk_context *ctx, size_t handle) {
+static void window_call_callback(duk_context *ctx, size_t handle, bool clear_entry) {
NSLOG(dukky, DEEPDEBUG, "ctx=%p, handle=%"PRIsizet, ctx, handle);
/* Stack is ... */
- duk_push_context_dump(ctx);
- NSLOG(dukky, DEEPDEBUG, "On entry to callback, stack is: %s", duk_get_string(ctx, -1));
- duk_pop(ctx);
duk_push_global_object(ctx);
+ /* ..., win */
duk_get_prop_string(ctx, -1, WINDOW_CALLBACKS);
+ /* ..., win, cbt */
duk_push_int(ctx, (duk_int_t)handle);
+ /* ..., win, cbt, handle */
duk_get_prop(ctx, -2);
/* ..., win, cbt, cbo */
+ duk_push_context_dump(ctx);
+ NSLOG(dukky, DEEPDEBUG, "On entry to callback, stack is: %s", duk_get_string(ctx, -1));
+ duk_pop(ctx);
+ /* ..., win, cbt, cbo */
/* What we want to do is call cbo.func passing all of cbo.args */
duk_get_prop_string(ctx, -1, "func");
duk_get_prop_string(ctx, -2, "args");
@@ -79,7 +83,18 @@ static void window_call_callback(duk_context *ctx, size_t handle) {
duk_pop(ctx);
(void) dukky_pcall(ctx, arrlen, true);
/* ..., win, cbt, cbo, retval */
- duk_pop_n(ctx, 4);
+ if (clear_entry) {
+ NSLOG(dukky, DEEPDEBUG, "Not recurring callback, removing from cbt");
+ duk_pop_n(ctx, 2);
+ /* ..., win, cbt */
+ duk_push_int(ctx, (duk_int_t)handle);
+ /* ..., win, cbt, handle */
+ duk_del_prop(ctx, -2);
+ /* ..., win, cbt */
+ duk_pop_n(ctx, 2);
+ } else {
+ duk_pop_n(ctx, 4);
+ }
/* ... */
duk_push_context_dump(ctx);
NSLOG(dukky, DEEPDEBUG, "On leaving callback, stack is: %s", duk_get_string(ctx, -1));
@@ -91,7 +106,7 @@ static void window_schedule_callback(void *p) {
NSLOG(dukky, DEEPDEBUG, "Entered window scheduler callback: %"PRIsizet, priv->handle);
- window_call_callback(priv->ctx, priv->handle);
+ window_call_callback(priv->ctx, priv->handle, priv->repeat_timeout == 0);
if (priv->repeat_timeout > 0) {
/* Reschedule */
@@ -102,7 +117,6 @@ static void window_schedule_callback(void *p) {
/* Remove this from the ring */
RING_REMOVE(priv->owner->schedule_ring, priv);
window_remove_callback_bits(priv->ctx, priv->handle);
- /* TODO: Remove the entry from the JS part */
free(priv);
}
}