From ff8e5c99a038d6325b72e90ada824bcfd3ab9cc7 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Wed, 22 Mar 2017 15:42:40 +0000 Subject: Duktape 2.x: duk_safe_call callbacks now have a void ptr user data param. https://github.com/svaarala/duktape/blob/master/doc/release-notes-v2-0.rst#duk_safe_call-userdata --- content/handlers/javascript/duktape/dukky.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'content/handlers/javascript/duktape/dukky.c') diff --git a/content/handlers/javascript/duktape/dukky.c b/content/handlers/javascript/duktape/dukky.c index 4a6b9c398..52604f994 100644 --- a/content/handlers/javascript/duktape/dukky.c +++ b/content/handlers/javascript/duktape/dukky.c @@ -48,7 +48,7 @@ #define HANDLER_MAGIC MAGIC(HANDLER_MAP) #define EVENT_LISTENER_JS_MAGIC MAGIC(EVENT_LISTENER_JS_MAP) -static duk_ret_t dukky_populate_object(duk_context *ctx) +static duk_ret_t dukky_populate_object(duk_context *ctx, void *udata) { /* ... obj args protoname nargs */ int nargs = duk_get_int(ctx, -1); @@ -103,7 +103,7 @@ duk_ret_t dukky_create_object(duk_context *ctx, const char *name, int args) /* ... obj args name */ duk_push_int(ctx, args); /* ... obj args name nargs */ - if ((ret = duk_safe_call(ctx, dukky_populate_object, args + 3, 1)) + if ((ret = duk_safe_call(ctx, dukky_populate_object, NULL, args + 3, 1)) != DUK_EXEC_SUCCESS) return ret; LOG("created"); @@ -143,7 +143,7 @@ dukky_push_node_stacked(duk_context *ctx) /* ... nodeptr klass nodes obj nodeptr klass */ duk_push_int(ctx, 1); /* ... nodeptr klass nodes obj nodeptr klass 1 */ - if (duk_safe_call(ctx, dukky_populate_object, 4, 1) + if (duk_safe_call(ctx, dukky_populate_object, NULL, 4, 1) != DUK_EXEC_SUCCESS) { duk_set_top(ctx, top_at_fail); LOG("Boo and also hiss"); @@ -624,7 +624,7 @@ jsobject *js_newcompartment(jscontext *ctx, void *win_priv, void *doc_priv) return (jsobject *)ctx; } -static duk_ret_t eval_top_string(duk_context *ctx) +static duk_ret_t eval_top_string(duk_context *ctx, void *udata) { duk_eval(ctx); return 0; @@ -654,7 +654,7 @@ bool js_exec(jscontext *ctx, const char *txt, size_t txtlen) duk_push_lstring(CTX, txt, txtlen); (void) nsu_getmonotonic_ms(&ctx->exec_start_time); - if (duk_safe_call(CTX, eval_top_string, 1, 1) == DUK_EXEC_ERROR) { + if (duk_safe_call(CTX, eval_top_string, NULL, 1, 1) == DUK_EXEC_ERROR) { duk_get_prop_string(CTX, 0, "name"); duk_get_prop_string(CTX, 0, "message"); duk_get_prop_string(CTX, 0, "fileName"); -- cgit v1.2.3 From 5d39972b9fe74b3618d08cf1bf4b14a01d420809 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Wed, 22 Mar 2017 15:44:53 +0000 Subject: Duktape 2.X: duk_error now returns a duk_ret_t https://github.com/svaarala/duktape/blob/master/doc/release-notes-v2-0.rst#duk_error-duk_error_va-duk_throw-duk_fatal-have-a-return-value This also changes Console.bnd to return on error, rather than ignoring it. --- content/handlers/javascript/duktape/Console.bnd | 4 ++-- content/handlers/javascript/duktape/Window.bnd | 9 +++------ content/handlers/javascript/duktape/dukky.c | 3 +-- 3 files changed, 6 insertions(+), 10 deletions(-) (limited to 'content/handlers/javascript/duktape/dukky.c') diff --git a/content/handlers/javascript/duktape/Console.bnd b/content/handlers/javascript/duktape/Console.bnd index 734f0035a..7b4de1ee3 100644 --- a/content/handlers/javascript/duktape/Console.bnd +++ b/content/handlers/javascript/duktape/Console.bnd @@ -110,7 +110,7 @@ method Console::time() return 0; if (!duk_is_string(ctx, 0)) { - duk_error(ctx, DUK_ERR_ERROR, "Console.time() takes a string"); + return duk_error(ctx, DUK_ERR_ERROR, "Console.time() takes a string"); } duk_set_top(ctx, 1); @@ -136,7 +136,7 @@ method Console::timeEnd() return 0; if (!duk_is_string(ctx, 0)) { - duk_error(ctx, DUK_ERR_ERROR, "Console.time() takes a string"); + return duk_error(ctx, DUK_ERR_ERROR, "Console.time() takes a string"); } duk_set_top(ctx, 1); diff --git a/content/handlers/javascript/duktape/Window.bnd b/content/handlers/javascript/duktape/Window.bnd index 489587899..4af8c7aa9 100644 --- a/content/handlers/javascript/duktape/Window.bnd +++ b/content/handlers/javascript/duktape/Window.bnd @@ -72,8 +72,7 @@ getter Window::console() if (duk_is_undefined(ctx, -1)) { duk_pop(ctx); if (dukky_create_object(ctx, PROTO_NAME(CONSOLE), 0) != DUK_EXEC_SUCCESS) { - duk_error(ctx, DUK_ERR_ERROR, "Unable to create console object"); - return 0; + return duk_error(ctx, DUK_ERR_ERROR, "Unable to create console object"); } duk_dup(ctx, -1); duk_put_prop_string(ctx, -3, MAGIC(Console)); @@ -91,8 +90,7 @@ getter Window::location() duk_push_pointer(ctx, llcache_handle_get_url(priv->htmlc->base.llcache)); if (dukky_create_object(ctx, PROTO_NAME(LOCATION), 1) != DUK_EXEC_SUCCESS) { - duk_error(ctx, DUK_ERR_ERROR, "Unable to create location object"); - return 0; + return duk_error(ctx, DUK_ERR_ERROR, "Unable to create location object"); } duk_dup(ctx, -1); duk_put_prop_string(ctx, -3, MAGIC(Location)); @@ -110,10 +108,9 @@ getter Window::navigator() if (dukky_create_object(ctx, PROTO_NAME(NAVIGATOR), 0) != DUK_EXEC_SUCCESS) { - duk_error(ctx, + return duk_error(ctx, DUK_ERR_ERROR, "Unable to create navigator object"); - return 0; } duk_dup(ctx, -1); duk_put_prop_string(ctx, -3, MAGIC(Navigator)); diff --git a/content/handlers/javascript/duktape/dukky.c b/content/handlers/javascript/duktape/dukky.c index 52604f994..dd4378b7a 100644 --- a/content/handlers/javascript/duktape/dukky.c +++ b/content/handlers/javascript/duktape/dukky.c @@ -474,8 +474,7 @@ dukky_push_node(duk_context *ctx, struct dom_node *node) static duk_ret_t dukky_bad_constructor(duk_context *ctx) { - duk_error(ctx, DUK_ERR_ERROR, "Bad constructor"); - return 0; + return duk_error(ctx, DUK_ERR_ERROR, "Bad constructor"); } void -- cgit v1.2.3