1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/webidl/Promise.webidl Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,47 @@ 1.4 +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.7 + * You can obtain one at http://mozilla.org/MPL/2.0/. 1.8 + * 1.9 + * The origin of this IDL file is 1.10 + * http://dom.spec.whatwg.org/#promises 1.11 + */ 1.12 + 1.13 +// TODO We use object instead Function. There is an open issue on WebIDL to 1.14 +// have different types for "platform-provided function" and "user-provided 1.15 +// function"; for now, we just use "object". 1.16 +callback PromiseInit = void (object resolve, object reject); 1.17 + 1.18 +[TreatNonCallableAsNull] 1.19 +callback AnyCallback = any (any value); 1.20 + 1.21 +// REMOVE THE RELEVANT ENTRY FROM test_interfaces.html WHEN THIS IS IMPLEMENTED IN JS. 1.22 +[Constructor(PromiseInit init)] 1.23 +interface Promise { 1.24 + // TODO bug 875289 - static Promise fulfill(any value); 1.25 + 1.26 + // Disable the static methods when the interface object is supposed to be 1.27 + // disabled, just in case some code decides to walk over to .constructor from 1.28 + // the proto of a promise object or someone screws up and manages to create a 1.29 + // Promise object in this scope without having resolved the interface object 1.30 + // first. 1.31 + [NewObject, Throws] 1.32 + static Promise resolve(optional any value); 1.33 + [NewObject, Throws] 1.34 + static Promise reject(optional any value); 1.35 + 1.36 + // The [TreatNonCallableAsNull] annotation is required since then() should do 1.37 + // nothing instead of throwing errors when non-callable arguments are passed. 1.38 + [NewObject] 1.39 + Promise then([TreatNonCallableAsNull] optional AnyCallback? fulfillCallback = null, 1.40 + [TreatNonCallableAsNull] optional AnyCallback? rejectCallback = null); 1.41 + 1.42 + [NewObject] 1.43 + Promise catch([TreatNonCallableAsNull] optional AnyCallback? rejectCallback = null); 1.44 + 1.45 + [NewObject, Throws] 1.46 + static Promise all(sequence<any> iterable); 1.47 + 1.48 + [NewObject, Throws] 1.49 + static Promise race(sequence<any> iterable); 1.50 +};