• 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_JS_STABLE_ARRAY_H
17 #define ECMASCRIPT_JS_STABLE_ARRAY_H
18 
19 #include "ecmascript/js_array.h"
20 #include "ecmascript/js_dataview.h"
21 #include "ecmascript/js_typed_array.h"
22 #include "ecmascript/js_tagged_value.h"
23 
24 namespace panda::ecmascript {
25 class JSStableArray {
26 public:
27     enum SeparatorFlag : int { MINUS_ONE = -1, MINUS_TWO = -2 };
28     static JSTaggedValue Push(JSHandle<JSArray> receiver, EcmaRuntimeCallInfo *argv);
29     static JSTaggedValue Pop(JSHandle<JSArray> receiver, EcmaRuntimeCallInfo *argv);
30     static JSTaggedValue Splice(JSHandle<JSArray> receiver, EcmaRuntimeCallInfo *argv,
31                                 uint32_t start, uint32_t insertCount, uint32_t actualDeleteCount);
32     static JSTaggedValue Shift(JSHandle<JSArray> receiver, EcmaRuntimeCallInfo *argv);
33     static JSTaggedValue Join(JSHandle<JSArray> receiver, EcmaRuntimeCallInfo *argv);
34     static JSTaggedValue HandleFindIndexOfStable(JSThread *thread, JSHandle<JSObject> thisObjHandle,
35                                                  JSHandle<JSTaggedValue> callbackFnHandle,
36                                                  JSHandle<JSTaggedValue> thisArgHandle, uint32_t &k);
37     static JSTaggedValue HandleFindLastIndexOfStable(JSThread *thread, JSHandle<JSObject> thisObjHandle,
38                                                      JSHandle<JSTaggedValue> callbackFnHandle,
39                                                      JSHandle<JSTaggedValue> thisArgHandle, int64_t &k);
40     static JSTaggedValue HandleEveryOfStable(JSThread *thread, JSHandle<JSObject> thisObjHandle,
41                                              JSHandle<JSTaggedValue> callbackFnHandle,
42                                              JSHandle<JSTaggedValue> thisArgHandle, uint32_t &k);
43     static JSTaggedValue HandleforEachOfStable(JSThread *thread, JSHandle<JSObject> thisObjHandle,
44                                                JSHandle<JSTaggedValue> callbackFnHandle,
45                                                JSHandle<JSTaggedValue> thisArgHandle, uint32_t &k);
46     static JSTaggedValue IndexOf(JSThread *thread, JSHandle<JSTaggedValue> receiver,
47                                  JSHandle<JSTaggedValue> searchElement, uint32_t from, uint32_t len);
48     static JSTaggedValue Filter(JSHandle<JSObject> newArrayHandle, JSHandle<JSObject> thisObjHandle,
49                                  EcmaRuntimeCallInfo *argv, uint32_t &k, uint32_t &toIndex);
50     static JSTaggedValue Map(JSHandle<JSObject> newArrayHandle, JSHandle<JSObject> thisObjHandle,
51                                  EcmaRuntimeCallInfo *argv, uint32_t &k, uint32_t len);
52     static JSTaggedValue Reverse(JSThread *thread, JSHandle<JSObject> thisObjHandle,
53                                  JSHandle<JSTaggedValue> thisHandle, int64_t &lower, uint32_t len);
54     static JSTaggedValue Concat(JSThread *thread, JSHandle<JSObject> newArrayHandle,
55                                 JSHandle<JSObject> thisObjHandle, int64_t &k, int64_t &n);
56     static JSTaggedValue FastCopyFromArrayToTypedArray(JSThread *thread, JSHandle<JSTypedArray> &target,
57                                                        DataViewType targetType, uint32_t targetOffset,
58                                                        uint32_t srcLength, JSHandle<TaggedArray> &elements);
59     static JSTaggedValue At(JSHandle<JSArray> receiver, EcmaRuntimeCallInfo *argv);
60     static JSTaggedValue With(JSThread *thread, JSHandle<JSArray> receiver,
61                               int64_t insertCount, int64_t index, JSHandle<JSTaggedValue> value);
62     static JSTaggedValue ToSpliced(JSHandle<JSArray> receiver, EcmaRuntimeCallInfo *argv,
63                                    int64_t argc, int64_t actualStart, int64_t actualSkipCount, int64_t insertCount);
64     static JSTaggedValue ToReversed(JSThread *thread, JSHandle<JSArray> receiver,   int64_t insertCount);
65     static JSTaggedValue Reduce(JSThread *thread, JSHandle<JSObject> thisObjHandle,
66                                 JSHandle<JSTaggedValue> callbackFnHandle,
67                                 JSMutableHandle<JSTaggedValue> accumulator, int64_t &k, int64_t &len);
68 };
69 }  // namespace panda::ecmascript
70 #endif  // ECMASCRIPT_JS_STABLE_ARRAY_H
71