修改JSTypedArray::FastGetPropertyByIndex当IsDetachedBuffer时不抛出异常

Change-Id: I9df9ed0b847903087114af574f9f91c242fa0980
Signed-off-by: yanpeng <yanpeng51@huawei.com>
This commit is contained in:
yanpeng 2023-12-05 19:58:55 +08:00
parent dc116a611d
commit 254e8e87e3
5 changed files with 58 additions and 2 deletions

View File

@ -650,9 +650,8 @@ JSTaggedValue JSTypedArray::FastGetPropertyByIndex(JSThread *thread, const JSTag
// Let buffer be the value of Os [[ViewedArrayBuffer]] internal slot.
JSTypedArray *typedarrayObj = JSTypedArray::Cast(typedarray.GetTaggedObject());
JSTaggedValue buffer = typedarrayObj->GetViewedArrayBufferOrByteArray();
// If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer)) {
THROW_TYPE_ERROR_AND_RETURN(thread, "Is Detached Buffer", JSTaggedValue::Exception());
return JSTaggedValue::Undefined();
}
DISALLOW_GARBAGE_COLLECTION;

View File

@ -149,6 +149,7 @@ group("ark_js_moduletest") {
"regexp",
"deregistermodule",
"getpropertybyic",
"regressbufferdetach",
"regressdate",
"objectfreeze",
]

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("regressbufferdetach") {
deps = []
}

View File

@ -0,0 +1,14 @@
# 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.
6

View File

@ -0,0 +1,24 @@
/*
* 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.
*/
delete Float64Array.prototype.__proto__[Symbol.iterator];
let a = new Float64Array(9);
Object.defineProperty(a, "length", {
get: function () {
ArkTools.arrayBufferDetach(a.buffer);
return 6;
}
});
print(Float64Array.from(a).length);