rv = xpc->WrapNative(jscontext, ::JS_GetGlobalObject(jscontext), mDB,
nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper; rv = xpc->WrapNative(jscontext, jselement, mDB,
nsXULTemplateBuilder::InitHTMLTemplateRoot(){    // Use XPConnect and the JS APIs to whack aDatabase as the    // 'database' and 'builder' properties onto aElement.    nsresult rv;    nsCOMPtr<nsIDocument> doc;    mRoot->GetDocument(*getter_AddRefs(doc));    NS_ASSERTION(doc != nsnull, "no document");    if (! doc)        return NS_ERROR_UNEXPECTED;    nsCOMPtr<nsIScriptGlobalObject> global;    doc->GetScriptGlobalObject(getter_AddRefs(global));    if (! global)        return NS_ERROR_UNEXPECTED;    nsCOMPtr<nsIScriptContext> context;    global->GetContext(getter_AddRefs(context));    if (! context)        return NS_ERROR_UNEXPECTED;    JSContext* jscontext = NS_STATIC_CAST(JSContext*, context->GetNativeContext());    NS_ASSERTION(context != nsnull, "no jscontext");    if (! jscontext)        return NS_ERROR_UNEXPECTED;    static NS_DEFINE_CID(kXPConnectCID, NS_XPCONNECT_CID);    nsCOMPtr<nsIXPConnect> xpc = do_GetService(kXPConnectCID, &rv);    NS_ENSURE_SUCCESS(rv, rv);    JSObject* jselement = nsnull;    nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;    rv = xpc->WrapNative(jscontext, ::JS_GetGlobalObject(jscontext), mRoot,                         NS_GET_IID(nsIDOMElement),                         getter_AddRefs(wrapper));    NS_ENSURE_SUCCESS(rv, rv);    rv = wrapper->GetJSObject(&jselement);    NS_ENSURE_SUCCESS(rv, rv);    {        // database        rv = xpc->WrapNative(jscontext, ::JS_GetGlobalObject(jscontext), mDB,                             NS_GET_IID(nsIRDFCompositeDataSource),                             getter_AddRefs(wrapper));        NS_ENSURE_SUCCESS(rv, rv);        JSObject* jsobj;        rv = wrapper->GetJSObject(&jsobj);        NS_ENSURE_SUCCESS(rv, rv);        jsval jsdatabase = OBJECT_TO_JSVAL(jsobj);        PRBool ok;        ok = JS_SetProperty(jscontext, jselement, "database", &jsdatabase);        NS_ASSERTION(ok, "unable to set database property");        if (! ok)            return NS_ERROR_FAILURE;    }    {        // builder        nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;        rv = xpc->WrapNative(jscontext, jselement,                             NS_STATIC_CAST(nsIXULTemplateBuilder*, this),                             NS_GET_IID(nsIXULTemplateBuilder),                             getter_AddRefs(wrapper));        NS_ENSURE_SUCCESS(rv, rv);        JSObject* jsobj;        rv = wrapper->GetJSObject(&jsobj);        NS_ENSURE_SUCCESS(rv, rv);        jsval jsbuilder = OBJECT_TO_JSVAL(jsobj);        PRBool ok;        ok = JS_SetProperty(jscontext, jselement, "builder", &jsbuilder);        if (! ok)            return NS_ERROR_FAILURE;    }    return NS_OK;}