Auto merge of #12830 - jdm:promises, r=Ms2ger

Implement promise bindings

This implements support for using Promises in WebIDL, executing promise callbacks in batches (equivalent to running all enqueued jobs from a setTimeout(0)), and attaching native callbacks to promise objects. This is the combined work of myself, @dati91, and @mmatyas based on the following prior work in Gecko:
* Codegen.py
* Promise.webidl
* Promise.cpp/Promise.h
* PromiseNativeHandler.h

This does not implement microtasks per #4283. This allows us to make progress on testing code that requires the use of Promises right now; the microtasks work is more complicated, but also largely orthogonal to implement.

Requires https://github.com/servo/mozjs/pull/89, https://github.com/servo/rust-mozjs/pull/287, and https://github.com/servo/rust-mozjs/pull/294.

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #4282
- [X] There are tests for these changes

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12830)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-09-22 15:23:23 -05:00 committed by GitHub
commit 2b1a39c2ae
133 changed files with 9477 additions and 263 deletions

View file

@ -0,0 +1,16 @@
/* 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/. */
// This interface is entirely internal to Servo, and should not be accessible to
// web pages.
callback PromiseJobCallback = void();
[TreatNonCallableAsNull]
callback AnyCallback = any (any value);
[NoInterfaceObject, Exposed=(Window,Worker)]
// Need to escape "Promise" so it's treated as an identifier.
interface _Promise {
};

View file

@ -0,0 +1,13 @@
/* 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/. */
// This interface is entirely internal to Servo, and should not be accessible to
// web pages.
// Hack to allow us to have JS owning and properly tracing/CCing/etc a
// PromiseNativeHandler.
[NoInterfaceObject,
Exposed=(Window,Worker)]
interface PromiseNativeHandler {
};

View file

@ -508,9 +508,24 @@ interface TestBinding {
[Func="TestBinding::condition_satisfied"]
const unsigned short funcControlledConstEnabled = 0;
[Throws]
Promise<any> returnResolvedPromise(any value);
[Throws]
Promise<any> returnRejectedPromise(any value);
readonly attribute Promise<boolean> promiseAttribute;
void acceptPromise(Promise<DOMString> string);
void acceptNullablePromise(Promise<DOMString>? string);
Promise<any> promiseNativeHandler(SimpleCallback? resolve, SimpleCallback? reject);
void promiseResolveNative(Promise<any> p, any value);
void promiseRejectNative(Promise<any> p, any value);
void promiseRejectWithTypeError(Promise<any> p, USVString message);
void resolvePromiseDelayed(Promise<any> p, DOMString value, unsigned long long ms);
void panic();
};
callback SimpleCallback = void(any value);
partial interface TestBinding {
[Pref="dom.testable_crash.enabled"]
void crashHard();