From 8b4ec11b8958b7b7893d2b0f6aad20b2ddc3599f Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sun, 5 May 2019 21:53:08 +0100 Subject: 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 --- content/handlers/javascript/duktape/Document.bnd | 4 ++-- content/handlers/javascript/duktape/dukky.c | 19 +++++++++++++------ content/handlers/javascript/duktape/dukky.h | 3 +++ 3 files changed, 18 insertions(+), 8 deletions(-) (limited to 'content') 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 -- cgit v1.2.3