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

Side by Side Diff: src/bootstrapper.cc

Issue 2645313003: [async-iteration] implement Async-from-Sync Iterator (Closed)
Patch Set: Refactor + add more tests 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/bootstrapper.h" 5 #include "src/bootstrapper.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/api-natives.h" 8 #include "src/api-natives.h"
9 #include "src/base/ieee754.h" 9 #include "src/base/ieee754.h"
10 #include "src/code-stubs.h" 10 #include "src/code-stubs.h"
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 void CreateRoots(); 167 void CreateRoots();
168 // Creates the empty function. Used for creating a context from scratch. 168 // Creates the empty function. Used for creating a context from scratch.
169 Handle<JSFunction> CreateEmptyFunction(Isolate* isolate); 169 Handle<JSFunction> CreateEmptyFunction(Isolate* isolate);
170 // Creates the ThrowTypeError function. ECMA 5th Ed. 13.2.3 170 // Creates the ThrowTypeError function. ECMA 5th Ed. 13.2.3
171 Handle<JSFunction> GetRestrictedFunctionPropertiesThrower(); 171 Handle<JSFunction> GetRestrictedFunctionPropertiesThrower();
172 Handle<JSFunction> GetStrictArgumentsPoisonFunction(); 172 Handle<JSFunction> GetStrictArgumentsPoisonFunction();
173 Handle<JSFunction> GetThrowTypeErrorIntrinsic(Builtins::Name builtin_name); 173 Handle<JSFunction> GetThrowTypeErrorIntrinsic(Builtins::Name builtin_name);
174 174
175 void CreateStrictModeFunctionMaps(Handle<JSFunction> empty); 175 void CreateStrictModeFunctionMaps(Handle<JSFunction> empty);
176 void CreateIteratorMaps(Handle<JSFunction> empty); 176 void CreateIteratorMaps(Handle<JSFunction> empty);
177 void CreateAsyncIteratorMaps();
177 void CreateAsyncFunctionMaps(Handle<JSFunction> empty); 178 void CreateAsyncFunctionMaps(Handle<JSFunction> empty);
178 void CreateJSProxyMaps(); 179 void CreateJSProxyMaps();
179 180
180 // Make the "arguments" and "caller" properties throw a TypeError on access. 181 // Make the "arguments" and "caller" properties throw a TypeError on access.
181 void AddRestrictedFunctionProperties(Handle<JSFunction> empty); 182 void AddRestrictedFunctionProperties(Handle<JSFunction> empty);
182 183
183 // Creates the global objects using the global proxy and the template passed 184 // Creates the global objects using the global proxy and the template passed
184 // in through the API. We call this regardless of whether we are building a 185 // in through the API. We call this regardless of whether we are building a
185 // context from scratch or using a deserialized one from the partial snapshot 186 // context from scratch or using a deserialized one from the partial snapshot
186 // but in the latter case we don't use the objects it produces directly, as 187 // but in the latter case we don't use the objects it produces directly, as
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 Map::SetPrototype(generator_function_map, generator_function_prototype); 782 Map::SetPrototype(generator_function_map, generator_function_prototype);
782 native_context()->set_generator_function_map(*generator_function_map); 783 native_context()->set_generator_function_map(*generator_function_map);
783 784
784 Handle<JSFunction> object_function(native_context()->object_function()); 785 Handle<JSFunction> object_function(native_context()->object_function());
785 Handle<Map> generator_object_prototype_map = Map::Create(isolate(), 0); 786 Handle<Map> generator_object_prototype_map = Map::Create(isolate(), 0);
786 Map::SetPrototype(generator_object_prototype_map, generator_object_prototype); 787 Map::SetPrototype(generator_object_prototype_map, generator_object_prototype);
787 native_context()->set_generator_object_prototype_map( 788 native_context()->set_generator_object_prototype_map(
788 *generator_object_prototype_map); 789 *generator_object_prototype_map);
789 } 790 }
790 791
792 void Genesis::CreateAsyncIteratorMaps() {
793 // %AsyncIteratorPrototype%
794 // proposal-async-iteration/#sec-asynciteratorprototype
795 Handle<JSObject> async_iterator_prototype =
796 factory()->NewJSObject(isolate()->object_function(), TENURED);
797
798 Handle<JSFunction> async_iterator_prototype_iterator = SimpleCreateFunction(
799 isolate(), factory()->NewStringFromAsciiChecked("[Symbol.asyncIterator]"),
800 Builtins::kReturnReceiver, 0, true);
801
802 JSObject::AddProperty(async_iterator_prototype,
803 factory()->async_iterator_symbol(),
804 async_iterator_prototype_iterator, DONT_ENUM);
805
806 // %AsyncFromSyncIteratorPrototype%
807 // proposal-async-iteration/#sec-%asyncfromsynciteratorprototype%-object
808 Handle<JSObject> async_from_sync_iterator_prototype =
809 factory()->NewJSObject(isolate()->object_function(), TENURED);
810 SimpleInstallFunction(async_from_sync_iterator_prototype,
811 factory()->next_string(),
812 Builtins::kAsyncFromSyncIteratorPrototypeNext, 1, true);
813 SimpleInstallFunction(
814 async_from_sync_iterator_prototype, factory()->return_string(),
815 Builtins::kAsyncFromSyncIteratorPrototypeReturn, 1, true);
816 SimpleInstallFunction(
817 async_from_sync_iterator_prototype, factory()->throw_string(),
818 Builtins::kAsyncFromSyncIteratorPrototypeThrow, 1, true);
819
820 JSObject::AddProperty(
821 async_from_sync_iterator_prototype, factory()->to_string_tag_symbol(),
822 factory()->NewStringFromAsciiChecked("Async-from-Sync Iterator"),
823 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
824
825 JSObject::ForceSetPrototype(async_from_sync_iterator_prototype,
826 async_iterator_prototype);
827
828 Handle<Map> async_from_sync_iterator_map = factory()->NewMap(
829 JS_ASYNC_FROM_SYNC_ITERATOR_TYPE, JSAsyncFromSyncIterator::kSize);
830 Map::SetPrototype(async_from_sync_iterator_map,
831 async_from_sync_iterator_prototype);
832 native_context()->set_async_from_sync_iterator_map(
833 *async_from_sync_iterator_map);
834 }
835
791 void Genesis::CreateAsyncFunctionMaps(Handle<JSFunction> empty) { 836 void Genesis::CreateAsyncFunctionMaps(Handle<JSFunction> empty) {
792 // %AsyncFunctionPrototype% intrinsic 837 // %AsyncFunctionPrototype% intrinsic
793 Handle<JSObject> async_function_prototype = 838 Handle<JSObject> async_function_prototype =
794 factory()->NewJSObject(isolate()->object_function(), TENURED); 839 factory()->NewJSObject(isolate()->object_function(), TENURED);
795 JSObject::ForceSetPrototype(async_function_prototype, empty); 840 JSObject::ForceSetPrototype(async_function_prototype, empty);
796 841
797 JSObject::AddProperty(async_function_prototype, 842 JSObject::AddProperty(async_function_prototype,
798 factory()->to_string_tag_symbol(), 843 factory()->to_string_tag_symbol(),
799 factory()->NewStringFromAsciiChecked("AsyncFunction"), 844 factory()->NewStringFromAsciiChecked("AsyncFunction"),
800 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); 845 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 1336
1292 // Install the "constructor" property on the %FunctionPrototype%. 1337 // Install the "constructor" property on the %FunctionPrototype%.
1293 JSObject::AddProperty(prototype, factory->constructor_string(), 1338 JSObject::AddProperty(prototype, factory->constructor_string(),
1294 function_fun, DONT_ENUM); 1339 function_fun, DONT_ENUM);
1295 1340
1296 sloppy_function_map_writable_prototype_->SetConstructor(*function_fun); 1341 sloppy_function_map_writable_prototype_->SetConstructor(*function_fun);
1297 strict_function_map_writable_prototype_->SetConstructor(*function_fun); 1342 strict_function_map_writable_prototype_->SetConstructor(*function_fun);
1298 class_function_map_->SetConstructor(*function_fun); 1343 class_function_map_->SetConstructor(*function_fun);
1299 } 1344 }
1300 1345
1346 {
1347 // --- A s y n c F r o m S y n c I t e r a t o r
1348 Handle<Code> code = isolate->builtins()->AsyncIteratorValueUnwrap();
1349 Handle<SharedFunctionInfo> info =
1350 factory->NewSharedFunctionInfo(factory->empty_string(), code, false);
1351 info->set_internal_formal_parameter_count(1);
1352 info->set_length(1);
1353 native_context()->set_async_iterator_value_unwrap_shared_fun(*info);
1354 }
1355
1301 { // --- A r r a y --- 1356 { // --- A r r a y ---
1302 Handle<JSFunction> array_function = 1357 Handle<JSFunction> array_function =
1303 InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize, 1358 InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize,
1304 isolate->initial_object_prototype(), 1359 isolate->initial_object_prototype(),
1305 Builtins::kArrayCode); 1360 Builtins::kArrayCode);
1306 array_function->shared()->DontAdaptArguments(); 1361 array_function->shared()->DontAdaptArguments();
1307 array_function->shared()->set_builtin_function_id(kArrayCode); 1362 array_function->shared()->set_builtin_function_id(kArrayCode);
1308 1363
1309 // This seems a bit hackish, but we need to make sure Array.length 1364 // This seems a bit hackish, but we need to make sure Array.length
1310 // is 1. 1365 // is 1.
(...skipping 3439 matching lines...) Expand 10 before | Expand all | Expand 10 after
4750 HookUpGlobalProxy(global_proxy); 4805 HookUpGlobalProxy(global_proxy);
4751 } 4806 }
4752 DCHECK(!global_proxy->IsDetachedFrom(native_context()->global_object())); 4807 DCHECK(!global_proxy->IsDetachedFrom(native_context()->global_object()));
4753 } else { 4808 } else {
4754 DCHECK_EQ(0u, context_snapshot_index); 4809 DCHECK_EQ(0u, context_snapshot_index);
4755 // We get here if there was no context snapshot. 4810 // We get here if there was no context snapshot.
4756 CreateRoots(); 4811 CreateRoots();
4757 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); 4812 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate);
4758 CreateStrictModeFunctionMaps(empty_function); 4813 CreateStrictModeFunctionMaps(empty_function);
4759 CreateIteratorMaps(empty_function); 4814 CreateIteratorMaps(empty_function);
4815 CreateAsyncIteratorMaps();
4760 CreateAsyncFunctionMaps(empty_function); 4816 CreateAsyncFunctionMaps(empty_function);
4761 Handle<JSGlobalObject> global_object = 4817 Handle<JSGlobalObject> global_object =
4762 CreateNewGlobals(global_proxy_template, global_proxy); 4818 CreateNewGlobals(global_proxy_template, global_proxy);
4763 InitializeGlobal(global_object, empty_function, context_type); 4819 InitializeGlobal(global_object, empty_function, context_type);
4764 InitializeNormalizedMapCaches(); 4820 InitializeNormalizedMapCaches();
4765 4821
4766 if (!InstallNatives(context_type)) return; 4822 if (!InstallNatives(context_type)) return;
4767 4823
4768 MakeFunctionInstancePrototypeWritable(); 4824 MakeFunctionInstancePrototypeWritable();
4769 4825
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
4901 } 4957 }
4902 4958
4903 4959
4904 // Called when the top-level V8 mutex is destroyed. 4960 // Called when the top-level V8 mutex is destroyed.
4905 void Bootstrapper::FreeThreadResources() { 4961 void Bootstrapper::FreeThreadResources() {
4906 DCHECK(!IsActive()); 4962 DCHECK(!IsActive());
4907 } 4963 }
4908 4964
4909 } // namespace internal 4965 } // namespace internal
4910 } // namespace v8 4966 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698