Gitweb links:

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

The branch, master has been updated
       via  730d59776a33ba2633a4978eb0bdb0020061bfb3 (commit)
       via  90530c419e3393675ef37718986fce6f85d8a772 (commit)
      from  cfdaf181a28c463e041ee55585b8d559fd14aed9 (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=730d59776a33ba2633a4978eb0bdb0020061bfb3
commit 730d59776a33ba2633a4978eb0bdb0020061bfb3
Author: Vincent Sanders <[email protected]>
Commit: Vincent Sanders <[email protected]>

    cleanup some javascript documentation comments

diff --git a/content/handlers/javascript/duktape/Window.bnd 
b/content/handlers/javascript/duktape/Window.bnd
index b2e8166..1a76862 100644
--- a/content/handlers/javascript/duktape/Window.bnd
+++ b/content/handlers/javascript/duktape/Window.bnd
@@ -52,7 +52,9 @@ static void window_remove_callback_bits(duk_context *ctx, 
size_t handle) {
        /* ... */
 }
 
-static void window_call_callback(duk_context *ctx, size_t handle, bool 
clear_entry) {
+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_global_object(ctx);
@@ -96,21 +98,32 @@ static void window_call_callback(duk_context *ctx, size_t 
handle, bool clear_ent
        //dukky_log_stack_frame(ctx, "On leaving callback");
 }
 
-static void window_schedule_callback(void *p) {
+
+static void
+window_schedule_callback(void *p)
+{
        window_schedule_t *priv = (window_schedule_t *)p;
 
-       NSLOG(dukky, DEEPDEBUG, "Entered window scheduler callback: %"PRIsizet, 
priv->handle);
+       NSLOG(dukky, DEEPDEBUG,
+             "Entered window scheduler callback: %"PRIsizet, priv->handle);
 
        priv->running = true;
-       window_call_callback(priv->ctx, priv->handle, priv->repeat_timeout == 
0);
+       window_call_callback(priv->ctx,
+                            priv->handle,
+                            priv->repeat_timeout == 0);
        priv->running = false;
 
        if (priv->repeat_timeout > 0) {
                /* Reschedule */
-               NSLOG(dukky, DEEPDEBUG, "Rescheduling repeating callback 
%"PRIsizet, priv->handle);
-               guit->misc->schedule(priv->repeat_timeout, 
window_schedule_callback, priv);
+               NSLOG(dukky, DEEPDEBUG,
+                     "Rescheduling repeating callback %"PRIsizet,
+                     priv->handle);
+               guit->misc->schedule(priv->repeat_timeout,
+                                    window_schedule_callback,
+                                    priv);
        } else {
-               NSLOG(dukky, DEEPDEBUG, "Removing completed callback 
%"PRIsizet, priv->handle);
+               NSLOG(dukky, DEEPDEBUG,
+                     "Removing completed callback %"PRIsizet, priv->handle);
                /* Remove this from the ring */
                RING_REMOVE(priv->owner->schedule_ring, priv);
                window_remove_callback_bits(priv->ctx, priv->handle);
@@ -118,8 +131,12 @@ static void window_schedule_callback(void *p) {
        }
 }
 
-static size_t window_alloc_new_callback(duk_context *ctx, window_private_t 
*window,
-                                       bool repeating, int timeout) {
+static size_t
+window_alloc_new_callback(duk_context *ctx,
+                         window_private_t *window,
+                         bool repeating,
+                         int timeout)
+{
        size_t new_handle = next_handle++;
        window_schedule_t *sched = calloc(sizeof *sched, 1);
        if (sched == NULL) {
@@ -168,18 +185,24 @@ static size_t window_alloc_new_callback(duk_context *ctx, 
window_private_t *wind
        return new_handle;
 }
 
-static void window_remove_callback_by_handle(duk_context *ctx,
-                                            window_private_t *window,
-                                            size_t handle) {
+static void
+window_remove_callback_by_handle(duk_context *ctx,
+                                window_private_t *window,
+                                size_t handle)
+{
        int res;
 
        RING_ITERATE_START(window_schedule_t, window->schedule_ring, sched) {
                if (sched->handle == handle) {
                        if (sched->running) {
-                               NSLOG(dukky, DEEPDEBUG, "Cancelling in-train 
callback %"PRIsizet, sched->handle);
+                               NSLOG(dukky, DEEPDEBUG,
+                                     "Cancelling in-train callback %"PRIsizet,
+                                     sched->handle);
                                sched->repeat_timeout = 0;
                        } else {
-                               NSLOG(dukky, DEEPDEBUG, "Cancelled callback 
%"PRIsizet, sched->handle);
+                               NSLOG(dukky, DEEPDEBUG,
+                                     "Cancelled callback %"PRIsizet,
+                                     sched->handle);
                                res = guit->misc->schedule(-1,
                                                           
window_schedule_callback,
                                                           sched);
@@ -209,7 +232,9 @@ static duk_ret_t 
dukky_window_closedown_compartment(duk_context *ctx)
 
        NSLOG(dukky, DEEPDEBUG, "Closing down compartment");
        while (priv->schedule_ring != NULL) {
-               window_remove_callback_by_handle(ctx, priv, 
priv->schedule_ring->handle);
+               window_remove_callback_by_handle(ctx,
+                                                priv,
+                                                priv->schedule_ring->handle);
        }
 
        return 0;
diff --git a/content/handlers/javascript/js.h b/content/handlers/javascript/js.h
index 31ab8f7..d5af721 100644
--- a/content/handlers/javascript/js.h
+++ b/content/handlers/javascript/js.h
@@ -20,12 +20,11 @@
  * Interface to javascript engine functions.
  */
 
-#ifndef _NETSURF_JAVASCRIPT_JS_H_
-#define _NETSURF_JAVASCRIPT_JS_H_
+#ifndef NETSURF_JAVASCRIPT_JS_H_
+#define NETSURF_JAVASCRIPT_JS_H_
 
 #include "utils/errors.h"
 
-
 typedef struct jscontext jscontext;
 typedef struct jsobject jsobject;
 
@@ -37,40 +36,50 @@ struct dom_node;
 struct dom_element;
 struct dom_string;
 
-/** Initialise javascript interpreter */
+/**
+ * Initialise javascript interpreter
+ */
 void js_initialise(void);
 
-/** finalise javascript interpreter */
+/**
+ * finalise javascript interpreter
+ */
 void js_finalise(void);
 
-/** Create a new javascript context.
+/**
+ * Create a new javascript context.
  *
- * There is usually one context per browser context
+ * There is usually one context per browsing context (browser window)
  *
- * \param timeout elapsed wallclock time (in seconds)  before \a callback is 
called
+ * \param timeout elapsed wallclock time (in seconds) before \a callback is 
called
  * \param cb the callback when the runtime exceeds the timeout
  * \param cbctx The context to pass to the callback
  * \param jsctx Updated to the created JS context
  * \return NSERROR_OK on success, appropriate error otherwise.
  */
-nserror js_newcontext(int timeout, jscallback *cb, void *cbctx,
-               jscontext **jsctx);
+nserror js_newcontext(int timeout, jscallback *cb, void *cbctx, jscontext 
**jsctx);
 
-/** Destroy a previously created context */
+/**
+ * Destroy a previously created context
+ */
 void js_destroycontext(jscontext *ctx);
 
-/** Create a new javascript compartment
+/**
+ * Create a new javascript compartment
  *
  * This is called once for a page with javascript script tags on
  * it. It constructs a fresh global window object.
  */
 jsobject *js_newcompartment(jscontext *ctx, void *win_priv, void *doc_priv);
 
-/* execute some javascript in a context */
+/**
+ * execute some javascript in a context
+ */
 bool js_exec(jscontext *ctx, const uint8_t *txt, size_t txtlen, const char 
*name);
 
-
-/* fire an event at a dom node */
+/**
+ * fire an event at a dom node
+ */
 bool js_fire_event(jscontext *ctx, const char *type, struct dom_document *doc, 
struct dom_node *target);
 
 bool
@@ -82,7 +91,8 @@ js_dom_event_add_listener(jscontext *ctx,
 
 /*** New Events ***/
 
-/** Handle a new element being created.
+/**
+ * Handle a new element being created.
  *
  * This is called once an element is inserted into the DOM document handled
  * by the context provided.  The JS implementation must then scan the element
@@ -90,7 +100,8 @@ js_dom_event_add_listener(jscontext *ctx,
  */
 void js_handle_new_element(jscontext *ctx, struct dom_element *node);
 
-/** Handle an event propagation finished callback.
+/**
+ * Handle an event propagation finished callback.
  *
  * This is called once an event finishes propagating, no matter how it
  * finishes.  The intent here is that the JS context can perform any cleanups
@@ -99,4 +110,4 @@ void js_handle_new_element(jscontext *ctx, struct 
dom_element *node);
  */
 void js_event_cleanup(jscontext *ctx, struct dom_event *evt);
 
-#endif /* _NETSURF_JAVASCRIPT_JS_H_ */
+#endif /* NETSURF_JAVASCRIPT_JS_H_ */


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=90530c419e3393675ef37718986fce6f85d8a772
commit 90530c419e3393675ef37718986fce6f85d8a772
Author: Vincent Sanders <[email protected]>
Commit: Vincent Sanders <[email protected]>

    when owning context is destroyed ensure that active js compartment is 
destroyed first

diff --git a/content/handlers/javascript/duktape/dukky.c 
b/content/handlers/javascript/duktape/dukky.c
index a828667..538a15b 100644
--- a/content/handlers/javascript/duktape/dukky.c
+++ b/content/handlers/javascript/duktape/dukky.c
@@ -19,7 +19,8 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-/** \file
+/**
+ * \file
  * Duktapeish implementation of javascript engine functions.
  */
 
@@ -50,6 +51,15 @@
 #define EVENT_LISTENER_JS_MAGIC MAGIC(EVENT_LISTENER_JS_MAP)
 #define GENERICS_MAGIC MAGIC(GENERICS_TABLE)
 
+/**
+ * dukky javascript context
+ */
+struct jscontext {
+       duk_context *ctx; /**< duktape base context */
+       duk_context *thread; /**< duktape compartment */
+       uint64_t exec_start_time;
+};
+
 static duk_ret_t dukky_populate_object(duk_context *ctx, void *udata)
 {
        /* ... obj args protoname nargs */
@@ -535,6 +545,7 @@ static void *dukky_realloc_function(void *udata, void *ptr, 
duk_size_t size)
        return realloc(ptr, size);
 }
 
+
 static void dukky_free_function(void *udata, void *ptr)
 {
        if (ptr != NULL)
@@ -542,15 +553,36 @@ static void dukky_free_function(void *udata, void *ptr)
 }
 
 
-/**************************************** js.h ******************************/
-struct jscontext {
-       duk_context *ctx;
-       duk_context *thread;
-       uint64_t exec_start_time;
-};
-
 #define CTX (ctx->thread)
 
+/**
+ * close current compartment
+ *
+ * \param ctx javascript context
+ * \return NSERROR_OK on sucess.
+ */
+static nserror dukky_closecompartment(jscontext *ctx)
+{
+       /* ensure there is an active compartment */
+       if (ctx->thread == NULL) {
+               return NSERROR_OK;
+       }
+
+       /* Closing down the extant compartment */
+       NSLOG(dukky, DEEPDEBUG, "Closing down extant compartment...");
+       duk_get_global_string(ctx->thread, MAGIC(closedownCompartment));
+       dukky_pcall(CTX, 0, true);
+       NSLOG(dukky, DEEPDEBUG, "Popping the thread off the stack");
+       duk_set_top(ctx->ctx, 0);
+       duk_gc(ctx->ctx, 0);
+       duk_gc(ctx->ctx, DUK_GC_COMPACT);
+
+       ctx->thread = NULL;
+
+       return NSERROR_OK;
+}
+
+/* exported interface documented in js.h */
 void js_initialise(void)
 {
        /** TODO: Forces JS on for our testing, needs changing before a release
@@ -562,16 +594,17 @@ void js_initialise(void)
        javascript_init();
 }
 
+
+/* exported interface documented in js.h */
 void js_finalise(void)
 {
        /* NADA for now */
 }
 
-#define DUKKY_NEW_PROTOTYPE(klass, uklass, klass_name)                 \
-       dukky_create_prototype(ctx, dukky_##klass##___proto, 
PROTO_NAME(uklass), klass_name)
 
-nserror js_newcontext(int timeout, jscallback *cb, void *cbctx,
-               jscontext **jsctx)
+/* exported interface documented in js.h */
+nserror
+js_newcontext(int timeout, jscallback *cb, void *cbctx, jscontext **jsctx)
 {
        duk_context *ctx;
        jscontext *ret = calloc(1, sizeof(*ret));
@@ -597,30 +630,29 @@ nserror js_newcontext(int timeout, jscallback *cb, void 
*cbctx,
        return NSERROR_OK;
 }
 
+
+/* exported interface documented in js.h */
 void js_destroycontext(jscontext *ctx)
 {
        NSLOG(dukky, DEBUG, "Destroying duktape javascript context");
+       dukky_closecompartment(ctx);
        duk_destroy_heap(ctx->ctx);
        free(ctx);
 }
 
+
+/* exported interface documented in js.h */
 jsobject *js_newcompartment(jscontext *ctx, void *win_priv, void *doc_priv)
 {
        assert(ctx != NULL);
        NSLOG(dukky, DEBUG,
-             "New javascript/duktape compartment, win_priv=%p, doc_priv=%p", 
win_priv,
-             doc_priv);
+             "New javascript/duktape compartment, win_priv=%p, doc_priv=%p",
+             win_priv, doc_priv);
+
        /* Pop any active thread off */
-       if (CTX != NULL) {
-               /* Closing down the extant compartment */
-               NSLOG(dukky, DEEPDEBUG, "Closing down extant compartment...");
-               duk_get_global_string(CTX, MAGIC(closedownCompartment));
-               dukky_pcall(CTX, 0, true);
-               NSLOG(dukky, DEEPDEBUG, "Popping the thread off the stack");
-               duk_set_top(ctx->ctx, 0);
-               duk_gc(ctx->ctx, 0);
-               duk_gc(ctx->ctx, DUK_GC_COMPACT);
-       }
+       dukky_closecompartment(ctx);
+
+       /* create new compartment thread */
        duk_push_thread(ctx->ctx);
        ctx->thread = duk_require_context(ctx->ctx, -1);
        duk_push_int(CTX, 0);


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

Summary of changes:
 content/handlers/javascript/duktape/Window.bnd |   55 +++++++++++-----
 content/handlers/javascript/duktape/dukky.c    |   80 +++++++++++++++++-------
 content/handlers/javascript/js.h               |   47 ++++++++------
 3 files changed, 125 insertions(+), 57 deletions(-)

diff --git a/content/handlers/javascript/duktape/Window.bnd 
b/content/handlers/javascript/duktape/Window.bnd
index b2e8166..1a76862 100644
--- a/content/handlers/javascript/duktape/Window.bnd
+++ b/content/handlers/javascript/duktape/Window.bnd
@@ -52,7 +52,9 @@ static void window_remove_callback_bits(duk_context *ctx, 
size_t handle) {
        /* ... */
 }
 
-static void window_call_callback(duk_context *ctx, size_t handle, bool 
clear_entry) {
+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_global_object(ctx);
@@ -96,21 +98,32 @@ static void window_call_callback(duk_context *ctx, size_t 
handle, bool clear_ent
        //dukky_log_stack_frame(ctx, "On leaving callback");
 }
 
-static void window_schedule_callback(void *p) {
+
+static void
+window_schedule_callback(void *p)
+{
        window_schedule_t *priv = (window_schedule_t *)p;
 
-       NSLOG(dukky, DEEPDEBUG, "Entered window scheduler callback: %"PRIsizet, 
priv->handle);
+       NSLOG(dukky, DEEPDEBUG,
+             "Entered window scheduler callback: %"PRIsizet, priv->handle);
 
        priv->running = true;
-       window_call_callback(priv->ctx, priv->handle, priv->repeat_timeout == 
0);
+       window_call_callback(priv->ctx,
+                            priv->handle,
+                            priv->repeat_timeout == 0);
        priv->running = false;
 
        if (priv->repeat_timeout > 0) {
                /* Reschedule */
-               NSLOG(dukky, DEEPDEBUG, "Rescheduling repeating callback 
%"PRIsizet, priv->handle);
-               guit->misc->schedule(priv->repeat_timeout, 
window_schedule_callback, priv);
+               NSLOG(dukky, DEEPDEBUG,
+                     "Rescheduling repeating callback %"PRIsizet,
+                     priv->handle);
+               guit->misc->schedule(priv->repeat_timeout,
+                                    window_schedule_callback,
+                                    priv);
        } else {
-               NSLOG(dukky, DEEPDEBUG, "Removing completed callback 
%"PRIsizet, priv->handle);
+               NSLOG(dukky, DEEPDEBUG,
+                     "Removing completed callback %"PRIsizet, priv->handle);
                /* Remove this from the ring */
                RING_REMOVE(priv->owner->schedule_ring, priv);
                window_remove_callback_bits(priv->ctx, priv->handle);
@@ -118,8 +131,12 @@ static void window_schedule_callback(void *p) {
        }
 }
 
-static size_t window_alloc_new_callback(duk_context *ctx, window_private_t 
*window,
-                                       bool repeating, int timeout) {
+static size_t
+window_alloc_new_callback(duk_context *ctx,
+                         window_private_t *window,
+                         bool repeating,
+                         int timeout)
+{
        size_t new_handle = next_handle++;
        window_schedule_t *sched = calloc(sizeof *sched, 1);
        if (sched == NULL) {
@@ -168,18 +185,24 @@ static size_t window_alloc_new_callback(duk_context *ctx, 
window_private_t *wind
        return new_handle;
 }
 
-static void window_remove_callback_by_handle(duk_context *ctx,
-                                            window_private_t *window,
-                                            size_t handle) {
+static void
+window_remove_callback_by_handle(duk_context *ctx,
+                                window_private_t *window,
+                                size_t handle)
+{
        int res;
 
        RING_ITERATE_START(window_schedule_t, window->schedule_ring, sched) {
                if (sched->handle == handle) {
                        if (sched->running) {
-                               NSLOG(dukky, DEEPDEBUG, "Cancelling in-train 
callback %"PRIsizet, sched->handle);
+                               NSLOG(dukky, DEEPDEBUG,
+                                     "Cancelling in-train callback %"PRIsizet,
+                                     sched->handle);
                                sched->repeat_timeout = 0;
                        } else {
-                               NSLOG(dukky, DEEPDEBUG, "Cancelled callback 
%"PRIsizet, sched->handle);
+                               NSLOG(dukky, DEEPDEBUG,
+                                     "Cancelled callback %"PRIsizet,
+                                     sched->handle);
                                res = guit->misc->schedule(-1,
                                                           
window_schedule_callback,
                                                           sched);
@@ -209,7 +232,9 @@ static duk_ret_t 
dukky_window_closedown_compartment(duk_context *ctx)
 
        NSLOG(dukky, DEEPDEBUG, "Closing down compartment");
        while (priv->schedule_ring != NULL) {
-               window_remove_callback_by_handle(ctx, priv, 
priv->schedule_ring->handle);
+               window_remove_callback_by_handle(ctx,
+                                                priv,
+                                                priv->schedule_ring->handle);
        }
 
        return 0;
diff --git a/content/handlers/javascript/duktape/dukky.c 
b/content/handlers/javascript/duktape/dukky.c
index a828667..538a15b 100644
--- a/content/handlers/javascript/duktape/dukky.c
+++ b/content/handlers/javascript/duktape/dukky.c
@@ -19,7 +19,8 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-/** \file
+/**
+ * \file
  * Duktapeish implementation of javascript engine functions.
  */
 
@@ -50,6 +51,15 @@
 #define EVENT_LISTENER_JS_MAGIC MAGIC(EVENT_LISTENER_JS_MAP)
 #define GENERICS_MAGIC MAGIC(GENERICS_TABLE)
 
+/**
+ * dukky javascript context
+ */
+struct jscontext {
+       duk_context *ctx; /**< duktape base context */
+       duk_context *thread; /**< duktape compartment */
+       uint64_t exec_start_time;
+};
+
 static duk_ret_t dukky_populate_object(duk_context *ctx, void *udata)
 {
        /* ... obj args protoname nargs */
@@ -535,6 +545,7 @@ static void *dukky_realloc_function(void *udata, void *ptr, 
duk_size_t size)
        return realloc(ptr, size);
 }
 
+
 static void dukky_free_function(void *udata, void *ptr)
 {
        if (ptr != NULL)
@@ -542,15 +553,36 @@ static void dukky_free_function(void *udata, void *ptr)
 }
 
 
-/**************************************** js.h ******************************/
-struct jscontext {
-       duk_context *ctx;
-       duk_context *thread;
-       uint64_t exec_start_time;
-};
-
 #define CTX (ctx->thread)
 
+/**
+ * close current compartment
+ *
+ * \param ctx javascript context
+ * \return NSERROR_OK on sucess.
+ */
+static nserror dukky_closecompartment(jscontext *ctx)
+{
+       /* ensure there is an active compartment */
+       if (ctx->thread == NULL) {
+               return NSERROR_OK;
+       }
+
+       /* Closing down the extant compartment */
+       NSLOG(dukky, DEEPDEBUG, "Closing down extant compartment...");
+       duk_get_global_string(ctx->thread, MAGIC(closedownCompartment));
+       dukky_pcall(CTX, 0, true);
+       NSLOG(dukky, DEEPDEBUG, "Popping the thread off the stack");
+       duk_set_top(ctx->ctx, 0);
+       duk_gc(ctx->ctx, 0);
+       duk_gc(ctx->ctx, DUK_GC_COMPACT);
+
+       ctx->thread = NULL;
+
+       return NSERROR_OK;
+}
+
+/* exported interface documented in js.h */
 void js_initialise(void)
 {
        /** TODO: Forces JS on for our testing, needs changing before a release
@@ -562,16 +594,17 @@ void js_initialise(void)
        javascript_init();
 }
 
+
+/* exported interface documented in js.h */
 void js_finalise(void)
 {
        /* NADA for now */
 }
 
-#define DUKKY_NEW_PROTOTYPE(klass, uklass, klass_name)                 \
-       dukky_create_prototype(ctx, dukky_##klass##___proto, 
PROTO_NAME(uklass), klass_name)
 
-nserror js_newcontext(int timeout, jscallback *cb, void *cbctx,
-               jscontext **jsctx)
+/* exported interface documented in js.h */
+nserror
+js_newcontext(int timeout, jscallback *cb, void *cbctx, jscontext **jsctx)
 {
        duk_context *ctx;
        jscontext *ret = calloc(1, sizeof(*ret));
@@ -597,30 +630,29 @@ nserror js_newcontext(int timeout, jscallback *cb, void 
*cbctx,
        return NSERROR_OK;
 }
 
+
+/* exported interface documented in js.h */
 void js_destroycontext(jscontext *ctx)
 {
        NSLOG(dukky, DEBUG, "Destroying duktape javascript context");
+       dukky_closecompartment(ctx);
        duk_destroy_heap(ctx->ctx);
        free(ctx);
 }
 
+
+/* exported interface documented in js.h */
 jsobject *js_newcompartment(jscontext *ctx, void *win_priv, void *doc_priv)
 {
        assert(ctx != NULL);
        NSLOG(dukky, DEBUG,
-             "New javascript/duktape compartment, win_priv=%p, doc_priv=%p", 
win_priv,
-             doc_priv);
+             "New javascript/duktape compartment, win_priv=%p, doc_priv=%p",
+             win_priv, doc_priv);
+
        /* Pop any active thread off */
-       if (CTX != NULL) {
-               /* Closing down the extant compartment */
-               NSLOG(dukky, DEEPDEBUG, "Closing down extant compartment...");
-               duk_get_global_string(CTX, MAGIC(closedownCompartment));
-               dukky_pcall(CTX, 0, true);
-               NSLOG(dukky, DEEPDEBUG, "Popping the thread off the stack");
-               duk_set_top(ctx->ctx, 0);
-               duk_gc(ctx->ctx, 0);
-               duk_gc(ctx->ctx, DUK_GC_COMPACT);
-       }
+       dukky_closecompartment(ctx);
+
+       /* create new compartment thread */
        duk_push_thread(ctx->ctx);
        ctx->thread = duk_require_context(ctx->ctx, -1);
        duk_push_int(CTX, 0);
diff --git a/content/handlers/javascript/js.h b/content/handlers/javascript/js.h
index 31ab8f7..d5af721 100644
--- a/content/handlers/javascript/js.h
+++ b/content/handlers/javascript/js.h
@@ -20,12 +20,11 @@
  * Interface to javascript engine functions.
  */
 
-#ifndef _NETSURF_JAVASCRIPT_JS_H_
-#define _NETSURF_JAVASCRIPT_JS_H_
+#ifndef NETSURF_JAVASCRIPT_JS_H_
+#define NETSURF_JAVASCRIPT_JS_H_
 
 #include "utils/errors.h"
 
-
 typedef struct jscontext jscontext;
 typedef struct jsobject jsobject;
 
@@ -37,40 +36,50 @@ struct dom_node;
 struct dom_element;
 struct dom_string;
 
-/** Initialise javascript interpreter */
+/**
+ * Initialise javascript interpreter
+ */
 void js_initialise(void);
 
-/** finalise javascript interpreter */
+/**
+ * finalise javascript interpreter
+ */
 void js_finalise(void);
 
-/** Create a new javascript context.
+/**
+ * Create a new javascript context.
  *
- * There is usually one context per browser context
+ * There is usually one context per browsing context (browser window)
  *
- * \param timeout elapsed wallclock time (in seconds)  before \a callback is 
called
+ * \param timeout elapsed wallclock time (in seconds) before \a callback is 
called
  * \param cb the callback when the runtime exceeds the timeout
  * \param cbctx The context to pass to the callback
  * \param jsctx Updated to the created JS context
  * \return NSERROR_OK on success, appropriate error otherwise.
  */
-nserror js_newcontext(int timeout, jscallback *cb, void *cbctx,
-               jscontext **jsctx);
+nserror js_newcontext(int timeout, jscallback *cb, void *cbctx, jscontext 
**jsctx);
 
-/** Destroy a previously created context */
+/**
+ * Destroy a previously created context
+ */
 void js_destroycontext(jscontext *ctx);
 
-/** Create a new javascript compartment
+/**
+ * Create a new javascript compartment
  *
  * This is called once for a page with javascript script tags on
  * it. It constructs a fresh global window object.
  */
 jsobject *js_newcompartment(jscontext *ctx, void *win_priv, void *doc_priv);
 
-/* execute some javascript in a context */
+/**
+ * execute some javascript in a context
+ */
 bool js_exec(jscontext *ctx, const uint8_t *txt, size_t txtlen, const char 
*name);
 
-
-/* fire an event at a dom node */
+/**
+ * fire an event at a dom node
+ */
 bool js_fire_event(jscontext *ctx, const char *type, struct dom_document *doc, 
struct dom_node *target);
 
 bool
@@ -82,7 +91,8 @@ js_dom_event_add_listener(jscontext *ctx,
 
 /*** New Events ***/
 
-/** Handle a new element being created.
+/**
+ * Handle a new element being created.
  *
  * This is called once an element is inserted into the DOM document handled
  * by the context provided.  The JS implementation must then scan the element
@@ -90,7 +100,8 @@ js_dom_event_add_listener(jscontext *ctx,
  */
 void js_handle_new_element(jscontext *ctx, struct dom_element *node);
 
-/** Handle an event propagation finished callback.
+/**
+ * Handle an event propagation finished callback.
  *
  * This is called once an event finishes propagating, no matter how it
  * finishes.  The intent here is that the JS context can perform any cleanups
@@ -99,4 +110,4 @@ void js_handle_new_element(jscontext *ctx, struct 
dom_element *node);
  */
 void js_event_cleanup(jscontext *ctx, struct dom_event *evt);
 
-#endif /* _NETSURF_JAVASCRIPT_JS_H_ */
+#endif /* NETSURF_JAVASCRIPT_JS_H_ */


-- 
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