From 0c61abc9f71a128c5045738af3489aac743986bd Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 21 Oct 2012 18:36:40 +0100 Subject: add generation of constructor and finalizer --- src/jsapi-libdom-operator.c | 2 +- src/jsapi-libdom.c | 69 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 65 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/jsapi-libdom-operator.c b/src/jsapi-libdom-operator.c index 05b0239..97369a3 100644 --- a/src/jsapi-libdom-operator.c +++ b/src/jsapi-libdom-operator.c @@ -333,7 +333,7 @@ static int webidl_operator_body_cb(struct webidl_node *node, void *ctx) "\t\t\tJS_THIS_OBJECT(cx,vp),\n" "\t\t\t&jsclass_object,\n" "\t\t\tNULL);\n" - "\tif (priv == NULL)\n" + "\tif (private == NULL)\n" "\t\treturn JS_FALSE;\n\n"); diff --git a/src/jsapi-libdom.c b/src/jsapi-libdom.c index aa6d2bb..fdcebe7 100644 --- a/src/jsapi-libdom.c +++ b/src/jsapi-libdom.c @@ -335,16 +335,71 @@ static int webidl_private_cb(struct genbind_node *node, void *ctx) } +static int +output_con_de_structors(struct binding *binding) +{ + int res = 0; + + fprintf(binding->outfile, + "static void jsclass_finalize(JSContext *cx, JSObject *obj)\n" + "{" + "\tstruct jsclass_private *private;\n" + "\n" + "\tprivate = JS_GetInstancePrivate(cx, obj, &jsclass_object, NULL);\n" + "\tif (private != NULL) {\n" + "\t\tfree(private);\n" + "\t}\n" + "}\n\n"); + + fprintf(binding->outfile, + "JSObject *jsapi_new_%s(JSContext *cx, JSObject *parent, struct html_content *htmlc)\n" + "{\n" + "\tJSObject *jsobject;\n" + "\tstruct jsclass_private *private;\n" + "\n" + "\tprivate = malloc(sizeof(struct jsclass_private));\n" + "\tif (private == NULL) {\n" + "\t\treturn NULL;\n" + "\t}\n" + "\tprivate->htmlc = htmlc;\n" + "\tprivate->node = htmlc->document;\n" + "\t\n" + "\tjsobject = JS_InitClass(cx,\n" + "\t\tparent,\n" + "\t\tNULL,\n" + "\t\t&jsclass_object,\n" + "\t\tNULL,\n" + "\t\t0,\n" + "\t\tjsclass_properties,\n" + "\t\tjsclass_function, \n" + "\t\tNULL, \n" + "\t\tNULL);\n" + "\tif (jsdocument == NULL) {\n" + "\t\tfree(document);\n" + "\t\treturn NULL;\n" + "\t}\n" + "\n" + "\t/* attach private pointer */\n" + "\tif (JS_SetPrivate(cx, jsobject, private) != JS_TRUE) {\n" + "\t\tfree(private);\n" + "\t\treturn NULL;\n" + "\t}\n" + "\n" + "\treturn jsobject;\n" + "}\n", + binding->name); + return res; +} + static int output_property_spec(struct binding *binding) { int res; fprintf(binding->outfile, - "static JSPropertySpec jsproperties_%s[] = {\n", - binding->name); + "static JSPropertySpec jsclass_properties[] = {\n"); res = generate_property_spec(binding, binding->interface); @@ -359,8 +414,7 @@ output_function_spec(struct binding *binding) int res; fprintf(binding->outfile, - "static JSFunctionSpec jsfunctions_%s[] = {\n", - binding->name); + "static JSFunctionSpec jsclass_functions[] = {\n"); res = generate_function_spec(binding, binding->interface); @@ -441,7 +495,7 @@ output_jsclass(struct binding *binding) " JS_EnumerateStub,\n" " (JSResolveOp)jsresove_node,\n" " JS_ConvertStub,\n" - " jsfinalize_document,\n" + " jsclass_finalize,\n" " JSCLASS_NO_OPTIONAL_MEMBERS\n" "};\n\n", binding->interface); return 0; @@ -626,6 +680,11 @@ int jsapi_libdom_output(char *outfilename, struct genbind_node *genbind_ast) return 12; } + res = output_con_de_structors(binding); + if (res) { + return 13; + } + fclose(binding->outfile); return 0; -- cgit v1.2.3