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

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. 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
« no previous file with comments | « src/ia32/code-stubs-ia32.cc ('k') | src/ia32/ic-ia32.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 SetFunctionPosition(function()); 124 SetFunctionPosition(function());
125 Comment cmnt(masm_, "[ function compiled by full code generator"); 125 Comment cmnt(masm_, "[ function compiled by full code generator");
126 126
127 #ifdef DEBUG 127 #ifdef DEBUG
128 if (strlen(FLAG_stop_at) > 0 && 128 if (strlen(FLAG_stop_at) > 0 &&
129 info->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) { 129 info->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) {
130 __ int3(); 130 __ int3();
131 } 131 }
132 #endif 132 #endif
133 133
134 // Strict mode functions need to replace the receiver with undefined
135 // when called as functions (without an explicit receiver
136 // object). ecx is zero for method calls and non-zero for function
137 // calls.
138 if (info->is_strict_mode()) {
139 Label ok;
140 __ test(ecx, Operand(ecx));
141 __ j(zero, &ok, Label::kNear);
142 // +1 for return address.
143 int receiver_offset = (scope()->num_parameters() + 1) * kPointerSize;
144 __ mov(Operand(esp, receiver_offset),
145 Immediate(isolate()->factory()->undefined_value()));
146 __ bind(&ok);
147 }
148
134 __ push(ebp); // Caller's frame pointer. 149 __ push(ebp); // Caller's frame pointer.
135 __ mov(ebp, esp); 150 __ mov(ebp, esp);
136 __ push(esi); // Callee's context. 151 __ push(esi); // Callee's context.
137 __ push(edi); // Callee's JS Function. 152 __ push(edi); // Callee's JS Function.
138 153
139 { Comment cmnt(masm_, "[ Allocate locals"); 154 { Comment cmnt(masm_, "[ Allocate locals");
140 int locals_count = scope()->num_stack_slots(); 155 int locals_count = scope()->num_stack_slots();
141 if (locals_count == 1) { 156 if (locals_count == 1) {
142 __ push(Immediate(isolate()->factory()->undefined_value())); 157 __ push(Immediate(isolate()->factory()->undefined_value()));
143 } else if (locals_count > 1) { 158 } else if (locals_count > 1) {
(...skipping 1878 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, in_loop, RECEIVER_MIGHT_BE_IMPLICIT);
2180 __ CallStub(&stub); 2194 __ CallStub(&stub);
2181 RecordJSReturnSite(expr); 2195 RecordJSReturnSite(expr);
2182 // Restore context register. 2196 // Restore context register.
2183 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); 2197 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
2184 context()->DropAndPlug(1, eax); 2198 context()->DropAndPlug(1, eax);
2185 } else if (var != NULL && !var->is_this() && var->is_global()) { 2199 } else if (var != NULL && !var->is_this() && var->is_global()) {
2186 // Push global object as receiver for the call IC. 2200 // Push global object as receiver for the call IC.
2187 __ push(GlobalObjectOperand()); 2201 __ push(GlobalObjectOperand());
2188 EmitCallWithIC(expr, var->name(), RelocInfo::CODE_TARGET_CONTEXT); 2202 EmitCallWithIC(expr, var->name(), RelocInfo::CODE_TARGET_CONTEXT);
2189 } else if (var != NULL && var->AsSlot() != NULL && 2203 } else if (var != NULL && var->AsSlot() != NULL &&
(...skipping 27 matching lines...) Expand all
2217 __ jmp(&call); 2231 __ jmp(&call);
2218 __ bind(&done); 2232 __ bind(&done);
2219 // Push function. 2233 // Push function.
2220 __ push(eax); 2234 __ push(eax);
2221 // Push global receiver. 2235 // Push global receiver.
2222 __ mov(ebx, GlobalObjectOperand()); 2236 __ mov(ebx, GlobalObjectOperand());
2223 __ push(FieldOperand(ebx, GlobalObject::kGlobalReceiverOffset)); 2237 __ push(FieldOperand(ebx, GlobalObject::kGlobalReceiverOffset));
2224 __ bind(&call); 2238 __ bind(&call);
2225 } 2239 }
2226 2240
2227 // The receiver is either the global receiver or a JSObject found by 2241 // The receiver is either the global receiver or an object found
2228 // LoadContextSlot. 2242 // by LoadContextSlot. That object could be the hole if the
2229 EmitCallWithStub(expr, NO_CALL_FUNCTION_FLAGS); 2243 // receiver is implicitly the global object.
2244 EmitCallWithStub(expr, RECEIVER_MIGHT_BE_IMPLICIT);
2230 } else if (fun->AsProperty() != NULL) { 2245 } else if (fun->AsProperty() != NULL) {
2231 // Call to an object property. 2246 // Call to an object property.
2232 Property* prop = fun->AsProperty(); 2247 Property* prop = fun->AsProperty();
2233 Literal* key = prop->key()->AsLiteral(); 2248 Literal* key = prop->key()->AsLiteral();
2234 if (key != NULL && key->handle()->IsSymbol()) { 2249 if (key != NULL && key->handle()->IsSymbol()) {
2235 // Call to a named property, use call IC. 2250 // Call to a named property, use call IC.
2236 { PreservePositionScope scope(masm()->positions_recorder()); 2251 { PreservePositionScope scope(masm()->positions_recorder());
2237 VisitForStackValue(prop->obj()); 2252 VisitForStackValue(prop->obj());
2238 } 2253 }
2239 EmitCallWithIC(expr, key->handle(), RelocInfo::CODE_TARGET); 2254 EmitCallWithIC(expr, key->handle(), RelocInfo::CODE_TARGET);
(...skipping 22 matching lines...) Expand all
2262 // Push result (function). 2277 // Push result (function).
2263 __ push(eax); 2278 __ push(eax);
2264 // Push Global receiver. 2279 // Push Global receiver.
2265 __ mov(ecx, GlobalObjectOperand()); 2280 __ mov(ecx, GlobalObjectOperand());
2266 __ push(FieldOperand(ecx, GlobalObject::kGlobalReceiverOffset)); 2281 __ push(FieldOperand(ecx, GlobalObject::kGlobalReceiverOffset));
2267 EmitCallWithStub(expr, NO_CALL_FUNCTION_FLAGS); 2282 EmitCallWithStub(expr, NO_CALL_FUNCTION_FLAGS);
2268 } else { 2283 } else {
2269 { PreservePositionScope scope(masm()->positions_recorder()); 2284 { PreservePositionScope scope(masm()->positions_recorder());
2270 VisitForStackValue(prop->obj()); 2285 VisitForStackValue(prop->obj());
2271 } 2286 }
2272 EmitKeyedCallWithIC(expr, prop->key(), RelocInfo::CODE_TARGET); 2287 EmitKeyedCallWithIC(expr, prop->key());
2273 } 2288 }
2274 } 2289 }
2275 } else { 2290 } else {
2276 { PreservePositionScope scope(masm()->positions_recorder()); 2291 { PreservePositionScope scope(masm()->positions_recorder());
2277 VisitForStackValue(fun); 2292 VisitForStackValue(fun);
2278 } 2293 }
2279 // Load global receiver object. 2294 // Load global receiver object.
2280 __ mov(ebx, GlobalObjectOperand()); 2295 __ mov(ebx, GlobalObjectOperand());
2281 __ push(FieldOperand(ebx, GlobalObject::kGlobalReceiverOffset)); 2296 __ push(FieldOperand(ebx, GlobalObject::kGlobalReceiverOffset));
2282 // Emit function call. 2297 // Emit function call.
(...skipping 1325 matching lines...) Expand 10 before | Expand all | Expand 10 after
3608 // Push the arguments ("left-to-right"). 3623 // Push the arguments ("left-to-right").
3609 int arg_count = args->length(); 3624 int arg_count = args->length();
3610 for (int i = 0; i < arg_count; i++) { 3625 for (int i = 0; i < arg_count; i++) {
3611 VisitForStackValue(args->at(i)); 3626 VisitForStackValue(args->at(i));
3612 } 3627 }
3613 3628
3614 if (expr->is_jsruntime()) { 3629 if (expr->is_jsruntime()) {
3615 // Call the JS runtime function via a call IC. 3630 // Call the JS runtime function via a call IC.
3616 __ Set(ecx, Immediate(expr->name())); 3631 __ Set(ecx, Immediate(expr->name()));
3617 InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; 3632 InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP;
3633 RelocInfo::Mode mode = RelocInfo::CODE_TARGET;
3618 Handle<Code> ic = isolate()->stub_cache()->ComputeCallInitialize( 3634 Handle<Code> ic = isolate()->stub_cache()->ComputeCallInitialize(
3619 arg_count, in_loop); 3635 arg_count, in_loop, mode);
3620 EmitCallIC(ic, RelocInfo::CODE_TARGET, expr->id()); 3636 EmitCallIC(ic, mode, expr->id());
3621 // Restore context register. 3637 // Restore context register.
3622 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); 3638 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
3623 } else { 3639 } else {
3624 // Call the C runtime function. 3640 // Call the C runtime function.
3625 __ CallRuntime(expr->function(), arg_count); 3641 __ CallRuntime(expr->function(), arg_count);
3626 } 3642 }
3627 context()->Plug(eax); 3643 context()->Plug(eax);
3628 } 3644 }
3629 3645
3630 3646
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after
4315 // And return. 4331 // And return.
4316 __ ret(0); 4332 __ ret(0);
4317 } 4333 }
4318 4334
4319 4335
4320 #undef __ 4336 #undef __
4321 4337
4322 } } // namespace v8::internal 4338 } } // namespace v8::internal
4323 4339
4324 #endif // V8_TARGET_ARCH_IA32 4340 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/ia32/code-stubs-ia32.cc ('k') | src/ia32/ic-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698