2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-11-09 19:43:57 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2013-01-28 17:34:29 +04:00
|
|
|
#include "mozilla/dom/CallbackObject.h"
|
2013-09-03 16:01:53 +04:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2012-11-09 19:43:57 +04:00
|
|
|
#include "jsfriendapi.h"
|
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "nsIXPConnect.h"
|
|
|
|
#include "nsIScriptContext.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsJSUtils.h"
|
2013-02-27 00:10:15 +04:00
|
|
|
#include "xpcprivate.h"
|
2013-09-10 01:58:29 +04:00
|
|
|
#include "WorkerPrivate.h"
|
2013-11-20 20:48:00 +04:00
|
|
|
#include "nsGlobalWindow.h"
|
2013-12-12 05:51:57 +04:00
|
|
|
#include "WorkerScope.h"
|
2015-01-16 01:39:01 +03:00
|
|
|
#include "jsapi.h"
|
|
|
|
#include "nsJSPrincipals.h"
|
2012-11-09 19:43:57 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-01-28 17:34:29 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CallbackObject)
|
2013-04-17 01:14:30 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(mozilla::dom::CallbackObject)
|
2012-11-09 19:43:57 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-01-28 17:34:29 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(CallbackObject)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(CallbackObject)
|
2012-11-09 19:43:57 +04:00
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(CallbackObject)
|
|
|
|
|
2013-01-28 17:34:29 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(CallbackObject)
|
2014-03-03 20:53:42 +04:00
|
|
|
tmp->DropJSObjects();
|
2013-12-12 05:51:58 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mIncumbentGlobal)
|
2012-11-09 19:43:57 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2013-01-28 17:34:29 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(CallbackObject)
|
2012-11-09 19:43:57 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
2013-12-12 05:51:58 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIncumbentGlobal)
|
2012-11-09 19:43:57 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2013-01-28 17:34:29 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(CallbackObject)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mCallback)
|
2015-07-24 14:01:00 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mCreationStack)
|
2014-03-03 20:53:42 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mIncumbentJSGlobal)
|
2012-11-09 19:43:57 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
2016-05-18 19:23:35 +03:00
|
|
|
void
|
|
|
|
CallbackObject::Trace(JSTracer* aTracer)
|
|
|
|
{
|
|
|
|
JS::TraceEdge(aTracer, &mCallback, "CallbackObject.mCallback");
|
|
|
|
JS::TraceEdge(aTracer, &mCreationStack, "CallbackObject.mCreationStack");
|
|
|
|
JS::TraceEdge(aTracer, &mIncumbentJSGlobal,
|
|
|
|
"CallbackObject.mIncumbentJSGlobal");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-12-30 00:19:26 +03:00
|
|
|
CallbackObject::FinishSlowJSInitIfMoreThanOneOwner(JSContext* aCx)
|
2016-05-18 19:23:35 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mRefCnt.get() > 0);
|
|
|
|
if (mRefCnt.get() > 1) {
|
|
|
|
mozilla::HoldJSObjects(this);
|
2016-12-30 00:19:26 +03:00
|
|
|
if (JS::ContextOptionsRef(aCx).asyncStack()) {
|
|
|
|
JS::RootedObject stack(aCx);
|
|
|
|
if (!JS::CaptureCurrentStack(aCx, &stack)) {
|
|
|
|
JS_ClearPendingException(aCx);
|
|
|
|
}
|
|
|
|
mCreationStack = stack;
|
|
|
|
}
|
2016-05-18 19:23:35 +03:00
|
|
|
} else {
|
|
|
|
// We can just forget all our stuff.
|
|
|
|
ClearJSReferences();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-12 05:51:57 +04:00
|
|
|
CallbackObject::CallSetup::CallSetup(CallbackObject* aCallback,
|
2013-02-19 20:54:40 +04:00
|
|
|
ErrorResult& aRv,
|
2015-04-09 04:23:48 +03:00
|
|
|
const char* aExecutionReason,
|
2013-09-03 16:01:53 +04:00
|
|
|
ExceptionHandling aExceptionHandling,
|
2014-02-15 10:36:44 +04:00
|
|
|
JSCompartment* aCompartment,
|
|
|
|
bool aIsJSImplementedWebIDL)
|
2012-11-09 19:43:57 +04:00
|
|
|
: mCx(nullptr)
|
2013-09-03 16:01:53 +04:00
|
|
|
, mCompartment(aCompartment)
|
2013-02-19 20:54:40 +04:00
|
|
|
, mErrorResult(aRv)
|
|
|
|
, mExceptionHandling(aExceptionHandling)
|
2013-09-10 01:58:29 +04:00
|
|
|
, mIsMainThread(NS_IsMainThread())
|
2012-11-09 19:43:57 +04:00
|
|
|
{
|
2015-05-29 19:11:09 +03:00
|
|
|
if (mIsMainThread) {
|
|
|
|
nsContentUtils::EnterMicroTask();
|
|
|
|
}
|
|
|
|
|
2014-02-15 10:36:44 +04:00
|
|
|
// Compute the caller's subject principal (if necessary) early, before we
|
|
|
|
// do anything that might perturb the relevant state.
|
|
|
|
nsIPrincipal* webIDLCallerPrincipal = nullptr;
|
|
|
|
if (aIsJSImplementedWebIDL) {
|
2014-09-25 13:04:45 +04:00
|
|
|
webIDLCallerPrincipal = nsContentUtils::SubjectPrincipalOrSystemIfNativeCaller();
|
2014-02-15 10:36:44 +04:00
|
|
|
}
|
|
|
|
|
2013-01-28 17:34:29 +04:00
|
|
|
// First, find the real underlying callback.
|
2013-12-12 05:51:57 +04:00
|
|
|
JSObject* realCallback = js::UncheckedUnwrap(aCallback->CallbackPreserveColor());
|
2013-12-12 05:51:57 +04:00
|
|
|
nsIGlobalObject* globalObject = nullptr;
|
2013-09-10 01:58:29 +04:00
|
|
|
|
2016-04-07 10:11:52 +03:00
|
|
|
JSContext* cx;
|
2013-12-31 20:30:57 +04:00
|
|
|
{
|
2014-05-29 04:34:36 +04:00
|
|
|
// Bug 955660: we cannot do "proper" rooting here because we need the
|
|
|
|
// global to get a context. Everything here is simple getters that cannot
|
|
|
|
// GC, so just paper over the necessary dataflow inversion.
|
|
|
|
JS::AutoSuppressGCAnalysis nogc;
|
2016-06-03 12:11:45 +03:00
|
|
|
|
|
|
|
// Now get the global for this callback. Note that for the case of
|
|
|
|
// JS-implemented WebIDL we never have a window here.
|
|
|
|
nsGlobalWindow* win = mIsMainThread && !aIsJSImplementedWebIDL
|
|
|
|
? xpc::WindowGlobalOrNull(realCallback)
|
|
|
|
: nullptr;
|
|
|
|
if (win) {
|
|
|
|
MOZ_ASSERT(win->IsInnerWindow());
|
|
|
|
// We don't want to run script in windows that have been navigated away
|
|
|
|
// from.
|
|
|
|
if (!win->AsInner()->HasActiveDocument()) {
|
|
|
|
aRv.ThrowDOMException(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
|
|
|
|
NS_LITERAL_CSTRING("Refusing to execute function from window "
|
|
|
|
"whose document is no longer active."));
|
|
|
|
return;
|
2013-09-10 01:58:29 +04:00
|
|
|
}
|
2016-06-03 12:11:45 +03:00
|
|
|
globalObject = win;
|
2013-11-20 20:48:00 +04:00
|
|
|
} else {
|
2016-06-03 12:11:45 +03:00
|
|
|
// No DOM Window. Store the global.
|
|
|
|
JSObject* global = js::GetGlobalForObjectCrossCompartment(realCallback);
|
2016-04-08 04:58:21 +03:00
|
|
|
globalObject = xpc::NativeGlobal(global);
|
2015-03-04 02:51:53 +03:00
|
|
|
MOZ_ASSERT(globalObject);
|
2012-11-09 19:43:57 +04:00
|
|
|
}
|
2013-12-12 05:51:57 +04:00
|
|
|
|
2013-12-31 20:30:57 +04:00
|
|
|
// Bail out if there's no useful global. This seems to happen intermittently
|
|
|
|
// on gaia-ui tests, probably because nsInProcessTabChildGlobal is returning
|
|
|
|
// null in some kind of teardown state.
|
|
|
|
if (!globalObject->GetGlobalJSObject()) {
|
2016-05-04 20:59:42 +03:00
|
|
|
aRv.ThrowDOMException(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
|
|
|
|
NS_LITERAL_CSTRING("Refusing to execute function from global which is "
|
|
|
|
"being torn down."));
|
2013-12-31 20:30:57 +04:00
|
|
|
return;
|
|
|
|
}
|
2013-12-07 00:01:41 +04:00
|
|
|
|
2016-07-08 03:08:25 +03:00
|
|
|
mAutoEntryScript.emplace(globalObject, aExecutionReason, mIsMainThread);
|
2014-08-14 02:39:41 +04:00
|
|
|
mAutoEntryScript->SetWebIDLCallerPrincipal(webIDLCallerPrincipal);
|
2014-03-03 20:53:42 +04:00
|
|
|
nsIGlobalObject* incumbent = aCallback->IncumbentGlobalOrNull();
|
|
|
|
if (incumbent) {
|
|
|
|
// The callback object traces its incumbent JS global, so in general it
|
|
|
|
// should be alive here. However, it's possible that we could run afoul
|
|
|
|
// of the same IPC global weirdness described above, wherein the
|
|
|
|
// nsIGlobalObject has severed its reference to the JS global. Let's just
|
|
|
|
// be safe here, so that nobody has to waste a day debugging gaia-ui tests.
|
|
|
|
if (!incumbent->GetGlobalJSObject()) {
|
2016-05-04 20:59:42 +03:00
|
|
|
aRv.ThrowDOMException(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
|
|
|
|
NS_LITERAL_CSTRING("Refusing to execute function because our "
|
|
|
|
"incumbent global is being torn down."));
|
2014-03-03 20:53:42 +04:00
|
|
|
return;
|
|
|
|
}
|
2014-08-14 02:39:41 +04:00
|
|
|
mAutoIncumbentScript.emplace(incumbent);
|
2013-12-31 20:30:57 +04:00
|
|
|
}
|
2013-12-12 05:51:57 +04:00
|
|
|
|
2016-04-07 10:11:52 +03:00
|
|
|
cx = mAutoEntryScript->cx();
|
|
|
|
|
2013-12-31 20:30:57 +04:00
|
|
|
// Unmark the callable (by invoking Callback() and not the CallbackPreserveColor()
|
|
|
|
// variant), and stick it in a Rooted before it can go gray again.
|
|
|
|
// Nothing before us in this function can trigger a CC, so it's safe to wait
|
2016-04-07 10:11:52 +03:00
|
|
|
// until here it do the unmark. This allows us to construct mRootedCallable
|
|
|
|
// with the cx from mAutoEntryScript, avoiding the cost of finding another
|
|
|
|
// JSContext. (Rooted<> does not care about requests or compartments.)
|
2014-08-14 02:39:41 +04:00
|
|
|
mRootedCallable.emplace(cx, aCallback->Callback());
|
2013-12-31 20:30:57 +04:00
|
|
|
}
|
2013-06-20 22:05:34 +04:00
|
|
|
|
2014-06-03 19:38:37 +04:00
|
|
|
// JS-implemented WebIDL is always OK to run, since it runs with Chrome
|
|
|
|
// privileges anyway.
|
|
|
|
if (mIsMainThread && !aIsJSImplementedWebIDL) {
|
2013-09-10 01:58:29 +04:00
|
|
|
// Check that it's ok to run this callback at all.
|
2013-12-12 05:51:57 +04:00
|
|
|
// Make sure to use realCallback to get the global of the callback object,
|
|
|
|
// not the wrapper.
|
2016-05-28 03:26:56 +03:00
|
|
|
bool allowed = xpc::Scriptability::Get(realCallback).Allowed();
|
2013-11-13 04:43:32 +04:00
|
|
|
|
|
|
|
if (!allowed) {
|
2016-05-04 20:59:42 +03:00
|
|
|
aRv.ThrowDOMException(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
|
|
|
|
NS_LITERAL_CSTRING("Refusing to execute function from global in which "
|
|
|
|
"script is disabled."));
|
2013-09-10 01:58:29 +04:00
|
|
|
return;
|
|
|
|
}
|
2012-11-09 19:43:57 +04:00
|
|
|
}
|
|
|
|
|
2015-07-24 14:01:00 +03:00
|
|
|
mAsyncStack.emplace(cx, aCallback->GetCreationStack());
|
|
|
|
if (*mAsyncStack) {
|
2016-03-23 17:40:53 +03:00
|
|
|
mAsyncStackSetter.emplace(cx, *mAsyncStack, aExecutionReason);
|
2015-07-24 14:01:00 +03:00
|
|
|
}
|
|
|
|
|
2013-01-28 17:34:29 +04:00
|
|
|
// Enter the compartment of our callback, so we can actually work with it.
|
2013-12-12 05:51:57 +04:00
|
|
|
//
|
|
|
|
// Note that if the callback is a wrapper, this will not be the same
|
|
|
|
// compartment that we ended up in with mAutoEntryScript above, because the
|
|
|
|
// entry point is based off of the unwrapped callback (realCallback).
|
2014-08-14 02:39:41 +04:00
|
|
|
mAc.emplace(cx, *mRootedCallable);
|
2012-11-09 19:43:57 +04:00
|
|
|
|
|
|
|
// And now we're ready to go.
|
|
|
|
mCx = cx;
|
|
|
|
}
|
|
|
|
|
2013-09-03 16:01:53 +04:00
|
|
|
bool
|
|
|
|
CallbackObject::CallSetup::ShouldRethrowException(JS::Handle<JS::Value> aException)
|
|
|
|
{
|
|
|
|
if (mExceptionHandling == eRethrowExceptions) {
|
2015-01-16 01:39:01 +03:00
|
|
|
if (!mCompartment) {
|
|
|
|
// Caller didn't ask us to filter for only exceptions we subsume.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// On workers, we don't have nsIPrincipals to work with. But we also only
|
|
|
|
// have one compartment, so check whether mCompartment is the same as the
|
|
|
|
// current compartment of mCx.
|
|
|
|
if (mCompartment == js::GetContextCompartment(mCx)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
// At this point mCx is in the compartment of our unwrapped callback, so
|
|
|
|
// just check whether the principal of mCompartment subsumes that of the
|
|
|
|
// current compartment/global of mCx.
|
|
|
|
nsIPrincipal* callerPrincipal =
|
|
|
|
nsJSPrincipals::get(JS_GetCompartmentPrincipals(mCompartment));
|
|
|
|
nsIPrincipal* calleePrincipal = nsContentUtils::SubjectPrincipal();
|
|
|
|
if (callerPrincipal->SubsumesConsideringDomain(calleePrincipal)) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-09-03 16:01:53 +04:00
|
|
|
}
|
|
|
|
|
2015-01-16 01:39:01 +03:00
|
|
|
MOZ_ASSERT(mCompartment);
|
2013-09-03 16:01:53 +04:00
|
|
|
|
2015-01-16 01:39:01 +03:00
|
|
|
// Now we only want to throw an exception to the caller if the object that was
|
2015-06-16 03:09:36 +03:00
|
|
|
// thrown is in the caller compartment (which we stored in mCompartment).
|
2013-09-03 16:01:53 +04:00
|
|
|
|
|
|
|
if (!aException.isObject()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Rooted<JSObject*> obj(mCx, &aException.toObject());
|
2015-11-06 21:03:52 +03:00
|
|
|
obj = js::UncheckedUnwrap(obj, /* stopAtWindowProxy = */ false);
|
2015-06-16 03:09:36 +03:00
|
|
|
return js::GetObjectCompartment(obj) == mCompartment;
|
2013-09-03 16:01:53 +04:00
|
|
|
}
|
|
|
|
|
2013-01-28 17:34:29 +04:00
|
|
|
CallbackObject::CallSetup::~CallSetup()
|
2012-11-09 19:43:57 +04:00
|
|
|
{
|
2014-03-05 17:32:27 +04:00
|
|
|
// To get our nesting right we have to destroy our JSAutoCompartment first.
|
|
|
|
// In particular, we want to do this before we try reporting any exceptions,
|
|
|
|
// so we end up reporting them while in the compartment of our entry point,
|
|
|
|
// not whatever cross-compartment wrappper mCallback might be.
|
|
|
|
// Be careful: the JSAutoCompartment might not have been constructed at all!
|
2014-08-14 02:39:41 +04:00
|
|
|
mAc.reset();
|
2014-03-05 17:32:27 +04:00
|
|
|
|
|
|
|
// Now, if we have a JSContext, report any pending errors on it, unless we
|
|
|
|
// were told to re-throw them.
|
2012-11-09 19:43:57 +04:00
|
|
|
if (mCx) {
|
2015-06-08 23:16:27 +03:00
|
|
|
bool needToDealWithException = mAutoEntryScript->HasException();
|
2013-11-27 20:21:00 +04:00
|
|
|
if ((mCompartment && mExceptionHandling == eRethrowContentExceptions) ||
|
|
|
|
mExceptionHandling == eRethrowExceptions) {
|
2013-02-19 20:54:40 +04:00
|
|
|
mErrorResult.MightThrowJSException();
|
2014-06-03 19:38:37 +04:00
|
|
|
if (needToDealWithException) {
|
2013-04-11 22:31:06 +04:00
|
|
|
JS::Rooted<JS::Value> exn(mCx);
|
2015-06-08 23:16:27 +03:00
|
|
|
if (mAutoEntryScript->PeekException(&exn) &&
|
2013-09-03 16:01:53 +04:00
|
|
|
ShouldRethrowException(exn)) {
|
2015-06-08 23:16:27 +03:00
|
|
|
mAutoEntryScript->ClearException();
|
|
|
|
MOZ_ASSERT(!mAutoEntryScript->HasException());
|
2013-02-19 20:54:40 +04:00
|
|
|
mErrorResult.ThrowJSException(mCx, exn);
|
2014-06-03 19:38:37 +04:00
|
|
|
needToDealWithException = false;
|
2013-02-19 20:54:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-03 19:38:37 +04:00
|
|
|
if (needToDealWithException) {
|
2013-02-19 20:54:40 +04:00
|
|
|
// Either we're supposed to report our exceptions, or we're supposed to
|
2015-06-08 23:16:27 +03:00
|
|
|
// re-throw them but we failed to get the exception value. Either way,
|
2016-03-25 18:11:20 +03:00
|
|
|
// we'll just report the pending exception, if any, once ~mAutoEntryScript
|
|
|
|
// runs. Note that we've already run ~mAc, effectively, so we don't have
|
|
|
|
// to worry about ordering here.
|
2016-03-10 12:50:56 +03:00
|
|
|
if (mErrorResult.IsJSContextException()) {
|
2016-08-26 22:38:16 +03:00
|
|
|
// XXXkhuey bug 1117269. When this is fixed, please consider fixing
|
|
|
|
// ThrowExceptionValueIfSafe over in Exceptions.cpp in the same way.
|
|
|
|
|
|
|
|
// IsJSContextException shouldn't be true anymore because we will report
|
|
|
|
// the exception on the JSContext ... so throw something else.
|
2016-03-10 12:50:56 +03:00
|
|
|
mErrorResult.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
2013-02-19 20:54:40 +04:00
|
|
|
}
|
2012-11-09 19:43:57 +04:00
|
|
|
}
|
|
|
|
|
2014-08-14 02:39:41 +04:00
|
|
|
mAutoIncumbentScript.reset();
|
|
|
|
mAutoEntryScript.reset();
|
2015-05-29 19:11:09 +03:00
|
|
|
|
|
|
|
// It is important that this is the last thing we do, after leaving the
|
|
|
|
// compartment and undoing all our entry/incumbent script changes
|
|
|
|
if (mIsMainThread) {
|
|
|
|
nsContentUtils::LeaveMicroTask();
|
|
|
|
}
|
2012-11-09 19:43:57 +04:00
|
|
|
}
|
|
|
|
|
2013-02-27 00:10:15 +04:00
|
|
|
already_AddRefed<nsISupports>
|
|
|
|
CallbackObjectHolderBase::ToXPCOMCallback(CallbackObject* aCallback,
|
2013-04-17 01:15:57 +04:00
|
|
|
const nsIID& aIID) const
|
2013-02-27 00:10:15 +04:00
|
|
|
{
|
2013-09-10 01:58:29 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-02-27 00:10:15 +04:00
|
|
|
if (!aCallback) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-03-18 17:48:38 +03:00
|
|
|
// We don't init the AutoJSAPI with our callback because we don't want it
|
|
|
|
// reporting errors to its global's onerror handlers.
|
|
|
|
AutoJSAPI jsapi;
|
|
|
|
jsapi.Init();
|
|
|
|
JSContext* cx = jsapi.cx();
|
2013-05-04 03:29:09 +04:00
|
|
|
|
|
|
|
JS::Rooted<JSObject*> callback(cx, aCallback->Callback());
|
|
|
|
|
2013-02-27 00:10:15 +04:00
|
|
|
JSAutoCompartment ac(cx, callback);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsXPCWrappedJS> wrappedJS;
|
2013-02-27 00:10:15 +04:00
|
|
|
nsresult rv =
|
2013-12-20 06:08:07 +04:00
|
|
|
nsXPCWrappedJS::GetNewOrUsed(callback, aIID, getter_AddRefs(wrappedJS));
|
2013-02-27 00:10:15 +04:00
|
|
|
if (NS_FAILED(rv) || !wrappedJS) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> retval;
|
|
|
|
rv = wrappedJS->QueryInterface(aIID, getter_AddRefs(retval));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval.forget();
|
|
|
|
}
|
|
|
|
|
2012-11-09 19:43:57 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|