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