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 1497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1508 int instance_size) { | 1508 int instance_size) { |
1509 return NewFunction(name, code, the_hole_value(), type, instance_size); | 1509 return NewFunction(name, code, the_hole_value(), type, instance_size); |
1510 } | 1510 } |
1511 | 1511 |
1512 | 1512 |
1513 Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) { | 1513 Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) { |
1514 // Make sure to use globals from the function's context, since the function | 1514 // Make sure to use globals from the function's context, since the function |
1515 // can be from a different context. | 1515 // can be from a different context. |
1516 Handle<Context> native_context(function->context()->native_context()); | 1516 Handle<Context> native_context(function->context()->native_context()); |
1517 Handle<Map> new_map; | 1517 Handle<Map> new_map; |
1518 if (IsResumableFunction(function->shared()->kind())) { | 1518 if (IsAsyncGeneratorFunction(function->shared()->kind())) { |
| 1519 new_map = handle(native_context->async_generator_object_prototype_map()); |
| 1520 } else if (IsResumableFunction(function->shared()->kind())) { |
1519 // Generator and async function prototypes can share maps since they | 1521 // Generator and async function prototypes can share maps since they |
1520 // don't have "constructor" properties. | 1522 // don't have "constructor" properties. |
1521 new_map = handle(native_context->generator_object_prototype_map()); | 1523 new_map = handle(native_context->generator_object_prototype_map()); |
1522 } else { | 1524 } else { |
1523 // Each function prototype gets a fresh map to avoid unwanted sharing of | 1525 // Each function prototype gets a fresh map to avoid unwanted sharing of |
1524 // maps between prototypes of different constructors. | 1526 // maps between prototypes of different constructors. |
1525 Handle<JSFunction> object_function(native_context->object_function()); | 1527 Handle<JSFunction> object_function(native_context->object_function()); |
1526 DCHECK(object_function->has_initial_map()); | 1528 DCHECK(object_function->has_initial_map()); |
1527 new_map = handle(object_function->initial_map()); | 1529 new_map = handle(object_function->initial_map()); |
1528 } | 1530 } |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1885 Handle<JSModuleNamespace> Factory::NewJSModuleNamespace() { | 1887 Handle<JSModuleNamespace> Factory::NewJSModuleNamespace() { |
1886 Handle<Map> map = isolate()->js_module_namespace_map(); | 1888 Handle<Map> map = isolate()->js_module_namespace_map(); |
1887 return Handle<JSModuleNamespace>::cast(NewJSObjectFromMap(map)); | 1889 return Handle<JSModuleNamespace>::cast(NewJSObjectFromMap(map)); |
1888 } | 1890 } |
1889 | 1891 |
1890 Handle<JSGeneratorObject> Factory::NewJSGeneratorObject( | 1892 Handle<JSGeneratorObject> Factory::NewJSGeneratorObject( |
1891 Handle<JSFunction> function) { | 1893 Handle<JSFunction> function) { |
1892 DCHECK(IsResumableFunction(function->shared()->kind())); | 1894 DCHECK(IsResumableFunction(function->shared()->kind())); |
1893 JSFunction::EnsureHasInitialMap(function); | 1895 JSFunction::EnsureHasInitialMap(function); |
1894 Handle<Map> map(function->initial_map()); | 1896 Handle<Map> map(function->initial_map()); |
1895 DCHECK_EQ(JS_GENERATOR_OBJECT_TYPE, map->instance_type()); | 1897 DCHECK(JS_GENERATOR_OBJECT_TYPE == map->instance_type() || |
| 1898 JS_ASYNC_GENERATOR_OBJECT_TYPE == map->instance_type()); |
1896 CALL_HEAP_FUNCTION( | 1899 CALL_HEAP_FUNCTION( |
1897 isolate(), | 1900 isolate(), |
1898 isolate()->heap()->AllocateJSObjectFromMap(*map), | 1901 isolate()->heap()->AllocateJSObjectFromMap(*map), |
1899 JSGeneratorObject); | 1902 JSGeneratorObject); |
1900 } | 1903 } |
1901 | 1904 |
1902 Handle<Module> Factory::NewModule(Handle<SharedFunctionInfo> code) { | 1905 Handle<Module> Factory::NewModule(Handle<SharedFunctionInfo> code) { |
1903 Handle<ModuleInfo> module_info(code->scope_info()->ModuleDescriptorInfo(), | 1906 Handle<ModuleInfo> module_info(code->scope_info()->ModuleDescriptorInfo(), |
1904 isolate()); | 1907 isolate()); |
1905 Handle<ObjectHashTable> exports = | 1908 Handle<ObjectHashTable> exports = |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1950 Handle<JSIteratorResult> Factory::NewJSIteratorResult(Handle<Object> value, | 1953 Handle<JSIteratorResult> Factory::NewJSIteratorResult(Handle<Object> value, |
1951 bool done) { | 1954 bool done) { |
1952 Handle<Map> map(isolate()->native_context()->iterator_result_map()); | 1955 Handle<Map> map(isolate()->native_context()->iterator_result_map()); |
1953 Handle<JSIteratorResult> js_iter_result = | 1956 Handle<JSIteratorResult> js_iter_result = |
1954 Handle<JSIteratorResult>::cast(NewJSObjectFromMap(map)); | 1957 Handle<JSIteratorResult>::cast(NewJSObjectFromMap(map)); |
1955 js_iter_result->set_value(*value); | 1958 js_iter_result->set_value(*value); |
1956 js_iter_result->set_done(*ToBoolean(done)); | 1959 js_iter_result->set_done(*ToBoolean(done)); |
1957 return js_iter_result; | 1960 return js_iter_result; |
1958 } | 1961 } |
1959 | 1962 |
| 1963 Handle<JSAsyncFromSyncIterator> Factory::NewJSAsyncFromSyncIterator( |
| 1964 Handle<HeapObject> sync_iterator) { |
| 1965 Handle<Map> map( |
| 1966 isolate()->native_context()->initial_async_from_sync_iterator_map()); |
| 1967 Handle<JSAsyncFromSyncIterator> iterator = |
| 1968 Handle<JSAsyncFromSyncIterator>::cast(NewJSObjectFromMap(map)); |
| 1969 |
| 1970 iterator->set_sync_iterator(*sync_iterator); |
| 1971 return iterator; |
| 1972 } |
| 1973 |
1960 Handle<JSMap> Factory::NewJSMap() { | 1974 Handle<JSMap> Factory::NewJSMap() { |
1961 Handle<Map> map(isolate()->native_context()->js_map_map()); | 1975 Handle<Map> map(isolate()->native_context()->js_map_map()); |
1962 Handle<JSMap> js_map = Handle<JSMap>::cast(NewJSObjectFromMap(map)); | 1976 Handle<JSMap> js_map = Handle<JSMap>::cast(NewJSObjectFromMap(map)); |
1963 JSMap::Initialize(js_map, isolate()); | 1977 JSMap::Initialize(js_map, isolate()); |
1964 return js_map; | 1978 return js_map; |
1965 } | 1979 } |
1966 | 1980 |
1967 | 1981 |
1968 Handle<JSSet> Factory::NewJSSet() { | 1982 Handle<JSSet> Factory::NewJSSet() { |
1969 Handle<Map> map(isolate()->native_context()->js_set_map()); | 1983 Handle<Map> map(isolate()->native_context()->js_set_map()); |
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2832 Handle<AccessorInfo> prototype = | 2846 Handle<AccessorInfo> prototype = |
2833 Accessors::FunctionPrototypeInfo(isolate(), rw_attribs); | 2847 Accessors::FunctionPrototypeInfo(isolate(), rw_attribs); |
2834 Descriptor d = Descriptor::AccessorConstant( | 2848 Descriptor d = Descriptor::AccessorConstant( |
2835 Handle<Name>(Name::cast(prototype->name())), prototype, rw_attribs); | 2849 Handle<Name>(Name::cast(prototype->name())), prototype, rw_attribs); |
2836 map->AppendDescriptor(&d); | 2850 map->AppendDescriptor(&d); |
2837 } | 2851 } |
2838 } | 2852 } |
2839 | 2853 |
2840 } // namespace internal | 2854 } // namespace internal |
2841 } // namespace v8 | 2855 } // namespace v8 |
OLD | NEW |