OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1026 | 1026 |
1027 | 1027 |
1028 void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) { | 1028 void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) { |
1029 Comment cmnt(masm_, "[ ForInStatement"); | 1029 Comment cmnt(masm_, "[ ForInStatement"); |
1030 SetStatementPosition(stmt); | 1030 SetStatementPosition(stmt); |
1031 | 1031 |
1032 Label loop, exit; | 1032 Label loop, exit; |
1033 ForIn loop_statement(this, stmt); | 1033 ForIn loop_statement(this, stmt); |
1034 increment_loop_depth(); | 1034 increment_loop_depth(); |
1035 | 1035 |
1036 // Get the object to enumerate over. Both SpiderMonkey and JSC | 1036 // Get the object to enumerate over. If the object is null or undefined, skip |
1037 // ignore null and undefined in contrast to the specification; see | 1037 // over the loop. See ECMA-262 version 5, section 12.6.4. |
1038 // ECMA-262 section 12.6.4. | |
1039 VisitForAccumulatorValue(stmt->enumerable()); | 1038 VisitForAccumulatorValue(stmt->enumerable()); |
1040 __ cmp(eax, isolate()->factory()->undefined_value()); | 1039 __ cmp(eax, isolate()->factory()->undefined_value()); |
1041 __ j(equal, &exit); | 1040 __ j(equal, &exit); |
1042 __ cmp(eax, isolate()->factory()->null_value()); | 1041 __ cmp(eax, isolate()->factory()->null_value()); |
1043 __ j(equal, &exit); | 1042 __ j(equal, &exit); |
1044 | 1043 |
1045 PrepareForBailoutForId(stmt->PrepareId(), TOS_REG); | 1044 PrepareForBailoutForId(stmt->PrepareId(), TOS_REG); |
1046 | 1045 |
1047 // Convert the object to a JS object. | 1046 // Convert the object to a JS object. |
1048 Label convert, done_convert; | 1047 Label convert, done_convert; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1191 __ bind(loop_statement.break_label()); | 1190 __ bind(loop_statement.break_label()); |
1192 __ add(esp, Immediate(5 * kPointerSize)); | 1191 __ add(esp, Immediate(5 * kPointerSize)); |
1193 | 1192 |
1194 // Exit and decrement the loop depth. | 1193 // Exit and decrement the loop depth. |
1195 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); | 1194 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
1196 __ bind(&exit); | 1195 __ bind(&exit); |
1197 decrement_loop_depth(); | 1196 decrement_loop_depth(); |
1198 } | 1197 } |
1199 | 1198 |
1200 | 1199 |
| 1200 void FullCodeGenerator::VisitForOfStatement(ForOfStatement* stmt) { |
| 1201 Comment cmnt(masm_, "[ ForOfStatement"); |
| 1202 SetStatementPosition(stmt); |
| 1203 |
| 1204 Iteration loop_statement(this, stmt); |
| 1205 increment_loop_depth(); |
| 1206 |
| 1207 // var iterator = iterable[@@iterator]() |
| 1208 VisitForAccumulatorValue(stmt->assign_iterator()); |
| 1209 |
| 1210 // As with for-in, skip the loop if the iterator is null or undefined. |
| 1211 __ CompareRoot(eax, Heap::kUndefinedValueRootIndex); |
| 1212 __ j(equal, loop_statement.break_label()); |
| 1213 __ CompareRoot(eax, Heap::kNullValueRootIndex); |
| 1214 __ j(equal, loop_statement.break_label()); |
| 1215 |
| 1216 // Convert the iterator to a JS object. |
| 1217 Label convert, done_convert; |
| 1218 __ JumpIfSmi(eax, &convert); |
| 1219 __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 1220 __ j(above_equal, &done_convert); |
| 1221 __ bind(&convert); |
| 1222 __ push(eax); |
| 1223 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); |
| 1224 __ bind(&done_convert); |
| 1225 |
| 1226 // Loop entry. |
| 1227 __ bind(loop_statement.continue_label()); |
| 1228 |
| 1229 // result = iterator.next() |
| 1230 VisitForEffect(stmt->next_result()); |
| 1231 |
| 1232 // if (result.done) break; |
| 1233 Label result_not_done; |
| 1234 VisitForControl(stmt->result_done(), |
| 1235 loop_statement.break_label(), |
| 1236 &result_not_done, |
| 1237 &result_not_done); |
| 1238 __ bind(&result_not_done); |
| 1239 |
| 1240 // each = result.value |
| 1241 VisitForEffect(stmt->assign_each()); |
| 1242 |
| 1243 // Generate code for the body of the loop. |
| 1244 Visit(stmt->body()); |
| 1245 |
| 1246 // Check stack before looping. |
| 1247 PrepareForBailoutForId(stmt->BackEdgeId(), NO_REGISTERS); |
| 1248 EmitBackEdgeBookkeeping(stmt, loop_statement.continue_label()); |
| 1249 __ jmp(loop_statement.continue_label()); |
| 1250 |
| 1251 // Exit and decrement the loop depth. |
| 1252 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
| 1253 __ bind(loop_statement.break_label()); |
| 1254 decrement_loop_depth(); |
| 1255 } |
| 1256 |
| 1257 |
1201 void FullCodeGenerator::EmitNewClosure(Handle<SharedFunctionInfo> info, | 1258 void FullCodeGenerator::EmitNewClosure(Handle<SharedFunctionInfo> info, |
1202 bool pretenure) { | 1259 bool pretenure) { |
1203 // Use the fast case closure allocation code that allocates in new | 1260 // Use the fast case closure allocation code that allocates in new |
1204 // space for nested functions that don't need literals cloning. If | 1261 // space for nested functions that don't need literals cloning. If |
1205 // we're running with the --always-opt or the --prepare-always-opt | 1262 // we're running with the --always-opt or the --prepare-always-opt |
1206 // flag, we need to use the runtime function so that the new function | 1263 // flag, we need to use the runtime function so that the new function |
1207 // we are creating here gets a chance to have its code optimized and | 1264 // we are creating here gets a chance to have its code optimized and |
1208 // doesn't just get a copy of the existing unoptimized code. | 1265 // doesn't just get a copy of the existing unoptimized code. |
1209 if (!FLAG_always_opt && | 1266 if (!FLAG_always_opt && |
1210 !FLAG_prepare_always_opt && | 1267 !FLAG_prepare_always_opt && |
(...skipping 3658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4869 *stack_depth = 0; | 4926 *stack_depth = 0; |
4870 *context_length = 0; | 4927 *context_length = 0; |
4871 return previous_; | 4928 return previous_; |
4872 } | 4929 } |
4873 | 4930 |
4874 #undef __ | 4931 #undef __ |
4875 | 4932 |
4876 } } // namespace v8::internal | 4933 } } // namespace v8::internal |
4877 | 4934 |
4878 #endif // V8_TARGET_ARCH_IA32 | 4935 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |