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

Unified Diff: src/interpreter/bytecode-generator.cc

Issue 2637403008: [async-iteration] add support for for-await-of loops in Async Functions (Closed)
Patch Set: remove that comment Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/interpreter/bytecode-array-builder.cc ('k') | src/interpreter/constant-array-builder.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/interpreter/bytecode-generator.cc
diff --git a/src/interpreter/bytecode-generator.cc b/src/interpreter/bytecode-generator.cc
index 0269ca4e94199489b058bfad88f15a7e550eaafd..e2ef3ea199ad1d0c5ce45c9c61cf7f663cd5a711 100644
--- a/src/interpreter/bytecode-generator.cc
+++ b/src/interpreter/bytecode-generator.cc
@@ -2973,21 +2973,64 @@ void BytecodeGenerator::VisitGetIterator(GetIterator* expr) {
VisitForAccumulatorValue(expr->iterable());
- // Let method be GetMethod(obj, @@iterator).
- builder()
- ->StoreAccumulatorInRegister(obj)
- .LoadIteratorProperty(obj, feedback_index(load_slot))
- .StoreAccumulatorInRegister(method);
-
- // Let iterator be Call(method, obj).
- builder()->Call(method, args, feedback_index(call_slot),
- Call::NAMED_PROPERTY_CALL);
-
- // If Type(iterator) is not Object, throw a TypeError exception.
- BytecodeLabel no_type_error;
- builder()->JumpIfJSReceiver(&no_type_error);
- builder()->CallRuntime(Runtime::kThrowSymbolIteratorInvalid);
- builder()->Bind(&no_type_error);
+ if (expr->hint() == IteratorType::kAsync) {
+ FeedbackSlot async_load_slot = expr->AsyncIteratorPropertyFeedbackSlot();
+ FeedbackSlot async_call_slot = expr->AsyncIteratorCallFeedbackSlot();
+
+ // Set method to GetMethod(obj, @@asyncIterator)
+ builder()->StoreAccumulatorInRegister(obj).LoadAsyncIteratorProperty(
+ obj, feedback_index(async_load_slot));
+
+ BytecodeLabel async_iterator_undefined, async_iterator_null, done;
+ // TODO(ignition): Add a single opcode for JumpIfNullOrUndefined
+ builder()->JumpIfUndefined(&async_iterator_undefined);
+ builder()->JumpIfNull(&async_iterator_null);
+
+ // Let iterator be Call(method, obj)
+ builder()->StoreAccumulatorInRegister(method).Call(
+ method, args, feedback_index(async_call_slot),
+ Call::NAMED_PROPERTY_CALL);
+
+ // If Type(iterator) is not Object, throw a TypeError exception.
+ builder()->JumpIfJSReceiver(&done);
+ builder()->CallRuntime(Runtime::kThrowSymbolAsyncIteratorInvalid);
+
+ builder()->Bind(&async_iterator_undefined);
+ builder()->Bind(&async_iterator_null);
+ // If method is undefined,
+ // Let syncMethod be GetMethod(obj, @@iterator)
+ builder()
+ ->LoadIteratorProperty(obj, feedback_index(load_slot))
+ .StoreAccumulatorInRegister(method);
+
+ // Let syncIterator be Call(syncMethod, obj)
+ builder()->Call(method, args, feedback_index(call_slot),
+ Call::NAMED_PROPERTY_CALL);
+
+ // Return CreateAsyncFromSyncIterator(syncIterator)
+ // alias `method` register as it's no longer used
+ Register sync_iter = method;
+ builder()->StoreAccumulatorInRegister(sync_iter).CallRuntime(
+ Runtime::kInlineCreateAsyncFromSyncIterator, sync_iter);
+
+ builder()->Bind(&done);
+ } else {
+ // Let method be GetMethod(obj, @@iterator).
+ builder()
+ ->StoreAccumulatorInRegister(obj)
+ .LoadIteratorProperty(obj, feedback_index(load_slot))
+ .StoreAccumulatorInRegister(method);
+
+ // Let iterator be Call(method, obj).
+ builder()->Call(method, args, feedback_index(call_slot),
+ Call::NAMED_PROPERTY_CALL);
+
+ // If Type(iterator) is not Object, throw a TypeError exception.
+ BytecodeLabel no_type_error;
+ builder()->JumpIfJSReceiver(&no_type_error);
+ builder()->CallRuntime(Runtime::kThrowSymbolIteratorInvalid);
+ builder()->Bind(&no_type_error);
+ }
}
void BytecodeGenerator::VisitThisFunction(ThisFunction* expr) {
« no previous file with comments | « src/interpreter/bytecode-array-builder.cc ('k') | src/interpreter/constant-array-builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698