diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2015-08-09 18:54:37 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2015-08-09 18:54:37 +0100 |
commit | 0df3439eb26914466b91ce529e7f3366094030d6 (patch) | |
tree | 9a8a8011efff300ad46f994718304b646bac62e9 /javascript | |
parent | 3d7de6cf8d67bd7761a907cb171d8a4af8088a08 (diff) | |
download | netsurf-0df3439eb26914466b91ce529e7f3366094030d6.tar.gz netsurf-0df3439eb26914466b91ce529e7f3366094030d6.tar.bz2 |
Fix constructor injection to use new constructor type, add test
Diffstat (limited to 'javascript')
-rw-r--r-- | javascript/dukky.c | 20 | ||||
-rw-r--r-- | javascript/dukky.h | 2 | ||||
-rw-r--r-- | javascript/duktape/Window.bnd | 9 |
3 files changed, 28 insertions, 3 deletions
diff --git a/javascript/dukky.c b/javascript/dukky.c index 8f69d23c8..6c8c531fe 100644 --- a/javascript/dukky.c +++ b/javascript/dukky.c @@ -247,7 +247,27 @@ dukky_push_node(duk_context *ctx, struct dom_node *node) return dukky_push_node_stacked(ctx); } +static duk_ret_t +dukky_bad_constructor(duk_context *ctx) +{ + duk_error(ctx, DUK_ERR_ERROR, "Bad constructor"); + return 0; +} +void +dukky_inject_not_ctr(duk_context *ctx, int idx, const char *name) +{ + /* ... p[idx] ... proto */ + duk_push_c_function(ctx, dukky_bad_constructor, 0); + /* ... p[idx] ... proto cons */ + duk_insert(ctx, -2); + /* ... p[idx] ... cons proto */ + duk_put_prop_string(ctx, -2, "prototype"); + /* ... p[idx] ... cons[proto] */ + duk_put_prop_string(ctx, idx, name); + /* ... p ... */ + return; +} /**************************************** js.h ******************************/ struct jscontext { diff --git a/javascript/dukky.h b/javascript/dukky.h index b1ab2edf0..abe21ba35 100644 --- a/javascript/dukky.h +++ b/javascript/dukky.h @@ -27,6 +27,6 @@ duk_ret_t dukky_create_object(duk_context *ctx, const char *name, int args); duk_bool_t dukky_push_node_stacked(duk_context *ctx); duk_bool_t dukky_push_node(duk_context *ctx, struct dom_node *node); - +void dukky_inject_not_ctr(duk_context *ctx, int idx, const char *name); #endif diff --git a/javascript/duktape/Window.bnd b/javascript/duktape/Window.bnd index 95b55b2e2..fee5d2105 100644 --- a/javascript/duktape/Window.bnd +++ b/javascript/duktape/Window.bnd @@ -31,9 +31,14 @@ init Window("struct browser_window *" win, "struct html_content *" htmlc) prototype Window() %{ +#define EXPOSE(v) \ + duk_get_global_string(ctx, #v); \ + duk_put_prop_string(ctx, 0, #v) /* steal undefined */ - duk_get_global_string(ctx, "undefined"); - duk_put_prop_string(ctx, 0, "undefined"); + EXPOSE(undefined); + EXPOSE(eval); + EXPOSE(Object); +#undef EXPOSE %} getter Window::document() |