diff --git a/ecmascript/builtins/builtins_arraybuffer.cpp b/ecmascript/builtins/builtins_arraybuffer.cpp index c830126b..f99e0385 100644 --- a/ecmascript/builtins/builtins_arraybuffer.cpp +++ b/ecmascript/builtins/builtins_arraybuffer.cpp @@ -223,19 +223,9 @@ JSTaggedValue BuiltinsArrayBuffer::AllocateArrayBuffer(JSThread *thread, const J ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle arrBufFunc = env->GetArrayBufferFunction(); - JSHandle obj; - if (!newTarget->IsBoundFunction()) { - obj = factory->NewJSObjectByConstructor(JSHandle(arrBufFunc), newTarget); - // 2. ReturnIfAbrupt - RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - } else { - JSHandle prototypeKey = thread->GlobalConstants()->GetHandledPrototypeString(); - JSHandle constructTag(newTarget); - JSHandle constructProto = - JSTaggedValue::GetProperty(thread, constructTag, prototypeKey).GetValue(); - obj = JSObject::ObjectCreate(thread, JSHandle(constructProto)); - RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - } + JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(arrBufFunc), newTarget); + // 2. ReturnIfAbrupt + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. Assert: byteLength is a positive integer. ASSERT(JSTaggedValue(byteLength).IsInteger()); ASSERT(byteLength >= 0); diff --git a/test/moduletest/BUILD.gn b/test/moduletest/BUILD.gn index 7c0232d2..3890e70a 100755 --- a/test/moduletest/BUILD.gn +++ b/test/moduletest/BUILD.gn @@ -14,6 +14,7 @@ group("ark_js_moduletest") { testonly = true deps = [ + "allocatearraybuffer:allocatearraybufferAction", "async:asyncAction", "bitwiseop:bitwiseopAction", "callframe:callframeAction", diff --git a/test/moduletest/allocatearraybuffer/BUILD.gn b/test/moduletest/allocatearraybuffer/BUILD.gn new file mode 100644 index 00000000..64a1526f --- /dev/null +++ b/test/moduletest/allocatearraybuffer/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 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("//ark/js_runtime/test/test_helper.gni") + +host_moduletest_action("allocatearraybuffer") { + deps = [] +} diff --git a/test/moduletest/allocatearraybuffer/allocatearraybuffer.js b/test/moduletest/allocatearraybuffer/allocatearraybuffer.js new file mode 100644 index 00000000..d16629af --- /dev/null +++ b/test/moduletest/allocatearraybuffer/allocatearraybuffer.js @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2022 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. + */ + +var newTarget = function() {}.bind(null); +var arrayBuffer = Reflect.construct(ArrayBuffer, [16], newTarget); +print(arrayBuffer.length); \ No newline at end of file diff --git a/test/moduletest/allocatearraybuffer/expect_output.txt b/test/moduletest/allocatearraybuffer/expect_output.txt new file mode 100644 index 00000000..7645b4eb --- /dev/null +++ b/test/moduletest/allocatearraybuffer/expect_output.txt @@ -0,0 +1,14 @@ +# Copyright (c) 2021 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. + +undefined