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

Side by Side Diff: src/factory.cc

Issue 2622833002: WIP [esnext] implement async iteration proposal (Closed)
Patch Set: 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/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
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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1818 Handle<JSModuleNamespace> Factory::NewJSModuleNamespace() { 1820 Handle<JSModuleNamespace> Factory::NewJSModuleNamespace() {
1819 Handle<Map> map = isolate()->js_module_namespace_map(); 1821 Handle<Map> map = isolate()->js_module_namespace_map();
1820 return Handle<JSModuleNamespace>::cast(NewJSObjectFromMap(map)); 1822 return Handle<JSModuleNamespace>::cast(NewJSObjectFromMap(map));
1821 } 1823 }
1822 1824
1823 Handle<JSGeneratorObject> Factory::NewJSGeneratorObject( 1825 Handle<JSGeneratorObject> Factory::NewJSGeneratorObject(
1824 Handle<JSFunction> function) { 1826 Handle<JSFunction> function) {
1825 DCHECK(IsResumableFunction(function->shared()->kind())); 1827 DCHECK(IsResumableFunction(function->shared()->kind()));
1826 JSFunction::EnsureHasInitialMap(function); 1828 JSFunction::EnsureHasInitialMap(function);
1827 Handle<Map> map(function->initial_map()); 1829 Handle<Map> map(function->initial_map());
1828 DCHECK_EQ(JS_GENERATOR_OBJECT_TYPE, map->instance_type()); 1830 DCHECK(JS_GENERATOR_OBJECT_TYPE == map->instance_type() ||
1831 JS_ASYNC_GENERATOR_OBJECT_TYPE == map->instance_type());
1829 CALL_HEAP_FUNCTION( 1832 CALL_HEAP_FUNCTION(
1830 isolate(), 1833 isolate(),
1831 isolate()->heap()->AllocateJSObjectFromMap(*map), 1834 isolate()->heap()->AllocateJSObjectFromMap(*map),
1832 JSGeneratorObject); 1835 JSGeneratorObject);
1833 } 1836 }
1834 1837
1835 Handle<Module> Factory::NewModule(Handle<SharedFunctionInfo> code) { 1838 Handle<Module> Factory::NewModule(Handle<SharedFunctionInfo> code) {
1836 Handle<ModuleInfo> module_info(code->scope_info()->ModuleDescriptorInfo(), 1839 Handle<ModuleInfo> module_info(code->scope_info()->ModuleDescriptorInfo(),
1837 isolate()); 1840 isolate());
1838 Handle<ObjectHashTable> exports = 1841 Handle<ObjectHashTable> exports =
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1883 Handle<JSIteratorResult> Factory::NewJSIteratorResult(Handle<Object> value, 1886 Handle<JSIteratorResult> Factory::NewJSIteratorResult(Handle<Object> value,
1884 bool done) { 1887 bool done) {
1885 Handle<Map> map(isolate()->native_context()->iterator_result_map()); 1888 Handle<Map> map(isolate()->native_context()->iterator_result_map());
1886 Handle<JSIteratorResult> js_iter_result = 1889 Handle<JSIteratorResult> js_iter_result =
1887 Handle<JSIteratorResult>::cast(NewJSObjectFromMap(map)); 1890 Handle<JSIteratorResult>::cast(NewJSObjectFromMap(map));
1888 js_iter_result->set_value(*value); 1891 js_iter_result->set_value(*value);
1889 js_iter_result->set_done(*ToBoolean(done)); 1892 js_iter_result->set_done(*ToBoolean(done));
1890 return js_iter_result; 1893 return js_iter_result;
1891 } 1894 }
1892 1895
1896 Handle<JSAsyncFromSyncIterator> Factory::NewJSAsyncFromSyncIterator(
1897 Handle<HeapObject> sync_iterator) {
1898 Handle<Map> map(
1899 isolate()->native_context()->initial_async_from_sync_iterator_map());
1900 Handle<JSAsyncFromSyncIterator> iterator =
1901 Handle<JSAsyncFromSyncIterator>::cast(NewJSObjectFromMap(map));
1902
1903 iterator->set_sync_iterator(*sync_iterator);
1904 return iterator;
1905 }
1906
1893 Handle<JSMap> Factory::NewJSMap() { 1907 Handle<JSMap> Factory::NewJSMap() {
1894 Handle<Map> map(isolate()->native_context()->js_map_map()); 1908 Handle<Map> map(isolate()->native_context()->js_map_map());
1895 Handle<JSMap> js_map = Handle<JSMap>::cast(NewJSObjectFromMap(map)); 1909 Handle<JSMap> js_map = Handle<JSMap>::cast(NewJSObjectFromMap(map));
1896 JSMap::Initialize(js_map, isolate()); 1910 JSMap::Initialize(js_map, isolate());
1897 return js_map; 1911 return js_map;
1898 } 1912 }
1899 1913
1900 1914
1901 Handle<JSSet> Factory::NewJSSet() { 1915 Handle<JSSet> Factory::NewJSSet() {
1902 Handle<Map> map(isolate()->native_context()->js_set_map()); 1916 Handle<Map> map(isolate()->native_context()->js_set_map());
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after
2765 Handle<AccessorInfo> prototype = 2779 Handle<AccessorInfo> prototype =
2766 Accessors::FunctionPrototypeInfo(isolate(), rw_attribs); 2780 Accessors::FunctionPrototypeInfo(isolate(), rw_attribs);
2767 Descriptor d = Descriptor::AccessorConstant( 2781 Descriptor d = Descriptor::AccessorConstant(
2768 Handle<Name>(Name::cast(prototype->name())), prototype, rw_attribs); 2782 Handle<Name>(Name::cast(prototype->name())), prototype, rw_attribs);
2769 map->AppendDescriptor(&d); 2783 map->AppendDescriptor(&d);
2770 } 2784 }
2771 } 2785 }
2772 2786
2773 } // namespace internal 2787 } // namespace internal
2774 } // namespace v8 2788 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698