1 /*
2 * Copyright (c) 2021-2024 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_JSOBJECT_INL_H
17 #define ECMASCRIPT_JSOBJECT_INL_H
18
19 #include "ecmascript/js_object.h"
20
21 #include "ecmascript/element_accessor-inl.h"
22 #include "ecmascript/js_array.h"
23 #include "ecmascript/js_hclass-inl.h"
24 #include "ecmascript/js_tagged_value-inl.h"
25 #include "ecmascript/js_typed_array.h"
26 #include "ecmascript/object_operator.h"
27 #include "ecmascript/tagged_array-inl.h"
28 #include "ecmascript/tagged_dictionary.h"
29 #include "ecmascript/tagged_queue.h"
30
31 namespace panda::ecmascript {
SetCallable(bool flag)32 inline void ECMAObject::SetCallable(bool flag)
33 {
34 GetClass()->SetCallable(flag);
35 }
36
IsCallable()37 inline bool ECMAObject::IsCallable() const
38 {
39 return GetClass()->IsCallable();
40 }
41
42 // JSObject
IsExtensible()43 inline bool JSObject::IsExtensible() const
44 {
45 return GetJSHClass()->IsExtensible();
46 }
47
FillElementsWithHoles(const JSThread * thread,uint32_t start,uint32_t end)48 inline void JSObject::FillElementsWithHoles(const JSThread *thread, uint32_t start, uint32_t end)
49 {
50 if (start >= end) {
51 return;
52 }
53
54 JSHandle<JSTaggedValue> holeHandle(thread, JSTaggedValue::Hole());
55 JSHandle<JSObject> thisObj(thread, this);
56 for (uint32_t i = start; i < end; i++) {
57 ElementAccessor::Set(thread, thisObj, i, holeHandle, false);
58 }
59 }
60
GetNonInlinedFastPropsCapacity()61 inline uint32_t JSObject::GetNonInlinedFastPropsCapacity() const
62 {
63 uint32_t inlineProps = GetJSHClass()->GetInlinedProperties();
64 return PropertyAttributes::MAX_FAST_PROPS_CAPACITY - inlineProps;
65 }
66
IsJSGlobalObject()67 inline bool JSObject::IsJSGlobalObject() const
68 {
69 return GetJSHClass()->IsJSGlobalObject();
70 }
71
IsConstructor()72 inline bool JSObject::IsConstructor() const
73 {
74 return GetJSHClass()->IsConstructor();
75 }
76
IsECMAObject()77 inline bool JSObject::IsECMAObject() const
78 {
79 return GetJSHClass()->IsECMAObject();
80 }
81
IsJSError()82 inline bool JSObject::IsJSError() const
83 {
84 return GetJSHClass()->IsJSError();
85 }
86
IsArguments()87 inline bool JSObject::IsArguments() const
88 {
89 return GetJSHClass()->IsArguments();
90 }
91
IsDate()92 inline bool JSObject::IsDate() const
93 {
94 return GetJSHClass()->IsDate();
95 }
96
IsJSArray()97 inline bool JSObject::IsJSArray() const
98 {
99 return GetJSHClass()->IsJSArray();
100 }
101
IsJSSArray()102 inline bool JSObject::IsJSSArray() const
103 {
104 return GetJSHClass()->IsJSSharedArray();
105 }
106
IsJSShared()107 inline bool JSObject::IsJSShared() const
108 {
109 return GetJSHClass()->IsJSShared();
110 }
111
IsJSMap()112 inline bool JSObject::IsJSMap() const
113 {
114 return GetJSHClass()->IsJSMap();
115 }
116
IsJSSet()117 inline bool JSObject::IsJSSet() const
118 {
119 return GetJSHClass()->IsJSSet();
120 }
121
IsJSRegExp()122 inline bool JSObject::IsJSRegExp() const
123 {
124 return GetJSHClass()->IsJSRegExp();
125 }
126
IsJSFunction()127 inline bool JSObject::IsJSFunction() const
128 {
129 return GetJSHClass()->IsJSFunction();
130 }
131
IsBoundFunction()132 inline bool JSObject::IsBoundFunction() const
133 {
134 return GetJSHClass()->IsJsBoundFunction();
135 }
136
IsJSIntlBoundFunction()137 inline bool JSObject::IsJSIntlBoundFunction() const
138 {
139 return GetJSHClass()->IsJSIntlBoundFunction();
140 }
141
IsProxyRevocFunction()142 inline bool JSObject::IsProxyRevocFunction() const
143 {
144 return GetJSHClass()->IsJSProxyRevocFunction();
145 }
146
IsAccessorData()147 inline bool JSObject::IsAccessorData() const
148 {
149 return GetJSHClass()->IsAccessorData();
150 }
151
IsJSGlobalEnv()152 inline bool JSObject::IsJSGlobalEnv() const
153 {
154 return GetJSHClass()->IsJsGlobalEnv();
155 }
156
IsJSProxy()157 inline bool JSObject::IsJSProxy() const
158 {
159 return GetJSHClass()->IsJSProxy();
160 }
161
IsGeneratorObject()162 inline bool JSObject::IsGeneratorObject() const
163 {
164 return GetJSHClass()->IsGeneratorObject();
165 }
166
IsAsyncGeneratorObject()167 inline bool JSObject::IsAsyncGeneratorObject() const
168 {
169 return GetJSHClass()->IsAsyncGeneratorObject();
170 }
171
IsForinIterator()172 inline bool JSObject::IsForinIterator() const
173 {
174 return GetJSHClass()->IsForinIterator();
175 }
176
IsJSSetIterator()177 inline bool JSObject::IsJSSetIterator() const
178 {
179 return GetJSHClass()->IsJSSetIterator();
180 }
181
IsJSRegExpIterator()182 inline bool JSObject::IsJSRegExpIterator() const
183 {
184 return GetJSHClass()->IsJSRegExpIterator();
185 }
186
IsJSMapIterator()187 inline bool JSObject::IsJSMapIterator() const
188 {
189 return GetJSHClass()->IsJSMapIterator();
190 }
191
IsJSArrayIterator()192 inline bool JSObject::IsJSArrayIterator() const
193 {
194 return GetJSHClass()->IsJSArrayIterator();
195 }
196
IsJSAPIArrayListIterator()197 inline bool JSObject::IsJSAPIArrayListIterator() const
198 {
199 return GetJSHClass()->IsJSAPIArrayListIterator();
200 }
201
IsJSAPIStackIterator()202 inline bool JSObject::IsJSAPIStackIterator() const
203 {
204 return GetJSHClass()->IsJSAPIStackIterator();
205 }
206
IsJSAPIVectorIterator()207 inline bool JSObject::IsJSAPIVectorIterator() const
208 {
209 return GetJSHClass()->IsJSAPIVectorIterator();
210 }
211
IsJSAPIBitVectorIterator()212 inline bool JSObject::IsJSAPIBitVectorIterator() const
213 {
214 return GetJSHClass()->IsJSAPIBitVectorIterator();
215 }
216
IsJSAPILinkedListIterator()217 inline bool JSObject::IsJSAPILinkedListIterator() const
218 {
219 return GetJSHClass()->IsJSAPILinkedListIterator();
220 }
221
IsJSAPIListIterator()222 inline bool JSObject::IsJSAPIListIterator() const
223 {
224 return GetJSHClass()->IsJSAPIListIterator();
225 }
226
IsJSPrimitiveRef()227 inline bool JSObject::IsJSPrimitiveRef() const
228 {
229 return GetJSHClass()->IsJsPrimitiveRef();
230 }
231
IsElementDict()232 inline bool JSObject::IsElementDict() const
233 {
234 return TaggedArray::Cast(GetElements().GetTaggedObject())->IsDictionaryMode();
235 }
236
IsPropertiesDict()237 inline bool JSObject::IsPropertiesDict() const
238 {
239 return TaggedArray::Cast(GetProperties().GetTaggedObject())->IsDictionaryMode();
240 }
241
IsTypedArray()242 inline bool JSObject::IsTypedArray() const
243 {
244 return GetJSHClass()->IsTypedArray();
245 }
246
ConvertValueWithRep(PropertyAttributes attr,JSTaggedValue value)247 std::pair<bool, JSTaggedValue> JSObject::ConvertValueWithRep(PropertyAttributes attr, JSTaggedValue value)
248 {
249 if (attr.IsDoubleRep()) {
250 if (value.IsInt()) {
251 double doubleValue = value.GetInt();
252 return std::pair(true, JSTaggedValue(bit_cast<JSTaggedType>(doubleValue)));
253 } else if (value.IsDouble()) {
254 return std::pair(true, JSTaggedValue(bit_cast<JSTaggedType>(value.GetDouble())));
255 } else {
256 return std::pair(false, value);
257 }
258 } else if (attr.IsIntRep()) {
259 if (value.IsInt()) {
260 int intValue = value.GetInt();
261 return std::pair(true, JSTaggedValue(static_cast<JSTaggedType>(intValue)));
262 } else {
263 return std::pair(false, value);
264 }
265 }
266 return std::pair(true, value);
267 }
268
SetPropertyInlinedPropsWithRep(const JSThread * thread,uint32_t index,JSTaggedValue value)269 void JSObject::SetPropertyInlinedPropsWithRep(const JSThread *thread, uint32_t index, JSTaggedValue value)
270 {
271 auto layout = LayoutInfo::Cast(GetJSHClass()->GetLayout().GetTaggedObject());
272 auto attr = layout->GetAttr(index);
273 if (attr.IsTaggedRep()) {
274 SetPropertyInlinedProps<true>(thread, index, value);
275 } else {
276 SetPropertyInlinedProps<false>(thread, index, value);
277 }
278 }
279
280 template <bool needBarrier>
SetPropertyInlinedProps(const JSThread * thread,uint32_t index,JSTaggedValue value)281 void JSObject::SetPropertyInlinedProps(const JSThread *thread, uint32_t index, JSTaggedValue value)
282 {
283 SetPropertyInlinedProps<needBarrier>(thread, GetJSHClass(), index, value);
284 }
285
GetPropertyInlinedPropsWithRep(uint32_t index,PropertyAttributes attr)286 JSTaggedValue JSObject::GetPropertyInlinedPropsWithRep(uint32_t index, PropertyAttributes attr) const
287 {
288 return GetPropertyInlinedPropsWithRep(GetJSHClass(), index, attr);
289 }
290
GetPropertyInlinedPropsWithRep(const JSHClass * hclass,uint32_t index,PropertyAttributes attr)291 JSTaggedValue JSObject::GetPropertyInlinedPropsWithRep(const JSHClass *hclass, uint32_t index,
292 PropertyAttributes attr) const
293 {
294 auto value = GetPropertyInlinedProps(hclass, index);
295 if (attr.IsDoubleRep()) {
296 value = JSTaggedValue(bit_cast<double>(value.GetRawData()));
297 } else if (attr.IsIntRep()) {
298 value = JSTaggedValue(static_cast<int32_t>(value.GetRawData()));
299 }
300 return value;
301 }
302
GetPropertyInlinedProps(uint32_t index)303 JSTaggedValue JSObject::GetPropertyInlinedProps(uint32_t index) const
304 {
305 return GetPropertyInlinedProps(GetJSHClass(), index);
306 }
307
308 template <bool needBarrier>
SetPropertyInlinedProps(const JSThread * thread,const JSHClass * hclass,uint32_t index,JSTaggedValue value)309 void JSObject::SetPropertyInlinedProps(const JSThread *thread, const JSHClass *hclass, uint32_t index,
310 JSTaggedValue value)
311 {
312 uint32_t offset = hclass->GetInlinedPropertiesOffset(index);
313 ASSERT(hclass->GetObjectSize() > offset);
314 if constexpr (needBarrier) {
315 SET_VALUE_WITH_BARRIER(thread, this, offset, value);
316 } else {
317 SET_VALUE_PRIMITIVE(this, offset, value);
318 }
319 }
320
GetPropertyInlinedProps(const JSHClass * hclass,uint32_t index)321 JSTaggedValue JSObject::GetPropertyInlinedProps(const JSHClass *hclass, uint32_t index) const
322 {
323 uint32_t offset = hclass->GetInlinedPropertiesOffset(index);
324 return JSTaggedValue(GET_VALUE(this, offset));
325 }
326
GetProperty(const JSHClass * hclass,PropertyAttributes attr)327 JSTaggedValue JSObject::GetProperty(const JSHClass *hclass, PropertyAttributes attr) const
328 {
329 if (attr.IsInlinedProps()) {
330 return GetPropertyInlinedPropsWithRep(hclass, attr.GetOffset(), attr);
331 }
332 TaggedArray *array = TaggedArray::Cast(GetProperties().GetTaggedObject());
333 return array->Get(attr.GetOffset() - hclass->GetInlinedProperties());
334 }
335
336 template <bool needBarrier>
SetProperty(const JSThread * thread,const JSHClass * hclass,PropertyAttributes attr,JSTaggedValue value)337 void JSObject::SetProperty(const JSThread *thread, const JSHClass *hclass, PropertyAttributes attr, JSTaggedValue value)
338 {
339 if (attr.IsInlinedProps()) {
340 SetPropertyInlinedProps<needBarrier>(thread, hclass, attr.GetOffset(), value);
341 } else {
342 TaggedArray *array = TaggedArray::Cast(GetProperties().GetTaggedObject());
343 array->Set<needBarrier>(thread, attr.GetOffset() - hclass->GetInlinedProperties(), value);
344 }
345 }
346
ShouldTransToDict(uint32_t capacity,uint32_t index)347 inline bool JSObject::ShouldTransToDict(uint32_t capacity, uint32_t index)
348 {
349 if (index < capacity) {
350 return false;
351 }
352
353 if (index - capacity > MAX_GAP) {
354 return true;
355 }
356
357 if (index >= static_cast<uint32_t>(INT32_MAX)) {
358 return true;
359 }
360
361 if (capacity >= MIN_GAP) {
362 return index > capacity * FAST_ELEMENTS_FACTOR;
363 }
364
365 return false;
366 }
367
ShouldTransToFastElements(JSHandle<NumberDictionary> dictionary,uint32_t capacity,uint32_t index)368 inline bool JSObject::ShouldTransToFastElements(JSHandle<NumberDictionary> dictionary,
369 uint32_t capacity, uint32_t index)
370 {
371 if (index >= static_cast<uint32_t>(INT32_MAX)) {
372 return false;
373 }
374 uint32_t dictionarySize = static_cast<uint32_t>(dictionary->GetLength());
375 // Turn fast if only saves 50% space.
376 if (dictionarySize * SHOULD_TRANS_TO_FAST_ELEMENTS_FACTOR >= capacity) {
377 return true;
378 }
379 return false;
380 }
381
ComputeElementCapacity(uint32_t oldCapacity,bool isNew)382 inline uint32_t JSObject::ComputeElementCapacity(uint32_t oldCapacity, bool isNew)
383 {
384 uint32_t newCapacity = isNew ? oldCapacity : (oldCapacity + (oldCapacity >> 1U));
385 return newCapacity > MIN_ELEMENTS_LENGTH ? newCapacity : MIN_ELEMENTS_LENGTH;
386 }
387
ComputeElementCapacityHighGrowth(uint32_t oldCapacity)388 inline uint32_t JSObject::ComputeElementCapacityHighGrowth(uint32_t oldCapacity)
389 {
390 uint32_t newCapacity = oldCapacity * 2;
391 return newCapacity > MIN_ELEMENTS_LENGTH ? newCapacity : MIN_ELEMENTS_LENGTH;
392 }
393
ComputeElementCapacityWithHint(uint32_t oldCapacity,uint32_t hint)394 inline uint32_t JSObject::ComputeElementCapacityWithHint(uint32_t oldCapacity, uint32_t hint)
395 {
396 uint32_t newCapacity = 0;
397 if ((oldCapacity >= hint) || (hint < MIN_ELEMENTS_HINT_LENGTH) || (hint >= MAX_ELEMENTS_HINT_LENGTH)) {
398 return newCapacity;
399 }
400 if ((hint / oldCapacity) <= ELEMENTS_HINT_FACTOR) {
401 newCapacity = hint;
402 }
403 return newCapacity;
404 }
405
ComputeNonInlinedFastPropsCapacity(JSThread * thread,uint32_t oldCapacity,uint32_t maxNonInlinedFastPropsCapacity)406 inline uint32_t JSObject::ComputeNonInlinedFastPropsCapacity(JSThread *thread, uint32_t oldCapacity,
407 uint32_t maxNonInlinedFastPropsCapacity)
408 {
409 uint32_t newCapacity = oldCapacity + thread->GetPropertiesGrowStep();
410 return newCapacity > maxNonInlinedFastPropsCapacity ? maxNonInlinedFastPropsCapacity : newCapacity;
411 }
412
413 // static
414 template<ElementTypes types>
CreateListFromArrayLike(JSThread * thread,const JSHandle<JSTaggedValue> & obj)415 JSHandle<JSTaggedValue> JSObject::CreateListFromArrayLike(JSThread *thread, const JSHandle<JSTaggedValue> &obj)
416 {
417 // 3. If Type(obj) is not Object, throw a TypeError exception.
418 if (!obj->IsECMAObject()) {
419 THROW_TYPE_ERROR_AND_RETURN(thread, "CreateListFromArrayLike must accept object",
420 JSHandle<JSTaggedValue>(thread, JSTaggedValue::Exception()));
421 }
422 if (obj->IsTypedArray()) {
423 uint32_t len = JSHandle<JSTypedArray>::Cast(obj)->GetArrayLength();
424 JSHandle<TaggedArray> array = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(len);
425 JSTypedArray::FastCopyElementToArray(thread, obj, array);
426 // c. ReturnIfAbrupt(next).
427 RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
428 return JSHandle<JSTaggedValue>(array);
429 }
430 // 4. Let len be ToLength(Get(obj, "length")).
431 JSHandle<JSTaggedValue> lengthKeyHandle = thread->GlobalConstants()->GetHandledLengthString();
432
433 JSHandle<JSTaggedValue> value = GetProperty(thread, obj, lengthKeyHandle).GetValue();
434 JSTaggedNumber number = JSTaggedValue::ToLength(thread, value);
435 // 5. ReturnIfAbrupt(len).
436 RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
437 if (number.GetNumber() > MAX_ELEMENT_INDEX) {
438 THROW_TYPE_ERROR_AND_RETURN(thread, "len is bigger than 2^32 - 1",
439 JSHandle<JSTaggedValue>(thread, JSTaggedValue::Exception()));
440 }
441
442 uint32_t len = number.ToUint32();
443 // 6. Let list be an empty List.
444 JSHandle<TaggedArray> array = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(len);
445 // 8. Repeat while index < len
446 for (uint32_t i = 0; i < len; i++) {
447 JSTaggedValue next = JSTaggedValue::GetProperty(thread, obj, i).GetValue().GetTaggedValue();
448 // c. ReturnIfAbrupt(next).
449 RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
450
451 if constexpr (types == ElementTypes::STRING_AND_SYMBOL) {
452 if (!next.IsString() && !next.IsSymbol()) {
453 THROW_TYPE_ERROR_AND_RETURN(thread, "CreateListFromArrayLike: not an element of elementTypes",
454 JSHandle<JSTaggedValue>(thread, JSTaggedValue::Exception()));
455 }
456 }
457
458 array->Set(thread, i, next);
459 }
460 return JSHandle<JSTaggedValue>(array);
461 }
462
ShouldGetValueFromBox(ObjectOperator * op)463 inline JSTaggedValue JSObject::ShouldGetValueFromBox(ObjectOperator *op)
464 {
465 JSTaggedValue result = op->GetValue();
466 if (result.IsPropertyBox()) {
467 result = PropertyBox::Cast(result.GetTaggedObject())->GetValue();
468 }
469 return result;
470 }
471
CheckHClassHit(const JSHandle<JSObject> & obj,const JSHandle<JSHClass> & cls)472 inline bool JSObject::CheckHClassHit(const JSHandle<JSObject> &obj, const JSHandle<JSHClass> &cls)
473 {
474 return obj->GetJSHClass() == *cls;
475 }
476
SetValuesOrEntries(JSThread * thread,const JSHandle<TaggedArray> & prop,uint32_t index,const JSHandle<JSTaggedValue> & key,const JSHandle<JSTaggedValue> & value,PropertyKind kind)477 inline uint32_t JSObject::SetValuesOrEntries(JSThread *thread, const JSHandle<TaggedArray> &prop, uint32_t index,
478 const JSHandle<JSTaggedValue> &key, const JSHandle<JSTaggedValue> &value,
479 PropertyKind kind)
480 {
481 if (kind == PropertyKind::VALUE) {
482 prop->Set(thread, index++, value);
483 return index;
484 }
485 JSHandle<TaggedArray> keyValue = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(2); // 2: key-value pair
486 keyValue->Set(thread, 0, key);
487 keyValue->Set(thread, 1, value);
488 JSHandle<JSArray> entry = JSArray::CreateArrayFromList(thread, keyValue);
489 prop->Set(thread, index++, entry.GetTaggedValue());
490 return index;
491 }
492
SetEnumCacheKind(JSThread * thread,TaggedArray * array,EnumCacheKind kind)493 inline void JSObject::SetEnumCacheKind(JSThread *thread, TaggedArray *array, EnumCacheKind kind)
494 {
495 array->Set(thread, EnumCache::ENUM_CACHE_KIND_OFFSET, JSTaggedValue(static_cast<uint8_t>(kind)));
496 }
497
GetEnumCacheKind(JSThread * thread,TaggedArray * array)498 inline EnumCacheKind JSObject::GetEnumCacheKind(JSThread *thread, TaggedArray *array)
499 {
500 return static_cast<EnumCacheKind>(array->Get(thread, EnumCache::ENUM_CACHE_KIND_OFFSET).GetInt());
501 }
502
GetEnumCacheKind(JSThread * thread,JSTaggedValue enumCache)503 inline EnumCacheKind JSObject::GetEnumCacheKind(JSThread *thread, JSTaggedValue enumCache)
504 {
505 if (enumCache.IsUndefinedOrNull()) {
506 return EnumCacheKind::NONE;
507 }
508 JSTaggedValue emptyArray = thread->GlobalConstants()->GetEmptyArray();
509 if (enumCache == emptyArray) {
510 return EnumCacheKind::SIMPLE;
511 }
512 TaggedArray *array = TaggedArray::Cast(enumCache.GetTaggedObject());
513 return JSObject::GetEnumCacheKind(thread, array);
514 }
515
GetPrototype(JSTaggedValue obj)516 inline JSTaggedValue JSObject::GetPrototype(JSTaggedValue obj)
517 {
518 JSHClass *hclass = obj.GetTaggedObject()->GetClass();
519 return hclass->GetPrototype();
520 }
521
IsDepulicateKeys(JSThread * thread,JSHandle<TaggedArray> keys,int32_t lastLength,JSHandle<TaggedQueue> shadowQueue,JSHandle<JSTaggedValue> key)522 inline bool JSObject::IsDepulicateKeys(JSThread *thread, JSHandle<TaggedArray> keys, int32_t lastLength,
523 JSHandle<TaggedQueue> shadowQueue, JSHandle<JSTaggedValue> key)
524 {
525 if (lastLength < 0) {
526 return false;
527 }
528 JSMutableHandle<JSTaggedValue> value(thread, JSTaggedValue::Undefined());
529 for (int32_t i = EnumCache::ENUM_CACHE_HEADER_SIZE; i < lastLength; i++) {
530 value.Update(keys->Get(i));
531 bool has = JSTaggedValue::Equal(thread, value, key);
532 if (has) {
533 return true;
534 }
535 }
536
537 uint32_t shadowSize = shadowQueue->Size();
538 for (uint32_t i = 0; i < shadowSize; i++) {
539 value.Update(shadowQueue->Get(i));
540 bool has = JSTaggedValue::Equal(thread, value, key);
541 if (has) {
542 return true;
543 }
544 }
545 return false;
546 }
547
ClearHasDeleteProperty(JSHandle<JSTaggedValue> object)548 inline void JSObject::ClearHasDeleteProperty(JSHandle<JSTaggedValue> object)
549 {
550 object->GetTaggedObject()->GetClass()->SetHasDeleteProperty(false);
551 }
552
GetOwnEnumerableNamesInFastMode(JSThread * thread,const JSHandle<JSObject> & obj,uint32_t * copyLengthOfKeys,uint32_t * copyLengthOfElements)553 inline std::pair<JSHandle<TaggedArray>, JSHandle<TaggedArray>> JSObject::GetOwnEnumerableNamesInFastMode(
554 JSThread *thread, const JSHandle<JSObject> &obj, uint32_t *copyLengthOfKeys, uint32_t *copyLengthOfElements)
555 {
556 ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
557 std::pair<uint32_t, uint32_t> numOfKeys = obj->GetNumberOfEnumKeys();
558 uint32_t numOfEnumKeys = numOfKeys.first;
559 uint32_t numOfElements = obj->GetNumberOfElements();
560 JSHandle<TaggedArray> elementArray = numOfElements > 0 ? JSObject::GetEnumElementKeys(
561 thread, obj, 0, numOfElements, copyLengthOfElements) : factory->EmptyArray();
562 JSHandle<TaggedArray> keyArray = numOfEnumKeys > 0 ? JSObject::GetAllEnumKeys(
563 thread, obj, numOfEnumKeys, copyLengthOfKeys) : factory->EmptyArray();
564 return std::make_pair(keyArray, elementArray);
565 }
566
HasMutantTaggedArrayElements(const JSHandle<JSObject> & obj)567 inline bool JSObject::HasMutantTaggedArrayElements(const JSHandle<JSObject> &obj)
568 {
569 return obj->GetElements().IsMutantTaggedArray();
570 }
571 } // namespace panda::ecmascript
572 #endif // ECMASCRIPT_JSOBJECT_INL_H
573