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

Unified Diff: src/bootstrapper.cc

Issue 2645313003: [async-iteration] implement Async-from-Sync Iterator (Closed)
Patch Set: rebase 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
Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index e89427988e6463085ef40492bd7a35d0b721e75e..eb96da34be80a79cea807c870cf5d611cddbb1b8 100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -174,6 +174,7 @@ class Genesis BASE_EMBEDDED {
void CreateStrictModeFunctionMaps(Handle<JSFunction> empty);
void CreateIteratorMaps(Handle<JSFunction> empty);
+ void CreateAsyncIteratorMaps(Handle<JSFunction> empty);
void CreateAsyncFunctionMaps(Handle<JSFunction> empty);
void CreateJSProxyMaps();
@@ -788,6 +789,51 @@ void Genesis::CreateIteratorMaps(Handle<JSFunction> empty) {
*generator_object_prototype_map);
}
+void Genesis::CreateAsyncIteratorMaps(Handle<JSFunction> empty) {
jgruber 2017/02/17 12:28:22 The argument is unused.
caitp 2017/02/17 14:56:10 Removed (will re-add in the next CL I guess)
+ // %AsyncIteratorPrototype%
+ // proposal-async-iteration/#sec-asynciteratorprototype
+ Handle<JSObject> async_iterator_prototype =
+ factory()->NewJSObject(isolate()->object_function(), TENURED);
+
+ Handle<JSFunction> async_iterator_prototype_iterator = SimpleCreateFunction(
+ isolate(), factory()->NewStringFromAsciiChecked("[Symbol.asyncIterator]"),
+ Builtins::kReturnReceiver, 0, true);
+ async_iterator_prototype_iterator->shared()->set_native(true);
jgruber 2017/02/17 12:28:22 set_native is done by SimpleCreateFunction AFAIK.
caitp 2017/02/17 14:56:10 Removed duplicate call
+
+ JSObject::AddProperty(async_iterator_prototype,
+ factory()->async_iterator_symbol(),
+ async_iterator_prototype_iterator, DONT_ENUM);
+
+ // %AsyncFromSyncIteratorPrototype%
+ // proposal-async-iteration/#sec-%asyncfromsynciteratorprototype%-object
+ Handle<JSObject> async_from_sync_iterator_prototype =
+ factory()->NewJSObject(isolate()->object_function(), TENURED);
+ SimpleInstallFunction(async_from_sync_iterator_prototype,
+ factory()->next_string(),
+ Builtins::kAsyncFromSyncIteratorPrototypeNext, 1, true);
+ SimpleInstallFunction(
+ async_from_sync_iterator_prototype, factory()->return_string(),
+ Builtins::kAsyncFromSyncIteratorPrototypeReturn, 1, true);
+ SimpleInstallFunction(
+ async_from_sync_iterator_prototype, factory()->throw_string(),
+ Builtins::kAsyncFromSyncIteratorPrototypeThrow, 1, true);
+
+ JSObject::AddProperty(
+ async_from_sync_iterator_prototype, factory()->to_string_tag_symbol(),
+ factory()->NewStringFromAsciiChecked("Async-from-Sync Iterator"),
+ static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
+
+ JSObject::ForceSetPrototype(async_from_sync_iterator_prototype,
+ async_iterator_prototype);
+
+ Handle<Map> async_from_sync_iterator_map = factory()->NewMap(
+ JS_ASYNC_FROM_SYNC_ITERATOR_TYPE, JSAsyncFromSyncIterator::kSize);
+ Map::SetPrototype(async_from_sync_iterator_map,
+ async_from_sync_iterator_prototype);
+ native_context()->set_async_from_sync_iterator_map(
+ *async_from_sync_iterator_map);
+}
+
void Genesis::CreateAsyncFunctionMaps(Handle<JSFunction> empty) {
// %AsyncFunctionPrototype% intrinsic
Handle<JSObject> async_function_prototype =
@@ -1298,6 +1344,16 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
class_function_map_->SetConstructor(*function_fun);
}
+ {
+ // --- A s y n c F r o m S y n c I t e r a t o r
+ Handle<Code> code = isolate->builtins()->AsyncIteratorValueUnwrap();
+ Handle<SharedFunctionInfo> info =
+ factory->NewSharedFunctionInfo(factory->empty_string(), code, false);
+ info->set_internal_formal_parameter_count(1);
+ info->set_length(1);
+ native_context()->set_async_iterator_value_unwrap_shared_fun(*info);
+ }
+
{ // --- A r r a y ---
Handle<JSFunction> array_function =
InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize,
@@ -4757,6 +4813,7 @@ Genesis::Genesis(
Handle<JSFunction> empty_function = CreateEmptyFunction(isolate);
CreateStrictModeFunctionMaps(empty_function);
CreateIteratorMaps(empty_function);
+ CreateAsyncIteratorMaps(empty_function);
CreateAsyncFunctionMaps(empty_function);
Handle<JSGlobalObject> global_object =
CreateNewGlobals(global_proxy_template, global_proxy);

Powered by Google App Engine
This is Rietveld 408576698