• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_BASE_ARRAY_HELPER_H
17 #define ECMASCRIPT_BASE_ARRAY_HELPER_H
18 
19 #include <string>
20 
21 #include "ecmascript/base/builtins_base.h"
22 
23 namespace panda::ecmascript::base {
24 struct FlattenArgs {
25     int64_t sourceLen = 0;
26     int64_t start = 0;
27     double depth = 0;
28 };
29 
30 enum class HolesType {
31     SKIP_HOLES,
32     READ_THROUGH_HOLES,
33 };
34 class ArrayHelper {
35 public:
36     static bool IsConcatSpreadable(JSThread *thread, const JSHandle<JSTaggedValue> &obj);
37     static double SortCompare(JSThread *thread, const JSHandle<JSTaggedValue> &callbackfnHandle,
38                               const JSHandle<JSTaggedValue> &valueX, const JSHandle<JSTaggedValue> &valueY);
39     static int64_t GetLength(JSThread *thread, const JSHandle<JSTaggedValue> &thisHandle);
40     static int64_t GetArrayLength(JSThread *thread, const JSHandle<JSTaggedValue> &thisHandle);
41     static JSTaggedValue FlattenIntoArray(JSThread *thread, const JSHandle<JSObject> &newArrayHandle,
42                                           const JSHandle<JSTaggedValue> &thisObjVal, const FlattenArgs &args,
43                                           const JSHandle<JSTaggedValue> &mapperFunctionHandle,
44                                           const JSHandle<JSTaggedValue> &thisArg);
45     static JSTaggedValue SortIndexedProperties(JSThread *thread, const JSHandle<JSObject> &thisObj,
46                                                int64_t len, const JSHandle<JSTaggedValue> &callbackFnHandle,
47                                                HolesType holes);
48 };
49 }  // namespace panda::ecmascript::base
50 
51 #endif  // ECMASCRIPT_BASE_ARRAY_HELPER_H
52