• 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/ecma_runtime_call_info.h"
20 #include "ecmascript/base/builtins_base.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 private:
52     static JSHandle<CompletionRecord> PerformPromiseAll(JSThread *thread,
53                                                         const JSHandle<PromiseIteratorRecord> &itRecord,
54                                                         const JSHandle<JSTaggedValue> &ctor,
55                                                         const JSHandle<PromiseCapability> &capa);
56 
57     static JSHandle<CompletionRecord> PerformPromiseRace(JSThread *thread,
58                                                          const JSHandle<PromiseIteratorRecord> &iteratorRecord,
59                                                          const JSHandle<PromiseCapability> &capability,
60                                                          const JSHandle<JSTaggedValue> &constructor);
61 };
62 }  // namespace panda::ecmascript::builtins
63 #endif  // ECMASCRIPT_BUILTINS_BUILTINS_PROMISE_H