Bug 705443 - Use IDL for nsIDOMWindowUtils::GetClassName; r=khuey

This commit is contained in:
Ms2ger
2011-12-03 22:50:16 +01:00
parent dff333b2a0
commit e272a33dff
2 changed files with 8 additions and 32 deletions

View File

@@ -1450,44 +1450,20 @@ nsDOMWindowUtils::SendContentCommandEvent(const nsAString& aType,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsDOMWindowUtils::GetClassName(char **aName) nsDOMWindowUtils::GetClassName(const JS::Value& aObject, JSContext* aCx, char** aName)
{ {
if (!nsContentUtils::IsCallerTrustedForRead()) { if (!nsContentUtils::IsCallerTrustedForRead()) {
return NS_ERROR_DOM_SECURITY_ERR; return NS_ERROR_DOM_SECURITY_ERR;
} }
// get the xpconnect native call context
nsAXPCNativeCallContext *cc = nsnull;
nsContentUtils::XPConnect()->GetCurrentNativeCallContext(&cc);
if(!cc)
return NS_ERROR_FAILURE;
// Get JSContext of current call
JSContext* cx;
nsresult rv = cc->GetJSContext(&cx);
if(NS_FAILED(rv) || !cx)
return NS_ERROR_FAILURE;
// get argc and argv and verify arg count
PRUint32 argc;
rv = cc->GetArgc(&argc);
if(NS_FAILED(rv))
return NS_ERROR_FAILURE;
if(argc < 1)
return NS_ERROR_XPC_NOT_ENOUGH_ARGS;
jsval* argv;
rv = cc->GetArgvPtr(&argv);
if(NS_FAILED(rv) || !argv)
return NS_ERROR_FAILURE;
// Our argument must be a non-null object. // Our argument must be a non-null object.
if(JSVAL_IS_PRIMITIVE(argv[0])) if (JSVAL_IS_PRIMITIVE(aObject)) {
return NS_ERROR_XPC_BAD_CONVERT_JS; return NS_ERROR_XPC_BAD_CONVERT_JS;
}
*aName = NS_strdup(JS_GET_CLASS(cx, JSVAL_TO_OBJECT(argv[0]))->name); *aName = NS_strdup(JS_GET_CLASS(aCx, JSVAL_TO_OBJECT(aObject))->name);
return *aName ? NS_OK : NS_ERROR_OUT_OF_MEMORY; NS_ABORT_IF_FALSE(*aName, "NS_strdup should be infallible.");
return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP

View File

@@ -68,7 +68,7 @@ interface nsIDOMWindow;
interface nsIDOMFile; interface nsIDOMFile;
interface nsIFile; interface nsIFile;
[scriptable, uuid(c5cf91b3-0b89-4417-b13c-5540ba6ebde8)] [scriptable, uuid(bf868921-0288-4799-a806-2fa642590197)]
interface nsIDOMWindowUtils : nsISupports { interface nsIDOMWindowUtils : nsISupports {
/** /**
@@ -557,7 +557,7 @@ interface nsIDOMWindowUtils : nsISupports {
* Returns the real classname (possibly of the mostly-transparent security * Returns the real classname (possibly of the mostly-transparent security
* wrapper) of aObj. * wrapper) of aObj.
*/ */
string getClassName(/*in JSObjectPtr aObj*/); [implicit_jscontext] string getClassName(in jsval aObject);
/** /**
* Generate a content command event. * Generate a content command event.