Gitweb links:
...log
http://git.netsurf-browser.org/netsurf.git/shortlog/c0aadc56162e73509a155...
...commit
http://git.netsurf-browser.org/netsurf.git/commit/c0aadc56162e73509a1557e...
...tree
http://git.netsurf-browser.org/netsurf.git/tree/c0aadc56162e73509a1557e2c...
The branch, dsilvers/eventtarget has been updated
via c0aadc56162e73509a1557e2cd69e2fd6125cf8f (commit)
from bf80b18929da2dc3beb36aa96a6cea645e4088ef (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=c0aadc56162e73509a1...
commit c0aadc56162e73509a1557e2cd69e2fd6125cf8f
Author: Daniel Silverstone <dsilvers(a)digital-scurf.org>
Commit: Daniel Silverstone <dsilvers(a)digital-scurf.org>
More useful utilities for event listeners
diff --git a/content/handlers/javascript/duktape/EventTarget.bnd
b/content/handlers/javascript/duktape/EventTarget.bnd
index a53e71d..9f7c91a 100644
--- a/content/handlers/javascript/duktape/EventTarget.bnd
+++ b/content/handlers/javascript/duktape/EventTarget.bnd
@@ -17,24 +17,69 @@ prologue EventTarget()
#define EVENT_LISTENER_JS_MAGIC MAGIC(EVENT_LISTENER_JS_MAP)
static void event_target_push_listeners(duk_context *ctx) {
- /* ... (this=EventTarget) */
+ /* ... type (this=EventTarget) */
duk_push_this(ctx);
- /* ... this */
+ /* ... type this */
duk_get_prop_string(ctx, -1, EVENT_LISTENER_JS_MAGIC);
if (duk_is_null(ctx, -1)) {
- /* ... this null */
+ /* ... type this null */
duk_pop(ctx);
duk_push_object(ctx);
duk_dup(ctx, -1);
- /* ... this listeners listeners */
+ /* ... type this listeners listeners */
duk_put_prop_string(ctx, -3, EVENT_LISTENER_JS_MAGIC);
- /* ... this listeners */
+ /* ... type this listeners */
}
- /* ... this listeners */
- duk_insert(ctx, -2);
- /* ... listeners this */
+ /* ... type this listeners */
+ duk_insert(ctx, -3);
+ /* ... listeners type this */
duk_pop(ctx);
- /* ... listeners */
+ /* ... listeners type */
+ duk_dup(ctx, -1);
+ /* ... listeners type type */
+ duk_get_prop(ctx, -3);
+ /* ... listeners type ??? */
+ if (duk_is_null(ctx, -1)) {
+ /* ... listeners type ??? */
+ duk_pop(ctx);
+ duk_push_object(ctx);
+ duk dup(ctx, -2);
+ duk dup(ctx, -2);
+ /* ... listeners type sublisteners type sublisteners */
+ duk_put_prop(ctx, -5);
+ /* ... listeners type sublisteners */
+ }
+ duk_insert(ctx, -3);
+ /* ... sublisteners listeners type */
+ duk_pop_2(ctx);
+ /* ... sublisteners */
+}
+
+typedef enum {
+ ELF_CAPTURE = 1 << 0,
+ ELF_PASSIVE = 1 << 1,
+ ELF_ONCE = 1 << 2,
+ ELF_NONE = 0
+} event_listener_flags;
+
+static event_listener_flags event_listener_pop_options(duk_context *ctx)
+{
+ event_listener_flags ret = ELF_NONE;
+ /* ... options */
+ duk_get_prop_string(ctx, -1, "capture");
+ if (duk_to_boolean(ctx, -1))
+ ret |= ELF_CAPTURE;
+ duk_pop(ctx);
+ duk_get_prop_string(ctx, -1, "passive");
+ if (duk_to_boolean(ctx, -1))
+ ret |= ELF_PASSIVE;
+ duk_pop(ctx);
+ duk_get_prop_string(ctx, -1, "once");
+ if (duk_to_boolean(ctx, -1))
+ ret |= ELF_CAPTURE;
+ duk_pop_2(ctx);
+ /* ... */
+ return ret;
}
%}
@@ -47,6 +92,7 @@ init EventTarget()
method EventTarget::addEventListener()
%{
dom_exception exc;
+ event_listener_flags flags = ELF_NONE;
/* Incoming stack is: type callback [options] */
if (duk_get_top(ctx) < 2) return 0; /* Bad arguments */
if (duk_get_top(ctx) > 3) return 0; /* Bad arguments */
@@ -64,8 +110,13 @@ method EventTarget::addEventListener()
/* ... options */
}
/* type callback options */
+ flags = event_listener_pop_options(ctx);
+ /* type callback */
+ duk_dup(ctx, -2);
+ /* type callback type */
event_target_push_listeners(ctx);
- /* type callback options listeners */
+ /* type callback typelisteners */
+
return 0;
%}
-----------------------------------------------------------------------
Summary of changes:
.../handlers/javascript/duktape/EventTarget.bnd | 71 +++++++++++++++++---
1 file changed, 61 insertions(+), 10 deletions(-)
diff --git a/content/handlers/javascript/duktape/EventTarget.bnd
b/content/handlers/javascript/duktape/EventTarget.bnd
index a53e71d..9f7c91a 100644
--- a/content/handlers/javascript/duktape/EventTarget.bnd
+++ b/content/handlers/javascript/duktape/EventTarget.bnd
@@ -17,24 +17,69 @@ prologue EventTarget()
#define EVENT_LISTENER_JS_MAGIC MAGIC(EVENT_LISTENER_JS_MAP)
static void event_target_push_listeners(duk_context *ctx) {
- /* ... (this=EventTarget) */
+ /* ... type (this=EventTarget) */
duk_push_this(ctx);
- /* ... this */
+ /* ... type this */
duk_get_prop_string(ctx, -1, EVENT_LISTENER_JS_MAGIC);
if (duk_is_null(ctx, -1)) {
- /* ... this null */
+ /* ... type this null */
duk_pop(ctx);
duk_push_object(ctx);
duk_dup(ctx, -1);
- /* ... this listeners listeners */
+ /* ... type this listeners listeners */
duk_put_prop_string(ctx, -3, EVENT_LISTENER_JS_MAGIC);
- /* ... this listeners */
+ /* ... type this listeners */
}
- /* ... this listeners */
- duk_insert(ctx, -2);
- /* ... listeners this */
+ /* ... type this listeners */
+ duk_insert(ctx, -3);
+ /* ... listeners type this */
duk_pop(ctx);
- /* ... listeners */
+ /* ... listeners type */
+ duk_dup(ctx, -1);
+ /* ... listeners type type */
+ duk_get_prop(ctx, -3);
+ /* ... listeners type ??? */
+ if (duk_is_null(ctx, -1)) {
+ /* ... listeners type ??? */
+ duk_pop(ctx);
+ duk_push_object(ctx);
+ duk dup(ctx, -2);
+ duk dup(ctx, -2);
+ /* ... listeners type sublisteners type sublisteners */
+ duk_put_prop(ctx, -5);
+ /* ... listeners type sublisteners */
+ }
+ duk_insert(ctx, -3);
+ /* ... sublisteners listeners type */
+ duk_pop_2(ctx);
+ /* ... sublisteners */
+}
+
+typedef enum {
+ ELF_CAPTURE = 1 << 0,
+ ELF_PASSIVE = 1 << 1,
+ ELF_ONCE = 1 << 2,
+ ELF_NONE = 0
+} event_listener_flags;
+
+static event_listener_flags event_listener_pop_options(duk_context *ctx)
+{
+ event_listener_flags ret = ELF_NONE;
+ /* ... options */
+ duk_get_prop_string(ctx, -1, "capture");
+ if (duk_to_boolean(ctx, -1))
+ ret |= ELF_CAPTURE;
+ duk_pop(ctx);
+ duk_get_prop_string(ctx, -1, "passive");
+ if (duk_to_boolean(ctx, -1))
+ ret |= ELF_PASSIVE;
+ duk_pop(ctx);
+ duk_get_prop_string(ctx, -1, "once");
+ if (duk_to_boolean(ctx, -1))
+ ret |= ELF_CAPTURE;
+ duk_pop_2(ctx);
+ /* ... */
+ return ret;
}
%}
@@ -47,6 +92,7 @@ init EventTarget()
method EventTarget::addEventListener()
%{
dom_exception exc;
+ event_listener_flags flags = ELF_NONE;
/* Incoming stack is: type callback [options] */
if (duk_get_top(ctx) < 2) return 0; /* Bad arguments */
if (duk_get_top(ctx) > 3) return 0; /* Bad arguments */
@@ -64,8 +110,13 @@ method EventTarget::addEventListener()
/* ... options */
}
/* type callback options */
+ flags = event_listener_pop_options(ctx);
+ /* type callback */
+ duk_dup(ctx, -2);
+ /* type callback type */
event_target_push_listeners(ctx);
- /* type callback options listeners */
+ /* type callback typelisteners */
+
return 0;
%}
--
NetSurf Browser