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

Side by Side Diff: src/interpreter/bytecode-generator.cc

Issue 2637403008: [async-iteration] add support for for-await-of loops in Async Functions (Closed)
Patch Set: rebase Created 3 years, 11 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
OLDNEW
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 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 object_literals_(0, info->zone()), 580 object_literals_(0, info->zone()),
581 array_literals_(0, info->zone()), 581 array_literals_(0, info->zone()),
582 execution_control_(nullptr), 582 execution_control_(nullptr),
583 execution_context_(nullptr), 583 execution_context_(nullptr),
584 execution_result_(nullptr), 584 execution_result_(nullptr),
585 generator_resume_points_(info->literal()->yield_count(), info->zone()), 585 generator_resume_points_(info->literal()->yield_count(), info->zone()),
586 generator_state_(), 586 generator_state_(),
587 loop_depth_(0), 587 loop_depth_(0),
588 home_object_symbol_(info->isolate()->factory()->home_object_symbol()), 588 home_object_symbol_(info->isolate()->factory()->home_object_symbol()),
589 iterator_symbol_(info->isolate()->factory()->iterator_symbol()), 589 iterator_symbol_(info->isolate()->factory()->iterator_symbol()),
590 async_iterator_symbol_(
591 info->isolate()->factory()->async_iterator_symbol()),
590 prototype_string_(info->isolate()->factory()->prototype_string()), 592 prototype_string_(info->isolate()->factory()->prototype_string()),
591 empty_fixed_array_(info->isolate()->factory()->empty_fixed_array()), 593 empty_fixed_array_(info->isolate()->factory()->empty_fixed_array()),
592 undefined_string_( 594 undefined_string_(
593 info->isolate()->ast_string_constants()->undefined_string()) {} 595 info->isolate()->ast_string_constants()->undefined_string()) {}
594 596
595 Handle<BytecodeArray> BytecodeGenerator::FinalizeBytecode(Isolate* isolate) { 597 Handle<BytecodeArray> BytecodeGenerator::FinalizeBytecode(Isolate* isolate) {
596 AllocateDeferredConstants(isolate); 598 AllocateDeferredConstants(isolate);
597 if (HasStackOverflow()) return Handle<BytecodeArray>(); 599 if (HasStackOverflow()) return Handle<BytecodeArray>();
598 return builder()->ToBytecodeArray(isolate); 600 return builder()->ToBytecodeArray(isolate);
599 } 601 }
(...skipping 2292 matching lines...) Expand 10 before | Expand all | Expand 10 after
2892 builder()->BinaryOperation(expr->op(), lhs, feedback_index(slot)); 2894 builder()->BinaryOperation(expr->op(), lhs, feedback_index(slot));
2893 } 2895 }
2894 2896
2895 void BytecodeGenerator::VisitSpread(Spread* expr) { Visit(expr->expression()); } 2897 void BytecodeGenerator::VisitSpread(Spread* expr) { Visit(expr->expression()); }
2896 2898
2897 void BytecodeGenerator::VisitEmptyParentheses(EmptyParentheses* expr) { 2899 void BytecodeGenerator::VisitEmptyParentheses(EmptyParentheses* expr) {
2898 UNREACHABLE(); 2900 UNREACHABLE();
2899 } 2901 }
2900 2902
2901 void BytecodeGenerator::VisitGetIterator(GetIterator* expr) { 2903 void BytecodeGenerator::VisitGetIterator(GetIterator* expr) {
2902 FeedbackVectorSlot load_slot = expr->IteratorPropertyFeedbackSlot(); 2904 FeedbackVectorSlot load_iter_slot = expr->IteratorPropertyFeedbackSlot();
2903 FeedbackVectorSlot call_slot = expr->IteratorCallFeedbackSlot(); 2905 FeedbackVectorSlot call_iter_slot = expr->IteratorCallFeedbackSlot();
2904 2906
2905 RegisterList args = register_allocator()->NewRegisterList(1); 2907 RegisterList args = register_allocator()->NewRegisterList(1);
2906 Register method = register_allocator()->NewRegister(); 2908 Register method = register_allocator()->NewRegister();
2907 Register obj = args[0]; 2909 Register obj = args[0];
2908 2910
2909 VisitForAccumulatorValue(expr->iterable()); 2911 VisitForAccumulatorValue(expr->iterable());
2910 2912
2911 // Let method be GetMethod(obj, @@iterator). 2913 if (expr->hint() == GetIterator::Hint::kAsync) {
2912 builder() 2914 FeedbackVectorSlot load_async_iter_slot =
2913 ->StoreAccumulatorInRegister(obj) 2915 expr->AsyncIteratorPropertyFeedbackSlot();
2914 .LoadNamedProperty(obj, iterator_symbol(), feedback_index(load_slot)) 2916 FeedbackVectorSlot call_async_iter_slot =
2915 .StoreAccumulatorInRegister(method); 2917 expr->AsyncIteratorCallFeedbackSlot();
2916 2918
2917 // Let iterator be Call(method, obj). 2919 // Set method to GetMethod(obj, @@asyncIterator)
2918 builder()->Call(method, args, feedback_index(call_slot), 2920 builder()->StoreAccumulatorInRegister(obj).LoadNamedProperty(
2919 Call::NAMED_PROPERTY_CALL); 2921 obj, async_iterator_symbol(), feedback_index(load_async_iter_slot));
2920 2922
2921 // If Type(iterator) is not Object, throw a TypeError exception. 2923 BytecodeLabel async_iterator_undefined, async_iterator_null, done;
2922 BytecodeLabel no_type_error; 2924 builder()->JumpIfUndefined(&async_iterator_undefined);
2923 builder()->JumpIfJSReceiver(&no_type_error); 2925 builder()->JumpIfNull(&async_iterator_null);
2924 builder()->CallRuntime(Runtime::kThrowSymbolIteratorInvalid); 2926
2925 builder()->Bind(&no_type_error); 2927 // Let iterator be Call(method, obj)
2928 builder()->StoreAccumulatorInRegister(method).Call(
2929 method, args, feedback_index(call_async_iter_slot),
2930 Call::NAMED_PROPERTY_CALL);
2931
2932 // If Type(iterator) is not Object, throw a TypeError exception.
2933 builder()->JumpIfJSReceiver(&done);
2934 builder()->CallRuntime(Runtime::kThrowSymbolAsyncIteratorInvalid);
2935
2936 builder()->Bind(&async_iterator_undefined);
2937 builder()->Bind(&async_iterator_null);
2938 // If method is undefined,
2939 // Let syncMethod be GetMethod(obj, @@iterator)
2940 builder()
2941 ->LoadNamedProperty(obj, iterator_symbol(),
2942 feedback_index(load_iter_slot))
2943 .StoreAccumulatorInRegister(method);
2944
2945 // Let syncIterator be Call(syncMethod, obj)
2946 builder()->Call(method, args, feedback_index(call_iter_slot),
2947 Call::NAMED_PROPERTY_CALL);
2948
2949 // Return CreateAsyncFromSyncIterator(syncIterator)
2950 // alias `method` register as it's no longer used
2951 Register sync_iter = method;
2952 builder()->StoreAccumulatorInRegister(sync_iter).CallRuntime(
2953 Runtime::kInlineCreateAsyncFromSyncIterator, sync_iter);
2954
2955 builder()->Bind(&done);
2956 } else {
2957 // Let method be GetMethod(obj, @@iterator).
2958 builder()
2959 ->StoreAccumulatorInRegister(obj)
2960 .LoadNamedProperty(obj, iterator_symbol(),
2961 feedback_index(load_iter_slot))
2962 .StoreAccumulatorInRegister(method);
2963
2964 // Let iterator be Call(method, obj).
2965 builder()->Call(method, args, feedback_index(call_iter_slot),
2966 Call::NAMED_PROPERTY_CALL);
2967
2968 // If Type(iterator) is not Object, throw a TypeError exception.
2969 BytecodeLabel no_type_error;
2970 builder()->JumpIfJSReceiver(&no_type_error);
2971 builder()->CallRuntime(Runtime::kThrowSymbolIteratorInvalid);
2972 builder()->Bind(&no_type_error);
2973 }
2926 } 2974 }
2927 2975
2928 void BytecodeGenerator::VisitThisFunction(ThisFunction* expr) { 2976 void BytecodeGenerator::VisitThisFunction(ThisFunction* expr) {
2929 builder()->LoadAccumulatorWithRegister(Register::function_closure()); 2977 builder()->LoadAccumulatorWithRegister(Register::function_closure());
2930 } 2978 }
2931 2979
2932 void BytecodeGenerator::VisitSuperCallReference(SuperCallReference* expr) { 2980 void BytecodeGenerator::VisitSuperCallReference(SuperCallReference* expr) {
2933 // Handled by VisitCall(). 2981 // Handled by VisitCall().
2934 UNREACHABLE(); 2982 UNREACHABLE();
2935 } 2983 }
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
3341 } 3389 }
3342 3390
3343 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() { 3391 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() {
3344 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict 3392 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict
3345 : Runtime::kStoreKeyedToSuper_Sloppy; 3393 : Runtime::kStoreKeyedToSuper_Sloppy;
3346 } 3394 }
3347 3395
3348 } // namespace interpreter 3396 } // namespace interpreter
3349 } // namespace internal 3397 } // namespace internal
3350 } // namespace v8 3398 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/bytecode-generator.h ('k') | src/messages.h » ('j') | src/parsing/parser-base.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698