Reason:fix bug for defineProperties

Issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I8S67S?from=project-issue

Signed-off-by: wupengyong <wupengyong@huawei.com>
Change-Id: I3bc137a1f618b732073754b65643749ab4f0e0f2
This commit is contained in:
wupengyong 2023-12-28 20:17:29 +08:00
parent 858eb06b80
commit 3bc87f2bf4
6 changed files with 116 additions and 13 deletions

View File

@ -203,10 +203,11 @@ JSTaggedValue BuiltinsObject::ObjectDefineProperties(JSThread *thread, const JSH
// iii.Let desc be ToPropertyDescriptor(descObj).
// iv.ReturnIfAbrupt(desc).
// v.Append the pair (a two element List) consisting of nextKey and desc to the end of descriptors.
JSMutableHandle<JSTaggedValue> handleKey(thread, JSTaggedValue::Undefined());
std::vector<PropertyDescriptor> desArr;
for (uint32_t i = 0; i < length; i++) {
PropertyDescriptor propDesc(thread);
handleKey.Update(handleKeys->Get(i));
JSHandle<JSTaggedValue> handleKey(thread, handleKeys->Get(i));
bool success = JSTaggedValue::GetOwnProperty(thread, JSHandle<JSTaggedValue>::Cast(props), handleKey, propDesc);
// ReturnIfAbrupt(propDesc)
@ -220,22 +221,25 @@ JSTaggedValue BuiltinsObject::ObjectDefineProperties(JSThread *thread, const JSH
PropertyDescriptor desc(thread);
JSObject::ToPropertyDescriptor(thread, descObj, desc);
// ReturnIfAbrupt(desc)
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
// 8.For each pair from descriptors in list order,
// a.Let P be the first element of pair.
// b.Let desc be the second element of pair.
// c.Let status be DefinePropertyOrThrow(O,P, desc).
// d.ReturnIfAbrupt(status).
[[maybe_unused]] bool setSuccess = JSTaggedValue::DefinePropertyOrThrow(thread, obj, handleKey, desc);
// ReturnIfAbrupt(status)
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
desc.SetKey(handleKey);
desArr.emplace_back(desc);
}
}
uint32_t desLength = desArr.size();
for (uint32_t i = 0; i < desLength; i++) {
// 8.For each pair from descriptors in list order,
// a.Let P be the first element of pair.
// b.Let desc be the second element of pair.
// c.Let status be DefinePropertyOrThrow(O,P, desc).
// d.ReturnIfAbrupt(status).
[[maybe_unused]] bool setSuccess =
JSTaggedValue::DefinePropertyOrThrow(thread, obj, desArr[i].GetKey(), desArr[i]);
// ReturnIfAbrupt(status)
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
}
// 9.Return O.
return obj.GetTaggedValue();
}

View File

@ -91,11 +91,24 @@ public:
return value_;
}
inline JSHandle<JSTaggedValue> GetKey() const
{
if (key_.IsEmpty()) {
return JSHandle<JSTaggedValue>(thread_, JSTaggedValue::Undefined());
}
return key_;
}
inline void SetValue(JSHandle<JSTaggedValue> value)
{
value_ = value;
}
inline void SetKey(JSHandle<JSTaggedValue> key)
{
key_ = key;
}
inline void SetTrackType(TrackType trackType)
{
trackType_ = trackType;
@ -235,6 +248,7 @@ private:
JSHandle<JSTaggedValue> value_ {};
JSHandle<JSTaggedValue> getter_ {};
JSHandle<JSTaggedValue> setter_ {};
JSHandle<JSTaggedValue> key_ {};
};
enum class ElementTypes { ALLTYPES, STRING_AND_SYMBOL };

View File

@ -107,6 +107,7 @@ group("ark_js_moduletest") {
"negintmin",
"newobjdynrange",
"objectcloneproperties",
"objectdefineproperties",
"objecthasownproperty",
"objectkeys",
"objoperate",

View File

@ -0,0 +1,18 @@
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_runtime/test/test_helper.gni")
host_moduletest_action("objectdefineproperties") {
deps = []
}

View File

@ -0,0 +1,19 @@
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
TypeError: either Value or Writable is present
undefined
undefined
1
2
3

View File

@ -0,0 +1,47 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* @tc.name:fromCharCode
* @tc.desc:test String.fromCharCode and charat
* @tc.type: FUNC
* @tc.require: issueI5NO8G
*/
var obj = {};
try {
Object.defineProperties(obj, {
foo: {value:1},
bar: {value:2, get:function() {return 3;}}
});
} catch (e) {
print(e)
}
print(obj.foo);
print(obj.bar);
var obj1 = {};
try {
Object.defineProperties(obj1, {
foo: {value:1},
bar: {value:2, enumerable:false},
hhh: {value:3, enumerable:true, writable:false},
});
} catch (e) {
print(e)
}
print(obj1.foo);
print(obj1.bar);
print(obj1.hhh);