Bug 705344 - Use IDL for Components.(utils.)lookupMethod; r=bholley

This commit is contained in:
Ms2ger 2011-12-18 11:08:04 +01:00
Родитель 5e28ff9735
Коммит 985487f28e
2 изменённых файлов: 35 добавлений и 84 удалений

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

@ -1,6 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* ***** BEGIN LICENSE BLOCK *****
/* -*- Mode: IDL; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
@ -153,7 +152,7 @@ interface ScheduledGCCallback : nsISupports
/**
* interface of Components.utils
*/
[scriptable, uuid(1fbd5d17-707f-4874-9635-59ad2438caf0)]
[scriptable, uuid(d41d626c-c222-4c38-ba5f-6499baff3b11)]
interface nsIXPCComponents_Utils : nsISupports
{
@ -182,7 +181,8 @@ interface nsIXPCComponents_Utils : nsISupports
* replaced in the content JS code. This method is not recommended for
* any other use.
*/
void lookupMethod();
[implicit_jscontext]
jsval lookupMethod(in jsval obj, in jsval name);
readonly attribute nsIXPCComponents_utils_Sandbox Sandbox;
@ -347,7 +347,7 @@ interface nsIXPCComponents_Utils : nsISupports
/**
* interface of JavaScript's 'Components' object
*/
[scriptable, uuid(155809f1-71f1-47c5-be97-d812ba560405)]
[scriptable, uuid(9d654574-cb2c-4bd0-a0fd-c10443fe2135)]
interface nsIXPCComponents : nsISupports
{
readonly attribute nsIXPCComponents_Interfaces interfaces;
@ -369,7 +369,8 @@ interface nsIXPCComponents : nsISupports
* (But are you sure you really want this method any more?
* See http://developer-test.mozilla.org/en/docs/XPCNativeWrapper )
*/
[deprecated] void lookupMethod();
[deprecated,implicit_jscontext]
jsval lookupMethod(in jsval obj, in jsval name);
/* @deprecated Use Components.utils.reportError instead. */
[deprecated] void reportError();

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

@ -2608,91 +2608,43 @@ nsXPCComponents_Utils::GetSandbox(nsIXPCComponents_utils_Sandbox **aSandbox)
/* void lookupMethod (); */
NS_IMETHODIMP
nsXPCComponents_Utils::LookupMethod()
nsXPCComponents_Utils::LookupMethod(const JS::Value& object,
const JS::Value& name,
JSContext *cx,
JS::Value *retval)
{
nsresult rv;
nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID(), &rv));
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
// get the xpconnect native call context
nsAXPCNativeCallContext *cc = nsnull;
xpc->GetCurrentNativeCallContext(&cc);
if (!cc)
return NS_ERROR_FAILURE;
// Check disabled until deprecated Components.lookupMethod removed.
#undef CHECK_FOR_INDIRECT_CALL
#ifdef CHECK_FOR_INDIRECT_CALL
// verify that we are being called from JS (i.e. the current call is
// to this object - though we don't verify that it is to this exact method)
nsCOMPtr<nsISupports> callee;
cc->GetCallee(getter_AddRefs(callee));
if (!callee || callee.get() !=
static_cast<const nsISupports*>
(static_cast<const nsIXPCComponents_Utils*>(this)))
return NS_ERROR_FAILURE;
#endif
// Get JSContext of current call
JSContext* cx;
rv = cc->GetJSContext(&cx);
if (NS_FAILED(rv) || !cx)
return NS_ERROR_FAILURE;
JSAutoRequest ar(cx);
// get place for return value
jsval *retval = nsnull;
rv = cc->GetRetValPtr(&retval);
if (NS_FAILED(rv) || !retval)
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 < 2)
return NS_ERROR_XPC_NOT_ENOUGH_ARGS;
jsval* argv;
rv = cc->GetArgvPtr(&argv);
if (NS_FAILED(rv) || !argv)
return NS_ERROR_FAILURE;
// first param must be a JSObject
if (JSVAL_IS_PRIMITIVE(argv[0]))
if (JSVAL_IS_PRIMITIVE(object))
return NS_ERROR_XPC_BAD_CONVERT_JS;
JSObject* obj = JSVAL_TO_OBJECT(argv[0]);
JSObject* obj = JSVAL_TO_OBJECT(object);
while (obj && !js::IsWrapper(obj) && !IS_WRAPPER_CLASS(js::GetObjectClass(obj)))
obj = JS_GetPrototype(cx, obj);
if (!obj)
return NS_ERROR_XPC_BAD_CONVERT_JS;
argv[0] = OBJECT_TO_JSVAL(obj);
rv = nsXPConnect::GetXPConnect()->GetJSObjectOfWrapper(cx, obj, &obj);
JSObject* unwrappedObject;
nsresult rv = nsXPConnect::GetXPConnect()->GetJSObjectOfWrapper(cx, obj, &unwrappedObject);
if (NS_FAILED(rv))
return rv;
obj = JS_ObjectToInnerObject(cx, obj);
if (!obj)
unwrappedObject = JS_ObjectToInnerObject(cx, unwrappedObject);
if (!unwrappedObject)
return NS_ERROR_XPC_BAD_CONVERT_JS;
// second param must be a string
if (!JSVAL_IS_STRING(argv[1]))
if (!JSVAL_IS_STRING(name))
return NS_ERROR_XPC_BAD_CONVERT_JS;
// Make sure the name (argv[1]) that we use for looking up the
// method/property is atomized.
// Make sure the name that we use for looking up the method/property is
// atomized.
jsid name_id;
if (!JS_ValueToId(cx, argv[1], &name_id) ||
!JS_IdToValue(cx, name_id, &argv[1]))
JS::Value dummy;
if (!JS_ValueToId(cx, name, &name_id) ||
!JS_IdToValue(cx, name_id, &dummy))
return NS_ERROR_XPC_BAD_CONVERT_JS;
// this will do verification and the method lookup for us
@ -2701,7 +2653,7 @@ nsXPCComponents_Utils::LookupMethod()
// XPCWrappedNative. This means no deep wrapping, unfortunately, but we
// can't keep track of both the underlying function and the
// XPCNativeWrapper at once in a single parent slot...
XPCCallContext inner_cc(JS_CALLER, cx, obj, nsnull, name_id);
XPCCallContext inner_cc(JS_CALLER, cx, unwrappedObject, nsnull, name_id);
// was our jsobject really a wrapped native at all?
XPCWrappedNative* wrapper = inner_cc.GetWrapper();
@ -2721,9 +2673,7 @@ nsXPCComponents_Utils::LookupMethod()
jsval funval;
// get (and perhaps lazily create) the member's cloned function
if (!member->NewFunctionObject(inner_cc, iface,
JSVAL_TO_OBJECT(argv[0]),
&funval))
if (!member->NewFunctionObject(inner_cc, iface, obj, &funval))
return NS_ERROR_XPC_BAD_CONVERT_JS;
NS_ASSERTION(JS_ValueToFunction(inner_cc, funval),
@ -2731,9 +2681,6 @@ nsXPCComponents_Utils::LookupMethod()
// Stick the function in the return value. This roots it.
*retval = funval;
// Tell XPConnect that we returned the function through the call context.
cc->SetReturnValueWasSet(true);
return NS_OK;
}
@ -4347,17 +4294,20 @@ nsXPCComponents::AttachNewComponentsObject(XPCCallContext& ccx,
}
/* void lookupMethod (); */
NS_IMETHODIMP nsXPCComponents::LookupMethod()
NS_IMETHODIMP
nsXPCComponents::LookupMethod(const JS::Value& object,
const JS::Value& name,
JSContext *cx,
JS::Value *retval)
{
nsresult rv;
nsCOMPtr<nsIXPCComponents_Utils> utils;
NS_WARNING("Components.lookupMethod deprecated, use Components.utils.lookupMethod");
rv = GetUtils(getter_AddRefs(utils));
nsCOMPtr<nsIXPCComponents_Utils> utils;
nsresult rv = GetUtils(getter_AddRefs(utils));
if (NS_FAILED(rv))
return rv;
return utils->LookupMethod();
return utils->LookupMethod(object, name, cx, retval);
}
/* void reportError (); */