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