Convert properties value to match attr rep in CreateObjectFromProperties

Issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/IAGE45
Reason:the value in const pool not match with hclass
Description:when JSObject::CreateObjectFromProperties, the object
            literal value not match with attr's rep

Signed-off-by: huanghuijin <huanghuijin@huawei.com>
This commit is contained in:
huanghuijin 2024-07-29 20:56:12 +08:00
parent 39c011cc97
commit cd95704bf5
5 changed files with 29 additions and 4 deletions

View File

@ -2334,7 +2334,8 @@ void TypedBytecodeLowering::LowerCreateObjectWithBuffer(GateRef gate)
if (!converted.first) {
return;
}
inlinedProps.emplace_back(converted.second.GetRawData());
// CanOptimize.GetObject had convert value, just used directly
inlinedProps.emplace_back(value.GetRawData());
} else if (compilationEnv_ != nullptr && compilationEnv_->IsJitCompiler() && value.IsString()) {
inlinedProps.emplace_back(value.GetRawData());
} else {

View File

@ -2711,13 +2711,24 @@ JSHandle<JSObject> JSObject::CreateObjectFromProperties(const JSThread *thread,
propsLen++;
}
if (propsLen <= PropertyAttributes::MAX_FAST_PROPS_CAPACITY) {
JSHandle<JSHClass> hclass;
bool isLiteral = false;
if (ihcVal.IsJSHClass()) {
auto hclass = JSHandle<JSHClass>(thread, ihcVal);
hclass = JSHandle<JSHClass>(thread, ihcVal);
} else {
hclass = factory->GetObjectLiteralHClass(properties, propsLen);
isLiteral = true;
}
if (hclass->IsTS()) {
if (CheckPropertiesForRep(properties, propsLen, hclass)) {
return CreateObjectFromPropertiesByIHClass(thread, properties, propsLen, hclass);
} else if (!isLiteral) {
hclass = factory->GetObjectLiteralHClass(properties, propsLen);
// if check failed, get literal object again
return CreateObjectFromPropertiesByIHClass(thread, properties, propsLen, hclass);
}
}
return CreateObjectFromProperties(thread, properties, propsLen);
return CreateObjectFromProperties(thread, hclass, properties, propsLen);
} else {
JSHandle<JSObject> obj = factory->NewEmptyJSObject(0); // 0: no inline field
JSHClass::TransitionToDictionary(thread, obj);
@ -2741,11 +2752,11 @@ JSHandle<JSObject> JSObject::CreateObjectFromProperties(const JSThread *thread,
}
JSHandle<JSObject> JSObject::CreateObjectFromProperties(const JSThread *thread,
const JSHandle<JSHClass> &hclass,
const JSHandle<TaggedArray> &properties,
uint32_t propsLen)
{
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
auto hclass = factory->GetObjectLiteralHClass(properties, propsLen);
JSHandle<JSObject> obj = factory->NewOldSpaceObjLiteralByHClass(hclass);
ASSERT_PRINT(obj->IsECMAObject(), "Obj is not a valid object");

View File

@ -656,6 +656,7 @@ public:
const JSHandle<TaggedArray> &properties,
JSTaggedValue ihc = JSTaggedValue::Undefined());
static JSHandle<JSObject> CreateObjectFromProperties(const JSThread *thread,
const JSHandle<JSHClass> &hclass,
const JSHandle<TaggedArray> &properties,
uint32_t propsLen);
static JSHandle<JSObject> CreateObjectFromPropertiesByIHClass(const JSThread *thread,

View File

@ -41,3 +41,14 @@ class A {
let a = new A();
a.Measure();
const o46 = {
3503: 4096,
"maxByteLength": 4096,
};
const o48 = {
"maxByteLength": 3012855560,
};
print(o46[3503]);

View File

@ -14,3 +14,4 @@
1
str
11.1
4096