diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2019-05-02 23:05:29 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2019-05-02 23:05:29 +0100 |
commit | c7f58c742de14f20b48ad32b023d478283995521 (patch) | |
tree | 3e23d8db5871518c46f79928a210bd4dd8622a73 | |
parent | 9656f1ff87136263d44a54a4e3081ac92ad3b699 (diff) | |
download | nsgenbind-c7f58c742de14f20b48ad32b023d478283995521.tar.gz nsgenbind-c7f58c742de14f20b48ad32b023d478283995521.tar.bz2 |
duk-libdom: Use PrimaryGlobal for Window to change method private
In order to support methods on `Window` being called via the global
object (which does not set `this`) we notice that the interface
we are generating the private data fetcher for as being the
global one, and use `duk_push_global_object` rather than `duk_push_this`.
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
-rw-r--r-- | src/duk-libdom-interface.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/duk-libdom-interface.c b/src/duk-libdom-interface.c index b3c9f19..0e6697a 100644 --- a/src/duk-libdom-interface.c +++ b/src/duk-libdom-interface.c @@ -244,11 +244,15 @@ output_prototype_constant_int(FILE *outf, const char *constant_name, int value) * generate code that gets a private pointer for a method */ static int -output_get_method_private(FILE* outf, char *class_name) +output_get_method_private(FILE* outf, char *class_name, bool is_global) { fprintf(outf, "\t/* Get private data for method */\n"); fprintf(outf, "\t%s_private_t *priv = NULL;\n", class_name); - fprintf(outf, "\tduk_push_this(ctx);\n"); + if (is_global) { + fprintf(outf, "\tduk_push_global_object(ctx);\n"); + } else { + fprintf(outf, "\tduk_push_this(ctx);\n"); + } fprintf(outf, "\tduk_get_prop_string(ctx, -1, %s_magic_string_private);\n", DLPFX); fprintf(outf, "\tpriv = duk_get_pointer(ctx, -1);\n"); @@ -820,7 +824,8 @@ output_interface_elipsis_operation(FILE* outf, "Elipsis parameters not checked: method %s::%s();", interfacee->name, operatione->name); - output_get_method_private(outf, interfacee->class_name); + output_get_method_private(outf, interfacee->class_name, + interfacee->u.interface.primary_global); cdatac = output_ccode(outf, operatione->method); if (cdatac == 0) { @@ -856,7 +861,8 @@ output_interface_overloaded_operation(FILE* outf, * overloaded operation should go */ - output_get_method_private(outf, interfacee->class_name); + output_get_method_private(outf, interfacee->class_name, + interfacee->u.interface.primary_global); cdatac = output_cdata(outf, operatione->method, @@ -1153,7 +1159,8 @@ output_interface_operation(FILE* outf, argidx); } - output_get_method_private(outf, interfacee->class_name); + output_get_method_private(outf, interfacee->class_name, + interfacee->u.interface.primary_global); cdatac = output_ccode(outf, operatione->method); if (cdatac == 0) { @@ -1212,7 +1219,8 @@ output_attribute_getter(FILE* outf, DLPFX, interfacee->class_name, atributee->name); fprintf(outf,"{\n"); - output_get_method_private(outf, interfacee->class_name); + output_get_method_private(outf, interfacee->class_name, + interfacee->u.interface.primary_global); /* if binding available for this attribute getter process it */ if (atributee->getter != NULL) { @@ -1310,7 +1318,8 @@ output_attribute_setter(FILE* outf, DLPFX, interfacee->class_name, atributee->name); fprintf(outf,"{\n"); - output_get_method_private(outf, interfacee->class_name); + output_get_method_private(outf, interfacee->class_name, + interfacee->u.interface.primary_global); /* if binding available for this attribute getter process it */ if (atributee->setter != NULL) { |