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/base/bits.h" | 9 #include "src/base/bits.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 2636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2647 function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE ? rw_attribs | 2647 function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE ? rw_attribs |
2648 : ro_attribs; | 2648 : ro_attribs; |
2649 Handle<AccessorInfo> prototype = | 2649 Handle<AccessorInfo> prototype = |
2650 Accessors::FunctionPrototypeInfo(isolate(), attribs); | 2650 Accessors::FunctionPrototypeInfo(isolate(), attribs); |
2651 AccessorConstantDescriptor d(Handle<Name>(Name::cast(prototype->name())), | 2651 AccessorConstantDescriptor d(Handle<Name>(Name::cast(prototype->name())), |
2652 prototype, attribs); | 2652 prototype, attribs); |
2653 map->AppendDescriptor(&d); | 2653 map->AppendDescriptor(&d); |
2654 } | 2654 } |
2655 } | 2655 } |
2656 | 2656 |
| 2657 Handle<Map> Factory::CreateClassFunctionMap(Handle<JSFunction> empty_function) { |
| 2658 Handle<Map> map = NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); |
| 2659 SetClassFunctionInstanceDescriptor(map); |
| 2660 map->set_is_constructor(true); |
| 2661 map->set_is_callable(); |
| 2662 Map::SetPrototype(map, empty_function); |
| 2663 return map; |
| 2664 } |
| 2665 |
| 2666 void Factory::SetClassFunctionInstanceDescriptor(Handle<Map> map) { |
| 2667 Map::EnsureDescriptorSlack(map, 2); |
| 2668 |
| 2669 PropertyAttributes rw_attribs = |
| 2670 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); |
| 2671 PropertyAttributes roc_attribs = |
| 2672 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); |
| 2673 |
| 2674 STATIC_ASSERT(JSFunction::kLengthDescriptorIndex == 0); |
| 2675 { // Add length. |
| 2676 Handle<AccessorInfo> length = |
| 2677 Accessors::FunctionLengthInfo(isolate(), roc_attribs); |
| 2678 AccessorConstantDescriptor d(handle(Name::cast(length->name())), length, |
| 2679 roc_attribs); |
| 2680 map->AppendDescriptor(&d); |
| 2681 } |
| 2682 |
| 2683 { |
| 2684 // Add prototype. |
| 2685 Handle<AccessorInfo> prototype = |
| 2686 Accessors::FunctionPrototypeInfo(isolate(), rw_attribs); |
| 2687 AccessorConstantDescriptor d(Handle<Name>(Name::cast(prototype->name())), |
| 2688 prototype, rw_attribs); |
| 2689 map->AppendDescriptor(&d); |
| 2690 } |
| 2691 } |
| 2692 |
2657 Handle<JSFixedArrayIterator> Factory::NewJSFixedArrayIterator( | 2693 Handle<JSFixedArrayIterator> Factory::NewJSFixedArrayIterator( |
2658 Handle<FixedArray> array) { | 2694 Handle<FixedArray> array) { |
2659 // Create the "next" function (must be unique per iterator object). | 2695 // Create the "next" function (must be unique per iterator object). |
2660 Handle<Code> code( | 2696 Handle<Code> code( |
2661 isolate()->builtins()->builtin(Builtins::kFixedArrayIteratorNext)); | 2697 isolate()->builtins()->builtin(Builtins::kFixedArrayIteratorNext)); |
2662 // TODO(neis): Don't create a new SharedFunctionInfo each time. | 2698 // TODO(neis): Don't create a new SharedFunctionInfo each time. |
2663 Handle<JSFunction> next = isolate()->factory()->NewFunctionWithoutPrototype( | 2699 Handle<JSFunction> next = isolate()->factory()->NewFunctionWithoutPrototype( |
2664 isolate()->factory()->next_string(), code, false); | 2700 isolate()->factory()->next_string(), code, false); |
2665 next->shared()->set_native(true); | 2701 next->shared()->set_native(true); |
2666 | 2702 |
2667 // Create the iterator. | 2703 // Create the iterator. |
2668 Handle<Map> map(isolate()->native_context()->fixed_array_iterator_map()); | 2704 Handle<Map> map(isolate()->native_context()->fixed_array_iterator_map()); |
2669 Handle<JSFixedArrayIterator> iterator = | 2705 Handle<JSFixedArrayIterator> iterator = |
2670 Handle<JSFixedArrayIterator>::cast(NewJSObjectFromMap(map)); | 2706 Handle<JSFixedArrayIterator>::cast(NewJSObjectFromMap(map)); |
2671 iterator->set_initial_next(*next); | 2707 iterator->set_initial_next(*next); |
2672 iterator->set_array(*array); | 2708 iterator->set_array(*array); |
2673 iterator->set_index(0); | 2709 iterator->set_index(0); |
2674 iterator->InObjectPropertyAtPut(JSFixedArrayIterator::kNextIndex, *next); | 2710 iterator->InObjectPropertyAtPut(JSFixedArrayIterator::kNextIndex, *next); |
2675 return iterator; | 2711 return iterator; |
2676 } | 2712 } |
2677 | 2713 |
2678 } // namespace internal | 2714 } // namespace internal |
2679 } // namespace v8 | 2715 } // namespace v8 |
OLD | NEW |