summaryrefslogtreecommitdiff
path: root/content/handlers
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2019-05-05 21:53:08 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2019-05-05 22:17:10 +0100
commit8b4ec11b8958b7b7893d2b0f6aad20b2ddc3599f (patch)
treed7cf6aee20d37e59f7f7b747621d3fd9c6b8a3dc /content/handlers
parent8474c5d4c0b59e74e2ef001b5033b78d7a99fcad (diff)
downloadnetsurf-8b4ec11b8958b7b7893d2b0f6aad20b2ddc3599f.tar.gz
netsurf-8b4ec11b8958b7b7893d2b0f6aad20b2ddc3599f.tar.bz2
Dukky: Change from specifically named generics
Instead of specifically having to extract each generic by name, such as makeListProxy, instead support the entire generics table and use `dukky_push_generics()` to gain access to it. Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'content/handlers')
-rw-r--r--content/handlers/javascript/duktape/Document.bnd4
-rw-r--r--content/handlers/javascript/duktape/dukky.c19
-rw-r--r--content/handlers/javascript/duktape/dukky.h3
3 files changed, 18 insertions, 8 deletions
diff --git a/content/handlers/javascript/duktape/Document.bnd b/content/handlers/javascript/duktape/Document.bnd
index d27591759..9c63a61c4 100644
--- a/content/handlers/javascript/duktape/Document.bnd
+++ b/content/handlers/javascript/duktape/Document.bnd
@@ -18,7 +18,7 @@ prologue Document()
#include "content/urldb.h"
#define HANDLER_MAGIC MAGIC(HANDLER_MAP)
-#define LIST_PROXY_MAGIC MAGIC(LIST_PROXY)
+#define GENERICS_MAGIC MAGIC(GENERICS_TABLE)
%}
@@ -345,7 +345,7 @@ method Document::getElementsByTagName()
if (nodes == NULL) return 0; /* coerced to undefined */
- duk_get_global_string(ctx, LIST_PROXY_MAGIC);
+ dukky_push_generics(ctx, "makeListProxy");
duk_push_pointer(ctx, nodes);
dukky_create_object(ctx, PROTO_NAME(NODELIST), 1);
diff --git a/content/handlers/javascript/duktape/dukky.c b/content/handlers/javascript/duktape/dukky.c
index 8af3165b6..d1bd4ec49 100644
--- a/content/handlers/javascript/duktape/dukky.c
+++ b/content/handlers/javascript/duktape/dukky.c
@@ -48,7 +48,7 @@
#define HANDLER_LISTENER_MAGIC MAGIC(HANDLER_LISTENER_MAP)
#define HANDLER_MAGIC MAGIC(HANDLER_MAP)
#define EVENT_LISTENER_JS_MAGIC MAGIC(EVENT_LISTENER_JS_MAP)
-#define LIST_PROXY_MAGIC MAGIC(LIST_PROXY)
+#define GENERICS_MAGIC MAGIC(GENERICS_TABLE)
static duk_ret_t dukky_populate_object(duk_context *ctx, void *udata)
{
@@ -663,11 +663,7 @@ jsobject *js_newcompartment(jscontext *ctx, void *win_priv, void *doc_priv)
/* ..., Win */
duk_get_prop_string(CTX, -1, "NetSurf");
/* ..., Win, NetSurf */
- duk_get_prop_string(CTX, -1, "makeListProxy");
- /* ..., Win, NetSurf, MLP */
- duk_put_global_string(CTX, LIST_PROXY_MAGIC);
- /* ..., Win, NetSurf */
- duk_pop(CTX);
+ duk_put_global_string(CTX, GENERICS_MAGIC);
/* ..., Win */
duk_del_prop_string(CTX, -1, "NetSurf");
duk_pop(CTX);
@@ -754,6 +750,17 @@ duk_int_t dukky_pcall(duk_context *ctx, duk_size_t argc, bool reset_timeout)
}
+void dukky_push_generics(duk_context *ctx, const char *generic)
+{
+ /* ... */
+ duk_get_global_string(ctx, GENERICS_MAGIC);
+ /* ..., generics */
+ duk_get_prop_string(ctx, -1, generic);
+ /* ..., generics, generic */
+ duk_remove(ctx, -2);
+ /* ..., generic */
+}
+
bool js_exec(jscontext *ctx, const char *txt, size_t txtlen, const char *name)
{
assert(ctx);
diff --git a/content/handlers/javascript/duktape/dukky.h b/content/handlers/javascript/duktape/dukky.h
index ee9f47409..93d416983 100644
--- a/content/handlers/javascript/duktape/dukky.h
+++ b/content/handlers/javascript/duktape/dukky.h
@@ -51,4 +51,7 @@ void dukky_shuffle_array(duk_context *ctx, duk_uarridx_t idx);
/* pcall something, and if it errored, also dump the error to the log */
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);
+
#endif