|
| 1 | +/* |
| 2 | + * Copyright (C) 2018 Apple Inc. All rights reserved. |
| 3 | + * |
| 4 | + * Redistribution and use in source and binary forms, with or without |
| 5 | + * modification, are permitted provided that the following conditions |
| 6 | + * are met: |
| 7 | + * 1. Redistributions of source code must retain the above copyright |
| 8 | + * notice, this list of conditions and the following disclaimer. |
| 9 | + * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | + * notice, this list of conditions and the following disclaimer in the |
| 11 | + * documentation and/or other materials provided with the distribution. |
| 12 | + * |
| 13 | + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 | + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | + */ |
| 25 | + |
| 26 | +#if JSC_OBJC_API_ENABLED |
| 27 | + |
| 28 | +#import <JavaScriptCore/JavaScriptCore.h> |
| 29 | + |
| 30 | +@interface JSValue(JSPrivate) |
| 31 | + |
| 32 | +/*! |
| 33 | + @method |
| 34 | + @abstract Create a new promise object using the provided executor callback. |
| 35 | + @param callback A callback block invoked while the promise object is |
| 36 | + being initialized. The resolve and reject parameters are functions that |
| 37 | + can be called to notify any pending reactions about the state of the |
| 38 | + new promise object. |
| 39 | + @param context The JSContext to which the resulting JSValue belongs. |
| 40 | + @result The JSValue representing a new promise JavaScript object. |
| 41 | + @discussion This method is equivalent to calling the Promise constructor in JavaScript. |
| 42 | + the resolve and reject callbacks each normally take a single value, which they |
| 43 | + forward to all relevent pending reactions. While inside the executor callback context will act |
| 44 | + as if it were in any other callback, except calleeFunction will be <code>nil</code>. This also means |
| 45 | + means the new promise object may be accessed via <code>[context thisValue]</code>. |
| 46 | + */ |
| 47 | ++ (JSValue *)valueWithNewPromiseInContext:(JSContext *)context fromExecutor:(void (^)(JSValue *resolve, JSValue *reject))callback JSC_API_AVAILABLE(macosx(JSC_MAC_TBA), ios(JSC_IOS_TBA)); |
| 48 | + |
| 49 | +/*! |
| 50 | + @method |
| 51 | + @abstract Create a new resolved promise object with the provided value. |
| 52 | + @param result The result value to be passed to any reactions. |
| 53 | + @param context The JSContext to which the resulting JSValue belongs. |
| 54 | + @result The JSValue representing a new promise JavaScript object. |
| 55 | + @discussion This method is equivalent to calling <code>[JSValue valueWithNewPromiseFromExecutor:^(JSValue *resolve, JSValue *reject) { [resolve callWithArguments:@[result]]; } inContext:context]</code> |
| 56 | + */ |
| 57 | ++ (JSValue *)valueWithNewPromiseResolvedWithResult:(id)result inContext:(JSContext *)context JSC_API_AVAILABLE(macosx(JSC_MAC_TBA), ios(JSC_IOS_TBA)); |
| 58 | + |
| 59 | +/*! |
| 60 | + @method |
| 61 | + @abstract Create a new rejected promise object with the provided value. |
| 62 | + @param reason The result value to be passed to any reactions. |
| 63 | + @param context The JSContext to which the resulting JSValue belongs. |
| 64 | + @result The JSValue representing a new promise JavaScript object. |
| 65 | + @discussion This method is equivalent to calling <code>[JSValue valueWithNewPromiseFromExecutor:^(JSValue *resolve, JSValue *reject) { [reject callWithArguments:@[reason]]; } inContext:context]</code> |
| 66 | + */ |
| 67 | ++ (JSValue *)valueWithNewPromiseRejectedWithReason:(id)reason inContext:(JSContext *)context JSC_API_AVAILABLE(macosx(JSC_MAC_TBA), ios(JSC_IOS_TBA)); |
| 68 | + |
| 69 | +@end |
| 70 | + |
| 71 | +#endif // JSC_OBJC_API_ENABLED |
0 commit comments