OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/interpreter/bytecode-generator.h" | 5 #include "src/interpreter/bytecode-generator.h" |
6 | 6 |
7 #include "src/ast/compile-time-value.h" | 7 #include "src/ast/compile-time-value.h" |
8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
9 #include "src/builtins/builtins-constructor.h" | 9 #include "src/builtins/builtins-constructor.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 object_literals_(0, info->zone()), | 596 object_literals_(0, info->zone()), |
597 array_literals_(0, info->zone()), | 597 array_literals_(0, info->zone()), |
598 execution_control_(nullptr), | 598 execution_control_(nullptr), |
599 execution_context_(nullptr), | 599 execution_context_(nullptr), |
600 execution_result_(nullptr), | 600 execution_result_(nullptr), |
601 generator_resume_points_(info->literal()->yield_count(), info->zone()), | 601 generator_resume_points_(info->literal()->yield_count(), info->zone()), |
602 generator_state_(), | 602 generator_state_(), |
603 loop_depth_(0), | 603 loop_depth_(0), |
604 home_object_symbol_(info->isolate()->factory()->home_object_symbol()), | 604 home_object_symbol_(info->isolate()->factory()->home_object_symbol()), |
605 iterator_symbol_(info->isolate()->factory()->iterator_symbol()), | 605 iterator_symbol_(info->isolate()->factory()->iterator_symbol()), |
| 606 async_iterator_symbol_( |
| 607 info->isolate()->factory()->async_iterator_symbol()), |
606 prototype_string_(info->isolate()->factory()->prototype_string()), | 608 prototype_string_(info->isolate()->factory()->prototype_string()), |
607 empty_fixed_array_(info->isolate()->factory()->empty_fixed_array()), | 609 empty_fixed_array_(info->isolate()->factory()->empty_fixed_array()), |
608 undefined_string_( | 610 undefined_string_( |
609 info->isolate()->ast_string_constants()->undefined_string()) {} | 611 info->isolate()->ast_string_constants()->undefined_string()) {} |
610 | 612 |
611 Handle<BytecodeArray> BytecodeGenerator::FinalizeBytecode(Isolate* isolate) { | 613 Handle<BytecodeArray> BytecodeGenerator::FinalizeBytecode(Isolate* isolate) { |
612 AllocateDeferredConstants(isolate); | 614 AllocateDeferredConstants(isolate); |
613 if (HasStackOverflow()) return Handle<BytecodeArray>(); | 615 if (HasStackOverflow()) return Handle<BytecodeArray>(); |
614 return builder()->ToBytecodeArray(isolate); | 616 return builder()->ToBytecodeArray(isolate); |
615 } | 617 } |
(...skipping 2310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2926 builder()->BinaryOperation(expr->op(), lhs, feedback_index(slot)); | 2928 builder()->BinaryOperation(expr->op(), lhs, feedback_index(slot)); |
2927 } | 2929 } |
2928 | 2930 |
2929 void BytecodeGenerator::VisitSpread(Spread* expr) { Visit(expr->expression()); } | 2931 void BytecodeGenerator::VisitSpread(Spread* expr) { Visit(expr->expression()); } |
2930 | 2932 |
2931 void BytecodeGenerator::VisitEmptyParentheses(EmptyParentheses* expr) { | 2933 void BytecodeGenerator::VisitEmptyParentheses(EmptyParentheses* expr) { |
2932 UNREACHABLE(); | 2934 UNREACHABLE(); |
2933 } | 2935 } |
2934 | 2936 |
2935 void BytecodeGenerator::VisitGetIterator(GetIterator* expr) { | 2937 void BytecodeGenerator::VisitGetIterator(GetIterator* expr) { |
2936 FeedbackVectorSlot load_slot = expr->IteratorPropertyFeedbackSlot(); | 2938 FeedbackVectorSlot load_iter_slot = expr->IteratorPropertyFeedbackSlot(); |
2937 FeedbackVectorSlot call_slot = expr->IteratorCallFeedbackSlot(); | 2939 FeedbackVectorSlot call_iter_slot = expr->IteratorCallFeedbackSlot(); |
2938 | 2940 |
2939 RegisterList args = register_allocator()->NewRegisterList(1); | 2941 RegisterList args = register_allocator()->NewRegisterList(1); |
2940 Register method = register_allocator()->NewRegister(); | 2942 Register method = register_allocator()->NewRegister(); |
2941 Register obj = args[0]; | 2943 Register obj = args[0]; |
2942 | 2944 |
2943 VisitForAccumulatorValue(expr->iterable()); | 2945 VisitForAccumulatorValue(expr->iterable()); |
2944 | 2946 |
2945 // Let method be GetMethod(obj, @@iterator). | 2947 if (expr->hint() == IteratorType::kAsync) { |
2946 builder() | 2948 FeedbackVectorSlot load_async_iter_slot = |
2947 ->StoreAccumulatorInRegister(obj) | 2949 expr->AsyncIteratorPropertyFeedbackSlot(); |
2948 .LoadNamedProperty(obj, iterator_symbol(), feedback_index(load_slot)) | 2950 FeedbackVectorSlot call_async_iter_slot = |
2949 .StoreAccumulatorInRegister(method); | 2951 expr->AsyncIteratorCallFeedbackSlot(); |
2950 | 2952 |
2951 // Let iterator be Call(method, obj). | 2953 // Set method to GetMethod(obj, @@asyncIterator) |
2952 builder()->Call(method, args, feedback_index(call_slot), | 2954 builder()->StoreAccumulatorInRegister(obj).LoadNamedProperty( |
2953 Call::NAMED_PROPERTY_CALL); | 2955 obj, async_iterator_symbol(), feedback_index(load_async_iter_slot)); |
2954 | 2956 |
2955 // If Type(iterator) is not Object, throw a TypeError exception. | 2957 BytecodeLabel async_iterator_undefined, async_iterator_null, done; |
2956 BytecodeLabel no_type_error; | 2958 // TODO(ignition): Add a single opcode for JumpIfNullOrUndefined |
2957 builder()->JumpIfJSReceiver(&no_type_error); | 2959 builder()->JumpIfUndefined(&async_iterator_undefined); |
2958 builder()->CallRuntime(Runtime::kThrowSymbolIteratorInvalid); | 2960 builder()->JumpIfNull(&async_iterator_null); |
2959 builder()->Bind(&no_type_error); | 2961 |
| 2962 // Let iterator be Call(method, obj) |
| 2963 builder()->StoreAccumulatorInRegister(method).Call( |
| 2964 method, args, feedback_index(call_async_iter_slot), |
| 2965 Call::NAMED_PROPERTY_CALL); |
| 2966 |
| 2967 // If Type(iterator) is not Object, throw a TypeError exception. |
| 2968 builder()->JumpIfJSReceiver(&done); |
| 2969 builder()->CallRuntime(Runtime::kThrowSymbolAsyncIteratorInvalid); |
| 2970 |
| 2971 builder()->Bind(&async_iterator_undefined); |
| 2972 builder()->Bind(&async_iterator_null); |
| 2973 // If method is undefined, |
| 2974 // Let syncMethod be GetMethod(obj, @@iterator) |
| 2975 builder() |
| 2976 ->LoadNamedProperty(obj, iterator_symbol(), |
| 2977 feedback_index(load_iter_slot)) |
| 2978 .StoreAccumulatorInRegister(method); |
| 2979 |
| 2980 // Let syncIterator be Call(syncMethod, obj) |
| 2981 builder()->Call(method, args, feedback_index(call_iter_slot), |
| 2982 Call::NAMED_PROPERTY_CALL); |
| 2983 |
| 2984 // Return CreateAsyncFromSyncIterator(syncIterator) |
| 2985 // alias `method` register as it's no longer used |
| 2986 Register sync_iter = method; |
| 2987 builder()->StoreAccumulatorInRegister(sync_iter).CallRuntime( |
| 2988 Runtime::kInlineCreateAsyncFromSyncIterator, sync_iter); |
| 2989 |
| 2990 builder()->Bind(&done); |
| 2991 } else { |
| 2992 // Let method be GetMethod(obj, @@iterator). |
| 2993 builder() |
| 2994 ->StoreAccumulatorInRegister(obj) |
| 2995 .LoadNamedProperty(obj, iterator_symbol(), |
| 2996 feedback_index(load_iter_slot)) |
| 2997 .StoreAccumulatorInRegister(method); |
| 2998 |
| 2999 // Let iterator be Call(method, obj). |
| 3000 builder()->Call(method, args, feedback_index(call_iter_slot), |
| 3001 Call::NAMED_PROPERTY_CALL); |
| 3002 |
| 3003 // If Type(iterator) is not Object, throw a TypeError exception. |
| 3004 BytecodeLabel no_type_error; |
| 3005 builder()->JumpIfJSReceiver(&no_type_error); |
| 3006 builder()->CallRuntime(Runtime::kThrowSymbolIteratorInvalid); |
| 3007 builder()->Bind(&no_type_error); |
| 3008 } |
2960 } | 3009 } |
2961 | 3010 |
2962 void BytecodeGenerator::VisitThisFunction(ThisFunction* expr) { | 3011 void BytecodeGenerator::VisitThisFunction(ThisFunction* expr) { |
2963 builder()->LoadAccumulatorWithRegister(Register::function_closure()); | 3012 builder()->LoadAccumulatorWithRegister(Register::function_closure()); |
2964 } | 3013 } |
2965 | 3014 |
2966 void BytecodeGenerator::VisitSuperCallReference(SuperCallReference* expr) { | 3015 void BytecodeGenerator::VisitSuperCallReference(SuperCallReference* expr) { |
2967 // Handled by VisitCall(). | 3016 // Handled by VisitCall(). |
2968 UNREACHABLE(); | 3017 UNREACHABLE(); |
2969 } | 3018 } |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3375 } | 3424 } |
3376 | 3425 |
3377 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() { | 3426 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() { |
3378 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict | 3427 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict |
3379 : Runtime::kStoreKeyedToSuper_Sloppy; | 3428 : Runtime::kStoreKeyedToSuper_Sloppy; |
3380 } | 3429 } |
3381 | 3430 |
3382 } // namespace interpreter | 3431 } // namespace interpreter |
3383 } // namespace internal | 3432 } // namespace internal |
3384 } // namespace v8 | 3433 } // namespace v8 |
OLD | NEW |