OLD | NEW |
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/factory.h" | 5 #include "src/factory.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/allocation-site-scopes.h" | 8 #include "src/allocation-site-scopes.h" |
9 #include "src/ast/ast.h" | 9 #include "src/ast/ast.h" |
10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
(...skipping 1461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1472 int instance_size) { | 1472 int instance_size) { |
1473 return NewFunction(name, code, the_hole_value(), type, instance_size); | 1473 return NewFunction(name, code, the_hole_value(), type, instance_size); |
1474 } | 1474 } |
1475 | 1475 |
1476 | 1476 |
1477 Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) { | 1477 Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) { |
1478 // Make sure to use globals from the function's context, since the function | 1478 // Make sure to use globals from the function's context, since the function |
1479 // can be from a different context. | 1479 // can be from a different context. |
1480 Handle<Context> native_context(function->context()->native_context()); | 1480 Handle<Context> native_context(function->context()->native_context()); |
1481 Handle<Map> new_map; | 1481 Handle<Map> new_map; |
1482 if (IsResumableFunction(function->shared()->kind())) { | 1482 if (IsAsyncGeneratorFunction(function->shared()->kind())) { |
| 1483 new_map = handle(native_context->async_generator_object_prototype_map()); |
| 1484 } else if (IsResumableFunction(function->shared()->kind())) { |
1483 // Generator and async function prototypes can share maps since they | 1485 // Generator and async function prototypes can share maps since they |
1484 // don't have "constructor" properties. | 1486 // don't have "constructor" properties. |
1485 new_map = handle(native_context->generator_object_prototype_map()); | 1487 new_map = handle(native_context->generator_object_prototype_map()); |
1486 } else { | 1488 } else { |
1487 // Each function prototype gets a fresh map to avoid unwanted sharing of | 1489 // Each function prototype gets a fresh map to avoid unwanted sharing of |
1488 // maps between prototypes of different constructors. | 1490 // maps between prototypes of different constructors. |
1489 Handle<JSFunction> object_function(native_context->object_function()); | 1491 Handle<JSFunction> object_function(native_context->object_function()); |
1490 DCHECK(object_function->has_initial_map()); | 1492 DCHECK(object_function->has_initial_map()); |
1491 new_map = handle(object_function->initial_map()); | 1493 new_map = handle(object_function->initial_map()); |
1492 } | 1494 } |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1849 Handle<JSModuleNamespace> Factory::NewJSModuleNamespace() { | 1851 Handle<JSModuleNamespace> Factory::NewJSModuleNamespace() { |
1850 Handle<Map> map = isolate()->js_module_namespace_map(); | 1852 Handle<Map> map = isolate()->js_module_namespace_map(); |
1851 return Handle<JSModuleNamespace>::cast(NewJSObjectFromMap(map)); | 1853 return Handle<JSModuleNamespace>::cast(NewJSObjectFromMap(map)); |
1852 } | 1854 } |
1853 | 1855 |
1854 Handle<JSGeneratorObject> Factory::NewJSGeneratorObject( | 1856 Handle<JSGeneratorObject> Factory::NewJSGeneratorObject( |
1855 Handle<JSFunction> function) { | 1857 Handle<JSFunction> function) { |
1856 DCHECK(IsResumableFunction(function->shared()->kind())); | 1858 DCHECK(IsResumableFunction(function->shared()->kind())); |
1857 JSFunction::EnsureHasInitialMap(function); | 1859 JSFunction::EnsureHasInitialMap(function); |
1858 Handle<Map> map(function->initial_map()); | 1860 Handle<Map> map(function->initial_map()); |
1859 DCHECK_EQ(JS_GENERATOR_OBJECT_TYPE, map->instance_type()); | 1861 DCHECK(JS_GENERATOR_OBJECT_TYPE == map->instance_type() || |
| 1862 JS_ASYNC_GENERATOR_OBJECT_TYPE == map->instance_type()); |
1860 CALL_HEAP_FUNCTION( | 1863 CALL_HEAP_FUNCTION( |
1861 isolate(), | 1864 isolate(), |
1862 isolate()->heap()->AllocateJSObjectFromMap(*map), | 1865 isolate()->heap()->AllocateJSObjectFromMap(*map), |
1863 JSGeneratorObject); | 1866 JSGeneratorObject); |
1864 } | 1867 } |
1865 | 1868 |
1866 Handle<Module> Factory::NewModule(Handle<SharedFunctionInfo> code) { | 1869 Handle<Module> Factory::NewModule(Handle<SharedFunctionInfo> code) { |
1867 Handle<ModuleInfo> module_info(code->scope_info()->ModuleDescriptorInfo(), | 1870 Handle<ModuleInfo> module_info(code->scope_info()->ModuleDescriptorInfo(), |
1868 isolate()); | 1871 isolate()); |
1869 Handle<ObjectHashTable> exports = | 1872 Handle<ObjectHashTable> exports = |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1914 Handle<JSIteratorResult> Factory::NewJSIteratorResult(Handle<Object> value, | 1917 Handle<JSIteratorResult> Factory::NewJSIteratorResult(Handle<Object> value, |
1915 bool done) { | 1918 bool done) { |
1916 Handle<Map> map(isolate()->native_context()->iterator_result_map()); | 1919 Handle<Map> map(isolate()->native_context()->iterator_result_map()); |
1917 Handle<JSIteratorResult> js_iter_result = | 1920 Handle<JSIteratorResult> js_iter_result = |
1918 Handle<JSIteratorResult>::cast(NewJSObjectFromMap(map)); | 1921 Handle<JSIteratorResult>::cast(NewJSObjectFromMap(map)); |
1919 js_iter_result->set_value(*value); | 1922 js_iter_result->set_value(*value); |
1920 js_iter_result->set_done(*ToBoolean(done)); | 1923 js_iter_result->set_done(*ToBoolean(done)); |
1921 return js_iter_result; | 1924 return js_iter_result; |
1922 } | 1925 } |
1923 | 1926 |
| 1927 Handle<JSAsyncFromSyncIterator> Factory::NewJSAsyncFromSyncIterator( |
| 1928 Handle<HeapObject> sync_iterator) { |
| 1929 Handle<Map> map( |
| 1930 isolate()->native_context()->initial_async_from_sync_iterator_map()); |
| 1931 Handle<JSAsyncFromSyncIterator> iterator = |
| 1932 Handle<JSAsyncFromSyncIterator>::cast(NewJSObjectFromMap(map)); |
| 1933 |
| 1934 iterator->set_sync_iterator(*sync_iterator); |
| 1935 return iterator; |
| 1936 } |
| 1937 |
1924 Handle<JSMap> Factory::NewJSMap() { | 1938 Handle<JSMap> Factory::NewJSMap() { |
1925 Handle<Map> map(isolate()->native_context()->js_map_map()); | 1939 Handle<Map> map(isolate()->native_context()->js_map_map()); |
1926 Handle<JSMap> js_map = Handle<JSMap>::cast(NewJSObjectFromMap(map)); | 1940 Handle<JSMap> js_map = Handle<JSMap>::cast(NewJSObjectFromMap(map)); |
1927 JSMap::Initialize(js_map, isolate()); | 1941 JSMap::Initialize(js_map, isolate()); |
1928 return js_map; | 1942 return js_map; |
1929 } | 1943 } |
1930 | 1944 |
1931 | 1945 |
1932 Handle<JSSet> Factory::NewJSSet() { | 1946 Handle<JSSet> Factory::NewJSSet() { |
1933 Handle<Map> map(isolate()->native_context()->js_set_map()); | 1947 Handle<Map> map(isolate()->native_context()->js_set_map()); |
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2796 Handle<AccessorInfo> prototype = | 2810 Handle<AccessorInfo> prototype = |
2797 Accessors::FunctionPrototypeInfo(isolate(), rw_attribs); | 2811 Accessors::FunctionPrototypeInfo(isolate(), rw_attribs); |
2798 Descriptor d = Descriptor::AccessorConstant( | 2812 Descriptor d = Descriptor::AccessorConstant( |
2799 Handle<Name>(Name::cast(prototype->name())), prototype, rw_attribs); | 2813 Handle<Name>(Name::cast(prototype->name())), prototype, rw_attribs); |
2800 map->AppendDescriptor(&d); | 2814 map->AppendDescriptor(&d); |
2801 } | 2815 } |
2802 } | 2816 } |
2803 | 2817 |
2804 } // namespace internal | 2818 } // namespace internal |
2805 } // namespace v8 | 2819 } // namespace v8 |
OLD | NEW |