if (mDOMSlots && mDOMSlots->mScriptObject) return nsGenericHTMLLeafElement::GetScriptObject(aContext, aScriptObject);  nsresult rv; *aScriptObject = nsnull;     JSObject* elementObject = nsnull; rv = nsGenericHTMLLeafElement::GetScriptObject(aContext, (void**)&elementObject); if (NS_FAILED(rv) || !elementObject) return rv;    if (mDocument) { mDocument->FlushPendingNotifications(); }  nsCOMPtr<nsIPluginInstance> pi; rv = GetPluginInstance(getter_AddRefs(pi));      if (NS_FAILED(rv)) { if (mDocument) {    aContext->RemoveReference((void *)&mDOMSlots->mScriptObject, mDOMSlots->mScriptObject); }  SetScriptObject(nsnull);  *aScriptObject = elementObject;  return NS_OK; }       nsIID scriptableInterface; nsCOMPtr<nsISupports> scriptablePeer; if (NS_SUCCEEDED(rv) && pi) { nsCOMPtr<nsIScriptablePlugin> spi(do_QueryInterface(pi, &rv)); if (NS_SUCCEEDED(rv) && spi) { nsIID *scriptableInterfacePtr = nsnull; rv = spi->GetScriptableInterface(&scriptableInterfacePtr);  if (NS_SUCCEEDED(rv) && scriptableInterfacePtr) { rv = spi->GetScriptablePeer(getter_AddRefs(scriptablePeer));  scriptableInterface = *scriptableInterfacePtr;  nsMemory::Free(scriptableInterfacePtr); } } }  if (NS_FAILED(rv) || !scriptablePeer) {  *aScriptObject = elementObject;  return NS_OK; }   JSObject* interfaceObject; JSContext *cx = (JSContext *)aContext->GetNativeContext(); nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID()); if (cx && xpc) { JSObject* parentObject = JS_GetParent(cx, elementObject); nsCOMPtr<nsIXPConnectJSObjectHolder> holder; if (NS_SUCCEEDED(xpc->WrapNative(cx, parentObject, scriptablePeer, scriptableInterface, getter_AddRefs(holder))) && holder && NS_SUCCEEDED(holder->GetJSObject(&interfaceObject)) && interfaceObject) { *aScriptObject = interfaceObject; } }    if (!*aScriptObject || !JS_SetPrototype(cx, interfaceObject, elementObject)) { *aScriptObject = elementObject; return NS_OK; }   SetScriptObject(*aScriptObject);  return NS_OK;
return GetPluginScriptObject(aContext, aScriptObject);
nsHTMLEmbedElement::GetScriptObject(nsIScriptContext* aContext,                                    void** aScriptObject){  if (mDOMSlots && mDOMSlots->mScriptObject)    return nsGenericHTMLLeafElement::GetScriptObject(aContext, aScriptObject);  nsresult rv;  *aScriptObject = nsnull;  // Get the JS object corresponding to this dom node.  This will become  // the javascript prototype object of the object we eventually reflect to the  // DOM.  JSObject* elementObject = nsnull;  rv = nsGenericHTMLLeafElement::GetScriptObject(aContext,                                                 (void**)&elementObject);  if (NS_FAILED(rv) || !elementObject)    return rv;  // Flush pending reflows to ensure the plugin is instansiated, assuming  // it's visible  if (mDocument) {    mDocument->FlushPendingNotifications();  }  nsCOMPtr<nsIPluginInstance> pi;  rv = GetPluginInstance(getter_AddRefs(pi));  // If GetPluginInstance() fails it means there's no frame for this element  // yet, in that case we return the script object for the element but we  // don't cache it so that the next call can get the correct script object  // if the plugin instance is available at the next call.  if (NS_FAILED(rv)) {    if (mDocument) {      // Since we're resetting the script object to null we'll remove the      // reference to it so that we won't add the same named reference      // again the next time someone requests the script object.      aContext->RemoveReference((void *)&mDOMSlots->mScriptObject,                                mDOMSlots->mScriptObject);    }    SetScriptObject(nsnull);    *aScriptObject = elementObject;    return NS_OK;  }  // Check if the plugin object has the nsIScriptablePlugin  // interface, describing how to expose it to JavaScript.  Given this  // interface, use it to get the scriptable peer object (possibly the  // plugin object itself) and the scriptable interface to expose it  // with  nsIID scriptableInterface;  nsCOMPtr<nsISupports> scriptablePeer;  if (NS_SUCCEEDED(rv) && pi) {    nsCOMPtr<nsIScriptablePlugin> spi(do_QueryInterface(pi, &rv));    if (NS_SUCCEEDED(rv) && spi) {      nsIID *scriptableInterfacePtr = nsnull;      rv = spi->GetScriptableInterface(&scriptableInterfacePtr);      if (NS_SUCCEEDED(rv) && scriptableInterfacePtr) {        rv = spi->GetScriptablePeer(getter_AddRefs(scriptablePeer));        scriptableInterface = *scriptableInterfacePtr;        nsMemory::Free(scriptableInterfacePtr);      }    }  }  if (NS_FAILED(rv) || !scriptablePeer) {    // Fall back to returning the element object.    *aScriptObject = elementObject;    return NS_OK;  }  // Wrap it.  JSObject* interfaceObject; // XPConnect-wrapped peer object, when we get it.  JSContext *cx = (JSContext *)aContext->GetNativeContext();  nsCOMPtr<nsIXPConnect> xpc =    do_GetService(nsIXPConnect::GetCID());   if (cx && xpc) {    JSObject* parentObject = JS_GetParent(cx, elementObject);    nsCOMPtr<nsIXPConnectJSObjectHolder> holder;    if (NS_SUCCEEDED(xpc->WrapNative(cx, parentObject,                                     scriptablePeer, scriptableInterface,                                     getter_AddRefs(holder))) && holder &&         NS_SUCCEEDED(holder->GetJSObject(&interfaceObject)) && interfaceObject) {      *aScriptObject = interfaceObject;    }  }  // If we got an xpconnect-wrapped plugin object, set its' prototype to the  // element object.  if (!*aScriptObject || !JS_SetPrototype(cx, interfaceObject,                                          elementObject)) {    *aScriptObject = elementObject; // fall back    return NS_OK;  }  // Cache it.  SetScriptObject(*aScriptObject);  return NS_OK;}