summaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2019-05-06 15:09:39 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2019-05-06 15:09:39 +0100
commit378383ea3bf04ab6e083c597298db63ff665837e (patch)
tree96a3726e54925efbb69bc543a7c13c51d9997a81 /content
parentd719bdcee3bf4cae2649535251d69a33839ae13a (diff)
downloadnetsurf-378383ea3bf04ab6e083c597298db63ff665837e.tar.gz
netsurf-378383ea3bf04ab6e083c597298db63ff665837e.tar.bz2
Support context dump safely in duktape
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'content')
-rw-r--r--content/handlers/javascript/duktape/dukky.c23
-rw-r--r--content/handlers/javascript/duktape/dukky.h3
2 files changed, 24 insertions, 2 deletions
diff --git a/content/handlers/javascript/duktape/dukky.c b/content/handlers/javascript/duktape/dukky.c
index e9e579d4d..c3b956902 100644
--- a/content/handlers/javascript/duktape/dukky.c
+++ b/content/handlers/javascript/duktape/dukky.c
@@ -669,6 +669,8 @@ jsobject *js_newcompartment(jscontext *ctx, void *win_priv, void *doc_priv)
duk_pop(CTX);
/* ... */
+ dukky_log_stack_frame(CTX, "New compartment created");
+
return (jsobject *)ctx;
}
@@ -698,8 +700,8 @@ static void dukky_dump_error(duk_context *ctx)
{
/* stack is ..., errobj */
duk_idx_t stacktop = duk_get_top(ctx);
- if (!duk_is_error(ctx, stacktop - 1)) {
- NSLOG(dukky, INFO, "Uncaught non-Error derived error in JS: %s", duk_safe_to_string(ctx, stacktop - 1));
+ if (!duk_is_error(ctx, -1)) {
+ NSLOG(dukky, INFO, "Uncaught non-Error derived error in JS: %s", duk_safe_to_string(ctx, -1));
} else {
#define GETTER(what) \
if (duk_has_prop_string(ctx, stacktop - 1, what)) { \
@@ -761,6 +763,23 @@ void dukky_push_generics(duk_context *ctx, const char *generic)
/* ..., generic */
}
+static duk_int_t dukky_push_context_dump(duk_context *ctx, void *udata)
+{
+ duk_push_context_dump(ctx);
+ return 1;
+}
+
+void dukky_log_stack_frame(duk_context *ctx, const char * reason)
+{
+ if (duk_safe_call(ctx, dukky_push_context_dump, NULL, 0, 1) != 0) {
+ duk_pop(ctx);
+ duk_push_string(ctx, "[???]");
+ }
+ NSLOG(dukky, DEEPDEBUG, "%s, stack is: %s", reason, duk_safe_to_string(ctx, -1));
+ duk_pop(ctx);
+}
+
+
/* exported interface documented in js.h */
bool
js_exec(jscontext *ctx, const uint8_t *txt, size_t txtlen, const char *name)
diff --git a/content/handlers/javascript/duktape/dukky.h b/content/handlers/javascript/duktape/dukky.h
index 93d416983..5a67951dc 100644
--- a/content/handlers/javascript/duktape/dukky.h
+++ b/content/handlers/javascript/duktape/dukky.h
@@ -54,4 +54,7 @@ duk_int_t dukky_pcall(duk_context *ctx, duk_size_t argc, bool reset_timeout);
/* Push a generics function onto the stack */
void dukky_push_generics(duk_context *ctx, const char *generic);
+/* Log the current stack frame if possible */
+void dukky_log_stack_frame(duk_context *ctx, const char * reason);
+
#endif