Commit f618401a authored by bmeurer's avatar bmeurer Committed by Commit bot

[builtins] Remove some (now) unused code from C++ builtin adaptor.

Sanitize ConstructStub handling and add a test case to ensure that the
Symbol constructor is using the correct context.

R=jarin@chromium.org
BUG=v8:4413
LOG=n

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

Cr-Commit-Position: refs/heads/master@{#32491}
parent a0134a6d
......@@ -22,8 +22,6 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
BuiltinExtraArguments extra_args) {
// ----------- S t a t e -------------
// -- r0 : number of arguments excluding receiver
// (only guaranteed when the called function
// is not marked as DontAdaptArguments)
// -- r1 : called function
// -- sp[0] : last argument
// -- ...
......@@ -32,13 +30,6 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
// -----------------------------------
__ AssertFunction(r1);
// Make sure we operate in the context of the called function (for example
// ConstructStubs implemented in C++ will be run in the context of the caller
// instead of the callee, due to the way that [[Construct]] is defined for
// ordinary functions).
// TODO(bmeurer): Can we make this more robust?
__ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
// Insert extra arguments.
int num_extra_args = 0;
if (extra_args == NEEDS_CALLED_FUNCTION) {
......@@ -49,15 +40,7 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
}
// JumpToExternalReference expects r0 to contain the number of arguments
// including the receiver and the extra arguments. But r0 is only valid
// if the called function is marked as DontAdaptArguments, otherwise we
// need to load the argument count from the SharedFunctionInfo.
__ ldr(r2, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
__ ldr(r2,
FieldMemOperand(r2, SharedFunctionInfo::kFormalParameterCountOffset));
__ SmiUntag(r2);
__ cmp(r2, Operand(SharedFunctionInfo::kDontAdaptArgumentsSentinel));
__ mov(r0, r2, LeaveCC, ne);
// including the receiver and the extra arguments.
__ add(r0, r0, Operand(num_extra_args + 1));
__ JumpToExternalReference(ExternalReference(id, masm->isolate()));
......
......@@ -38,8 +38,6 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
BuiltinExtraArguments extra_args) {
// ----------- S t a t e -------------
// -- x0 : number of arguments excluding receiver
// (only guaranteed when the called function
// is not marked as DontAdaptArguments)
// -- x1 : called function
// -- sp[0] : last argument
// -- ...
......@@ -48,13 +46,6 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
// -----------------------------------
__ AssertFunction(x1);
// Make sure we operate in the context of the called function (for example
// ConstructStubs implemented in C++ will be run in the context of the caller
// instead of the callee, due to the way that [[Construct]] is defined for
// ordinary functions).
// TODO(bmeurer): Can we make this more robust?
__ Ldr(cp, FieldMemOperand(x1, JSFunction::kContextOffset));
// Insert extra arguments.
int num_extra_args = 0;
if (extra_args == NEEDS_CALLED_FUNCTION) {
......@@ -65,14 +56,7 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
}
// JumpToExternalReference expects x0 to contain the number of arguments
// including the receiver and the extra arguments. But x0 is only valid
// if the called function is marked as DontAdaptArguments, otherwise we
// need to load the argument count from the SharedFunctionInfo.
__ Ldr(x2, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset));
__ Ldrsw(
x2, FieldMemOperand(x2, SharedFunctionInfo::kFormalParameterCountOffset));
__ Cmp(x2, SharedFunctionInfo::kDontAdaptArgumentsSentinel);
__ Csel(x0, x0, x2, eq);
// including the receiver and the extra arguments.
__ Add(x0, x0, num_extra_args + 1);
__ JumpToExternalReference(ExternalReference(id, masm->isolate()));
......
......@@ -1762,6 +1762,9 @@ BUILTIN(SymbolConstructor) {
// ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Construct]] case.
BUILTIN(SymbolConstructor_ConstructStub) {
HandleScope scope(isolate);
// The ConstructStub is executed in the context of the caller, so we need
// to enter the callee context first before raising an exception.
isolate->set_context(args.called_function()->context());
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewTypeError(MessageTemplate::kNotConstructor,
isolate->factory()->Symbol_string()));
......
......@@ -72,7 +72,7 @@ enum BuiltinExtraArguments {
V(ReflectSetPrototypeOf, NO_EXTRA_ARGUMENTS) \
\
V(SymbolConstructor, NO_EXTRA_ARGUMENTS) \
V(SymbolConstructor_ConstructStub, NO_EXTRA_ARGUMENTS) \
V(SymbolConstructor_ConstructStub, NEEDS_CALLED_FUNCTION) \
\
V(HandleApiCall, NEEDS_CALLED_FUNCTION) \
V(HandleApiCallConstruct, NEEDS_CALLED_FUNCTION) \
......
......@@ -22,8 +22,6 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
BuiltinExtraArguments extra_args) {
// ----------- S t a t e -------------
// -- eax : number of arguments excluding receiver
// (only guaranteed when the called function
// is not marked as DontAdaptArguments)
// -- edi : called function
// -- esp[0] : return address
// -- esp[4] : last argument
......@@ -33,13 +31,6 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
// -----------------------------------
__ AssertFunction(edi);
// Make sure we operate in the context of the called function (for example
// ConstructStubs implemented in C++ will be run in the context of the caller
// instead of the callee, due to the way that [[Construct]] is defined for
// ordinary functions).
// TODO(bmeurer): Can we make this more robust?
__ mov(esi, FieldOperand(edi, JSFunction::kContextOffset));
// Insert extra arguments.
int num_extra_args = 0;
if (extra_args == NEEDS_CALLED_FUNCTION) {
......@@ -53,21 +44,8 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
}
// JumpToExternalReference expects eax to contain the number of arguments
// including the receiver and the extra arguments. But eax is only valid
// if the called function is marked as DontAdaptArguments, otherwise we
// need to load the argument count from the SharedFunctionInfo.
Label argc, done_argc;
__ mov(edx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
__ mov(ebx,
FieldOperand(edx, SharedFunctionInfo::kFormalParameterCountOffset));
__ SmiUntag(ebx);
__ cmp(ebx, SharedFunctionInfo::kDontAdaptArgumentsSentinel);
__ j(equal, &argc, Label::kNear);
__ lea(eax, Operand(ebx, num_extra_args + 1));
__ jmp(&done_argc, Label::kNear);
__ bind(&argc);
// including the receiver and the extra arguments.
__ add(eax, Immediate(num_extra_args + 1));
__ bind(&done_argc);
__ JumpToExternalReference(ExternalReference(id, masm->isolate()));
}
......
......@@ -23,8 +23,6 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
BuiltinExtraArguments extra_args) {
// ----------- S t a t e -------------
// -- a0 : number of arguments excluding receiver
// (only guaranteed when the called function
// is not marked as DontAdaptArguments)
// -- a1 : called function
// -- sp[0] : last argument
// -- ...
......@@ -33,13 +31,6 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
// -----------------------------------
__ AssertFunction(a1);
// Make sure we operate in the context of the called function (for example
// ConstructStubs implemented in C++ will be run in the context of the caller
// instead of the callee, due to the way that [[Construct]] is defined for
// ordinary functions).
// TODO(bmeurer): Can we make this more robust?
__ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
// Insert extra arguments.
int num_extra_args = 0;
if (extra_args == NEEDS_CALLED_FUNCTION) {
......@@ -50,21 +41,8 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
}
// JumpToExternalReference expects a0 to contain the number of arguments
// including the receiver and the extra arguments. But a0 is only valid
// if the called function is marked as DontAdaptArguments, otherwise we
// need to load the argument count from the SharedFunctionInfo.
Label argc, done_argc;
__ lw(a2, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
__ lw(a2,
FieldMemOperand(a2, SharedFunctionInfo::kFormalParameterCountOffset));
__ SmiUntag(a2);
__ Branch(&argc, eq, a2,
Operand(SharedFunctionInfo::kDontAdaptArgumentsSentinel));
__ Addu(a0, a2, num_extra_args + 1);
__ jmp(&done_argc);
__ bind(&argc);
// including the receiver and the extra arguments.
__ Addu(a0, a0, num_extra_args + 1);
__ bind(&done_argc);
__ JumpToExternalReference(ExternalReference(id, masm->isolate()));
}
......
......@@ -22,8 +22,6 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
BuiltinExtraArguments extra_args) {
// ----------- S t a t e -------------
// -- a0 : number of arguments excluding receiver
// (only guaranteed when the called function
// is not marked as DontAdaptArguments)
// -- a1 : called function
// -- sp[0] : last argument
// -- ...
......@@ -32,13 +30,6 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
// -----------------------------------
__ AssertFunction(a1);
// Make sure we operate in the context of the called function (for example
// ConstructStubs implemented in C++ will be run in the context of the caller
// instead of the callee, due to the way that [[Construct]] is defined for
// ordinary functions).
// TODO(bmeurer): Can we make this more robust?
__ ld(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
// Insert extra arguments.
int num_extra_args = 0;
if (extra_args == NEEDS_CALLED_FUNCTION) {
......@@ -49,20 +40,8 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
}
// JumpToExternalReference expects a0 to contain the number of arguments
// including the receiver and the extra arguments. But a0 is only valid
// if the called function is marked as DontAdaptArguments, otherwise we
// need to load the argument count from the SharedFunctionInfo.
Label argc, done_argc;
__ ld(a2, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
__ lw(a2,
FieldMemOperand(a2, SharedFunctionInfo::kFormalParameterCountOffset));
__ Branch(&argc, eq, a2,
Operand(SharedFunctionInfo::kDontAdaptArgumentsSentinel));
__ Daddu(a0, a2, num_extra_args + 1);
__ jmp(&done_argc);
__ bind(&argc);
// including the receiver and the extra arguments.
__ Daddu(a0, a0, num_extra_args + 1);
__ bind(&done_argc);
__ JumpToExternalReference(ExternalReference(id, masm->isolate()));
}
......
......@@ -21,8 +21,6 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm, CFunctionId id,
BuiltinExtraArguments extra_args) {
// ----------- S t a t e -------------
// -- r3 : number of arguments excluding receiver
// (only guaranteed when the called function
// is not marked as DontAdaptArguments)
// -- r4 : called function
// -- sp[0] : last argument
// -- ...
......@@ -31,13 +29,6 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm, CFunctionId id,
// -----------------------------------
__ AssertFunction(r4);
// Make sure we operate in the context of the called function (for example
// ConstructStubs implemented in C++ will be run in the context of the caller
// instead of the callee, due to the way that [[Construct]] is defined for
// ordinary functions).
// TODO(bmeurer): Can we make this more robust?
__ LoadP(cp, FieldMemOperand(r4, JSFunction::kContextOffset));
// Insert extra arguments.
int num_extra_args = 0;
if (extra_args == NEEDS_CALLED_FUNCTION) {
......@@ -48,24 +39,7 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm, CFunctionId id,
}
// JumpToExternalReference expects r3 to contain the number of arguments
// including the receiver and the extra arguments. But r3 is only valid
// if the called function is marked as DontAdaptArguments, otherwise we
// need to load the argument count from the SharedFunctionInfo.
__ LoadP(r5, FieldMemOperand(r4, JSFunction::kSharedFunctionInfoOffset));
__ LoadWordArith(
r5, FieldMemOperand(r5, SharedFunctionInfo::kFormalParameterCountOffset));
#if !V8_TARGET_ARCH_PPC64
__ SmiUntag(r5);
#endif
__ cmpi(r5, Operand(SharedFunctionInfo::kDontAdaptArgumentsSentinel));
if (CpuFeatures::IsSupported(ISELECT)) {
__ isel(ne, r3, r5, r3);
} else {
Label skip;
__ beq(&skip);
__ mr(r3, r5);
__ bind(&skip);
}
// including the receiver and the extra arguments.
__ addi(r3, r3, Operand(num_extra_args + 1));
__ JumpToExternalReference(ExternalReference(id, masm->isolate()));
......
......@@ -21,8 +21,6 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
BuiltinExtraArguments extra_args) {
// ----------- S t a t e -------------
// -- rax : number of arguments excluding receiver
// (only guaranteed when the called function
// is not marked as DontAdaptArguments)
// -- rdi : called function
// -- rsp[0] : return address
// -- rsp[8] : last argument
......@@ -32,13 +30,6 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
// -----------------------------------
__ AssertFunction(rdi);
// Make sure we operate in the context of the called function (for example
// ConstructStubs implemented in C++ will be run in the context of the caller
// instead of the callee, due to the way that [[Construct]] is defined for
// ordinary functions).
// TODO(bmeurer): Can we make this more robust?
__ movp(rsi, FieldOperand(rdi, JSFunction::kContextOffset));
// Insert extra arguments.
int num_extra_args = 0;
if (extra_args == NEEDS_CALLED_FUNCTION) {
......@@ -51,20 +42,8 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
}
// JumpToExternalReference expects rax to contain the number of arguments
// including the receiver and the extra arguments. But rax is only valid
// if the called function is marked as DontAdaptArguments, otherwise we
// need to load the argument count from the SharedFunctionInfo.
Label argc, done_argc;
__ movp(rdx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
__ LoadSharedFunctionInfoSpecialField(
rbx, rdx, SharedFunctionInfo::kFormalParameterCountOffset);
__ cmpp(rbx, Immediate(SharedFunctionInfo::kDontAdaptArgumentsSentinel));
__ j(equal, &argc, Label::kNear);
__ leap(rax, Operand(rbx, num_extra_args + 1));
__ jmp(&done_argc, Label::kNear);
__ bind(&argc);
// including the receiver and the extra arguments.
__ addp(rax, Immediate(num_extra_args + 1));
__ bind(&done_argc);
__ JumpToExternalReference(ExternalReference(id, masm->isolate()), 1);
}
......
......@@ -22,8 +22,6 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
BuiltinExtraArguments extra_args) {
// ----------- S t a t e -------------
// -- eax : number of arguments excluding receiver
// (only guaranteed when the called function
// is not marked as DontAdaptArguments)
// -- edi : called function
// -- esp[0] : return address
// -- esp[4] : last argument
......@@ -33,13 +31,6 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
// -----------------------------------
__ AssertFunction(edi);
// Make sure we operate in the context of the called function (for example
// ConstructStubs implemented in C++ will be run in the context of the caller
// instead of the callee, due to the way that [[Construct]] is defined for
// ordinary functions).
// TODO(bmeurer): Can we make this more robust?
__ mov(esi, FieldOperand(edi, JSFunction::kContextOffset));
// Insert extra arguments.
int num_extra_args = 0;
if (extra_args == NEEDS_CALLED_FUNCTION) {
......@@ -53,21 +44,8 @@ void Builtins::Generate_Adaptor(MacroAssembler* masm,
}
// JumpToExternalReference expects eax to contain the number of arguments
// including the receiver and the extra arguments. But eax is only valid
// if the called function is marked as DontAdaptArguments, otherwise we
// need to load the argument count from the SharedFunctionInfo.
Label argc, done_argc;
__ mov(edx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
__ mov(ebx,
FieldOperand(edx, SharedFunctionInfo::kFormalParameterCountOffset));
__ SmiUntag(ebx);
__ cmp(ebx, SharedFunctionInfo::kDontAdaptArgumentsSentinel);
__ j(equal, &argc, Label::kNear);
__ lea(eax, Operand(ebx, num_extra_args + 1));
__ jmp(&done_argc, Label::kNear);
__ bind(&argc);
// including the receiver and the extra arguments.
__ add(eax, Immediate(num_extra_args + 1));
__ bind(&done_argc);
__ JumpToExternalReference(ExternalReference(id, masm->isolate()));
}
......
......@@ -526,3 +526,26 @@ function TestComparison() {
}
}
TestComparison();
// Make sure that throws occur in the context of the Symbol function.
function TestContext() {
var r = Realm.create();
var rSymbol = Realm.eval(r, "Symbol");
var rError = Realm.eval(r, "TypeError");
function verifier(symbol, error) {
try {
new symbol();
} catch(e) {
return e.__proto__ === error.__proto__;
}
assertTrue(false); // should never get here.
}
assertTrue(verifier(Symbol, TypeError()));
assertTrue(verifier(rSymbol, rError()));
assertFalse(verifier(Symbol, rError()));
assertFalse(verifier(rSymbol, TypeError()));
}
TestContext();
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