Commit c3953255 authored by Liu Yu's avatar Liu Yu Committed by V8 LUCI CQ

[loong64][mips] Create Instance Type for Class Constructors

Port commit 1cd7a582

Change-Id: Iec6b60caeb55fd240407acc99872ebf0558654bf
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3239087Reviewed-by: 's avatarZhao Jiazhong <zhaojiazhong-hf@loongson.cn>
Commit-Queue: Zhao Jiazhong <zhaojiazhong-hf@loongson.cn>
Auto-Submit: Liu yu <liuyu@loongson.cn>
Cr-Commit-Position: refs/heads/main@{#77512}
parent 8f99174c
......@@ -2300,14 +2300,7 @@ void Builtins::Generate_CallFunction(MacroAssembler* masm,
// -----------------------------------
__ AssertFunction(a1);
// See ES6 section 9.2.1 [[Call]] ( thisArgument, argumentsList)
// Check that function is not a "classConstructor".
Label class_constructor;
__ Ld_d(a2, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
__ Ld_wu(a3, FieldMemOperand(a2, SharedFunctionInfo::kFlagsOffset));
__ And(kScratchReg, a3,
Operand(SharedFunctionInfo::IsClassConstructorBit::kMask));
__ Branch(&class_constructor, ne, kScratchReg, Operand(zero_reg));
// Enter the context of the function; ToObject has to run in the function
// context, and we also need to take the global proxy from the function
......@@ -2383,14 +2376,6 @@ void Builtins::Generate_CallFunction(MacroAssembler* masm,
__ Ld_hu(
a2, FieldMemOperand(a2, SharedFunctionInfo::kFormalParameterCountOffset));
__ InvokeFunctionCode(a1, no_reg, a2, a0, InvokeType::kJump);
// The function is a "classConstructor", need to raise an exception.
__ bind(&class_constructor);
{
FrameScope frame(masm, StackFrame::INTERNAL);
__ Push(a1);
__ CallRuntime(Runtime::kThrowConstructorNonCallableError);
}
}
// static
......@@ -2471,14 +2456,14 @@ void Builtins::Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode) {
// -- a1 : the target to call (can be any Object).
// -----------------------------------
Label non_callable, non_smi;
Label non_callable, class_constructor;
__ JumpIfSmi(a1, &non_callable);
__ bind(&non_smi);
__ LoadMap(t1, a1);
__ GetInstanceTypeRange(t1, t2, FIRST_JS_FUNCTION_TYPE, t8);
__ GetInstanceTypeRange(t1, t2, FIRST_CALLABLE_JS_FUNCTION_TYPE, t8);
__ Jump(masm->isolate()->builtins()->CallFunction(mode),
RelocInfo::CODE_TARGET, ls, t8,
Operand(LAST_JS_FUNCTION_TYPE - FIRST_JS_FUNCTION_TYPE));
Operand(LAST_CALLABLE_JS_FUNCTION_TYPE -
FIRST_CALLABLE_JS_FUNCTION_TYPE));
__ Jump(BUILTIN_CODE(masm->isolate(), CallBoundFunction),
RelocInfo::CODE_TARGET, eq, t2, Operand(JS_BOUND_FUNCTION_TYPE));
......@@ -2490,6 +2475,10 @@ void Builtins::Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode) {
__ Jump(BUILTIN_CODE(masm->isolate(), CallProxy), RelocInfo::CODE_TARGET, eq,
t2, Operand(JS_PROXY_TYPE));
// ES6 section 9.2.1 [[Call]] ( thisArgument, argumentsList)
// Check that the function is not a "classConstructor".
__ Branch(&class_constructor, eq, t2, Operand(JS_CLASS_CONSTRUCTOR_TYPE));
// 2. Call to something else, which might have a [[Call]] internal method (if
// not we raise an exception).
// Overwrite the original receiver with the (original) target.
......@@ -2507,6 +2496,14 @@ void Builtins::Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode) {
__ Push(a1);
__ CallRuntime(Runtime::kThrowCalledNonCallable);
}
// 4. The function is a "classConstructor", need to raise an exception.
__ bind(&class_constructor);
{
FrameScope frame(masm, StackFrame::INTERNAL);
__ Push(a1);
__ CallRuntime(Runtime::kThrowConstructorNonCallableError);
}
}
void Builtins::Generate_ConstructFunction(MacroAssembler* masm) {
......
......@@ -2243,14 +2243,7 @@ void Builtins::Generate_CallFunction(MacroAssembler* masm,
// -----------------------------------
__ AssertFunction(a1);
// See ES6 section 9.2.1 [[Call]] ( thisArgument, argumentsList)
// Check that the function is not a "classConstructor".
Label class_constructor;
__ lw(a2, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
__ lw(a3, FieldMemOperand(a2, SharedFunctionInfo::kFlagsOffset));
__ And(kScratchReg, a3,
Operand(SharedFunctionInfo::IsClassConstructorBit::kMask));
__ Branch(&class_constructor, ne, kScratchReg, Operand(zero_reg));
// Enter the context of the function; ToObject has to run in the function
// context, and we also need to take the global proxy from the function
......@@ -2326,14 +2319,6 @@ void Builtins::Generate_CallFunction(MacroAssembler* masm,
__ lhu(a2,
FieldMemOperand(a2, SharedFunctionInfo::kFormalParameterCountOffset));
__ InvokeFunctionCode(a1, no_reg, a2, a0, InvokeType::kJump);
// The function is a "classConstructor", need to raise an exception.
__ bind(&class_constructor);
{
FrameScope frame(masm, StackFrame::INTERNAL);
__ Push(a1);
__ CallRuntime(Runtime::kThrowConstructorNonCallableError);
}
}
// static
......@@ -2414,14 +2399,14 @@ void Builtins::Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode) {
// -- a1 : the target to call (can be any Object).
// -----------------------------------
Label non_callable, non_smi;
Label non_callable, class_constructor;
__ JumpIfSmi(a1, &non_callable);
__ bind(&non_smi);
__ LoadMap(t1, a1);
__ GetInstanceTypeRange(t1, t2, FIRST_JS_FUNCTION_TYPE, t8);
__ GetInstanceTypeRange(t1, t2, FIRST_CALLABLE_JS_FUNCTION_TYPE, t8);
__ Jump(masm->isolate()->builtins()->CallFunction(mode),
RelocInfo::CODE_TARGET, ls, t8,
Operand(LAST_JS_FUNCTION_TYPE - FIRST_JS_FUNCTION_TYPE));
Operand(LAST_CALLABLE_JS_FUNCTION_TYPE -
FIRST_CALLABLE_JS_FUNCTION_TYPE));
__ Jump(BUILTIN_CODE(masm->isolate(), CallBoundFunction),
RelocInfo::CODE_TARGET, eq, t2, Operand(JS_BOUND_FUNCTION_TYPE));
......@@ -2434,6 +2419,10 @@ void Builtins::Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode) {
__ Jump(BUILTIN_CODE(masm->isolate(), CallProxy),
RelocInfo::CODE_TARGET, eq, t2, Operand(JS_PROXY_TYPE));
// ES6 section 9.2.1 [[Call]] ( thisArgument, argumentsList)
// Check that the function is not a "classConstructor".
__ Branch(&class_constructor, eq, t2, Operand(JS_CLASS_CONSTRUCTOR_TYPE));
// 2. Call to something else, which might have a [[Call]] internal method (if
// not we raise an exception).
// Overwrite the original receiver with the (original) target.
......@@ -2451,6 +2440,14 @@ void Builtins::Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode) {
__ Push(a1);
__ CallRuntime(Runtime::kThrowCalledNonCallable);
}
// 4. The function is a "classConstructor", need to raise an exception.
__ bind(&class_constructor);
{
FrameScope frame(masm, StackFrame::INTERNAL);
__ Push(a1);
__ CallRuntime(Runtime::kThrowConstructorNonCallableError);
}
}
// static
......
......@@ -2296,14 +2296,7 @@ void Builtins::Generate_CallFunction(MacroAssembler* masm,
// -----------------------------------
__ AssertFunction(a1);
// See ES6 section 9.2.1 [[Call]] ( thisArgument, argumentsList)
// Check that function is not a "classConstructor".
Label class_constructor;
__ Ld(a2, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
__ Lwu(a3, FieldMemOperand(a2, SharedFunctionInfo::kFlagsOffset));
__ And(kScratchReg, a3,
Operand(SharedFunctionInfo::IsClassConstructorBit::kMask));
__ Branch(&class_constructor, ne, kScratchReg, Operand(zero_reg));
// Enter the context of the function; ToObject has to run in the function
// context, and we also need to take the global proxy from the function
......@@ -2379,14 +2372,6 @@ void Builtins::Generate_CallFunction(MacroAssembler* masm,
__ Lhu(a2,
FieldMemOperand(a2, SharedFunctionInfo::kFormalParameterCountOffset));
__ InvokeFunctionCode(a1, no_reg, a2, a0, InvokeType::kJump);
// The function is a "classConstructor", need to raise an exception.
__ bind(&class_constructor);
{
FrameScope frame(masm, StackFrame::INTERNAL);
__ Push(a1);
__ CallRuntime(Runtime::kThrowConstructorNonCallableError);
}
}
// static
......@@ -2467,14 +2452,14 @@ void Builtins::Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode) {
// -- a1 : the target to call (can be any Object).
// -----------------------------------
Label non_callable, non_smi;
Label non_callable, class_constructor;
__ JumpIfSmi(a1, &non_callable);
__ bind(&non_smi);
__ LoadMap(t1, a1);
__ GetInstanceTypeRange(t1, t2, FIRST_JS_FUNCTION_TYPE, t8);
__ GetInstanceTypeRange(t1, t2, FIRST_CALLABLE_JS_FUNCTION_TYPE, t8);
__ Jump(masm->isolate()->builtins()->CallFunction(mode),
RelocInfo::CODE_TARGET, ls, t8,
Operand(LAST_JS_FUNCTION_TYPE - FIRST_JS_FUNCTION_TYPE));
Operand(LAST_CALLABLE_JS_FUNCTION_TYPE -
FIRST_CALLABLE_JS_FUNCTION_TYPE));
__ Jump(BUILTIN_CODE(masm->isolate(), CallBoundFunction),
RelocInfo::CODE_TARGET, eq, t2, Operand(JS_BOUND_FUNCTION_TYPE));
......@@ -2486,6 +2471,10 @@ void Builtins::Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode) {
__ Jump(BUILTIN_CODE(masm->isolate(), CallProxy),
RelocInfo::CODE_TARGET, eq, t2, Operand(JS_PROXY_TYPE));
// ES6 section 9.2.1 [[Call]] ( thisArgument, argumentsList)
// Check that the function is not a "classConstructor".
__ Branch(&class_constructor, eq, t2, Operand(JS_CLASS_CONSTRUCTOR_TYPE));
// 2. Call to something else, which might have a [[Call]] internal method (if
// not we raise an exception).
// Overwrite the original receiver with the (original) target.
......@@ -2503,6 +2492,14 @@ void Builtins::Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode) {
__ Push(a1);
__ CallRuntime(Runtime::kThrowCalledNonCallable);
}
// 4. The function is a "classConstructor", need to raise an exception.
__ bind(&class_constructor);
{
FrameScope frame(masm, StackFrame::INTERNAL);
__ Push(a1);
__ CallRuntime(Runtime::kThrowConstructorNonCallableError);
}
}
void Builtins::Generate_ConstructFunction(MacroAssembler* masm) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment