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