From 52a0b403fca3b37434c7ed5343d25dcae8734e0b Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Thu, 15 Nov 2012 20:10:21 +0000 Subject: correctly construct properties and functions so enumeration is correct. Seems to be an issue setting functions to be enumerable so left disabled for now --- src/jsapi-libdom-operator.c | 13 +++++++++++-- src/jsapi-libdom.c | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/jsapi-libdom-operator.c b/src/jsapi-libdom-operator.c index 2bb64d4..c3084f7 100644 --- a/src/jsapi-libdom-operator.c +++ b/src/jsapi-libdom-operator.c @@ -33,8 +33,9 @@ static int webidl_func_spec_cb(struct webidl_node *node, void *ctx) */ } else { fprintf(binding->outfile, - "\tJSAPI_FS(%s, 0, 0),\n", + "\tJSAPI_FS(%s, 0, 0 /* JSPROP_ENUMERATE */),\n", webidl_node_gettext(ident_node)); + /* @todo number of args to that FN_FS() call should be correct */ } return 0; } @@ -640,16 +641,24 @@ output_operation_input(struct binding *binding, case WEBIDL_TYPE_STRING: /* JSString * */ fprintf(binding->outfile, + "\tif (argc > %d) {\n" "\t%s_jsstr = JS_ValueToString(cx, argv[%d]);\n" "\tif (%s_jsstr == NULL) {\n" "\t\treturn JS_FALSE;\n" "\t}\n\n" - "\tJSString_to_char(%s_jsstr, %s, %s_len);\n", + "\tJSString_to_char(%s_jsstr, %s, %s_len);\n" + "\t} else {\n" + "\t\t%s = NULL;" + "\t\t%s_len = 0;" + "\t}\n", + arg_cur, webidl_node_gettext(arg_ident), arg_cur, webidl_node_gettext(arg_ident), webidl_node_gettext(arg_ident), webidl_node_gettext(arg_ident), + webidl_node_gettext(arg_ident), + webidl_node_gettext(arg_ident), webidl_node_gettext(arg_ident)); break; diff --git a/src/jsapi-libdom.c b/src/jsapi-libdom.c index 187d511..0711e75 100644 --- a/src/jsapi-libdom.c +++ b/src/jsapi-libdom.c @@ -272,8 +272,8 @@ output_class_init(struct binding *binding) "\t\t&JSClass_%s,\n" "\t\tNULL,\n" "\t\t0,\n" - "\t\tjsclass_properties,\n" - "\t\tjsclass_functions, \n" + "\t\tNULL,\n" + "\t\tNULL, \n" "\t\tNULL, \n" "\t\tNULL);\n", binding->interface); @@ -322,6 +322,7 @@ output_class_new(struct binding *binding) "{\n" "\tJSObject *newobject;\n"); + /* create private data */ if (binding->has_private) { fprintf(binding->outfile, "\tstruct jsclass_private *private;\n" @@ -362,8 +363,38 @@ output_class_new(struct binding *binding) "\tif (JS_SetPrivate(cx, newobject, private) != JS_TRUE) {\n" "\t\tfree(private);\n" "\t\treturn NULL;\n" + "\t}\n\n"); + + /* attach operations and attributes (functions and properties) */ + fprintf(binding->outfile, + "\tif (JS_DefineFunctions(cx, newobject, jsclass_functions) != JS_TRUE) {\n" + "\t\tfree(private);\n" + "\t\treturn NULL;\n" + "\t}\n\n"); + + fprintf(binding->outfile, + "\tif (JS_DefineProperties(cx, newobject, jsclass_properties) != JS_TRUE) {\n" + "\t\tfree(private);\n" + "\t\treturn NULL;\n" + "\t}\n\n"); + } else { + fprintf(binding->outfile, + "\tif (newobject == NULL) {\n" + "\t\treturn NULL;\n" "\t}\n"); + + /* attach operations and attributes (functions and properties) */ + fprintf(binding->outfile, + "\tif (JS_DefineFunctions(cx, newobject, jsclass_functions) != JS_TRUE) {\n" + "\t\treturn NULL;\n" + "\t}\n\n"); + + fprintf(binding->outfile, + "\tif (JS_DefineProperties(cx, newobject, jsclass_properties) != JS_TRUE) {\n" + "\t\treturn NULL;\n" + "\t}\n\n"); } + fprintf(binding->outfile, "\n" -- cgit v1.2.3