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

Side by Side Diff: src/factory.cc

Issue 2423053002: Install the 'name' property in classes at runtime (Closed)
Patch Set: rebased Created 4 years 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
« no previous file with comments | « src/factory.h ('k') | src/interpreter/bytecode-generator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 2709 matching lines...) Expand 10 before | Expand all | Expand 10 after
2720 function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE ? rw_attribs 2720 function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE ? rw_attribs
2721 : ro_attribs; 2721 : ro_attribs;
2722 Handle<AccessorInfo> prototype = 2722 Handle<AccessorInfo> prototype =
2723 Accessors::FunctionPrototypeInfo(isolate(), attribs); 2723 Accessors::FunctionPrototypeInfo(isolate(), attribs);
2724 AccessorConstantDescriptor d(Handle<Name>(Name::cast(prototype->name())), 2724 AccessorConstantDescriptor d(Handle<Name>(Name::cast(prototype->name())),
2725 prototype, attribs); 2725 prototype, attribs);
2726 map->AppendDescriptor(&d); 2726 map->AppendDescriptor(&d);
2727 } 2727 }
2728 } 2728 }
2729 2729
2730 Handle<Map> Factory::CreateClassFunctionMap(Handle<JSFunction> empty_function) {
2731 Handle<Map> map = NewMap(JS_FUNCTION_TYPE, JSFunction::kSize);
2732 SetClassFunctionInstanceDescriptor(map);
2733 map->set_is_constructor(true);
2734 map->set_is_callable();
2735 Map::SetPrototype(map, empty_function);
2736 return map;
2737 }
2738
2739 void Factory::SetClassFunctionInstanceDescriptor(Handle<Map> map) {
2740 Map::EnsureDescriptorSlack(map, 2);
2741
2742 PropertyAttributes rw_attribs =
2743 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE);
2744 PropertyAttributes roc_attribs =
2745 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY);
2746
2747 STATIC_ASSERT(JSFunction::kLengthDescriptorIndex == 0);
2748 { // Add length.
2749 Handle<AccessorInfo> length =
2750 Accessors::FunctionLengthInfo(isolate(), roc_attribs);
2751 AccessorConstantDescriptor d(handle(Name::cast(length->name())), length,
2752 roc_attribs);
2753 map->AppendDescriptor(&d);
2754 }
2755
2756 {
2757 // Add prototype.
2758 Handle<AccessorInfo> prototype =
2759 Accessors::FunctionPrototypeInfo(isolate(), rw_attribs);
2760 AccessorConstantDescriptor d(Handle<Name>(Name::cast(prototype->name())),
2761 prototype, rw_attribs);
2762 map->AppendDescriptor(&d);
2763 }
2764 }
2765
2730 Handle<JSFixedArrayIterator> Factory::NewJSFixedArrayIterator( 2766 Handle<JSFixedArrayIterator> Factory::NewJSFixedArrayIterator(
2731 Handle<FixedArray> array) { 2767 Handle<FixedArray> array) {
2732 // Create the "next" function (must be unique per iterator object). 2768 // Create the "next" function (must be unique per iterator object).
2733 Handle<Code> code( 2769 Handle<Code> code(
2734 isolate()->builtins()->builtin(Builtins::kFixedArrayIteratorNext)); 2770 isolate()->builtins()->builtin(Builtins::kFixedArrayIteratorNext));
2735 // TODO(neis): Don't create a new SharedFunctionInfo each time. 2771 // TODO(neis): Don't create a new SharedFunctionInfo each time.
2736 Handle<JSFunction> next = isolate()->factory()->NewFunctionWithoutPrototype( 2772 Handle<JSFunction> next = isolate()->factory()->NewFunctionWithoutPrototype(
2737 isolate()->factory()->next_string(), code, false); 2773 isolate()->factory()->next_string(), code, false);
2738 next->shared()->set_native(true); 2774 next->shared()->set_native(true);
2739 2775
2740 // Create the iterator. 2776 // Create the iterator.
2741 Handle<Map> map(isolate()->native_context()->fixed_array_iterator_map()); 2777 Handle<Map> map(isolate()->native_context()->fixed_array_iterator_map());
2742 Handle<JSFixedArrayIterator> iterator = 2778 Handle<JSFixedArrayIterator> iterator =
2743 Handle<JSFixedArrayIterator>::cast(NewJSObjectFromMap(map)); 2779 Handle<JSFixedArrayIterator>::cast(NewJSObjectFromMap(map));
2744 iterator->set_initial_next(*next); 2780 iterator->set_initial_next(*next);
2745 iterator->set_array(*array); 2781 iterator->set_array(*array);
2746 iterator->set_index(0); 2782 iterator->set_index(0);
2747 iterator->InObjectPropertyAtPut(JSFixedArrayIterator::kNextIndex, *next); 2783 iterator->InObjectPropertyAtPut(JSFixedArrayIterator::kNextIndex, *next);
2748 return iterator; 2784 return iterator;
2749 } 2785 }
2750 2786
2751 } // namespace internal 2787 } // namespace internal
2752 } // namespace v8 2788 } // namespace v8
OLDNEW
« no previous file with comments | « src/factory.h ('k') | src/interpreter/bytecode-generator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698