Commit 4013a8df authored by bmeurer's avatar bmeurer Committed by Commit bot

[builtins] Some refactoring on the builtin mechanism.

Allow to pass new.target (in addition to target) to C++ builtins, and
remove some obsolete/dangerous code from the C++ builtins.

R=yangguo@chromium.org

Review URL: https://codereview.chromium.org/1491883002

Cr-Commit-Position: refs/heads/master@{#32505}
parent d4fc4a8c
......@@ -22,7 +22,8 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
BuiltinExtraArguments extra_args) {
// ----------- S t a t e -------------
// -- r0 : number of arguments excluding receiver
// -- r1 : called function
// -- r1 : target
// -- r3 : new.target
// -- sp[0] : last argument
// -- ...
// -- sp[4 * (argc - 1)] : first argument
......@@ -32,11 +33,21 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
// Insert extra arguments.
int num_extra_args = 0;
if (extra_args == NEEDS_CALLED_FUNCTION) {
num_extra_args = 1;
__ push(r1);
} else {
DCHECK(extra_args == NO_EXTRA_ARGUMENTS);
switch (extra_args) {
case BuiltinExtraArguments::kTarget:
__ Push(r1);
++num_extra_args;
break;
case BuiltinExtraArguments::kNewTarget:
__ Push(r3);
++num_extra_args;
break;
case BuiltinExtraArguments::kTargetAndNewTarget:
__ Push(r1, r3);
num_extra_args += 2;
break;
case BuiltinExtraArguments::kNone:
break;
}
// JumpToExternalReference expects r0 to contain the number of arguments
......
......@@ -38,7 +38,8 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
BuiltinExtraArguments extra_args) {
// ----------- S t a t e -------------
// -- x0 : number of arguments excluding receiver
// -- x1 : called function
// -- x1 : target
// -- x3 : new target
// -- sp[0] : last argument
// -- ...
// -- sp[4 * (argc - 1)] : first argument
......@@ -48,11 +49,21 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
// Insert extra arguments.
int num_extra_args = 0;
if (extra_args == NEEDS_CALLED_FUNCTION) {
num_extra_args = 1;
__ Push(x1);
} else {
DCHECK(extra_args == NO_EXTRA_ARGUMENTS);
switch (extra_args) {
case BuiltinExtraArguments::kTarget:
__ Push(x1);
++num_extra_args;
break;
case BuiltinExtraArguments::kNewTarget:
__ Push(x3);
++num_extra_args;
break;
case BuiltinExtraArguments::kTargetAndNewTarget:
__ Push(x1, x3);
num_extra_args += 2;
break;
case BuiltinExtraArguments::kNone:
break;
}
// JumpToExternalReference expects x0 to contain the number of arguments
......
This diff is collapsed.
......@@ -5,17 +5,24 @@
#ifndef V8_BUILTINS_H_
#define V8_BUILTINS_H_
#include "src/base/flags.h"
#include "src/handles.h"
namespace v8 {
namespace internal {
// Specifies extra arguments required by a C++ builtin.
enum BuiltinExtraArguments {
NO_EXTRA_ARGUMENTS = 0,
NEEDS_CALLED_FUNCTION = 1
enum class BuiltinExtraArguments : uint8_t {
kNone = 0u,
kTarget = 1u << 0,
kNewTarget = 1u << 1,
kTargetAndNewTarget = kTarget | kNewTarget
};
inline bool operator&(BuiltinExtraArguments lhs, BuiltinExtraArguments rhs) {
return static_cast<uint8_t>(lhs) & static_cast<uint8_t>(rhs);
}
#define CODE_AGE_LIST_WITH_ARG(V, A) \
V(Quadragenarian, A) \
......@@ -44,43 +51,43 @@ enum BuiltinExtraArguments {
// Define list of builtins implemented in C++.
#define BUILTIN_LIST_C(V) \
V(Illegal, NO_EXTRA_ARGUMENTS) \
\
V(EmptyFunction, NO_EXTRA_ARGUMENTS) \
\
V(ArrayPush, NO_EXTRA_ARGUMENTS) \
V(ArrayPop, NO_EXTRA_ARGUMENTS) \
V(ArrayShift, NO_EXTRA_ARGUMENTS) \
V(ArrayUnshift, NO_EXTRA_ARGUMENTS) \
V(ArraySlice, NO_EXTRA_ARGUMENTS) \
V(ArraySplice, NO_EXTRA_ARGUMENTS) \
V(ArrayConcat, NO_EXTRA_ARGUMENTS) \
\
V(DateToPrimitive, NO_EXTRA_ARGUMENTS) \
\
V(ReflectDefineProperty, NO_EXTRA_ARGUMENTS) \
V(ReflectDeleteProperty, NO_EXTRA_ARGUMENTS) \
V(ReflectGet, NO_EXTRA_ARGUMENTS) \
V(ReflectGetOwnPropertyDescriptor, NO_EXTRA_ARGUMENTS) \
V(ReflectGetPrototypeOf, NO_EXTRA_ARGUMENTS) \
V(ReflectHas, NO_EXTRA_ARGUMENTS) \
V(ReflectIsExtensible, NO_EXTRA_ARGUMENTS) \
V(ReflectOwnKeys, NO_EXTRA_ARGUMENTS) \
V(ReflectPreventExtensions, NO_EXTRA_ARGUMENTS) \
V(ReflectSet, NO_EXTRA_ARGUMENTS) \
V(ReflectSetPrototypeOf, NO_EXTRA_ARGUMENTS) \
\
V(SymbolConstructor, NO_EXTRA_ARGUMENTS) \
V(SymbolConstructor_ConstructStub, NEEDS_CALLED_FUNCTION) \
\
V(HandleApiCall, NEEDS_CALLED_FUNCTION) \
V(HandleApiCallConstruct, NEEDS_CALLED_FUNCTION) \
V(HandleApiCallAsFunction, NO_EXTRA_ARGUMENTS) \
V(HandleApiCallAsConstructor, NO_EXTRA_ARGUMENTS) \
\
V(RestrictedFunctionPropertiesThrower, NO_EXTRA_ARGUMENTS) \
V(RestrictedStrictArgumentsPropertiesThrower, NO_EXTRA_ARGUMENTS)
#define BUILTIN_LIST_C(V) \
V(Illegal, kNone) \
\
V(EmptyFunction, kNone) \
\
V(ArrayPush, kNone) \
V(ArrayPop, kNone) \
V(ArrayShift, kNone) \
V(ArrayUnshift, kNone) \
V(ArraySlice, kNone) \
V(ArraySplice, kNone) \
V(ArrayConcat, kNone) \
\
V(DateToPrimitive, kNone) \
\
V(ReflectDefineProperty, kNone) \
V(ReflectDeleteProperty, kNone) \
V(ReflectGet, kNone) \
V(ReflectGetOwnPropertyDescriptor, kNone) \
V(ReflectGetPrototypeOf, kNone) \
V(ReflectHas, kNone) \
V(ReflectIsExtensible, kNone) \
V(ReflectOwnKeys, kNone) \
V(ReflectPreventExtensions, kNone) \
V(ReflectSet, kNone) \
V(ReflectSetPrototypeOf, kNone) \
\
V(SymbolConstructor, kNone) \
V(SymbolConstructor_ConstructStub, kTarget) \
\
V(HandleApiCall, kTarget) \
V(HandleApiCallConstruct, kTarget) \
V(HandleApiCallAsFunction, kNone) \
V(HandleApiCallAsConstructor, kNone) \
\
V(RestrictedFunctionPropertiesThrower, kNone) \
V(RestrictedStrictArgumentsPropertiesThrower, kNone)
// Define list of builtins implemented in assembly.
#define BUILTIN_LIST_A(V) \
......
......@@ -22,7 +22,8 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
BuiltinExtraArguments extra_args) {
// ----------- S t a t e -------------
// -- eax : number of arguments excluding receiver
// -- edi : called function
// -- edi : target
// -- edx : new.target
// -- esp[0] : return address
// -- esp[4] : last argument
// -- ...
......@@ -33,14 +34,17 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
// Insert extra arguments.
int num_extra_args = 0;
if (extra_args == NEEDS_CALLED_FUNCTION) {
num_extra_args = 1;
Register scratch = ebx;
__ pop(scratch); // Save return address.
__ push(edi);
__ push(scratch); // Restore return address.
} else {
DCHECK(extra_args == NO_EXTRA_ARGUMENTS);
if (extra_args != BuiltinExtraArguments::kNone) {
__ PopReturnAddressTo(ecx);
if (extra_args & BuiltinExtraArguments::kTarget) {
++num_extra_args;
__ Push(edi);
}
if (extra_args & BuiltinExtraArguments::kNewTarget) {
++num_extra_args;
__ Push(edx);
}
__ PushReturnAddressFrom(ecx);
}
// JumpToExternalReference expects eax to contain the number of arguments
......
......@@ -23,7 +23,8 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
BuiltinExtraArguments extra_args) {
// ----------- S t a t e -------------
// -- a0 : number of arguments excluding receiver
// -- a1 : called function
// -- a1 : target
// -- a3 : new.target
// -- sp[0] : last argument
// -- ...
// -- sp[4 * (argc - 1)] : first argument
......@@ -33,11 +34,21 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
// Insert extra arguments.
int num_extra_args = 0;
if (extra_args == NEEDS_CALLED_FUNCTION) {
num_extra_args = 1;
__ push(a1);
} else {
DCHECK(extra_args == NO_EXTRA_ARGUMENTS);
switch (extra_args) {
case BuiltinExtraArguments::kTarget:
__ Push(a1);
++num_extra_args;
break;
case BuiltinExtraArguments::kNewTarget:
__ Push(a3);
++num_extra_args;
break;
case BuiltinExtraArguments::kTargetAndNewTarget:
__ Push(a1, a3);
num_extra_args += 2;
break;
case BuiltinExtraArguments::kNone:
break;
}
// JumpToExternalReference expects a0 to contain the number of arguments
......
......@@ -22,7 +22,8 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
BuiltinExtraArguments extra_args) {
// ----------- S t a t e -------------
// -- a0 : number of arguments excluding receiver
// -- a1 : called function
// -- a1 : target
// -- a3 : new.target
// -- sp[0] : last argument
// -- ...
// -- sp[8 * (argc - 1)] : first argument
......@@ -32,11 +33,21 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
// Insert extra arguments.
int num_extra_args = 0;
if (extra_args == NEEDS_CALLED_FUNCTION) {
num_extra_args = 1;
__ push(a1);
} else {
DCHECK(extra_args == NO_EXTRA_ARGUMENTS);
switch (extra_args) {
case BuiltinExtraArguments::kTarget:
__ Push(a1);
++num_extra_args;
break;
case BuiltinExtraArguments::kNewTarget:
__ Push(a3);
++num_extra_args;
break;
case BuiltinExtraArguments::kTargetAndNewTarget:
__ Push(a1, a3);
num_extra_args += 2;
break;
case BuiltinExtraArguments::kNone:
break;
}
// JumpToExternalReference expects a0 to contain the number of arguments
......
......@@ -21,7 +21,8 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm, CFunctionId id,
BuiltinExtraArguments extra_args) {
// ----------- S t a t e -------------
// -- r3 : number of arguments excluding receiver
// -- r4 : called function
// -- r4 : target
// -- r6 : new.target
// -- sp[0] : last argument
// -- ...
// -- sp[4 * (argc - 1)] : first argument
......@@ -31,11 +32,21 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm, CFunctionId id,
// Insert extra arguments.
int num_extra_args = 0;
if (extra_args == NEEDS_CALLED_FUNCTION) {
num_extra_args = 1;
__ push(r4);
} else {
DCHECK(extra_args == NO_EXTRA_ARGUMENTS);
switch (extra_args) {
case BuiltinExtraArguments::kTarget:
__ Push(r4);
++num_extra_args;
break;
case BuiltinExtraArguments::kNewTarget:
__ Push(r6);
++num_extra_args;
break;
case BuiltinExtraArguments::kTargetAndNewTarget:
__ Push(r4, r6);
num_extra_args += 2;
break;
case BuiltinExtraArguments::kNone:
break;
}
// JumpToExternalReference expects r3 to contain the number of arguments
......
......@@ -21,7 +21,8 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
BuiltinExtraArguments extra_args) {
// ----------- S t a t e -------------
// -- rax : number of arguments excluding receiver
// -- rdi : called function
// -- rdi : target
// -- rdx : new.target
// -- rsp[0] : return address
// -- rsp[8] : last argument
// -- ...
......@@ -32,13 +33,17 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
// Insert extra arguments.
int num_extra_args = 0;
if (extra_args == NEEDS_CALLED_FUNCTION) {
num_extra_args = 1;
if (extra_args != BuiltinExtraArguments::kNone) {
__ PopReturnAddressTo(kScratchRegister);
__ Push(rdi);
if (extra_args & BuiltinExtraArguments::kTarget) {
++num_extra_args;
__ Push(rdi);
}
if (extra_args & BuiltinExtraArguments::kNewTarget) {
++num_extra_args;
__ Push(rdx);
}
__ PushReturnAddressFrom(kScratchRegister);
} else {
DCHECK(extra_args == NO_EXTRA_ARGUMENTS);
}
// JumpToExternalReference expects rax to contain the number of arguments
......
......@@ -22,7 +22,8 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
BuiltinExtraArguments extra_args) {
// ----------- S t a t e -------------
// -- eax : number of arguments excluding receiver
// -- edi : called function
// -- edi : target
// -- edx : new.target
// -- esp[0] : return address
// -- esp[4] : last argument
// -- ...
......@@ -33,14 +34,17 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
// Insert extra arguments.
int num_extra_args = 0;
if (extra_args == NEEDS_CALLED_FUNCTION) {
num_extra_args = 1;
Register scratch = ebx;
__ pop(scratch); // Save return address.
__ push(edi);
__ push(scratch); // Restore return address.
} else {
DCHECK(extra_args == NO_EXTRA_ARGUMENTS);
if (extra_args != BuiltinExtraArguments::kNone) {
__ PopReturnAddressTo(ecx);
if (extra_args & BuiltinExtraArguments::kTarget) {
++num_extra_args;
__ Push(edi);
}
if (extra_args & BuiltinExtraArguments::kNewTarget) {
++num_extra_args;
__ Push(edx);
}
__ PushReturnAddressFrom(ecx);
}
// JumpToExternalReference expects eax to contain the number of arguments
......
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