Bugfix on JSBoundFunction::ConstructInternal when target is not constructor

Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I8TAOP

Signed-off-by: chenjx-huawei <chenjingxiang1@huawei.com>
Change-Id: I7bf87364181488ea062e717ab1ade11cce491426
This commit is contained in:
chenjx-huawei 2024-01-03 16:12:21 +08:00
parent b5141dc676
commit f77921abd5
3 changed files with 12 additions and 1 deletions

View File

@ -648,6 +648,9 @@ JSTaggedValue JSBoundFunction::ConstructInternal(EcmaRuntimeCallInfo *info)
JSThread *thread = info->GetThread();
JSHandle<JSBoundFunction> func(info->GetFunction());
JSHandle<JSTaggedValue> target(thread, func->GetBoundTarget());
if (!target->IsConstructor()) {
THROW_TYPE_ERROR_AND_RETURN(thread, "Constructor is false", JSTaggedValue::Exception());
}
ASSERT(target->IsConstructor());
JSHandle<JSTaggedValue> newTarget = info->GetNewTarget();
JSMutableHandle<JSTaggedValue> newTargetMutable(thread, newTarget.GetTaggedValue());

View File

@ -12,3 +12,4 @@
# limitations under the License.
true
TypeError

View File

@ -24,4 +24,11 @@ function foo(arg1, arg2) {
this.arg2 = arg2
}
var p = new foo("arg1", "arg2")
print(p.arg1 === "arg1" && p.arg2 === "arg2")
print(p.arg1 === "arg1" && p.arg2 === "arg2")
const bind_func = Array.prototype.shift.bind();
try {
new bind_func(1, ...[1, 2, 3]);
} catch (e) {
print(e.name);
}