!7989 Cherry-pick 7831 7446 7435to 4.1Release

Merge pull request !7989 from 贺存茂/CherryPick
This commit is contained in:
openharmony_ci 2024-07-11 10:52:52 +00:00 committed by Gitee
commit a2cc2f609e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
13 changed files with 98 additions and 45 deletions

View File

@ -648,6 +648,7 @@ bool JsonStringifier::SerializeKeys(const JSHandle<JSObject> &obj, const JSHandl
if (JSObject::GetEnumCacheKind(thread_, enumCache) == EnumCacheKind::ONLY_OWN_KEYS) {
JSHandle<TaggedArray> cache(thread_, enumCache);
uint32_t length = cache->GetLength();
uint32_t dictStart = length;
for (uint32_t i = 0; i < length; i++) {
JSTaggedValue key = cache->Get(i);
if (!key.IsString()) {
@ -669,11 +670,40 @@ bool JsonStringifier::SerializeKeys(const JSHandle<JSObject> &obj, const JSHandl
value = JSObject::CallGetter(thread_, AccessorData::Cast(value.GetTaggedObject()),
JSHandle<JSTaggedValue>(obj));
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false);
if (obj->GetProperties().IsDictionary()) {
dictStart = i;
handleValue_.Update(value);
hasContent = JsonStringifier::AppendJsonString(obj, replacer, hasContent);
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false);
break;
}
}
handleValue_.Update(value);
hasContent = JsonStringifier::AppendJsonString(obj, replacer, hasContent);
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false);
}
if (dictStart < length) {
propertiesArr = JSHandle<TaggedArray>(thread_, obj->GetProperties());
JSHandle<NameDictionary> nameDic(propertiesArr);
for (uint32_t i = dictStart + 1;i < length; i++) {
JSTaggedValue key = cache->Get(i);
int hashIndex = nameDic->FindEntry(key);
PropertyAttributes attr = nameDic->GetAttributes(hashIndex);
if (!key.IsString() || hashIndex < 0 || !attr.IsEnumerable()) {
continue;
}
handleKey_.Update(key);
JSTaggedValue value = nameDic->GetValue(hashIndex);
if (UNLIKELY(value.IsAccessor())) {
value = JSObject::CallGetter(thread_, AccessorData::Cast(value.GetTaggedObject()),
JSHandle<JSTaggedValue>(obj));
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false);
}
handleValue_.Update(value);
hasContent = JsonStringifier::AppendJsonString(obj, replacer, hasContent);
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread_, false);
}
}
return hasContent;
}
int end = static_cast<int>(jsHclass->NumberOfProps());

View File

@ -1315,6 +1315,10 @@ JSTaggedValue BuiltinsArray::Join(EcmaRuntimeCallInfo *argv)
if (k > 0) {
concatStr.append(sepStr);
}
if (concatStr.size() > EcmaString::MAX_STRING_LENGTH) {
context->JoinStackPopFastPath(thisHandle);
THROW_RANGE_ERROR_AND_RETURN(thread, "Invalid string length", JSTaggedValue::Exception());
}
concatStr.append(nextStr);
}

View File

@ -138,7 +138,6 @@ JSTaggedValue BuiltinsReflect::ReflectGet(EcmaRuntimeCallInfo *argv)
if (!val->IsECMAObject()) {
THROW_TYPE_ERROR_AND_RETURN(thread, "Reflect.get target is not object", JSTaggedValue::Exception());
}
JSHandle<JSObject> target = JSHandle<JSObject>::Cast(val);
// 2. Let key be ? ToPropertyKey(propertyKey).
JSHandle<JSTaggedValue> key = JSTaggedValue::ToPropertyKey(thread, GetCallArg(argv, 1));
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
@ -146,10 +145,10 @@ JSTaggedValue BuiltinsReflect::ReflectGet(EcmaRuntimeCallInfo *argv)
// a. Set receiver to target.
// 4. Return ? target.[[Get]](key, receiver).
if (argv->GetArgsNumber() == 2) { // 2: 2 means that there are 2 args in total
return JSObject::GetProperty(thread, target, key).GetValue().GetTaggedValue();
return JSTaggedValue::GetProperty(thread, val, key).GetValue().GetTaggedValue();
}
JSHandle<JSTaggedValue> receiver = GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD);
return JSObject::GetProperty(thread, val, key, receiver).GetValue().GetTaggedValue();
return JSTaggedValue::GetProperty(thread, val, key, receiver).GetValue().GetTaggedValue();
}
// ecma 26.1.6 Reflect.getOwnPropertyDescriptor ( target, propertyKey )

View File

@ -795,7 +795,7 @@ JSTaggedValue BuiltinsTypedArray::Join(EcmaRuntimeCallInfo *argv)
const GlobalEnvConstants *globalConst = thread->GlobalConstants();
return globalConst->GetEmptyString();
}
size_t allocateLength = 0;
uint64_t allocateLength = 0;
bool isOneByte = (sep != BuiltinsTypedArray::SeparatorFlag::MINUS_ONE) ||
EcmaStringAccessor(sepStringHandle).IsUtf8();
CVector<JSHandle<EcmaString>> vec;
@ -820,7 +820,10 @@ JSTaggedValue BuiltinsTypedArray::Join(EcmaRuntimeCallInfo *argv)
vec.push_back(JSHandle<EcmaString>(globalConst->GetHandledEmptyString()));
}
}
allocateLength += sepLength * (length - 1);
allocateLength += static_cast<uint64_t>(sepLength) * (length - 1);
if (allocateLength > EcmaString::MAX_STRING_LENGTH) {
THROW_RANGE_ERROR_AND_RETURN(thread, "Invalid string length", JSTaggedValue::Exception());
}
if (allocateLength <= 1) {
// sep unused, set isOneByte to default(true)
isOneByte = true;

View File

@ -86,7 +86,6 @@ HWTEST_F_L0(BuiltinsNumberFormatTest, NumberFormatConstructor)
static JSTaggedValue BuiltinsFormatTest(JSThread *thread, JSHandle<JSObject> &options,
JSHandle<JSTaggedValue> &number, JSHandle<JSTaggedValue> &locale)
{
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
JSHandle<JSFunction> newTarget(env->GetNumberFormatFunction());
@ -109,20 +108,13 @@ static JSTaggedValue BuiltinsFormatTest(JSThread *thread, JSHandle<JSObject> &op
JSTaggedValue resultFunc = BuiltinsNumberFormat::Format(ecmaRuntimeCallInfo2);
JSHandle<JSFunction> jsFunction(thread, resultFunc);
TestHelper::TearDownFrame(thread, prev);
JSArray *jsArray =
JSArray::Cast(JSArray::ArrayCreate(thread, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject());
JSHandle<JSObject> jsObject(thread, jsArray);
PropertyDescriptor desc(thread, JSHandle<JSTaggedValue>(jsFunction), true, true, true);
JSHandle<JSTaggedValue> joinKey(factory->NewFromASCII("join"));
JSArray::DefineOwnProperty(thread, jsObject, joinKey, desc);
auto ecmaRuntimeCallInfo3 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6);
ecmaRuntimeCallInfo3->SetFunction(JSTaggedValue::Undefined());
ecmaRuntimeCallInfo3->SetThis(jsObject.GetTaggedValue());
ecmaRuntimeCallInfo3->SetFunction(jsFunction.GetTaggedValue());
ecmaRuntimeCallInfo3->SetThis(jsFunction.GetTaggedValue());
ecmaRuntimeCallInfo3->SetCallArg(0, number.GetTaggedValue());
prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3);
JSTaggedValue result = BuiltinsArray::ToString(ecmaRuntimeCallInfo3);
JSTaggedValue result = JSFunction::Call(ecmaRuntimeCallInfo3);
TestHelper::TearDownFrame(thread, prev);
return result;
}

View File

@ -1656,18 +1656,18 @@ GateRef StubBuilder::LoadGlobal(GateRef cell)
Label entry(env);
env->SubCfgEntry(&entry);
Label exit(env);
Label cellIsInvalid(env);
Label cellNotInvalid(env);
Label cellNotAccessor(env);
DEFVARIABLE(result, VariableType::JS_ANY(), Hole());
Branch(IsInvalidPropertyBox(cell), &cellIsInvalid, &cellNotInvalid);
Bind(&cellIsInvalid);
{
Jump(&exit);
}
Branch(IsInvalidPropertyBox(cell), &exit, &cellNotInvalid);
Bind(&cellNotInvalid);
{
result = GetValueFromPropertyBox(cell);
Jump(&exit);
Branch(IsAccessorPropertyBox(cell), &exit, &cellNotAccessor);
Bind(&cellNotAccessor);
{
result = GetValueFromPropertyBox(cell);
Jump(&exit);
}
}
Bind(&exit);
auto ret = *result;
@ -2405,27 +2405,19 @@ GateRef StubBuilder::StoreGlobal(GateRef glue, GateRef value, GateRef cell)
Label entry(env);
env->SubCfgEntry(&entry);
Label exit(env);
Label cellIsInvalid(env);
Label cellNotInvalid(env);
Label cellIsAccessorData(env);
Label cellIsNotAccessorData(env);
DEFVARIABLE(result, VariableType::JS_ANY(), Hole());
Branch(IsInvalidPropertyBox(cell), &cellIsInvalid, &cellNotInvalid);
Bind(&cellIsInvalid);
{
Jump(&exit);
}
Branch(IsInvalidPropertyBox(cell), &exit, &cellNotInvalid);
Bind(&cellNotInvalid);
Branch(IsAccessorPropertyBox(cell), &cellIsAccessorData, &cellIsNotAccessorData);
Bind(&cellIsAccessorData);
{
Jump(&exit);
}
Bind(&cellIsNotAccessorData);
{
Store(VariableType::JS_ANY(), glue, cell, IntPtr(PropertyBox::VALUE_OFFSET), value);
result = Undefined();
Jump(&exit);
Branch(IsAccessorPropertyBox(cell), &exit, &cellIsNotAccessorData);
Bind(&cellIsNotAccessorData);
{
Store(VariableType::JS_ANY(), glue, cell, IntPtr(PropertyBox::VALUE_OFFSET), value);
result = Undefined();
Jump(&exit);
}
}
Bind(&exit);
auto ret = *result;

View File

@ -257,7 +257,7 @@ JSTaggedValue JSStableArray::Join(JSHandle<JSArray> receiver, EcmaRuntimeCallInf
return globalConst->GetEmptyString();
}
JSHandle<JSObject> obj(thread, receiverValue.GetTaggedValue());
size_t allocateLength = 0;
uint64_t allocateLength = 0;
bool isOneByte = (sep != JSStableArray::SeparatorFlag::MINUS_ONE) || EcmaStringAccessor(sepStringHandle).IsUtf8();
CVector<JSHandle<EcmaString>> vec;
JSMutableHandle<JSTaggedValue> elementHandle(thread, JSTaggedValue::Undefined());
@ -293,9 +293,14 @@ JSTaggedValue JSStableArray::Join(JSHandle<JSArray> receiver, EcmaRuntimeCallInf
}
}
if (len > 0) {
allocateLength += sepLength * (len - 1);
allocateLength += static_cast<uint64_t>(sepLength) * (len - 1);
}
auto newString = EcmaStringAccessor::CreateLineString(thread->GetEcmaVM(), allocateLength, isOneByte);
if (allocateLength > EcmaString::MAX_STRING_LENGTH) {
context->JoinStackPopFastPath(receiverValue);
THROW_RANGE_ERROR_AND_RETURN(thread, "Invalid string length", JSTaggedValue::Exception());
}
auto newString =
EcmaStringAccessor::CreateLineString(thread->GetEcmaVM(), static_cast<size_t>(allocateLength), isOneByte);
int current = 0;
DISALLOW_GARBAGE_COLLECTION;
for (uint32_t k = 0; k < len; k++) {

View File

@ -29,4 +29,7 @@ var tag2 = Reflect.set(y, 'length', 5);
print(tag1);
print(tag2);
print("builtins reflect end");
let obj = {name:"tom"};
let pxobj = new Proxy(obj,{});
print(Reflect.get(pxobj,"name"))
print("builtins reflect end");

View File

@ -136,4 +136,5 @@ builtins object add property end
builtins reflect start
false
true
tom
builtins reflect end

View File

@ -26,3 +26,4 @@ test successful
{"a":"delete","b":{}}
{"a":"delete","b":{}}
end JSON.stringify(globalThis)
{"a":"a","b":"b"}

View File

@ -125,3 +125,13 @@ Reflect.defineProperty(globalThis,"c",{
Reflect.set(globalThis,"d","d");
JSON.stringify(globalThis);
print("end JSON.stringify(globalThis)")
let obj1 = {
get a() {
this[102400] = 1;
return "a";
},
b: "b",
}
Object.keys(obj1);
print(JSON.stringify(obj1));

View File

@ -13,3 +13,6 @@
false
number ic load success
1
1
load global ic with accessor success!

View File

@ -86,4 +86,14 @@ for (let i = 0; i < 50; i++)
str.h;
}
print("number ic load success")
print("number ic load success")
function f(){return 1};
Object.defineProperty(this,"g",{
get:f,
set:f,
})
for(let i=0;i<2;i++){
print(g)
}
print("load global ic with accessor success!");