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

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: [async-iteration] add support for for-await-of loops in Async Functions 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 2325 matching lines...) Expand 10 before | Expand all | Expand 10 after
2925 builder()->BinaryOperation(expr->op(), lhs, feedback_index(slot)); 2927 builder()->BinaryOperation(expr->op(), lhs, feedback_index(slot));
2926 } 2928 }
2927 2929
2928 void BytecodeGenerator::VisitSpread(Spread* expr) { Visit(expr->expression()); } 2930 void BytecodeGenerator::VisitSpread(Spread* expr) { Visit(expr->expression()); }
2929 2931
2930 void BytecodeGenerator::VisitEmptyParentheses(EmptyParentheses* expr) { 2932 void BytecodeGenerator::VisitEmptyParentheses(EmptyParentheses* expr) {
2931 UNREACHABLE(); 2933 UNREACHABLE();
2932 } 2934 }
2933 2935
2934 void BytecodeGenerator::VisitGetIterator(GetIterator* expr) { 2936 void BytecodeGenerator::VisitGetIterator(GetIterator* expr) {
2935 FeedbackVectorSlot load_slot = expr->IteratorPropertyFeedbackSlot(); 2937 FeedbackVectorSlot load_iter_slot = expr->IteratorPropertyFeedbackSlot();
2936 FeedbackVectorSlot call_slot = expr->IteratorCallFeedbackSlot(); 2938 FeedbackVectorSlot call_iter_slot = expr->IteratorCallFeedbackSlot();
2937 2939
2938 RegisterList args = register_allocator()->NewRegisterList(1); 2940 RegisterList args = register_allocator()->NewRegisterList(1);
2939 Register method = register_allocator()->NewRegister(); 2941 Register method = register_allocator()->NewRegister();
2940 Register obj = args[0]; 2942 Register obj = args[0];
2941 2943
2942 VisitForAccumulatorValue(expr->iterable()); 2944 VisitForAccumulatorValue(expr->iterable());
2943 2945
2944 // Let method be GetMethod(obj, @@iterator). 2946 if (expr->hint() == GetIterator::Hint::kAsync) {
2945 builder() 2947 FeedbackVectorSlot load_async_iter_slot =
2946 ->StoreAccumulatorInRegister(obj) 2948 expr->AsyncIteratorPropertyFeedbackSlot();
2947 .LoadNamedProperty(obj, iterator_symbol(), feedback_index(load_slot)) 2949 FeedbackVectorSlot call_async_iter_slot =
2948 .StoreAccumulatorInRegister(method); 2950 expr->AsyncIteratorCallFeedbackSlot();
2949 2951
2950 // Let iterator be Call(method, obj). 2952 // Set method to GetMethod(obj, @@asyncIterator)
2951 builder()->Call(method, args, feedback_index(call_slot), 2953 builder()->StoreAccumulatorInRegister(obj).LoadNamedProperty(
2952 Call::NAMED_PROPERTY_CALL); 2954 obj, async_iterator_symbol(), feedback_index(load_async_iter_slot));
2953 2955
2954 // If Type(iterator) is not Object, throw a TypeError exception. 2956 BytecodeLabel async_iterator_undefined, async_iterator_null, done;
2955 BytecodeLabel no_type_error; 2957 builder()->JumpIfUndefined(&async_iterator_undefined);
2956 builder()->JumpIfJSReceiver(&no_type_error); 2958 builder()->JumpIfNull(&async_iterator_null);
2957 builder()->CallRuntime(Runtime::kThrowSymbolIteratorInvalid); 2959
2958 builder()->Bind(&no_type_error); 2960 // Let iterator be Call(method, obj)
2961 builder()->StoreAccumulatorInRegister(method).Call(
2962 method, args, feedback_index(call_async_iter_slot),
2963 Call::NAMED_PROPERTY_CALL);
2964
2965 // If Type(iterator) is not Object, throw a TypeError exception.
2966 builder()->JumpIfJSReceiver(&done);
2967 builder()->CallRuntime(Runtime::kThrowSymbolAsyncIteratorInvalid);
2968
2969 builder()->Bind(&async_iterator_undefined);
2970 builder()->Bind(&async_iterator_null);
2971 // If method is undefined,
2972 // Let syncMethod be GetMethod(obj, @@iterator)
2973 builder()
2974 ->LoadNamedProperty(obj, iterator_symbol(),
2975 feedback_index(load_iter_slot))
2976 .StoreAccumulatorInRegister(method);
2977
2978 // Let syncIterator be Call(syncMethod, obj)
2979 builder()->Call(method, args, feedback_index(call_iter_slot),
2980 Call::NAMED_PROPERTY_CALL);
2981
2982 // Return CreateAsyncFromSyncIterator(syncIterator)
2983 // alias `method` register as it's no longer used
2984 Register sync_iter = method;
2985 builder()->StoreAccumulatorInRegister(sync_iter).CallRuntime(
2986 Runtime::kInlineCreateAsyncFromSyncIterator, sync_iter);
2987
2988 builder()->Bind(&done);
2989 } else {
2990 // Let method be GetMethod(obj, @@iterator).
2991 builder()
2992 ->StoreAccumulatorInRegister(obj)
2993 .LoadNamedProperty(obj, iterator_symbol(),
2994 feedback_index(load_iter_slot))
2995 .StoreAccumulatorInRegister(method);
2996
2997 // Let iterator be Call(method, obj).
2998 builder()->Call(method, args, feedback_index(call_iter_slot),
2999 Call::NAMED_PROPERTY_CALL);
3000
3001 // If Type(iterator) is not Object, throw a TypeError exception.
3002 BytecodeLabel no_type_error;
3003 builder()->JumpIfJSReceiver(&no_type_error);
3004 builder()->CallRuntime(Runtime::kThrowSymbolIteratorInvalid);
3005 builder()->Bind(&no_type_error);
3006 }
2959 } 3007 }
2960 3008
2961 void BytecodeGenerator::VisitThisFunction(ThisFunction* expr) { 3009 void BytecodeGenerator::VisitThisFunction(ThisFunction* expr) {
2962 builder()->LoadAccumulatorWithRegister(Register::function_closure()); 3010 builder()->LoadAccumulatorWithRegister(Register::function_closure());
2963 } 3011 }
2964 3012
2965 void BytecodeGenerator::VisitSuperCallReference(SuperCallReference* expr) { 3013 void BytecodeGenerator::VisitSuperCallReference(SuperCallReference* expr) {
2966 // Handled by VisitCall(). 3014 // Handled by VisitCall().
2967 UNREACHABLE(); 3015 UNREACHABLE();
2968 } 3016 }
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
3374 } 3422 }
3375 3423
3376 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() { 3424 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() {
3377 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict 3425 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict
3378 : Runtime::kStoreKeyedToSuper_Sloppy; 3426 : Runtime::kStoreKeyedToSuper_Sloppy;
3379 } 3427 }
3380 3428
3381 } // namespace interpreter 3429 } // namespace interpreter
3382 } // namespace internal 3430 } // namespace internal
3383 } // namespace v8 3431 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698