if (has_parameters) fputs(", ", state->file); fputs("&retval);\n", state->file); } else { fputs(");\n", state->file);
if (has_parameters) fputs(", ", state->file); fputs("&retval", state->file);
stub_op_dcl(TreeState *state){    IDL_tree method = state->tree;    struct _IDL_OP_DCL *op = &IDL_OP_DCL(method);    struct stub_private *priv = state->priv;    IDL_tree iface, iter, param;    char *className;    gboolean has_parameters = (op->parameter_dcls!=NULL);    gboolean has_retval = (op->op_type_spec != NULL);        if (op->f_noscript)        return TRUE;    append_to_vector(&priv->funcs, &priv->nfuncs, method);    xpidl_write_comment(state, 0);    assert(IDL_NODE_UP(IDL_NODE_UP(method)));    iface = IDL_NODE_UP(IDL_NODE_UP(method));    assert(IDL_NODE_TYPE(iface) == IDLN_INTERFACE);    className = IDL_IDENT(IDL_INTERFACE(iface).ident).str;    fprintf(state->file,            "static JSBool\n"            "%s_%s(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,"                 " jsval *rval)\n"            "{\n",            className, IDL_IDENT(op->ident).str);    fprintf(state->file,            "  %s *priv = (%s *)JS_GetPrivate(cx, obj);\n"            "  if (!priv)\n"            "    return JS_TRUE;\n",            className, className);    for (iter = op->parameter_dcls; iter; iter = IDL_LIST(iter).next) {        state->tree = IDL_LIST(iter).data;        fputs("  ", state->file);        if (!xpcom_param(state))            return FALSE;        fputs(";\n", state->file);    }    fputs("  if (!JS_ConvertArguments(cx, argc, argv, \"", state->file);    for (iter = op->parameter_dcls; iter; iter = IDL_LIST(iter).next) {        param = IDL_LIST(iter).data;        assert(param);        fputc(js_convert_arguments_format(IDL_PARAM_DCL(param).param_type_spec),              state->file);    }    fputc('\"', state->file);    for (iter = op->parameter_dcls; iter; iter = IDL_LIST(iter).next) {        param = IDL_LIST(iter).data;        fprintf(state->file, ", &%s",                IDL_IDENT(IDL_PARAM_DCL(param).simple_declarator).str);    }    fputs("))\n"          "    return JS_FALSE;\n",          state->file);        /* declare the variable which will hold the return value */    if (has_retval) {        state->tree = op->op_type_spec;        fputs("  ", state->file);        xpcom_type(state);        fputs(" retval;\n", state->file);    }    /* we need to get the return type right on [nonxpcom] objects */    fprintf(state->file,            "  %s rv = ", "nsresult");    fprintf(state->file,            "priv->%s(",            IDL_IDENT(op->ident).str);    for (iter = op->parameter_dcls; iter; iter = IDL_LIST(iter).next) {            param = IDL_LIST(iter).data;            fprintf(state->file,                    "%s",                    IDL_IDENT(IDL_PARAM_DCL(param).simple_declarator).str);            if (IDL_LIST(iter).next)                fputs(", ",state->file);    }    /* the retval is the last parameter */    if (has_retval) {        if (has_parameters) fputs(", ", state->file);        fputs("&retval);\n", state->file);    } else {        fputs(");\n", state->file);    }    fputs("  if (NS_FAILED(rv)) {\n"          "    JS_ReportError(cx, XXXnsresult2string(rv));\n"          "    return JS_FALSE;\n"          "  }\n",          state->file);        if (has_retval) {        if (!emit_convert_result(state, "retval", "rval", ""))            return FALSE;    }        fputs("  return JS_TRUE;\n"          "}\n",          state->file);    return TRUE;}