Gitweb links:

...log 
http://git.netsurf-browser.org/netsurf.git/shortlog/f1c98ccfa404f1890fa6299a69b165a226dc4d35
...commit 
http://git.netsurf-browser.org/netsurf.git/commit/f1c98ccfa404f1890fa6299a69b165a226dc4d35
...tree 
http://git.netsurf-browser.org/netsurf.git/tree/f1c98ccfa404f1890fa6299a69b165a226dc4d35

The branch, dsilvers/eventtarget has been updated
  discards  34d5d69e5db7a9dce3e1f1bcc92a681ae5d48083 (commit)
  discards  49b60d247fd060bf621f3518dba60eb7fd9679fc (commit)
  discards  5185c5fc974b70e7cafb26a15db63fd57f8bd173 (commit)
       via  f1c98ccfa404f1890fa6299a69b165a226dc4d35 (commit)
       via  57fec3504f29753128204bbf03cc92767f501fd4 (commit)
       via  8e9751d3b6cd555119ca195e6751c2675beb3b7d (commit)

This update added new revisions after undoing existing revisions.  That is
to say, the old revision is not a strict subset of the new revision.  This
situation occurs when you --force push a change and generate a repository
containing something like this:

 * -- * -- B -- O -- O -- O (34d5d69e5db7a9dce3e1f1bcc92a681ae5d48083)
            \
             N -- N -- N (f1c98ccfa404f1890fa6299a69b165a226dc4d35)

When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.

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=f1c98ccfa404f1890fa6299a69b165a226dc4d35
commit f1c98ccfa404f1890fa6299a69b165a226dc4d35
Author: Daniel Silverstone <[email protected]>
Commit: Daniel Silverstone <[email protected]>

    Record that we have implemented EventTarget

diff --git a/Docs/UnimplementedJavascript.txt b/Docs/UnimplementedJavascript.txt
index 2b3a7d9..1b851b8 100644
--- a/Docs/UnimplementedJavascript.txt
+++ b/Docs/UnimplementedJavascript.txt
@@ -439,9 +439,6 @@ setter EventSource::onopen(user);\n
 getter EventSource::readyState(unsigned short);\n
 getter EventSource::url(string);\n
 getter EventSource::withCredentials(boolean);\n
-method EventTarget::addEventListener();\n
-method EventTarget::dispatchEvent();\n
-method EventTarget::removeEventListener();\n
 getter Event::timeStamp(user);\n
 method External::AddSearchProvider();\n
 method External::IsSearchProviderInstalled();\n


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=57fec3504f29753128204bbf03cc92767f501fd4
commit 57fec3504f29753128204bbf03cc92767f501fd4
Author: Daniel Silverstone <[email protected]>
Commit: Daniel Silverstone <[email protected]>

    Add dom change event test

diff --git a/test/js/dom-change-event.html b/test/js/dom-change-event.html
new file mode 100644
index 0000000..a6d77b8
--- /dev/null
+++ b/test/js/dom-change-event.html
@@ -0,0 +1,17 @@
+<html>
+  <head>
+    <title>DOM Change event handling</title>
+    <script type="text/javascript">
+      document.addEventListener("DOMNodeInserted",
+      function(ev) {
+      console.log("\n\nHELLO WORLD!\n\n");
+      console.log(ev);
+      console.log("\n\n");
+      }, false);
+      console.log("Moooo!");
+    </script>
+  </head>
+  <body>
+    <div>I got inserted</div>
+  </body>
+</html>
diff --git a/test/js/index.html b/test/js/index.html
index f282ca4..2abe954 100644
--- a/test/js/index.html
+++ b/test/js/index.html
@@ -90,6 +90,7 @@
 <li><a href="event-onload.html">window.onload</a></li>
 <li><a href="event-onloadfrombody.html">body.onload</a></li>
 <li><a href="event-onclick.html">button.onclick</a></li>
+<li><a href="dom-change-event.html">DOMNodeInserted</a></li>
 </ul>
 
 


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=8e9751d3b6cd555119ca195e6751c2675beb3b7d
commit 8e9751d3b6cd555119ca195e6751c2675beb3b7d
Author: Daniel Silverstone <[email protected]>
Commit: Daniel Silverstone <[email protected]>

    Add EventTarget binding
    
    This adds the binding for EventTarget along with implementations for
    addEventListener() removeEventListener() and dispatchEvent()

diff --git a/content/handlers/javascript/duktape/EventTarget.bnd 
b/content/handlers/javascript/duktape/EventTarget.bnd
new file mode 100644
index 0000000..92e2ac8
--- /dev/null
+++ b/content/handlers/javascript/duktape/EventTarget.bnd
@@ -0,0 +1,277 @@
+/* Event Target binding for browser using duktape and libdom
+ *
+ * Copyright 2016 Daniel Silverstone <[email protected]>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * Released under the terms of the MIT License,
+ *         http://www.opensource.org/licenses/mit-license
+ */
+
+class EventTarget {
+       private bool is_node;
+       private bool capture_registered;
+       private bool bubbling_registered;
+};
+
+prologue EventTarget()
+%{
+
+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_ONCE;
+       duk_pop_2(ctx);
+       /* ... */
+       return ret;
+}
+
+static void event_target_register_listener(duk_context *ctx,
+                                          event_listener_flags flags)
+{
+       /* ... listeners callback */
+       /* If the given callback with the given flags is already present,
+        * we do not re-add it, otherwise we need to add to listeners
+        * a tuple of the callback and flags
+        */
+       duk_uarridx_t idx = 0;
+       while (duk_get_prop_index(ctx, -1, idx)) {
+               /* ... listeners callback candidate */
+               duk_get_prop_index(ctx, -1, 0);
+               duk_get_prop_index(ctx, -2, 1);
+               /* ... listeners callback candidate candidatecallback 
candidateflags */
+               if (duk_strict_equals(ctx, -1, -3) &&
+                   duk_get_int(ctx, -1) == (duk_int_t)flags) {
+                       /* already present, nothing to do */
+                       duk_pop_n(ctx, 5);
+                       /* ... */
+                       return;
+               }
+               /* ... listeners callback candidate candidatecallback 
candidateflags */
+               duk_pop_3(ctx);
+               /* ... listeners callback */
+               idx++;
+       }
+       /* ... listeners callback undefined */
+       duk_pop(ctx);
+       /* ... listeners callback */
+       duk_push_array(ctx);
+       /* ... listeners callback newcandidate */
+       duk_insert(ctx, -2);
+       /* ... listeners newcandidate callback */
+       duk_put_prop_index(ctx, -2, 0);
+       /* ... listeners newcandidate */
+       duk_push_int(ctx, (duk_int_t)flags);
+       /* ... listeners newcandidate flags */
+       duk_put_prop_index(ctx, -2, 1);
+       /* ... listeners newcandidate */
+       duk_put_prop_index(ctx, -2, idx);
+       /* ... listeners */
+       duk_pop(ctx);
+       /* ... */
+}
+
+static void event_target_unregister_listener(duk_context *ctx,
+                                            event_listener_flags flags)
+{
+       /* ... listeners callback */
+       /* If the given callback with the given flags is present,
+        * we remove it and shuffle the rest up.
+        */
+       duk_uarridx_t idx = 0;
+       while (duk_get_prop_index(ctx, -1, idx)) {
+               /* ... listeners callback candidate */
+               duk_get_prop_index(ctx, -1, 0);
+               duk_get_prop_index(ctx, -2, 1);
+               /* ... listeners callback candidate candidatecallback 
candidateflags */
+               if (duk_strict_equals(ctx, -1, -3) &&
+                   duk_get_int(ctx, -1) == (duk_int_t)flags) {
+                       /* present */
+                       duk_pop(ctx);
+                       /* ... listeners callback candidate candidatecallback */
+                       duk_put_prop_index(ctx, -2, 2);
+                       /* ... listeners callback candidate */
+                       duk_pop(ctx);
+                       /* ... listeners callback */
+                       duk_push_int(ctx, idx);
+                       /* ... listeners callback found_at */
+                       break;
+               }
+               /* ... listeners callback candidate candidatecallback 
candidateflags */
+               duk_pop_3(ctx);
+               /* ... listeners callback */
+               idx++;
+       }
+       /* ... listeners callback undefined/found_at */
+       if (duk_is_undefined(ctx, -1)) {
+               /* not found, clean up and come out */
+               duk_pop_3(ctx);
+               return;
+       }
+       idx = duk_to_int(ctx, -1);
+       duk_pop_2(ctx);
+       /* ... listeners */
+       dukky_shuffle_array(ctx, idx);
+       /* ... listeners */
+       duk_pop(ctx);
+       /* ... */
+}
+
+
+%}
+
+init EventTarget()
+%{
+       priv->is_node = false;
+       priv->capture_registered = false;
+       priv->bubbling_registered = false;
+%}
+
+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 */
+       if (duk_get_top(ctx) == 2) {
+               duk_push_object(ctx);
+               /* type callback options */
+       }
+       if (duk_get_type(ctx, -1) != DUK_TYPE_OBJECT) {
+               /* legacy support, if not object, it's the capture value */
+               duk_push_object(ctx);
+               /* ... capture options */
+               duk_insert(ctx, -2);
+               /* ... options capture */
+               duk_put_prop_string(ctx, -2, "capture");
+               /* ... options */
+       }
+       /* type callback options */
+       flags = event_listener_pop_options(ctx);
+       /* type callback */
+       duk_dup(ctx, -2);
+       /* type callback type */
+       duk_push_this(ctx);
+       /* type callback type this(=EventTarget) */
+       if (dukky_event_target_push_listeners(ctx, false) && priv->is_node) {
+               /* Take a moment to register a JS callback */
+               duk_size_t ev_ty_l;
+               const char *ev_ty = duk_to_lstring(ctx, -3, &ev_ty_l);
+               dom_string *ev_ty_s;
+               exc = dom_string_create((const uint8_t*)ev_ty, ev_ty_l,
+                                       &ev_ty_s);
+               if (exc != DOM_NO_ERR) {
+                       LOG("Oh dear, failed to create dom_string in 
addEventListener()");
+                       return 0;
+               }
+               dukky_register_event_listener_for(
+                       ctx, (dom_element *)((node_private_t *)priv)->node,
+                       ev_ty_s,
+                       !!(flags & ELF_CAPTURE));
+               dom_string_unref(ev_ty_s);
+       }
+       /* type callback typelisteners */
+       duk_insert(ctx, -2);
+       /* type typelisteners callback */
+       event_target_register_listener(ctx, flags);
+       /* type */
+       return 0;
+%}
+
+method EventTarget::removeEventListener()
+%{
+       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 */
+       if (duk_get_top(ctx) == 2) {
+               duk_push_object(ctx);
+               /* type callback options */
+       }
+       if (duk_get_type(ctx, -1) != DUK_TYPE_OBJECT) {
+               /* legacy support, if not object, it's the capture value */
+               duk_push_object(ctx);
+               /* ... capture options */
+               duk_insert(ctx, -2);
+               /* ... options capture */
+               duk_put_prop_string(ctx, -2, "capture");
+               /* ... options */
+       }
+       /* type callback options */
+       flags = event_listener_pop_options(ctx);
+       /* type callback */
+       duk_dup(ctx, -2);
+       /* type callback type */
+       duk_push_this(ctx);
+       /* type callback type this(=EventTarget) */
+       if (dukky_event_target_push_listeners(ctx, true)) {
+               /* nothing to do because the listener wasn't there at all */
+               duk_pop_3(ctx);
+               return 0;
+       }
+       /* type callback typelisteners */
+       duk_insert(ctx, -2);
+       /* type typelisteners callback */
+       event_target_unregister_listener(ctx, flags);
+       /* type */
+       return 0;
+%}
+
+
+
+method EventTarget::dispatchEvent()
+%{
+       dom_exception exc;
+       if (!dukky_instanceof(ctx, 0, PROTO_NAME(EVENT))) return 0;
+
+       duk_get_prop_string(ctx, 0, PRIVATE_MAGIC);
+       event_private_t *evpriv = duk_get_pointer(ctx, -1);
+       duk_pop(ctx);
+
+       dom_event *evt = evpriv->evt;
+
+       /* Dispatch event logic, see:
+        * https://dom.spec.whatwg.org/#dom-eventtarget-dispatchevent
+        */
+       bool in_dispatch;
+       if (dom_event_in_dispatch(evt, &in_dispatch) != DOM_NO_ERR) return 0;
+       if (in_dispatch) {
+               /** \todo Raise InvalidStateException */
+               return 0;
+       }
+
+       bool is_initialised;
+       if (dom_event_is_initialised(evt, &is_initialised) != DOM_NO_ERR) 
return 0;
+       if (is_initialised == false) {
+               /** \todo Raise InvalidStateException */
+               return 0;
+       }
+
+       if (dom_event_set_is_trusted(evt, false) != DOM_NO_ERR) return 0;
+
+       /** \todo work out how to dispatch against non-node things */
+       if (priv->is_node == false) return 0;
+
+       bool success;
+       /* Event prepared, dispatch against ourselves */
+       exc = dom_event_target_dispatch_event(
+               ((node_private_t *)priv)->node,
+               evt,
+               &success);
+       if (exc != DOM_NO_ERR) return 0; /**< \todo raise correct exception */
+
+       duk_push_boolean(ctx, success);
+       return 1;
+%}
diff --git a/content/handlers/javascript/duktape/Node.bnd 
b/content/handlers/javascript/duktape/Node.bnd
index f237c87..f14cfc1 100644
--- a/content/handlers/javascript/duktape/Node.bnd
+++ b/content/handlers/javascript/duktape/Node.bnd
@@ -16,6 +16,7 @@ init Node(struct dom_node *node)
 %{
        priv->node = node;
        dom_node_ref(node);
+       priv->parent.is_node = true;
 %}
 
 fini Node()
diff --git a/content/handlers/javascript/duktape/netsurf.bnd 
b/content/handlers/javascript/duktape/netsurf.bnd
index 4aca475..2a56ccc 100644
--- a/content/handlers/javascript/duktape/netsurf.bnd
+++ b/content/handlers/javascript/duktape/netsurf.bnd
@@ -54,6 +54,7 @@ struct dom_html_br_element;
 
 };
 
+#include "EventTarget.bnd"
 #include "Console.bnd"
 #include "Window.bnd"
 #include "Document.bnd"


-----------------------------------------------------------------------

Summary of changes:
 content/handlers/javascript/duktape/EventTarget.bnd |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/content/handlers/javascript/duktape/EventTarget.bnd 
b/content/handlers/javascript/duktape/EventTarget.bnd
index 4e168b9..92e2ac8 100644
--- a/content/handlers/javascript/duktape/EventTarget.bnd
+++ b/content/handlers/javascript/duktape/EventTarget.bnd
@@ -31,7 +31,7 @@ static event_listener_flags 
event_listener_pop_options(duk_context *ctx)
        duk_pop(ctx);
        duk_get_prop_string(ctx, -1, "once");
        if (duk_to_boolean(ctx, -1))
-               ret |= ELF_CAPTURE;
+               ret |= ELF_ONCE;
        duk_pop_2(ctx);
        /* ... */
        return ret;


-- 
NetSurf Browser

_______________________________________________
netsurf-commits mailing list
[email protected]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org

Reply via email to