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 int size = 3; // with prototype |
| 2668 Map::EnsureDescriptorSlack(map, size); |
| 2669 |
| 2670 PropertyAttributes rw_attribs = |
| 2671 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); |
| 2672 PropertyAttributes roc_attribs = |
| 2673 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); |
| 2674 |
| 2675 STATIC_ASSERT(JSFunction::kLengthDescriptorIndex == 0); |
| 2676 { // Add length. |
| 2677 Handle<AccessorInfo> length = |
| 2678 Accessors::FunctionLengthInfo(isolate(), roc_attribs); |
| 2679 AccessorConstantDescriptor d(handle(Name::cast(length->name())), length, |
| 2680 roc_attribs); |
| 2681 map->AppendDescriptor(&d); |
| 2682 } |
| 2683 |
| 2684 { |
| 2685 // Add prototype. |
| 2686 Handle<AccessorInfo> prototype = |
| 2687 Accessors::FunctionPrototypeInfo(isolate(), rw_attribs); |
| 2688 AccessorConstantDescriptor d(Handle<Name>(Name::cast(prototype->name())), |
| 2689 prototype, rw_attribs); |
| 2690 map->AppendDescriptor(&d); |
| 2691 } |
| 2692 } |
| 2693 |
2657 Handle<JSFixedArrayIterator> Factory::NewJSFixedArrayIterator( | 2694 Handle<JSFixedArrayIterator> Factory::NewJSFixedArrayIterator( |
2658 Handle<FixedArray> array) { | 2695 Handle<FixedArray> array) { |
2659 // Create the "next" function (must be unique per iterator object). | 2696 // Create the "next" function (must be unique per iterator object). |
2660 Handle<Code> code( | 2697 Handle<Code> code( |
2661 isolate()->builtins()->builtin(Builtins::kFixedArrayIteratorNext)); | 2698 isolate()->builtins()->builtin(Builtins::kFixedArrayIteratorNext)); |
2662 // TODO(neis): Don't create a new SharedFunctionInfo each time. | 2699 // TODO(neis): Don't create a new SharedFunctionInfo each time. |
2663 Handle<JSFunction> next = isolate()->factory()->NewFunctionWithoutPrototype( | 2700 Handle<JSFunction> next = isolate()->factory()->NewFunctionWithoutPrototype( |
2664 isolate()->factory()->next_string(), code, false); | 2701 isolate()->factory()->next_string(), code, false); |
2665 next->shared()->set_native(true); | 2702 next->shared()->set_native(true); |
2666 | 2703 |
2667 // Create the iterator. | 2704 // Create the iterator. |
2668 Handle<Map> map(isolate()->native_context()->fixed_array_iterator_map()); | 2705 Handle<Map> map(isolate()->native_context()->fixed_array_iterator_map()); |
2669 Handle<JSFixedArrayIterator> iterator = | 2706 Handle<JSFixedArrayIterator> iterator = |
2670 Handle<JSFixedArrayIterator>::cast(NewJSObjectFromMap(map)); | 2707 Handle<JSFixedArrayIterator>::cast(NewJSObjectFromMap(map)); |
2671 iterator->set_initial_next(*next); | 2708 iterator->set_initial_next(*next); |
2672 iterator->set_array(*array); | 2709 iterator->set_array(*array); |
2673 iterator->set_index(0); | 2710 iterator->set_index(0); |
2674 iterator->InObjectPropertyAtPut(JSFixedArrayIterator::kNextIndex, *next); | 2711 iterator->InObjectPropertyAtPut(JSFixedArrayIterator::kNextIndex, *next); |
2675 return iterator; | 2712 return iterator; |
2676 } | 2713 } |
2677 | 2714 |
2678 } // namespace internal | 2715 } // namespace internal |
2679 } // namespace v8 | 2716 } // namespace v8 |
OLD | NEW |