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

This commit is contained in:
Ms2ger 2011-12-03 22:50:16 +01:00
Родитель cdc32f1c63
Коммит 2786d49ade
2 изменённых файлов: 8 добавлений и 32 удалений

Просмотреть файл

@ -1450,44 +1450,20 @@ nsDOMWindowUtils::SendContentCommandEvent(const nsAString& aType,
}
NS_IMETHODIMP
nsDOMWindowUtils::GetClassName(char **aName)
nsDOMWindowUtils::GetClassName(const JS::Value& aObject, JSContext* aCx, char** aName)
{
if (!nsContentUtils::IsCallerTrustedForRead()) {
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.
if(JSVAL_IS_PRIMITIVE(argv[0]))
if (JSVAL_IS_PRIMITIVE(aObject)) {
return NS_ERROR_XPC_BAD_CONVERT_JS;
}
*aName = NS_strdup(JS_GET_CLASS(cx, JSVAL_TO_OBJECT(argv[0]))->name);
return *aName ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
*aName = NS_strdup(JS_GET_CLASS(aCx, JSVAL_TO_OBJECT(aObject))->name);
NS_ABORT_IF_FALSE(*aName, "NS_strdup should be infallible.");
return NS_OK;
}
NS_IMETHODIMP

Просмотреть файл

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