• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ECMASCRIPT_BUILTINS_BUILTINS_PROMISE_H
17 #define ECMASCRIPT_BUILTINS_BUILTINS_PROMISE_H
18 
19 #include "ecmascript/base/builtins_base.h"
20 #include "ecmascript/ecma_runtime_call_info.h"
21 #include "ecmascript/js_handle.h"
22 #include "ecmascript/js_promise.h"
23 #include "ecmascript/js_tagged_value.h"
24 #include "ecmascript/object_factory.h"
25 
26 namespace panda::ecmascript::builtins {
27 class BuiltinsPromise : public base::BuiltinsBase {
28 public:
29     // 25.4.3.1 Promise ( executor )
30     static JSTaggedValue PromiseConstructor(EcmaRuntimeCallInfo *argv);
31     // 25.4.4.1 Promise.all ( iterable )
32     static JSTaggedValue All(EcmaRuntimeCallInfo *argv);
33     // 25.4.4.3 Promise.race ( iterable )
34     static JSTaggedValue Race(EcmaRuntimeCallInfo *argv);
35     // 25.4.4.4 Promise.reject ( r )
36     static JSTaggedValue Reject(EcmaRuntimeCallInfo *argv);
37     // 25.4.4.5 Promise.resolve ( x )
38     static JSTaggedValue Resolve(EcmaRuntimeCallInfo *argv);
39     // 25.4.4.6 get Promise [ @@species ]
40     static JSTaggedValue GetSpecies(EcmaRuntimeCallInfo *argv);
41     // 25.4.5.1 Promise.prototype.catch ( onRejected )
42     static JSTaggedValue Catch(EcmaRuntimeCallInfo *argv);
43     // 25.4.5.3 Promise.prototype.then ( onFulfilled , onRejected )
44     static JSTaggedValue Then(EcmaRuntimeCallInfo *argv);
45 
46     static JSTaggedValue PerformPromiseThen(JSThread *thread, const JSHandle<JSPromise> &promise,
47                                             const JSHandle<JSTaggedValue> &onFulfilled,
48                                             const JSHandle<JSTaggedValue> &onRejected,
49                                             const JSHandle<PromiseCapability> &capability);
50 
51     static JSTaggedValue Any(EcmaRuntimeCallInfo *argv);
52 
53     static JSTaggedValue AllSettled(EcmaRuntimeCallInfo *argv);
54 
55     static JSTaggedValue Finally(EcmaRuntimeCallInfo *argv);
56 
57     static JSTaggedValue GetPromiseResolve(JSThread *thread, JSHandle<JSTaggedValue> promiseConstructor);
58 
59 private:
60     static JSTaggedValue PerformPromiseAll(JSThread *thread,
61                                            const JSHandle<PromiseIteratorRecord> &itRecord,
62                                            const JSHandle<JSTaggedValue> &ctor,
63                                            const JSHandle<PromiseCapability> &capa);
64 
65     static JSHandle<CompletionRecord> PerformPromiseRace(JSThread *thread,
66                                                          const JSHandle<PromiseIteratorRecord> &iteratorRecord,
67                                                          const JSHandle<PromiseCapability> &capability,
68                                                          const JSHandle<JSTaggedValue> &constructor);
69 
70     static JSHandle<CompletionRecord> PerformPromiseAllSettled(JSThread *thread,
71                                                                const JSHandle<PromiseIteratorRecord> &iterRecord,
72                                                                const JSHandle<JSTaggedValue> &constructor,
73                                                                const JSHandle<PromiseCapability> &resultCapa,
74                                                                const JSHandle<JSTaggedValue> &promiseResolve);
75 
76     static JSHandle<CompletionRecord> PerformPromiseAny(JSThread *thread,
77                                                         const JSHandle<PromiseIteratorRecord> &iteratorRecord,
78                                                         const JSHandle<JSTaggedValue> &constructor,
79                                                         const JSHandle<PromiseCapability> &resultCapability,
80                                                         const JSHandle<JSTaggedValue> &promiseResolve);
81 };
82 }  // namespace panda::ecmascript::builtins
83 #endif  // ECMASCRIPT_BUILTINS_BUILTINS_PROMISE_H