| 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 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1040 | 1040 |
| 1041 | 1041 |
| 1042 void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) { | 1042 void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) { |
| 1043 Comment cmnt(masm_, "[ ForInStatement"); | 1043 Comment cmnt(masm_, "[ ForInStatement"); |
| 1044 SetStatementPosition(stmt); | 1044 SetStatementPosition(stmt); |
| 1045 | 1045 |
| 1046 Label loop, exit; | 1046 Label loop, exit; |
| 1047 ForIn loop_statement(this, stmt); | 1047 ForIn loop_statement(this, stmt); |
| 1048 increment_loop_depth(); | 1048 increment_loop_depth(); |
| 1049 | 1049 |
| 1050 // Get the object to enumerate over. Both SpiderMonkey and JSC | 1050 // Get the object to enumerate over. If the object is null or undefined, skip |
| 1051 // ignore null and undefined in contrast to the specification; see | 1051 // over the loop. See ECMA-262 version 5, section 12.6.4. |
| 1052 // ECMA-262 section 12.6.4. | |
| 1053 VisitForAccumulatorValue(stmt->enumerable()); | 1052 VisitForAccumulatorValue(stmt->enumerable()); |
| 1054 __ CompareRoot(rax, Heap::kUndefinedValueRootIndex); | 1053 __ CompareRoot(rax, Heap::kUndefinedValueRootIndex); |
| 1055 __ j(equal, &exit); | 1054 __ j(equal, &exit); |
| 1056 Register null_value = rdi; | 1055 Register null_value = rdi; |
| 1057 __ LoadRoot(null_value, Heap::kNullValueRootIndex); | 1056 __ LoadRoot(null_value, Heap::kNullValueRootIndex); |
| 1058 __ cmpq(rax, null_value); | 1057 __ cmpq(rax, null_value); |
| 1059 __ j(equal, &exit); | 1058 __ j(equal, &exit); |
| 1060 | 1059 |
| 1061 PrepareForBailoutForId(stmt->PrepareId(), TOS_REG); | 1060 PrepareForBailoutForId(stmt->PrepareId(), TOS_REG); |
| 1062 | 1061 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1218 __ bind(loop_statement.break_label()); | 1217 __ bind(loop_statement.break_label()); |
| 1219 __ addq(rsp, Immediate(5 * kPointerSize)); | 1218 __ addq(rsp, Immediate(5 * kPointerSize)); |
| 1220 | 1219 |
| 1221 // Exit and decrement the loop depth. | 1220 // Exit and decrement the loop depth. |
| 1222 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); | 1221 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
| 1223 __ bind(&exit); | 1222 __ bind(&exit); |
| 1224 decrement_loop_depth(); | 1223 decrement_loop_depth(); |
| 1225 } | 1224 } |
| 1226 | 1225 |
| 1227 | 1226 |
| 1227 void FullCodeGenerator::VisitForOfStatement(ForOfStatement* stmt) { |
| 1228 Comment cmnt(masm_, "[ ForOfStatement"); |
| 1229 SetStatementPosition(stmt); |
| 1230 |
| 1231 Iteration loop_statement(this, stmt); |
| 1232 increment_loop_depth(); |
| 1233 |
| 1234 // var iterator = iterable[@@iterator]() |
| 1235 VisitForAccumulatorValue(stmt->assign_iterator()); |
| 1236 |
| 1237 // As with for-in, skip the loop if the iterator is null or undefined. |
| 1238 __ CompareRoot(rax, Heap::kUndefinedValueRootIndex); |
| 1239 __ j(equal, loop_statement.break_label()); |
| 1240 __ CompareRoot(rax, Heap::kNullValueRootIndex); |
| 1241 __ j(equal, loop_statement.break_label()); |
| 1242 |
| 1243 // Convert the iterator to a JS object. |
| 1244 Label convert, done_convert; |
| 1245 __ JumpIfSmi(rax, &convert); |
| 1246 __ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rcx); |
| 1247 __ j(above_equal, &done_convert); |
| 1248 __ bind(&convert); |
| 1249 __ push(rax); |
| 1250 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); |
| 1251 __ bind(&done_convert); |
| 1252 |
| 1253 // Loop entry. |
| 1254 __ bind(loop_statement.continue_label()); |
| 1255 |
| 1256 // result = iterator.next() |
| 1257 VisitForEffect(stmt->next_result()); |
| 1258 |
| 1259 // if (result.done) break; |
| 1260 Label result_not_done; |
| 1261 VisitForControl(stmt->result_done(), |
| 1262 loop_statement.break_label(), |
| 1263 &result_not_done, |
| 1264 &result_not_done); |
| 1265 __ bind(&result_not_done); |
| 1266 |
| 1267 // each = result.value |
| 1268 VisitForEffect(stmt->assign_each()); |
| 1269 |
| 1270 // Generate code for the body of the loop. |
| 1271 Visit(stmt->body()); |
| 1272 |
| 1273 // Check stack before looping. |
| 1274 PrepareForBailoutForId(stmt->BackEdgeId(), NO_REGISTERS); |
| 1275 EmitBackEdgeBookkeeping(stmt, loop_statement.continue_label()); |
| 1276 __ jmp(loop_statement.continue_label()); |
| 1277 |
| 1278 // Exit and decrement the loop depth. |
| 1279 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
| 1280 __ bind(loop_statement.break_label()); |
| 1281 decrement_loop_depth(); |
| 1282 } |
| 1283 |
| 1284 |
| 1228 void FullCodeGenerator::EmitNewClosure(Handle<SharedFunctionInfo> info, | 1285 void FullCodeGenerator::EmitNewClosure(Handle<SharedFunctionInfo> info, |
| 1229 bool pretenure) { | 1286 bool pretenure) { |
| 1230 // Use the fast case closure allocation code that allocates in new | 1287 // Use the fast case closure allocation code that allocates in new |
| 1231 // space for nested functions that don't need literals cloning. If | 1288 // space for nested functions that don't need literals cloning. If |
| 1232 // we're running with the --always-opt or the --prepare-always-opt | 1289 // we're running with the --always-opt or the --prepare-always-opt |
| 1233 // flag, we need to use the runtime function so that the new function | 1290 // flag, we need to use the runtime function so that the new function |
| 1234 // we are creating here gets a chance to have its code optimized and | 1291 // we are creating here gets a chance to have its code optimized and |
| 1235 // doesn't just get a copy of the existing unoptimized code. | 1292 // doesn't just get a copy of the existing unoptimized code. |
| 1236 if (!FLAG_always_opt && | 1293 if (!FLAG_always_opt && |
| 1237 !FLAG_prepare_always_opt && | 1294 !FLAG_prepare_always_opt && |
| (...skipping 3577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4815 *context_length = 0; | 4872 *context_length = 0; |
| 4816 return previous_; | 4873 return previous_; |
| 4817 } | 4874 } |
| 4818 | 4875 |
| 4819 | 4876 |
| 4820 #undef __ | 4877 #undef __ |
| 4821 | 4878 |
| 4822 } } // namespace v8::internal | 4879 } } // namespace v8::internal |
| 4823 | 4880 |
| 4824 #endif // V8_TARGET_ARCH_X64 | 4881 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |