Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: src/ia32/full-codegen-ia32.cc

Issue 7039036: Fix calls of strict mode function with an implicit receiver. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address comments. Get rid of value check. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 SetFunctionPosition(function()); 123 SetFunctionPosition(function());
124 Comment cmnt(masm_, "[ function compiled by full code generator"); 124 Comment cmnt(masm_, "[ function compiled by full code generator");
125 125
126 #ifdef DEBUG 126 #ifdef DEBUG
127 if (strlen(FLAG_stop_at) > 0 && 127 if (strlen(FLAG_stop_at) > 0 &&
128 info->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) { 128 info->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) {
129 __ int3(); 129 __ int3();
130 } 130 }
131 #endif 131 #endif
132 132
133 // Strict mode functions need to replace the receiver with undefined
134 // when called as functions (without an explicit receiver
135 // object). ecx is zero for method calls and non-zero for function
136 // calls.
137 if (info->is_strict_mode()) {
138 Label ok;
139 __ test(ecx, Operand(ecx));
140 __ j(zero, &ok, Label::kNear);
141 // +1 for return address.
142 int receiver_offset = (scope()->num_parameters() + 1) * kPointerSize;
143 __ mov(Operand(esp, receiver_offset),
144 Immediate(isolate()->factory()->undefined_value()));
145 __ bind(&ok);
146 }
147
133 __ push(ebp); // Caller's frame pointer. 148 __ push(ebp); // Caller's frame pointer.
134 __ mov(ebp, esp); 149 __ mov(ebp, esp);
135 __ push(esi); // Callee's context. 150 __ push(esi); // Callee's context.
136 __ push(edi); // Callee's JS Function. 151 __ push(edi); // Callee's JS Function.
137 152
138 { Comment cmnt(masm_, "[ Allocate locals"); 153 { Comment cmnt(masm_, "[ Allocate locals");
139 int locals_count = scope()->num_stack_slots(); 154 int locals_count = scope()->num_stack_slots();
140 if (locals_count == 1) { 155 if (locals_count == 1) {
141 __ push(Immediate(isolate()->factory()->undefined_value())); 156 __ push(Immediate(isolate()->factory()->undefined_value()));
142 } else if (locals_count > 1) { 157 } else if (locals_count > 1) {
(...skipping 1879 matching lines...) Expand 10 before | Expand all | Expand 10 after
2022 int arg_count = args->length(); 2037 int arg_count = args->length();
2023 { PreservePositionScope scope(masm()->positions_recorder()); 2038 { PreservePositionScope scope(masm()->positions_recorder());
2024 for (int i = 0; i < arg_count; i++) { 2039 for (int i = 0; i < arg_count; i++) {
2025 VisitForStackValue(args->at(i)); 2040 VisitForStackValue(args->at(i));
2026 } 2041 }
2027 __ Set(ecx, Immediate(name)); 2042 __ Set(ecx, Immediate(name));
2028 } 2043 }
2029 // Record source position of the IC call. 2044 // Record source position of the IC call.
2030 SetSourcePosition(expr->position()); 2045 SetSourcePosition(expr->position());
2031 InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; 2046 InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
2032 Handle<Code> ic = isolate()->stub_cache()->ComputeCallInitialize( 2047 Handle<Code> ic =
2033 arg_count, in_loop); 2048 isolate()->stub_cache()->ComputeCallInitialize(arg_count, in_loop, mode);
2034 EmitCallIC(ic, mode, expr->id()); 2049 EmitCallIC(ic, mode, expr->id());
2035 RecordJSReturnSite(expr); 2050 RecordJSReturnSite(expr);
2036 // Restore context register. 2051 // Restore context register.
2037 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); 2052 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
2038 context()->Plug(eax); 2053 context()->Plug(eax);
2039 } 2054 }
2040 2055
2041 2056
2042 void FullCodeGenerator::EmitKeyedCallWithIC(Call* expr, 2057 void FullCodeGenerator::EmitKeyedCallWithIC(Call* expr,
2043 Expression* key, 2058 Expression* key) {
2044 RelocInfo::Mode mode) {
2045 // Load the key. 2059 // Load the key.
2046 VisitForAccumulatorValue(key); 2060 VisitForAccumulatorValue(key);
2047 2061
2048 // Swap the name of the function and the receiver on the stack to follow 2062 // Swap the name of the function and the receiver on the stack to follow
2049 // the calling convention for call ICs. 2063 // the calling convention for call ICs.
2050 __ pop(ecx); 2064 __ pop(ecx);
2051 __ push(eax); 2065 __ push(eax);
2052 __ push(ecx); 2066 __ push(ecx);
2053 2067
2054 // Load the arguments. 2068 // Load the arguments.
2055 ZoneList<Expression*>* args = expr->arguments(); 2069 ZoneList<Expression*>* args = expr->arguments();
2056 int arg_count = args->length(); 2070 int arg_count = args->length();
2057 { PreservePositionScope scope(masm()->positions_recorder()); 2071 { PreservePositionScope scope(masm()->positions_recorder());
2058 for (int i = 0; i < arg_count; i++) { 2072 for (int i = 0; i < arg_count; i++) {
2059 VisitForStackValue(args->at(i)); 2073 VisitForStackValue(args->at(i));
2060 } 2074 }
2061 } 2075 }
2062 // Record source position of the IC call. 2076 // Record source position of the IC call.
2063 SetSourcePosition(expr->position()); 2077 SetSourcePosition(expr->position());
2064 InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; 2078 InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
2065 Handle<Code> ic = isolate()->stub_cache()->ComputeKeyedCallInitialize( 2079 Handle<Code> ic = isolate()->stub_cache()->ComputeKeyedCallInitialize(
2066 arg_count, in_loop); 2080 arg_count, in_loop);
2067 __ mov(ecx, Operand(esp, (arg_count + 1) * kPointerSize)); // Key. 2081 __ mov(ecx, Operand(esp, (arg_count + 1) * kPointerSize)); // Key.
2068 EmitCallIC(ic, mode, expr->id()); 2082 EmitCallIC(ic, RelocInfo::CODE_TARGET, expr->id());
2069 RecordJSReturnSite(expr); 2083 RecordJSReturnSite(expr);
2070 // Restore context register. 2084 // Restore context register.
2071 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); 2085 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
2072 context()->DropAndPlug(1, eax); // Drop the key still on the stack. 2086 context()->DropAndPlug(1, eax); // Drop the key still on the stack.
2073 } 2087 }
2074 2088
2075 2089
2076 void FullCodeGenerator::EmitCallWithStub(Call* expr, CallFunctionFlags flags) { 2090 void FullCodeGenerator::EmitCallWithStub(Call* expr, CallFunctionFlags flags) {
2077 // Code common for calls using the call stub. 2091 // Code common for calls using the call stub.
2078 ZoneList<Expression*>* args = expr->arguments(); 2092 ZoneList<Expression*>* args = expr->arguments();
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
2169 } 2183 }
2170 2184
2171 // The runtime call returns a pair of values in eax (function) and 2185 // The runtime call returns a pair of values in eax (function) and
2172 // edx (receiver). Touch up the stack with the right values. 2186 // edx (receiver). Touch up the stack with the right values.
2173 __ mov(Operand(esp, (arg_count + 0) * kPointerSize), edx); 2187 __ mov(Operand(esp, (arg_count + 0) * kPointerSize), edx);
2174 __ mov(Operand(esp, (arg_count + 1) * kPointerSize), eax); 2188 __ mov(Operand(esp, (arg_count + 1) * kPointerSize), eax);
2175 } 2189 }
2176 // Record source position for debugger. 2190 // Record source position for debugger.
2177 SetSourcePosition(expr->position()); 2191 SetSourcePosition(expr->position());
2178 InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; 2192 InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
2179 CallFunctionStub stub(arg_count, in_loop, RECEIVER_MIGHT_BE_VALUE); 2193 CallFunctionStub stub(arg_count,
2194 in_loop,
2195 RECEIVER_MIGHT_BE_IMPLICIT);
2180 __ CallStub(&stub); 2196 __ CallStub(&stub);
2181 RecordJSReturnSite(expr); 2197 RecordJSReturnSite(expr);
2182 // Restore context register. 2198 // Restore context register.
2183 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); 2199 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
2184 context()->DropAndPlug(1, eax); 2200 context()->DropAndPlug(1, eax);
2185 } else if (var != NULL && !var->is_this() && var->is_global()) { 2201 } else if (var != NULL && !var->is_this() && var->is_global()) {
2186 // Push global object as receiver for the call IC. 2202 // Push global object as receiver for the call IC.
2187 __ push(GlobalObjectOperand()); 2203 __ push(GlobalObjectOperand());
2188 EmitCallWithIC(expr, var->name(), RelocInfo::CODE_TARGET_CONTEXT); 2204 EmitCallWithIC(expr, var->name(), RelocInfo::CODE_TARGET_CONTEXT);
2189 } else if (var != NULL && var->AsSlot() != NULL && 2205 } else if (var != NULL && var->AsSlot() != NULL &&
(...skipping 27 matching lines...) Expand all
2217 __ jmp(&call); 2233 __ jmp(&call);
2218 __ bind(&done); 2234 __ bind(&done);
2219 // Push function. 2235 // Push function.
2220 __ push(eax); 2236 __ push(eax);
2221 // Push global receiver. 2237 // Push global receiver.
2222 __ mov(ebx, GlobalObjectOperand()); 2238 __ mov(ebx, GlobalObjectOperand());
2223 __ push(FieldOperand(ebx, GlobalObject::kGlobalReceiverOffset)); 2239 __ push(FieldOperand(ebx, GlobalObject::kGlobalReceiverOffset));
2224 __ bind(&call); 2240 __ bind(&call);
2225 } 2241 }
2226 2242
2227 // The receiver is either the global receiver or a JSObject found by 2243 // The receiver is either the global receiver or an object found
2228 // LoadContextSlot. 2244 // by LoadContextSlot. That object could be the hole if the
2229 EmitCallWithStub(expr, NO_CALL_FUNCTION_FLAGS); 2245 // receiver is implicitly the global object.
2246 EmitCallWithStub(expr, RECEIVER_MIGHT_BE_IMPLICIT);
2230 } else if (fun->AsProperty() != NULL) { 2247 } else if (fun->AsProperty() != NULL) {
2231 // Call to an object property. 2248 // Call to an object property.
2232 Property* prop = fun->AsProperty(); 2249 Property* prop = fun->AsProperty();
2233 Literal* key = prop->key()->AsLiteral(); 2250 Literal* key = prop->key()->AsLiteral();
2234 if (key != NULL && key->handle()->IsSymbol()) { 2251 if (key != NULL && key->handle()->IsSymbol()) {
2235 // Call to a named property, use call IC. 2252 // Call to a named property, use call IC.
2236 { PreservePositionScope scope(masm()->positions_recorder()); 2253 { PreservePositionScope scope(masm()->positions_recorder());
2237 VisitForStackValue(prop->obj()); 2254 VisitForStackValue(prop->obj());
2238 } 2255 }
2239 EmitCallWithIC(expr, key->handle(), RelocInfo::CODE_TARGET); 2256 EmitCallWithIC(expr, key->handle(), RelocInfo::CODE_TARGET);
(...skipping 22 matching lines...) Expand all
2262 // Push result (function). 2279 // Push result (function).
2263 __ push(eax); 2280 __ push(eax);
2264 // Push Global receiver. 2281 // Push Global receiver.
2265 __ mov(ecx, GlobalObjectOperand()); 2282 __ mov(ecx, GlobalObjectOperand());
2266 __ push(FieldOperand(ecx, GlobalObject::kGlobalReceiverOffset)); 2283 __ push(FieldOperand(ecx, GlobalObject::kGlobalReceiverOffset));
2267 EmitCallWithStub(expr, NO_CALL_FUNCTION_FLAGS); 2284 EmitCallWithStub(expr, NO_CALL_FUNCTION_FLAGS);
2268 } else { 2285 } else {
2269 { PreservePositionScope scope(masm()->positions_recorder()); 2286 { PreservePositionScope scope(masm()->positions_recorder());
2270 VisitForStackValue(prop->obj()); 2287 VisitForStackValue(prop->obj());
2271 } 2288 }
2272 EmitKeyedCallWithIC(expr, prop->key(), RelocInfo::CODE_TARGET); 2289 EmitKeyedCallWithIC(expr, prop->key());
2273 } 2290 }
2274 } 2291 }
2275 } else { 2292 } else {
2276 { PreservePositionScope scope(masm()->positions_recorder()); 2293 { PreservePositionScope scope(masm()->positions_recorder());
2277 VisitForStackValue(fun); 2294 VisitForStackValue(fun);
2278 } 2295 }
2279 // Load global receiver object. 2296 // Load global receiver object.
2280 __ mov(ebx, GlobalObjectOperand()); 2297 __ mov(ebx, GlobalObjectOperand());
2281 __ push(FieldOperand(ebx, GlobalObject::kGlobalReceiverOffset)); 2298 __ push(FieldOperand(ebx, GlobalObject::kGlobalReceiverOffset));
2282 // Emit function call. 2299 // Emit function call.
(...skipping 1325 matching lines...) Expand 10 before | Expand all | Expand 10 after
3608 // Push the arguments ("left-to-right"). 3625 // Push the arguments ("left-to-right").
3609 int arg_count = args->length(); 3626 int arg_count = args->length();
3610 for (int i = 0; i < arg_count; i++) { 3627 for (int i = 0; i < arg_count; i++) {
3611 VisitForStackValue(args->at(i)); 3628 VisitForStackValue(args->at(i));
3612 } 3629 }
3613 3630
3614 if (expr->is_jsruntime()) { 3631 if (expr->is_jsruntime()) {
3615 // Call the JS runtime function via a call IC. 3632 // Call the JS runtime function via a call IC.
3616 __ Set(ecx, Immediate(expr->name())); 3633 __ Set(ecx, Immediate(expr->name()));
3617 InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; 3634 InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
3635 RelocInfo::Mode mode = RelocInfo::CODE_TARGET;
3618 Handle<Code> ic = isolate()->stub_cache()->ComputeCallInitialize( 3636 Handle<Code> ic = isolate()->stub_cache()->ComputeCallInitialize(
3619 arg_count, in_loop); 3637 arg_count, in_loop, mode);
3620 EmitCallIC(ic, RelocInfo::CODE_TARGET, expr->id()); 3638 EmitCallIC(ic, mode, expr->id());
3621 // Restore context register. 3639 // Restore context register.
3622 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); 3640 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
3623 } else { 3641 } else {
3624 // Call the C runtime function. 3642 // Call the C runtime function.
3625 __ CallRuntime(expr->function(), arg_count); 3643 __ CallRuntime(expr->function(), arg_count);
3626 } 3644 }
3627 context()->Plug(eax); 3645 context()->Plug(eax);
3628 } 3646 }
3629 3647
3630 3648
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after
4315 // And return. 4333 // And return.
4316 __ ret(0); 4334 __ ret(0);
4317 } 4335 }
4318 4336
4319 4337
4320 #undef __ 4338 #undef __
4321 4339
4322 } } // namespace v8::internal 4340 } } // namespace v8::internal
4323 4341
4324 #endif // V8_TARGET_ARCH_IA32 4342 #endif // V8_TARGET_ARCH_IA32
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698