gecko-dev/dom/bindings/test/TestFunctions.h
Boris Zbarsky a6fdc48869 Bug 1436276. Bindings should create their return promises in the current compartment even when called over Xrays. r=bholley
These are cases that are implementing the "convert an exception to a Promise"
steps of the Web IDL spec.  Typically the exception is thrown in the current
compartment; the Promise returned should simply match that.  Otherwise we can
end up with a situation in which the promise doesn't actaully have access to
its rejection value, which will cause problems if someone uses then() on the
promise: the return value of the then() call will get a sanitized exception
instead of the real one.

We _could_ try to match the actual compartment of the exception, in theory.
But it's not clear why this would be preferable to using the current
compartment, even if there were cases in which the exception _doesn't_ match
the current compartment.  Which there likely are not.

MozReview-Commit-ID: Ac2BHIHxfvY

--HG--
rename : dom/promise/tests/test_promise_argument.html => dom/promise/tests/test_promise_retval.html
rename : dom/promise/tests/test_promise_argument_xrays.html => dom/promise/tests/test_promise_retval_xrays.html
2018-02-10 01:34:10 -05:00

59 lines
1.8 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef mozilla_dom_TestFunctions_h
#define mozilla_dom_TestFunctions_h
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/NonRefcountedDOMObject.h"
#include "nsString.h"
namespace mozilla {
namespace dom {
class Promise;
class PromiseReturner;
class TestFunctions : public NonRefcountedDOMObject {
public:
static TestFunctions* Constructor(GlobalObject& aGlobal, ErrorResult& aRv);
static void
ThrowUncatchableException(GlobalObject& aGlobal, ErrorResult& aRv);
static Promise*
PassThroughPromise(GlobalObject& aGlobal, Promise& aPromise);
static already_AddRefed<Promise>
PassThroughCallbackPromise(GlobalObject& aGlobal,
PromiseReturner& aCallback,
ErrorResult& aRv);
void SetStringData(const nsAString& aString);
void GetStringDataAsAString(nsAString& aString);
void GetStringDataAsAString(uint32_t aLength, nsAString& aString);
void GetStringDataAsDOMString(const Optional<uint32_t>& aLength,
DOMString& aString);
void TestThrowNsresult(ErrorResult& aError);
void TestThrowNsresultFromNative(ErrorResult& aError);
static already_AddRefed<Promise>
ThrowToRejectPromise(GlobalObject& aGlobal,
ErrorResult& aError);
bool WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto,
JS::MutableHandle<JSObject*> aWrapper);
private:
nsString mStringData;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_TestFunctions_h