Lines Matching refs:thread
24 JSTaggedValue JSArray::LengthGetter([[maybe_unused]] JSThread *thread, const JSHandle<JSObject> &self)
29 bool JSArray::LengthSetter(JSThread *thread, const JSHandle<JSObject> &self, const JSHandle<JSTaggedValue> &value,
33 if (!JSTaggedValue::ToArrayLength(thread, value, &newLen) && mayThrow) {
34 RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false);
42 if (!IsArrayLengthWritable(thread, self)) {
44 THROW_TYPE_ERROR_AND_RETURN(thread, GET_MESSAGE_STRING(SetReadOnlyProperty), false);
49 JSArray::SetCapacity(thread, self, oldLen, newLen);
53 THROW_TYPE_ERROR_AND_RETURN(thread, "Not all array elements is configurable", false);
61 JSHandle<JSTaggedValue> JSArray::ArrayCreate(JSThread *thread, JSTaggedNumber length, ArrayMode mode)
63 JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
65 return JSArray::ArrayCreate(thread, length, arrayFunction, mode);
69 JSHandle<JSTaggedValue> JSArray::ArrayCreate(JSThread *thread, JSTaggedNumber length,
72 ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
78 JSHandle<JSTaggedValue> exception(thread, JSTaggedValue::Exception());
79 THROW_RANGE_ERROR_AND_RETURN(thread, "array length must equal or less than 2^32.", exception);
84 JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
87 RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
94 JSArray::Cast(*obj)->SetArrayLength(thread, normalArrayLength);
96 JSArray::SetCapacity(thread, obj, 0, normalArrayLength, true);
100 if (thread->GetEcmaVM()->IsEnableElementsKind()) {
104 JSHClass::TransitToElementsKind(thread, newArray, ElementsKind::GENERIC);
106 JSHClass::TransitToElementsKind(thread, newArray, ElementsKind::HOLE);
115 JSTaggedValue JSArray::ArraySpeciesCreate(JSThread *thread, const JSHandle<JSObject> &originalArray,
118 JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
119 const GlobalEnvConstants *globalConst = thread->GlobalConstants();
130 bool isArray = originalValue->IsArray(thread);
132 RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
134 JSHandle<JSTaggedValue> constructor(thread, JSTaggedValue::Undefined());
140 return JSArray::ArrayCreate(thread, length).GetTaggedValue();
143 constructor = JSTaggedValue::GetProperty(thread, originalValue, constructorKey).GetValue();
145 RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
150 JSHandle<GlobalEnv> realmC = JSObject::GetFunctionRealm(thread, constructor);
152 RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
158 return JSArray::ArrayCreate(thread, length).GetTaggedValue();
167 constructor = JSTaggedValue::GetProperty(thread, constructor, speciesSymbol).GetValue();
169 RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
172 return JSArray::ArrayCreate(thread, length).GetTaggedValue();
179 return JSArray::ArrayCreate(thread, length).GetTaggedValue();
183 THROW_TYPE_ERROR_AND_RETURN(thread, "Not a constructor", JSTaggedValue::Exception());
186 JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
188 EcmaInterpreter::NewRuntimeCallInfo(thread, constructor, undefined, undefined, 1);
189 RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception());
192 RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
202 void JSArray::SetCapacity(JSThread *thread, const JSHandle<JSObject> &array,
208 ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
213 JSHandle<NumberDictionary> dictHandle(thread, element);
215 GetAllElementKeys(thread, array, 0, newArr);
225 JSHandle<NumberDictionary> newDict = NumberDictionary::Remove(thread, dictHandle, entry);
226 array->SetElements(thread, newDict);
237 JSArray::Cast(*array)->SetArrayLength(thread, newNumOfElements);
244 CheckAndCopyArray(thread, JSHandle<JSArray>(array));
245 array->FillElementsWithHoles(thread, newLen, oldLen < capacity ? oldLen : capacity);
248 JSObject::ElementsToDictionary(thread, array);
250 JSObject::GrowElementsCapacity(thread, array, newLen, isNew);
252 JSArray::Cast(*array)->SetArrayLength(thread, newLen);
273 JSHandle<TaggedArray> newTaggedArray = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(oldElementsLength);
274 array->SetElements(thread, newTaggedArray);
275 if (!JSHClass::TransitToElementsKindUncheck(thread, array, newKind)) {
279 if (JSHClass::TransitToElementsKindUncheck(thread, array, newKind)) {
280 Elements::MigrateArrayWithKind(thread, array, oldKind, newKind);
290 bool JSArray::ArraySetLength(JSThread *thread, const JSHandle<JSObject> &array, const PropertyDescriptor &desc)
292 JSHandle<JSTaggedValue> lengthKeyHandle(thread->GlobalConstants()->GetHandledLengthString());
297 return JSObject::OrdinaryDefineOwnProperty(thread, array, lengthKeyHandle, desc);
304 if (!JSTaggedValue::ToArrayLength(thread, desc.GetValue(), &newLen)) {
305 THROW_RANGE_ERROR_AND_RETURN(thread, "array length must equal or less than 2^32.", false);
310 PropertyDescriptor oldLenDesc(thread);
311 [[maybe_unused]] bool success = GetOwnProperty(thread, array, lengthKeyHandle, oldLenDesc);
317 JSTaggedValue::ToArrayLength(thread, oldLenDesc.GetValue(), &oldLen);
322 newLenDesc.SetValue(JSHandle<JSTaggedValue>(thread, JSTaggedValue(newLen)));
323 return JSObject::OrdinaryDefineOwnProperty(thread, array, lengthKeyHandle, newLenDesc);
349 JSArray::SetCapacity(thread, array, oldLen, newLen);
352 PropertyDescriptor readonly(thread);
354 success = JSObject::DefineOwnProperty(thread, array, lengthKeyHandle, readonly);
363 bool JSArray::PropertyKeyToArrayIndex(JSThread *thread, const JSHandle<JSTaggedValue> &key, uint32_t *output)
365 return JSTaggedValue::ToArrayLength(thread, key, output) && *output <= JSArray::MAX_ARRAY_INDEX;
369 bool JSArray::DefineOwnProperty(JSThread *thread, const JSHandle<JSObject> &array, const JSHandle<JSTaggedValue> &key,
375 if (IsLengthString(thread, key)) {
377 return ArraySetLength(thread, array, desc);
382 bool success = JSObject::OrdinaryDefineOwnProperty(thread, array, key, desc);
384 JSTaggedValue constructorKey = thread->GlobalConstants()->GetConstructorString();
393 bool JSArray::DefineOwnProperty(JSThread *thread, const JSHandle<JSObject> &array, uint32_t index,
396 return JSObject::OrdinaryDefineOwnProperty(thread, array, index, desc);
399 bool JSArray::IsLengthString(JSThread *thread, const JSHandle<JSTaggedValue> &key)
401 return key.GetTaggedValue() == thread->GlobalConstants()->GetLengthString();
405 JSHandle<JSArray> JSArray::CreateArrayFromList(JSThread *thread, const JSHandle<TaggedArray> &elements)
412 auto env = thread->GetEcmaVM()->GetGlobalEnv();
413 ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
417 JSArray::Cast(*obj)->SetArrayLength(thread, length);
419 obj->SetElements(thread, elements);
421 JSHClass::TransitToElementsKind(thread, arr, ElementsKind::GENERIC);
427 JSHandle<JSArray> JSArray::CreateArrayFromList(JSThread *thread, const JSHandle<JSTaggedValue> &newtarget,
434 auto env = thread->GetEcmaVM()->GetGlobalEnv();
435 ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
438 RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSArray, thread);
443 arr->SetArrayLength(thread, length);
444 obj->SetElements(thread, elements);
449 JSHandle<JSTaggedValue> JSArray::FastGetPropertyByValue(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
452 auto result = ObjectFastOperator::FastGetPropertyByIndex(thread, obj.GetTaggedValue(), index);
453 RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
454 return JSHandle<JSTaggedValue>(thread, result);
457 JSHandle<JSTaggedValue> JSArray::FastGetPropertyByValue(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
460 auto result = ObjectFastOperator::FastGetPropertyByValue(thread, obj.GetTaggedValue(), key.GetTaggedValue());
461 RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread);
462 return JSHandle<JSTaggedValue>(thread, result);
465 bool JSArray::FastSetPropertyByValue(JSThread *thread, const JSHandle<JSTaggedValue> &obj, uint32_t index,
468 return ObjectFastOperator::FastSetPropertyByIndex(thread, obj.GetTaggedValue(), index, value.GetTaggedValue());
471 bool JSArray::FastSetPropertyByValue(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
474 return ObjectFastOperator::FastSetPropertyByValue(thread, obj.GetTaggedValue(), key.GetTaggedValue(),
478 bool JSArray::TryFastCreateDataProperty(JSThread *thread, const JSHandle<JSObject> &obj, uint32_t index,
482 if (!objVal->IsStableJSArray(thread)) {
484 return JSObject::CreateDataPropertyOrThrow(thread, obj, index, value, sCheckMode);
492 return JSObject::CreateDataPropertyOrThrow(thread, obj, index, value, sCheckMode);
497 if (!IsArrayLengthWritable(thread, obj)) {
498 THROW_TYPE_ERROR_AND_RETURN(thread, "UnWritable ArrayLength", false);
504 return JSObject::CreateDataPropertyOrThrow(thread, obj, index, value, sCheckMode);
506 JSHandle<JSArray>::Cast(obj)->SetArrayLength(thread, newLen);
509 TaggedArray::Cast(obj->GetElements())->Set(thread, index, value);
514 JSTaggedValue JSArray::Sort(JSThread *thread, const JSHandle<JSTaggedValue> &obj, const JSHandle<JSTaggedValue> &fn)
518 int64_t len = ArrayHelper::GetArrayLength(thread, obj);
520 RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
531 ArrayHelper::SortIndexedProperties(thread, obj, len, fn, base::HolesType::SKIP_HOLES);
532 RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
541 JSMutableHandle<JSTaggedValue> item(thread, JSTaggedValue::Undefined());
544 JSArray::FastSetPropertyByValue(thread, obj, j, item);
545 RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
555 JSTaggedValue::DeletePropertyOrThrow(thread, obj, item);
556 RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
563 void JSArray::SortElements(JSThread *thread, const JSHandle<TaggedArray> &elements, const JSHandle<JSTaggedValue> &fn)
570 SortElementsByInsertionSort(thread, elements, len, fn);
572 SortElementsByMergeSort(thread, elements, fn, 0, len - 1);
576 void JSArray::SortElementsByMergeSort(JSThread *thread, const JSHandle<TaggedArray> &elements,
583 SortElementsByMergeSort(thread, elements, fn, startIdx, middleIdx);
584 SortElementsByMergeSort(thread, elements, fn, middleIdx + 1, endIdx);
585 MergeSortedElements(thread, elements, fn, startIdx, middleIdx, endIdx);
588 void JSArray::MergeSortedElements(JSThread *thread, const JSHandle<TaggedArray> &elements,
595 ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
600 leftArray->Set(thread, i, elements->Get(startIdx + i));
603 rightArray->Set(thread, j, elements->Get(static_cast<int32_t>(middleIdx + 1 + j)));
609 JSMutableHandle<JSTaggedValue> leftValue(thread, JSTaggedValue::Undefined());
610 JSMutableHandle<JSTaggedValue> rightValue(thread, JSTaggedValue::Undefined());
614 int64_t compareRet = base::ArrayHelper::SortCompare(thread, fn, leftValue, rightValue);
615 RETURN_IF_ABRUPT_COMPLETION(thread);
617 elements->Set(thread, k, leftArray->Get(i));
620 elements->Set(thread, k, rightArray->Get(j));
627 elements->Set(thread, k, leftArray->Get(i));
633 elements->Set(thread, k, rightArray->Get(j));
639 void JSArray::SortElementsByInsertionSort(JSThread *thread, const JSHandle<TaggedArray> &elements, uint32_t len,
645 JSMutableHandle<JSTaggedValue> presentValue(thread, JSTaggedValue::Undefined());
646 JSMutableHandle<JSTaggedValue> middleValue(thread, JSTaggedValue::Undefined());
647 JSMutableHandle<JSTaggedValue> previousValue(thread, JSTaggedValue::Undefined());
655 double compareResult = base::ArrayHelper::SortCompare(thread, fn, middleValue, presentValue);
656 RETURN_IF_ABRUPT_COMPLETION(thread);
667 elements->Set(thread, j, previousValue);
669 elements->Set(thread, endIndex, presentValue);
674 void JSArray::SortElementsByObject(JSThread *thread, const JSHandle<JSObject> &thisObjHandle,
679 JSMutableHandle<JSTaggedValue> presentValue(thread, JSTaggedValue::Undefined());
680 JSMutableHandle<JSTaggedValue> middleValue(thread, JSTaggedValue::Undefined());
681 JSMutableHandle<JSTaggedValue> previousValue(thread, JSTaggedValue::Undefined());
690 int32_t compareResult = base::ArrayHelper::SortCompare(thread, fn, middleValue, presentValue);
691 RETURN_IF_ABRUPT_COMPLETION(thread);
702 ElementAccessor::Set(thread, thisObjHandle, j, previousValue, false);
704 ElementAccessor::Set(thread, thisObjHandle, endIndex, presentValue, false);
709 bool JSArray::IncludeInSortedValue(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
722 JSHandle<JSTaggedValue> vv = JSArray::FastGetPropertyByValue(thread, obj, middle);
723 ComparisonResult res = JSTaggedValue::Compare(thread, vv, value);
735 JSHandle<TaggedArray> JSArray::ToTaggedArray(JSThread *thread, const JSHandle<JSTaggedValue> &obj)
740 ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
743 JSHandle<JSTaggedValue> vv = JSArray::FastGetPropertyByValue(thread, obj, idx);
744 taggedArray->Set(thread, idx, vv);
749 void JSArray::CheckAndCopyArray(const JSThread *thread, JSHandle<JSArray> obj)
751 JSHandle<TaggedArray> arr(thread, obj->GetElements());
754 ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
758 obj->SetElements(thread, newArray.GetTaggedValue());
760 JSHandle<TaggedArray> prop(thread, obj->GetProperties());
764 obj->SetProperties(thread, newProps.GetTaggedValue());