summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vincent.sanders@collabora.co.uk>2012-11-20 19:15:30 +0000
committerVincent Sanders <vincent.sanders@collabora.co.uk>2012-11-20 19:15:30 +0000
commit841e93e4bc21729853e56b6d6b188d7b21450950 (patch)
tree0c9f0a613a9de38c11103f5718b2074cd3102b0c
parentf2578192d04f4bc0ad70abaf070fffd5d1cf63ab (diff)
downloadnsgenbind-841e93e4bc21729853e56b6d6b188d7b21450950.tar.gz
nsgenbind-841e93e4bc21729853e56b6d6b188d7b21450950.tar.bz2
correctly generate setters and getters with unshared elements
changes signature of generated JSAPI_PS() macro
-rw-r--r--src/jsapi-libdom-property.c85
1 files changed, 63 insertions, 22 deletions
diff --git a/src/jsapi-libdom-property.c b/src/jsapi-libdom-property.c
index f97d352..a488058 100644
--- a/src/jsapi-libdom-property.c
+++ b/src/jsapi-libdom-property.c
@@ -30,22 +30,22 @@ static int webidl_property_spec_cb(struct webidl_node *node, void *ctx)
ident_node = webidl_node_find_type(webidl_node_getnode(node),
NULL,
WEBIDL_NODE_TYPE_IDENT);
- if (ident_node == NULL) {
+ ident = webidl_node_gettext(ident_node);
+ if (ident == NULL) {
/* properties must have an operator
* http://www.w3.org/TR/WebIDL/#idl-attributes
*/
return -1;
}
- ident = webidl_node_gettext(ident_node);
modifier_node = webidl_node_find_type(webidl_node_getnode(node),
NULL,
WEBIDL_NODE_TYPE_MODIFIER);
if (webidl_node_getint(modifier_node) == WEBIDL_TYPE_READONLY) {
- fprintf(binding->outfile, "\tJSAPI_PS_RO(");
+ fprintf(binding->outfile, "\tJSAPI_PS_RO(\"%s\", ", ident);
} else {
- fprintf(binding->outfile, "\tJSAPI_PS(");
+ fprintf(binding->outfile, "\tJSAPI_PS(\"%s\", ", ident);
}
unshared_node = genbind_node_find_type_ident(binding->binding_list,
@@ -499,44 +499,85 @@ static int output_property_getter(struct binding *binding,
return 0;
}
+static int output_property_setter(struct binding *binding,
+ struct webidl_node *node,
+ const char *ident)
+{
+ struct webidl_node *modifier_node;
+
+ modifier_node = webidl_node_find_type(webidl_node_getnode(node),
+ NULL,
+ WEBIDL_NODE_TYPE_MODIFIER);
+
+
+ if (webidl_node_getint(modifier_node) == WEBIDL_TYPE_READONLY) {
+ /* readonly so a set function is not required */
+ return 0;
+ }
+
+
+ fprintf(binding->outfile,
+ "static JSBool JSAPI_PROPERTYSET(%s, JSContext *cx, JSObject *obj, jsval *vp)\n",
+ ident);
+
+ fprintf(binding->outfile,
+ "{\n"
+ " return JS_FALSE;\n"
+ "}\n\n");
+
+
+ return 0;
+}
+
static int webidl_property_body_cb(struct webidl_node *node, void *ctx)
{
struct binding *binding = ctx;
struct webidl_node *ident_node;
- struct webidl_node *modifier_node;
+ const char *ident;
+ struct webidl_node *type_node;
+ int ret;
ident_node = webidl_node_find_type(webidl_node_getnode(node),
NULL,
WEBIDL_NODE_TYPE_IDENT);
- if (ident_node == NULL) {
+ ident = webidl_node_gettext(ident_node);
+ if (ident == NULL) {
/* properties must have an operator
* http://www.w3.org/TR/WebIDL/#idl-attributes
*/
- return 1;
+ return -1;
}
- modifier_node = webidl_node_find_type(webidl_node_getnode(node),
- NULL,
- WEBIDL_NODE_TYPE_MODIFIER);
-
+ /* do not generate individual getters/setters for an unshared type */
+ type_node = webidl_node_find_type(webidl_node_getnode(node),
+ NULL,
+ WEBIDL_NODE_TYPE_TYPE);
- if (webidl_node_getint(modifier_node) != WEBIDL_TYPE_READONLY) {
- /* no readonly so a set function is required */
+ ident_node = webidl_node_find_type(webidl_node_getnode(type_node),
+ NULL,
+ WEBIDL_NODE_TYPE_IDENT);
- fprintf(binding->outfile,
- "static JSBool JSAPI_PROPERTYSET(%s, JSContext *cx, JSObject *obj, jsval *vp)\n",
- webidl_node_gettext(ident_node));
- fprintf(binding->outfile,
- "{\n"
- " return JS_FALSE;\n"
- "}\n\n");
+ if (ident_node != NULL) {
+ struct genbind_node *unshared_node;
+ unshared_node = genbind_node_find_type_type(binding->binding_list,
+ NULL,
+ GENBIND_NODE_TYPE_BINDING_UNSHARED,
+ webidl_node_gettext(ident_node));
+ if (unshared_node != NULL) {
+ return 0;
+ }
}
- /* property getter */
- return output_property_getter(binding, node, webidl_node_gettext(ident_node));
+ ret = output_property_setter(binding, node, ident);
+ if (ret == 0) {
+ /* property getter */
+ ret = output_property_getter(binding, node, ident);
+ }
+ return ret;
}
+
/* callback to emit implements property bodys */
static int webidl_implements_cb(struct webidl_node *node, void *ctx)
{