arkcompiler_ets_runtime/ecmascript/js_array.h
wu_zhang_da 3ad520f3ba Array Lazy Loading Bugfix
Issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I7ES41

Signed-off-by: wu_zhang_da <wuzhangda@huawei.com>
Change-Id: I049055fa8ae7df475f27291af9d990356abd47d4
2023-06-20 09:19:06 +08:00

102 lines
4.7 KiB
C++

/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ECMASCRIPT_JSARRAY_H
#define ECMASCRIPT_JSARRAY_H
#include "ecmascript/js_object.h"
#include "ecmascript/js_tagged_value-inl.h"
#include "ecmascript/js_tagged_value.h"
#include "ecmascript/tagged_array.h"
namespace panda::ecmascript {
enum class ArrayMode : uint8_t { UNDEFINED = 0, DICTIONARY, LITERAL };
// ecma6 9.4.2 Array Exotic Object
class JSArray : public JSObject {
public:
static constexpr int LENGTH_INLINE_PROPERTY_INDEX = 0;
CAST_CHECK(JSArray, IsJSArray);
static JSHandle<JSTaggedValue> ArrayCreate(JSThread *thread, JSTaggedNumber length,
ArrayMode mode = ArrayMode::UNDEFINED);
static JSHandle<JSTaggedValue> ArrayCreate(JSThread *thread, JSTaggedNumber length,
const JSHandle<JSTaggedValue> &newTarget,
ArrayMode mode = ArrayMode::UNDEFINED);
static JSTaggedValue ArraySpeciesCreate(JSThread *thread, const JSHandle<JSObject> &originalArray,
JSTaggedNumber length);
static bool ArraySetLength(JSThread *thread, const JSHandle<JSObject> &array, const PropertyDescriptor &desc);
static bool DefineOwnProperty(JSThread *thread, const JSHandle<JSObject> &array, const JSHandle<JSTaggedValue> &key,
const PropertyDescriptor &desc);
static bool DefineOwnProperty(JSThread *thread, const JSHandle<JSObject> &array, uint32_t index,
const PropertyDescriptor &desc);
static bool IsLengthString(JSThread *thread, const JSHandle<JSTaggedValue> &key);
// ecma6 7.3 Operations on Objects
static JSHandle<JSArray> CreateArrayFromList(JSThread *thread, const JSHandle<TaggedArray> &elements);
// use first inlined property slot for array length
inline uint32_t GetArrayLength() const
{
return GetLength().GetArrayLength();
}
inline void SetArrayLength(const JSThread *thread, uint32_t length)
{
SetLength(thread, JSTaggedValue(length));
}
static constexpr size_t LENGTH_OFFSET = JSObject::SIZE;
ACCESSORS(Length, LENGTH_OFFSET, SIZE);
DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, LENGTH_OFFSET, SIZE)
static const uint32_t MAX_ARRAY_INDEX = MAX_ELEMENT_INDEX;
DECL_DUMP()
static int32_t GetArrayLengthOffset()
{
return LENGTH_OFFSET;
}
static bool PropertyKeyToArrayIndex(JSThread *thread, const JSHandle<JSTaggedValue> &key, uint32_t *output);
static JSTaggedValue LengthGetter(JSThread *thread, const JSHandle<JSObject> &self);
static bool LengthSetter(JSThread *thread, const JSHandle<JSObject> &self, const JSHandle<JSTaggedValue> &value,
bool mayThrow = false);
static JSHandle<JSTaggedValue> FastGetPropertyByValue(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
uint32_t index);
static JSHandle<JSTaggedValue> FastGetPropertyByValue(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
const JSHandle<JSTaggedValue> &key);
static bool FastSetPropertyByValue(JSThread *thread, const JSHandle<JSTaggedValue> &obj, uint32_t index,
const JSHandle<JSTaggedValue> &value);
static bool FastSetPropertyByValue(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
const JSHandle<JSTaggedValue> &key, const JSHandle<JSTaggedValue> &value);
static void Sort(JSThread *thread, const JSHandle<JSObject> &obj, const JSHandle<JSTaggedValue> &fn);
static bool IncludeInSortedValue(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
const JSHandle<JSTaggedValue> &value);
static JSHandle<TaggedArray> ToTaggedArray(JSThread *thread, const JSHandle<JSTaggedValue> &obj);
static void CheckAndCopyArray(const JSThread *thread, JSHandle<JSArray> obj);
static void SetCapacity(JSThread *thread, const JSHandle<JSObject> &array, uint32_t oldLen, uint32_t newLen);
};
} // namespace panda::ecmascript
#endif // ECMASCRIPT_JSARRAY_H