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

[builtins] Fix context for ConstructStub calls into C++.

When calling into C++ for a ConstructStub, we need to enter the target
context manually currently, which seems to be too fragile and easy to
forget. So instead of doing that manually, we just always enter the
correct context in the trampoline.

Drive-by-fix: Trivial cleanups for some builtins.

R=cbruni@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#33051}
parent 07c91dcc
......@@ -31,6 +31,12 @@ 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).
__ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
// Insert extra arguments.
int num_extra_args = 0;
switch (extra_args) {
......
......@@ -47,6 +47,12 @@ 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).
__ Ldr(cp, FieldMemOperand(x1, JSFunction::kContextOffset));
// Insert extra arguments.
int num_extra_args = 0;
switch (extra_args) {
......
......@@ -1208,8 +1208,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
isolate->initial_object_prototype(), Builtins::kSymbolConstructor);
symbol_fun->shared()->set_construct_stub(
*isolate->builtins()->SymbolConstructor_ConstructStub());
symbol_fun->shared()->set_internal_formal_parameter_count(1);
symbol_fun->shared()->set_length(1);
symbol_fun->shared()->DontAdaptArguments();
native_context()->set_symbol_function(*symbol_fun);
}
......@@ -2464,7 +2464,7 @@ bool Genesis::InstallNatives(ContextType context_type) {
{
Handle<JSFunction> eval = SimpleInstallFunction(
handle(native_context()->global_object()), factory()->eval_string(),
Builtins::kGlobalEval, 1, true);
Builtins::kGlobalEval, 1, false);
native_context()->set_global_eval_fun(*eval);
}
......
......@@ -1539,8 +1539,7 @@ MaybeHandle<JSFunction> CompileString(Handle<Context> context,
// ES6 section 18.2.1 eval (x)
BUILTIN(GlobalEval) {
HandleScope scope(isolate);
DCHECK_LE(1, args.length());
Handle<Object> x = args.at<Object>(1);
Handle<Object> x = args.atOrUndefined(isolate, 1);
Handle<JSFunction> target = args.target();
Handle<JSObject> target_global_proxy(target->global_proxy(), isolate);
if (!x->IsString()) return *x;
......@@ -2041,7 +2040,6 @@ BUILTIN(FunctionPrototypeBind) {
BUILTIN(FunctionPrototypeToString) {
HandleScope scope(isolate);
Handle<Object> receiver = args.receiver();
if (receiver->IsJSBoundFunction()) {
return *JSBoundFunction::ToString(Handle<JSBoundFunction>::cast(receiver));
} else if (receiver->IsJSFunction()) {
......@@ -2067,9 +2065,8 @@ BUILTIN(GeneratorFunctionConstructor) {
// ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Call]] case.
BUILTIN(SymbolConstructor) {
HandleScope scope(isolate);
DCHECK_EQ(2, args.length());
Handle<Symbol> result = isolate->factory()->NewSymbol();
Handle<Object> description = args.at<Object>(1);
Handle<Object> description = args.atOrUndefined(isolate, 1);
if (!description->IsUndefined()) {
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, description,
Object::ToString(isolate, description));
......@@ -2082,9 +2079,6 @@ 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.target()->context());
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewTypeError(MessageTemplate::kNotConstructor,
isolate->factory()->Symbol_string()));
......@@ -2102,11 +2096,6 @@ BUILTIN(ObjectProtoToString) {
}
namespace {
} // namespace
// ES6 section 26.2.1.1 Proxy ( target, handler ) for the [[Call]] case.
BUILTIN(ProxyConstructor) {
HandleScope scope(isolate);
......@@ -2123,9 +2112,6 @@ BUILTIN(ProxyConstructor_ConstructStub) {
DCHECK(isolate->proxy_function()->IsConstructor());
Handle<Object> target = args.atOrUndefined(isolate, 1);
Handle<Object> handler = args.atOrUndefined(isolate, 2);
// 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.target()->context());
Handle<JSProxy> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result,
JSProxy::New(isolate, target, handler));
......
......@@ -32,6 +32,12 @@ 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).
__ mov(esi, FieldOperand(edi, JSFunction::kContextOffset));
// Insert extra arguments.
int num_extra_args = 0;
if (extra_args != BuiltinExtraArguments::kNone) {
......
......@@ -32,6 +32,12 @@ 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).
__ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
// Insert extra arguments.
int num_extra_args = 0;
switch (extra_args) {
......
......@@ -31,6 +31,12 @@ 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).
__ ld(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
// Insert extra arguments.
int num_extra_args = 0;
switch (extra_args) {
......
......@@ -30,6 +30,12 @@ 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).
__ LoadP(cp, FieldMemOperand(r4, JSFunction::kContextOffset));
// Insert extra arguments.
int num_extra_args = 0;
switch (extra_args) {
......
......@@ -31,6 +31,12 @@ 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).
__ movp(rsi, FieldOperand(rdi, JSFunction::kContextOffset));
// Insert extra arguments.
int num_extra_args = 0;
if (extra_args != BuiltinExtraArguments::kNone) {
......
......@@ -32,6 +32,12 @@ 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).
__ mov(esi, FieldOperand(edi, JSFunction::kContextOffset));
// Insert extra arguments.
int num_extra_args = 0;
if (extra_args != BuiltinExtraArguments::kNone) {
......
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