!6558 挑单5752 5802 5784 5775 5797 5795到4.0release

Merge pull request !6558 from 韩靖/OpenHarmony-4.0-Release
This commit is contained in:
openharmony_ci 2024-03-19 13:11:20 +00:00 committed by Gitee
commit bd9398543b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
14 changed files with 81 additions and 35 deletions

View File

@ -63,6 +63,7 @@ JSTaggedValue BuiltinsDate::DateConstructor(EcmaRuntimeCallInfo *argv)
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
if (objValue->IsString()) { // The value is a string object. if (objValue->IsString()) { // The value is a string object.
timeValue = JSDate::Parse(argv); timeValue = JSDate::Parse(argv);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
} else { // The value is a number. } else { // The value is a number.
JSTaggedNumber val = JSTaggedValue::ToNumber(thread, objValue); JSTaggedNumber val = JSTaggedValue::ToNumber(thread, objValue);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
@ -72,25 +73,8 @@ JSTaggedValue BuiltinsDate::DateConstructor(EcmaRuntimeCallInfo *argv)
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
} }
} else { // two or more values } else { // two or more values
std::array<int64_t, DATE_LENGTH> fields = {0, 0, 1, 0, 0, 0, 0, 0, 0}; timeValue = ExtractDateFields(thread, length, argv, timeValue);
if (length > CONSTRUCTOR_MAX_LENGTH) { // The max length is 7. RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
length = CONSTRUCTOR_MAX_LENGTH;
}
uint32_t i = 0;
for (; i < length; ++i) {
JSHandle<JSTaggedValue> value = GetCallArg(argv, i);
JSTaggedNumber res = JSTaggedValue::ToNumber(thread, value);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
double temp = res.GetNumber();
if (std::isnan(temp) || !std::isfinite(temp)) { // Check the double value is finite.
break;
}
fields[i] = static_cast<int64_t>(temp);
if (i == 0 && fields[0] >= 0 && fields[0] < JSDate::HUNDRED) {
fields[0] += JSDate::NINETEEN_HUNDRED_YEAR;
}
}
timeValue = JSTaggedValue((i == length) ? JSDate::SetDateValues(&fields, true) : base::NAN_VALUE);
} }
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
@ -482,4 +466,29 @@ JSTaggedValue BuiltinsDate::ToLocaleTimeString(EcmaRuntimeCallInfo *argv)
#endif #endif
#endif #endif
} }
JSTaggedValue BuiltinsDate::ExtractDateFields(JSThread *thread, uint32_t &length, EcmaRuntimeCallInfo *argv,
JSTaggedValue &timeValue)
{
std::array<int64_t, DATE_LENGTH> fields = {0, 0, 1, 0, 0, 0, 0, 0, 0};
if (length > CONSTRUCTOR_MAX_LENGTH) { // The max length is 7.
length = CONSTRUCTOR_MAX_LENGTH;
}
uint32_t i = 0;
for (; i < length; ++i) {
JSHandle<JSTaggedValue> value = GetCallArg(argv, i);
JSTaggedNumber res = JSTaggedValue::ToNumber(thread, value);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
double temp = JSDate::TimeClip(res.GetNumber());
if (std::isnan(temp) || !std::isfinite(temp)) { // Check the double value is finite.
break;
}
fields[i] = static_cast<int64_t>(temp);
if (i == 0 && fields[0] >= 0 && fields[0] < JSDate::HUNDRED) {
fields[0] += JSDate::NINETEEN_HUNDRED_YEAR;
}
}
timeValue = JSTaggedValue((i == length) ? JSDate::SetDateValues(&fields, true) : base::NAN_VALUE);
return timeValue;
}
} // namespace panda::ecmascript::builtins } // namespace panda::ecmascript::builtins

View File

@ -166,6 +166,8 @@ public:
static JSTaggedValue ToPrimitive(EcmaRuntimeCallInfo *argv); static JSTaggedValue ToPrimitive(EcmaRuntimeCallInfo *argv);
private: private:
static JSTaggedValue ExtractDateFields(JSThread *thread, uint32_t &length, EcmaRuntimeCallInfo *argv,
JSTaggedValue &timeValue);
// definition for set data code. // definition for set data code.
static constexpr uint32_t CODE_SET_DATE = 0x32; static constexpr uint32_t CODE_SET_DATE = 0x32;
static constexpr uint32_t CODE_SET_MILLISECONDS = 0x76; static constexpr uint32_t CODE_SET_MILLISECONDS = 0x76;

View File

@ -303,13 +303,13 @@ JSTaggedValue BuiltinsMap::AddEntriesFromIterable(JSThread *thread, const JSHand
return ret; return ret;
} }
// Let k be Get(nextItem, "0"). // Let k be Get(nextItem, "0").
JSHandle<JSTaggedValue> key = JSObject::GetProperty(thread, nextValue, keyIndex).GetValue(); JSHandle<JSTaggedValue> key = JSTaggedValue::GetProperty(thread, nextValue, keyIndex).GetValue();
// If k is an abrupt completion, return IteratorClose(iter, k). // If k is an abrupt completion, return IteratorClose(iter, k).
if (thread->HasPendingException()) { if (thread->HasPendingException()) {
return JSIterator::IteratorCloseAndReturn(thread, iter); return JSIterator::IteratorCloseAndReturn(thread, iter);
} }
// Let v be Get(nextItem, "1"). // Let v be Get(nextItem, "1").
JSHandle<JSTaggedValue> value = JSObject::GetProperty(thread, nextValue, valueIndex).GetValue(); JSHandle<JSTaggedValue> value = JSTaggedValue::GetProperty(thread, nextValue, valueIndex).GetValue();
// If v is an abrupt completion, return IteratorClose(iter, v). // If v is an abrupt completion, return IteratorClose(iter, v).
if (thread->HasPendingException()) { if (thread->HasPendingException()) {
return JSIterator::IteratorCloseAndReturn(thread, iter); return JSIterator::IteratorCloseAndReturn(thread, iter);

View File

@ -105,6 +105,7 @@ JSTaggedValue BuiltinsNumber::IsInteger(EcmaRuntimeCallInfo *argv)
double value = JSTaggedNumber(msg.GetTaggedValue()).GetNumber(); double value = JSTaggedNumber(msg.GetTaggedValue()).GetNumber();
// 3. Let integer be ToInteger(number). // 3. Let integer be ToInteger(number).
JSTaggedNumber number = JSTaggedValue::ToInteger(thread, msg); JSTaggedNumber number = JSTaggedValue::ToInteger(thread, msg);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// 4. If integer is not equal to number, return false. // 4. If integer is not equal to number, return false.
// 5. Otherwise, return true. // 5. Otherwise, return true.
result = (value == number.GetNumber()); result = (value == number.GetNumber());
@ -142,6 +143,7 @@ JSTaggedValue BuiltinsNumber::IsSafeInteger(EcmaRuntimeCallInfo *argv)
double value = JSTaggedNumber(msg.GetTaggedValue()).GetNumber(); double value = JSTaggedNumber(msg.GetTaggedValue()).GetNumber();
// 3. Let integer be ToInteger(number). // 3. Let integer be ToInteger(number).
JSTaggedNumber number = JSTaggedValue::ToInteger(thread, msg); JSTaggedNumber number = JSTaggedValue::ToInteger(thread, msg);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// 4. If integer is not equal to number, return false. // 4. If integer is not equal to number, return false.
// 5. If abs(integer) ≤ 2531, return true. // 5. If abs(integer) ≤ 2531, return true.
result = (value == number.GetNumber()) && std::abs(value) <= base::MAX_SAFE_INTEGER; result = (value == number.GetNumber()) && std::abs(value) <= base::MAX_SAFE_INTEGER;
@ -266,6 +268,7 @@ JSTaggedValue BuiltinsNumber::ToFixed(EcmaRuntimeCallInfo *argv)
// 3. Let f be ToInteger(fractionDigits). (If fractionDigits is undefined, this step produces the value 0). // 3. Let f be ToInteger(fractionDigits). (If fractionDigits is undefined, this step produces the value 0).
JSHandle<JSTaggedValue> digitArgv = GetCallArg(argv, 0); JSHandle<JSTaggedValue> digitArgv = GetCallArg(argv, 0);
JSTaggedNumber digitInt = JSTaggedValue::ToInteger(thread, digitArgv); JSTaggedNumber digitInt = JSTaggedValue::ToInteger(thread, digitArgv);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
if (digitArgv->IsUndefined()) { if (digitArgv->IsUndefined()) {
digitInt = JSTaggedNumber(0); digitInt = JSTaggedNumber(0);
} }

View File

@ -1067,6 +1067,7 @@ JSTaggedValue BuiltinsPromise::Finally(EcmaRuntimeCallInfo *argv)
JSHandle<JSObject> ctor = JSHandle<JSObject>::Cast(promise); JSHandle<JSObject> ctor = JSHandle<JSObject>::Cast(promise);
JSHandle<JSTaggedValue> promiseFunc = JSHandle<JSTaggedValue>::Cast(env->GetPromiseFunction()); JSHandle<JSTaggedValue> promiseFunc = JSHandle<JSTaggedValue>::Cast(env->GetPromiseFunction());
JSHandle<JSTaggedValue> constructor = JSObject::SpeciesConstructor(thread, ctor, promiseFunc); JSHandle<JSTaggedValue> constructor = JSObject::SpeciesConstructor(thread, ctor, promiseFunc);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
ASSERT_PRINT(constructor->IsConstructor(), "constructor is not constructor"); ASSERT_PRINT(constructor->IsConstructor(), "constructor is not constructor");
JSHandle<JSTaggedValue> thenFinally; JSHandle<JSTaggedValue> thenFinally;
JSHandle<JSTaggedValue> catchFinally; JSHandle<JSTaggedValue> catchFinally;

View File

@ -807,6 +807,10 @@ JSTaggedValue BuiltinsTypedArray::Join(EcmaRuntimeCallInfo *argv)
} }
} }
allocateLength += sepLength * (length - 1); allocateLength += sepLength * (length - 1);
if (allocateLength <= 1) {
// sep unused, set isOneByte to default(true)
isOneByte = true;
}
auto newString = EcmaStringAccessor::CreateLineString(thread->GetEcmaVM(), allocateLength, isOneByte); auto newString = EcmaStringAccessor::CreateLineString(thread->GetEcmaVM(), allocateLength, isOneByte);
int current = 0; int current = 0;
DISALLOW_GARBAGE_COLLECTION; DISALLOW_GARBAGE_COLLECTION;

View File

@ -115,7 +115,7 @@ JSTaggedValue JSArray::ArraySpeciesCreate(JSThread *thread, const JSHandle<JSObj
// Let C be Get(originalArray, "constructor"). // Let C be Get(originalArray, "constructor").
auto *hclass = originalArray->GetJSHClass(); auto *hclass = originalArray->GetJSHClass();
if (hclass->IsJSArray() && !hclass->HasConstructor()) { if (hclass->IsJSArray() && !hclass->HasConstructor()) {
return JSArray::ArrayCreate(thread, length, ArrayMode::LITERAL).GetTaggedValue(); return JSArray::ArrayCreate(thread, length).GetTaggedValue();
} }
JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString(); JSHandle<JSTaggedValue> constructorKey = globalConst->GetHandledConstructorString();
constructor = JSTaggedValue::GetProperty(thread, originalValue, constructorKey).GetValue(); constructor = JSTaggedValue::GetProperty(thread, originalValue, constructorKey).GetValue();
@ -133,7 +133,7 @@ JSTaggedValue JSArray::ArraySpeciesCreate(JSThread *thread, const JSHandle<JSObj
JSTaggedValue realmArrayConstructor = realmC->GetArrayFunction().GetTaggedValue(); JSTaggedValue realmArrayConstructor = realmC->GetArrayFunction().GetTaggedValue();
// If SameValue(C, realmC.[[intrinsics]].[[%Array%]]) is true, let C be undefined. // If SameValue(C, realmC.[[intrinsics]].[[%Array%]]) is true, let C be undefined.
if (JSTaggedValue::SameValue(constructor.GetTaggedValue(), realmArrayConstructor)) { if (JSTaggedValue::SameValue(constructor.GetTaggedValue(), realmArrayConstructor)) {
return JSArray::ArrayCreate(thread, length, ArrayMode::LITERAL).GetTaggedValue(); return JSArray::ArrayCreate(thread, length).GetTaggedValue();
} }
} }
} }
@ -147,14 +147,14 @@ JSTaggedValue JSArray::ArraySpeciesCreate(JSThread *thread, const JSHandle<JSObj
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// If C is null, let C be undefined. // If C is null, let C be undefined.
if (constructor->IsNull()) { if (constructor->IsNull()) {
return JSArray::ArrayCreate(thread, length, ArrayMode::LITERAL).GetTaggedValue(); return JSArray::ArrayCreate(thread, length).GetTaggedValue();
} }
} }
} }
// If C is undefined, return ArrayCreate(length). // If C is undefined, return ArrayCreate(length).
if (constructor->IsUndefined()) { if (constructor->IsUndefined()) {
return JSArray::ArrayCreate(thread, length, ArrayMode::LITERAL).GetTaggedValue(); return JSArray::ArrayCreate(thread, length).GetTaggedValue();
} }
// If IsConstructor(C) is false, throw a TypeError exception. // If IsConstructor(C) is false, throw a TypeError exception.
if (!constructor->IsConstructor()) { if (!constructor->IsConstructor()) {

View File

@ -1479,15 +1479,21 @@ JSHandle<BigInt> BigInt::FloorMod(JSThread *thread, JSHandle<BigInt> leftVal, JS
JSTaggedValue BigInt::AsUintN(JSThread *thread, JSTaggedNumber &bits, JSHandle<BigInt> bigint) JSTaggedValue BigInt::AsUintN(JSThread *thread, JSTaggedNumber &bits, JSHandle<BigInt> bigint)
{ {
uint32_t bit = bits.ToUint32(); JSHandle<JSTaggedValue> bitsHandle = JSHandle<JSTaggedValue>(thread, bits);
JSTaggedNumber number = JSTaggedValue::ToNumber(thread, bitsHandle);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int64_t bit = base::NumberHelper::DoubleToInt64(number.GetNumber());
if (bit == 0) { if (bit == 0) {
return Int32ToBigInt(thread, 0).GetTaggedValue(); return Int32ToBigInt(thread, 0).GetTaggedValue();
} }
if (bigint->IsZero()) { if (bigint->IsZero()) {
return bigint.GetTaggedValue(); return bigint.GetTaggedValue();
} }
JSHandle<BigInt> exponent = Uint32ToBigInt(thread, bit); JSHandle<BigInt> exponent = Uint64ToBigInt(thread, bit);
JSHandle<BigInt> base = Int32ToBigInt(thread, 2); // 2 : base value JSHandle<BigInt> base = Int64ToBigInt(thread, 2); // 2 : base value
if (bit >= kMaxLengthBits && !bigint->GetSign()) {
return bigint.GetTaggedValue();
}
JSHandle<BigInt> tValue = Exponentiate(thread, base, exponent); JSHandle<BigInt> tValue = Exponentiate(thread, base, exponent);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
return FloorMod(thread, bigint, tValue).GetTaggedValue(); return FloorMod(thread, bigint, tValue).GetTaggedValue();
@ -1495,16 +1501,22 @@ JSTaggedValue BigInt::AsUintN(JSThread *thread, JSTaggedNumber &bits, JSHandle<B
JSTaggedValue BigInt::AsintN(JSThread *thread, JSTaggedNumber &bits, JSHandle<BigInt> bigint) JSTaggedValue BigInt::AsintN(JSThread *thread, JSTaggedNumber &bits, JSHandle<BigInt> bigint)
{ {
uint32_t bit = bits.ToUint32(); JSHandle<JSTaggedValue> bitsHandle = JSHandle<JSTaggedValue>(thread, bits);
JSTaggedNumber number = JSTaggedValue::ToNumber(thread, bitsHandle);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
int64_t bit = base::NumberHelper::DoubleToInt64(number.GetNumber());
if (bit == 0) { if (bit == 0) {
return Int32ToBigInt(thread, 0).GetTaggedValue(); return Int32ToBigInt(thread, 0).GetTaggedValue();
} }
if (bigint->IsZero()) { if (bigint->IsZero()) {
return bigint.GetTaggedValue(); return bigint.GetTaggedValue();
} }
JSHandle<BigInt> exp = Int32ToBigInt(thread, bit); JSHandle<BigInt> exp = Int64ToBigInt(thread, bit);
JSHandle<BigInt> exponent = Int32ToBigInt(thread, bit - 1); JSHandle<BigInt> exponent = Int64ToBigInt(thread, bit - 1);
JSHandle<BigInt> base = Int32ToBigInt(thread, 2); // 2 : base value JSHandle<BigInt> base = Int64ToBigInt(thread, 2); // 2 : base value
if (bit >= kMaxLengthBits && !bigint->GetSign()) {
return bigint.GetTaggedValue();
}
JSHandle<BigInt> tValue = Exponentiate(thread, base, exp); JSHandle<BigInt> tValue = Exponentiate(thread, base, exp);
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
JSHandle<BigInt> modValue = FloorMod(thread, bigint, tValue); JSHandle<BigInt> modValue = FloorMod(thread, bigint, tValue);
@ -1605,7 +1617,7 @@ JSTaggedNumber BigInt::BigIntToNumber(JSHandle<BigInt> bigint)
return Rounding(sign, mantissa, exponent, true); return Rounding(sign, mantissa, exponent, true);
} }
while (index > 0) { while (index > 0) {
if (bigint->GetDigit(index--) != 0) { if (bigint->GetDigit(--index) != 0) {
return Rounding(sign, mantissa, exponent, true); return Rounding(sign, mantissa, exponent, true);
} }
} }

View File

@ -32,6 +32,7 @@ class BigInt : public TaggedObject {
public: public:
static constexpr uint32_t DATEBITS = sizeof(uint32_t) * 8; // 8 : one-bit number of bytes static constexpr uint32_t DATEBITS = sizeof(uint32_t) * 8; // 8 : one-bit number of bytes
static constexpr uint32_t MAXBITS = 1_MB; // 1 MB : Maximum space that can be opened up static constexpr uint32_t MAXBITS = 1_MB; // 1 MB : Maximum space that can be opened up
static constexpr uint32_t kMaxLengthBits = 1 << 30; // ~1 billion.
static constexpr uint32_t MAXSIZE = MAXBITS / DATEBITS; // the maximum value of size static constexpr uint32_t MAXSIZE = MAXBITS / DATEBITS; // the maximum value of size
static constexpr uint32_t MAXOCTALVALUE = 7; // 7 : max octal value static constexpr uint32_t MAXOCTALVALUE = 7; // 7 : max octal value
static constexpr uint32_t BINARY = 2; // 2 : binary static constexpr uint32_t BINARY = 2; // 2 : binary

View File

@ -408,7 +408,7 @@ void ObjectOperator::TransitionForAttributeChanged(const JSHandle<JSObject> &rec
uint32_t index = GetIndex(); uint32_t index = GetIndex();
JSHandle<GlobalDictionary> dictHandle(thread_, receiver->GetProperties()); JSHandle<GlobalDictionary> dictHandle(thread_, receiver->GetProperties());
dictHandle->SetAttributes(thread_, index, attr); dictHandle->SetAttributes(thread_, index, attr);
GlobalDictionary::InvalidatePropertyBox(thread_, dictHandle, index, attr); GlobalDictionary::InvalidatePropertyBox(thread_, dictHandle, GetIndex(), attr);
} else { } else {
uint32_t index = GetIndex(); uint32_t index = GetIndex();
if (!receiver->GetJSHClass()->IsDictionaryMode()) { if (!receiver->GetJSHClass()->IsDictionaryMode()) {

View File

@ -20,6 +20,9 @@
* @tc.require: issueI7DG0J * @tc.require: issueI7DG0J
*/ */
var number = Number(0x01000000000000080000000000000000000000n)
print(number)
try { try {
BigInt.asUintN(2147483649, -1873965464n); BigInt.asUintN(2147483649, -1873965464n);
} catch (e) { } catch (e) {
@ -69,4 +72,7 @@ let v49 = -12n;
v49--; v49--;
const v52 = (v49 >> v49).constructor; const v52 = (v49 >> v49).constructor;
const t48 = v52.__defineSetter__; const t48 = v52.__defineSetter__;
print(v52(v35)); print(v52(v35));
print(BigInt.asUintN(2**32, 42n));
print(BigInt.asIntN(2**32, 42n));

View File

@ -11,6 +11,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
2.2300745198530623e+43
test successful test successful
9007130451115262 9007130451115262
1 1
@ -21,3 +22,5 @@ RangeError
RangeError RangeError
SyntaxError SyntaxError
0 0
42
42

View File

@ -37,3 +37,4 @@ not-equal
RangeError: The sum of srcLength and targetOffset is greater than targetLength. RangeError: The sum of srcLength and targetOffset is greater than targetLength.
RangeError: The sum of srcLength and targetOffset is greater than targetLength. RangeError: The sum of srcLength and targetOffset is greater than targetLength.
RangeError: The newByteLength is out of range. RangeError: The newByteLength is out of range.
0

View File

@ -253,3 +253,7 @@ try {
} catch (error) { } catch (error) {
print(error) print(error)
} }
const v3 = String.fromCharCode(564654156456456465465)
const v5 = new Int16Array(true);
print(v5["join"](v3));