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

Side by Side Diff: src/bootstrapper.cc

Issue 2645313003: [async-iteration] implement Async-from-Sync Iterator (Closed)
Patch Set: attempt #3 to fix merge conflicts 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 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(Handle<JSFunction> empty);
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 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 Map::SetPrototype(generator_function_map, generator_function_prototype); 780 Map::SetPrototype(generator_function_map, generator_function_prototype);
780 native_context()->set_generator_function_map(*generator_function_map); 781 native_context()->set_generator_function_map(*generator_function_map);
781 782
782 Handle<JSFunction> object_function(native_context()->object_function()); 783 Handle<JSFunction> object_function(native_context()->object_function());
783 Handle<Map> generator_object_prototype_map = Map::Create(isolate(), 0); 784 Handle<Map> generator_object_prototype_map = Map::Create(isolate(), 0);
784 Map::SetPrototype(generator_object_prototype_map, generator_object_prototype); 785 Map::SetPrototype(generator_object_prototype_map, generator_object_prototype);
785 native_context()->set_generator_object_prototype_map( 786 native_context()->set_generator_object_prototype_map(
786 *generator_object_prototype_map); 787 *generator_object_prototype_map);
787 } 788 }
788 789
790 void Genesis::CreateAsyncIteratorMaps(Handle<JSFunction> empty) {
791 // %AsyncIteratorPrototype%
792 // proposal-async-iteration/#sec-asynciteratorprototype
793 Handle<JSObject> async_iterator_prototype =
794 factory()->NewJSObject(isolate()->object_function(), TENURED);
795
796 Handle<JSFunction> async_iterator_prototype_iterator = SimpleCreateFunction(
797 isolate(), factory()->NewStringFromAsciiChecked("[Symbol.asyncIterator]"),
798 Builtins::kReturnReceiver, 0, true);
799 async_iterator_prototype_iterator->shared()->set_native(true);
800
801 JSObject::AddProperty(async_iterator_prototype,
802 factory()->async_iterator_symbol(),
803 async_iterator_prototype_iterator, DONT_ENUM);
804
805 // %AsyncFromSyncIteratorPrototype%
806 // proposal-async-iteration/#sec-%asyncfromsynciteratorprototype%-object
807 Handle<JSObject> async_from_sync_iterator_prototype =
808 factory()->NewJSObject(isolate()->object_function(), TENURED);
809 SimpleInstallFunction(async_from_sync_iterator_prototype,
810 factory()->next_string(),
811 Builtins::kAsyncFromSyncIteratorPrototypeNext, 1, true);
812 SimpleInstallFunction(
813 async_from_sync_iterator_prototype, factory()->return_string(),
814 Builtins::kAsyncFromSyncIteratorPrototypeReturn, 1, true);
815 SimpleInstallFunction(
816 async_from_sync_iterator_prototype, factory()->throw_string(),
817 Builtins::kAsyncFromSyncIteratorPrototypeThrow, 1, true);
818
819 JSObject::AddProperty(
820 async_from_sync_iterator_prototype, factory()->to_string_tag_symbol(),
821 factory()->NewStringFromAsciiChecked("Async-from-Sync Iterator"),
822 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
823
824 JSObject::ForceSetPrototype(async_from_sync_iterator_prototype,
825 async_iterator_prototype);
826
827 Handle<Map> async_from_sync_iterator_map = factory()->NewMap(
828 JS_ASYNC_FROM_SYNC_ITERATOR_TYPE, JSAsyncFromSyncIterator::kSize);
829 Map::SetPrototype(async_from_sync_iterator_map,
830 async_from_sync_iterator_prototype);
831 native_context()->set_async_from_sync_iterator_map(
832 *async_from_sync_iterator_map);
833 }
834
789 void Genesis::CreateAsyncFunctionMaps(Handle<JSFunction> empty) { 835 void Genesis::CreateAsyncFunctionMaps(Handle<JSFunction> empty) {
790 // %AsyncFunctionPrototype% intrinsic 836 // %AsyncFunctionPrototype% intrinsic
791 Handle<JSObject> async_function_prototype = 837 Handle<JSObject> async_function_prototype =
792 factory()->NewJSObject(isolate()->object_function(), TENURED); 838 factory()->NewJSObject(isolate()->object_function(), TENURED);
793 JSObject::ForceSetPrototype(async_function_prototype, empty); 839 JSObject::ForceSetPrototype(async_function_prototype, empty);
794 840
795 JSObject::AddProperty(async_function_prototype, 841 JSObject::AddProperty(async_function_prototype,
796 factory()->to_string_tag_symbol(), 842 factory()->to_string_tag_symbol(),
797 factory()->NewStringFromAsciiChecked("AsyncFunction"), 843 factory()->NewStringFromAsciiChecked("AsyncFunction"),
798 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY)); 844 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 1335
1290 // Install the "constructor" property on the %FunctionPrototype%. 1336 // Install the "constructor" property on the %FunctionPrototype%.
1291 JSObject::AddProperty(prototype, factory->constructor_string(), 1337 JSObject::AddProperty(prototype, factory->constructor_string(),
1292 function_fun, DONT_ENUM); 1338 function_fun, DONT_ENUM);
1293 1339
1294 sloppy_function_map_writable_prototype_->SetConstructor(*function_fun); 1340 sloppy_function_map_writable_prototype_->SetConstructor(*function_fun);
1295 strict_function_map_writable_prototype_->SetConstructor(*function_fun); 1341 strict_function_map_writable_prototype_->SetConstructor(*function_fun);
1296 class_function_map_->SetConstructor(*function_fun); 1342 class_function_map_->SetConstructor(*function_fun);
1297 } 1343 }
1298 1344
1345 {
1346 // --- A s y n c F r o m S y n c I t e r a t o r
1347 Handle<Code> code = isolate->builtins()->AsyncIteratorValueUnwrap();
1348 Handle<SharedFunctionInfo> info =
1349 factory->NewSharedFunctionInfo(factory->empty_string(), code, false);
1350 info->set_internal_formal_parameter_count(1);
1351 info->set_length(1);
1352 native_context()->set_async_iterator_value_unwrap_shared_fun(*info);
1353 }
1354
1299 { // --- A r r a y --- 1355 { // --- A r r a y ---
1300 Handle<JSFunction> array_function = 1356 Handle<JSFunction> array_function =
1301 InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize, 1357 InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize,
1302 isolate->initial_object_prototype(), 1358 isolate->initial_object_prototype(),
1303 Builtins::kArrayCode); 1359 Builtins::kArrayCode);
1304 array_function->shared()->DontAdaptArguments(); 1360 array_function->shared()->DontAdaptArguments();
1305 array_function->shared()->set_builtin_function_id(kArrayCode); 1361 array_function->shared()->set_builtin_function_id(kArrayCode);
1306 1362
1307 // This seems a bit hackish, but we need to make sure Array.length 1363 // This seems a bit hackish, but we need to make sure Array.length
1308 // is 1. 1364 // is 1.
(...skipping 3373 matching lines...) Expand 10 before | Expand all | Expand 10 after
4682 HookUpGlobalProxy(global_proxy); 4738 HookUpGlobalProxy(global_proxy);
4683 } 4739 }
4684 DCHECK(!global_proxy->IsDetachedFrom(native_context()->global_object())); 4740 DCHECK(!global_proxy->IsDetachedFrom(native_context()->global_object()));
4685 } else { 4741 } else {
4686 DCHECK_EQ(0u, context_snapshot_index); 4742 DCHECK_EQ(0u, context_snapshot_index);
4687 // We get here if there was no context snapshot. 4743 // We get here if there was no context snapshot.
4688 CreateRoots(); 4744 CreateRoots();
4689 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate); 4745 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate);
4690 CreateStrictModeFunctionMaps(empty_function); 4746 CreateStrictModeFunctionMaps(empty_function);
4691 CreateIteratorMaps(empty_function); 4747 CreateIteratorMaps(empty_function);
4748 CreateAsyncIteratorMaps(empty_function);
4692 CreateAsyncFunctionMaps(empty_function); 4749 CreateAsyncFunctionMaps(empty_function);
4693 Handle<JSGlobalObject> global_object = 4750 Handle<JSGlobalObject> global_object =
4694 CreateNewGlobals(global_proxy_template, global_proxy); 4751 CreateNewGlobals(global_proxy_template, global_proxy);
4695 InitializeGlobal(global_object, empty_function, context_type); 4752 InitializeGlobal(global_object, empty_function, context_type);
4696 InitializeNormalizedMapCaches(); 4753 InitializeNormalizedMapCaches();
4697 4754
4698 if (!InstallNatives(context_type)) return; 4755 if (!InstallNatives(context_type)) return;
4699 4756
4700 MakeFunctionInstancePrototypeWritable(); 4757 MakeFunctionInstancePrototypeWritable();
4701 4758
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
4824 } 4881 }
4825 4882
4826 4883
4827 // Called when the top-level V8 mutex is destroyed. 4884 // Called when the top-level V8 mutex is destroyed.
4828 void Bootstrapper::FreeThreadResources() { 4885 void Bootstrapper::FreeThreadResources() {
4829 DCHECK(!IsActive()); 4886 DCHECK(!IsActive());
4830 } 4887 }
4831 4888
4832 } // namespace internal 4889 } // namespace internal
4833 } // namespace v8 4890 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698