From b0b8fe9acf002cbfeb68873cac6e01345e173fa8 Mon Sep 17 00:00:00 2001 From: John-Mark Bell Date: Mon, 1 Feb 2016 11:34:35 +0000 Subject: Expose nullable flag in IR and have generated getters use it. --- src/duk-libdom-generated.c | 9 +++++++-- src/ir.c | 6 ++++++ src/ir.h | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/duk-libdom-generated.c b/src/duk-libdom-generated.c index bae0826..0790e00 100644 --- a/src/duk-libdom-generated.c +++ b/src/duk-libdom-generated.c @@ -102,8 +102,13 @@ output_generated_attribute_getter(FILE* outf, "\t\t\tdom_string_data(str),\n" "\t\t\tdom_string_length(str));\n" "\t\tdom_string_unref(str);\n" - "\t} else {\n" - "\t\tduk_push_lstring(ctx, NULL, 0);\n" + "\t} else {\n"); + if (atributee->typev[0].nullable) { + fprintf(outf, "\t\tduk_push_null(ctx);\n"); + } else { + fprintf(outf, "\t\tduk_push_lstring(ctx, NULL, 0);\n"); + } + fprintf(outf, "\t}\n" "\n" "\treturn 1;\n"); diff --git a/src/ir.c b/src/ir.c index 8084c40..7a1bc5a 100644 --- a/src/ir.c +++ b/src/ir.c @@ -483,6 +483,12 @@ type_map_new(struct webidl_node *node, cure->modifier = WEBIDL_TYPE_MODIFIER_NONE; } + /* type nullability */ + cure->nullable = (webidl_node_find_type( + webidl_node_getnode(type_node), + NULL, + WEBIDL_NODE_TYPE_TYPE_NULLABLE) != NULL); + /* type name */ cure->name = webidl_node_gettext( webidl_node_find_type( diff --git a/src/ir.h b/src/ir.h index d3dd5d0..a6fcf12 100644 --- a/src/ir.h +++ b/src/ir.h @@ -53,6 +53,7 @@ struct ir_operation_entry { struct ir_type_entry { enum webidl_type base; /**< base of the type (long, short, user etc.) */ enum webidl_type_modifier modifier; /**< modifier for the type */ + bool nullable; /**< the type is nullable */ const char *name; /**< name of type for user types */ }; -- cgit v1.2.3