nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper; rv = xpc->WrapNative(jscontext, jselement, mDB,
rv = xpc->WrapNative(jscontext, ::JS_GetGlobalObject(jscontext), 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 = do_QueryInterface(mDocument);    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;    nsCOMPtr<nsIScriptObjectOwner> owner = do_QueryInterface(mRoot);    NS_ASSERTION(owner != nsnull, "unable to get script object owner");    if (! owner)        return NS_ERROR_UNEXPECTED;    JSObject* jselement;    rv = owner->GetScriptObject(context, (void**) &jselement);    NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get element's script object");    if (NS_FAILED(rv)) return rv;    static NS_DEFINE_CID(kXPConnectCID, NS_XPCONNECT_CID);    NS_WITH_SERVICE(nsIXPConnect, xpc, kXPConnectCID, &rv);    if (NS_FAILED(rv)) return rv;    {        // database        nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;        rv = xpc->WrapNative(jscontext,                                                    jselement,                             mDB,                             NS_GET_IID(nsIRDFCompositeDataSource),                             getter_AddRefs(wrapper));        NS_ASSERTION(NS_SUCCEEDED(rv), "unable to xpconnect-wrap database");        if (NS_FAILED(rv)) return rv;        JSObject* jsobj;        rv = wrapper->GetJSObject(&jsobj);        NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get jsobj from xpconnect wrapper");        if (NS_FAILED(rv)) return 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));        if (NS_FAILED(rv)) return rv;        JSObject* jsobj;        rv = wrapper->GetJSObject(&jsobj);        if (NS_FAILED(rv)) return 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;}