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 2626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2637 | 2637 |
2638 PropertyAttributes ro_attribs = | 2638 PropertyAttributes ro_attribs = |
2639 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); | 2639 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
2640 PropertyAttributes roc_attribs = | 2640 PropertyAttributes roc_attribs = |
2641 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); | 2641 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); |
2642 | 2642 |
2643 STATIC_ASSERT(JSFunction::kLengthDescriptorIndex == 0); | 2643 STATIC_ASSERT(JSFunction::kLengthDescriptorIndex == 0); |
2644 Handle<AccessorInfo> length = | 2644 Handle<AccessorInfo> length = |
2645 Accessors::FunctionLengthInfo(isolate(), roc_attribs); | 2645 Accessors::FunctionLengthInfo(isolate(), roc_attribs); |
2646 { // Add length. | 2646 { // Add length. |
2647 AccessorConstantDescriptor d(Handle<Name>(Name::cast(length->name())), | 2647 Descriptor d = Descriptor::AccessorConstant( |
2648 length, roc_attribs); | 2648 Handle<Name>(Name::cast(length->name())), length, roc_attribs); |
2649 map->AppendDescriptor(&d); | 2649 map->AppendDescriptor(&d); |
2650 } | 2650 } |
2651 | 2651 |
2652 STATIC_ASSERT(JSFunction::kNameDescriptorIndex == 1); | 2652 STATIC_ASSERT(JSFunction::kNameDescriptorIndex == 1); |
2653 Handle<AccessorInfo> name = | 2653 Handle<AccessorInfo> name = |
2654 Accessors::FunctionNameInfo(isolate(), ro_attribs); | 2654 Accessors::FunctionNameInfo(isolate(), ro_attribs); |
2655 { // Add name. | 2655 { // Add name. |
2656 AccessorConstantDescriptor d(Handle<Name>(Name::cast(name->name())), name, | 2656 Descriptor d = Descriptor::AccessorConstant( |
2657 roc_attribs); | 2657 Handle<Name>(Name::cast(name->name())), name, roc_attribs); |
2658 map->AppendDescriptor(&d); | 2658 map->AppendDescriptor(&d); |
2659 } | 2659 } |
2660 Handle<AccessorInfo> args = | 2660 Handle<AccessorInfo> args = |
2661 Accessors::FunctionArgumentsInfo(isolate(), ro_attribs); | 2661 Accessors::FunctionArgumentsInfo(isolate(), ro_attribs); |
2662 { // Add arguments. | 2662 { // Add arguments. |
2663 AccessorConstantDescriptor d(Handle<Name>(Name::cast(args->name())), args, | 2663 Descriptor d = Descriptor::AccessorConstant( |
2664 ro_attribs); | 2664 Handle<Name>(Name::cast(args->name())), args, ro_attribs); |
2665 map->AppendDescriptor(&d); | 2665 map->AppendDescriptor(&d); |
2666 } | 2666 } |
2667 Handle<AccessorInfo> caller = | 2667 Handle<AccessorInfo> caller = |
2668 Accessors::FunctionCallerInfo(isolate(), ro_attribs); | 2668 Accessors::FunctionCallerInfo(isolate(), ro_attribs); |
2669 { // Add caller. | 2669 { // Add caller. |
2670 AccessorConstantDescriptor d(Handle<Name>(Name::cast(caller->name())), | 2670 Descriptor d = Descriptor::AccessorConstant( |
2671 caller, ro_attribs); | 2671 Handle<Name>(Name::cast(caller->name())), caller, ro_attribs); |
2672 map->AppendDescriptor(&d); | 2672 map->AppendDescriptor(&d); |
2673 } | 2673 } |
2674 if (IsFunctionModeWithPrototype(function_mode)) { | 2674 if (IsFunctionModeWithPrototype(function_mode)) { |
2675 if (function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE) { | 2675 if (function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE) { |
2676 ro_attribs = static_cast<PropertyAttributes>(ro_attribs & ~READ_ONLY); | 2676 ro_attribs = static_cast<PropertyAttributes>(ro_attribs & ~READ_ONLY); |
2677 } | 2677 } |
2678 Handle<AccessorInfo> prototype = | 2678 Handle<AccessorInfo> prototype = |
2679 Accessors::FunctionPrototypeInfo(isolate(), ro_attribs); | 2679 Accessors::FunctionPrototypeInfo(isolate(), ro_attribs); |
2680 AccessorConstantDescriptor d(Handle<Name>(Name::cast(prototype->name())), | 2680 Descriptor d = Descriptor::AccessorConstant( |
2681 prototype, ro_attribs); | 2681 Handle<Name>(Name::cast(prototype->name())), prototype, ro_attribs); |
2682 map->AppendDescriptor(&d); | 2682 map->AppendDescriptor(&d); |
2683 } | 2683 } |
2684 } | 2684 } |
2685 | 2685 |
2686 Handle<Map> Factory::CreateStrictFunctionMap( | 2686 Handle<Map> Factory::CreateStrictFunctionMap( |
2687 FunctionMode function_mode, Handle<JSFunction> empty_function) { | 2687 FunctionMode function_mode, Handle<JSFunction> empty_function) { |
2688 Handle<Map> map = NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); | 2688 Handle<Map> map = NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); |
2689 SetStrictFunctionInstanceDescriptor(map, function_mode); | 2689 SetStrictFunctionInstanceDescriptor(map, function_mode); |
2690 map->set_is_constructor(IsFunctionModeWithPrototype(function_mode)); | 2690 map->set_is_constructor(IsFunctionModeWithPrototype(function_mode)); |
2691 map->set_is_callable(); | 2691 map->set_is_callable(); |
(...skipping 13 matching lines...) Expand all Loading... |
2705 PropertyAttributes roc_attribs = | 2705 PropertyAttributes roc_attribs = |
2706 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); | 2706 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); |
2707 | 2707 |
2708 DCHECK(function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE || | 2708 DCHECK(function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE || |
2709 function_mode == FUNCTION_WITH_READONLY_PROTOTYPE || | 2709 function_mode == FUNCTION_WITH_READONLY_PROTOTYPE || |
2710 function_mode == FUNCTION_WITHOUT_PROTOTYPE); | 2710 function_mode == FUNCTION_WITHOUT_PROTOTYPE); |
2711 STATIC_ASSERT(JSFunction::kLengthDescriptorIndex == 0); | 2711 STATIC_ASSERT(JSFunction::kLengthDescriptorIndex == 0); |
2712 { // Add length. | 2712 { // Add length. |
2713 Handle<AccessorInfo> length = | 2713 Handle<AccessorInfo> length = |
2714 Accessors::FunctionLengthInfo(isolate(), roc_attribs); | 2714 Accessors::FunctionLengthInfo(isolate(), roc_attribs); |
2715 AccessorConstantDescriptor d(handle(Name::cast(length->name())), length, | 2715 Descriptor d = Descriptor::AccessorConstant( |
2716 roc_attribs); | 2716 handle(Name::cast(length->name())), length, roc_attribs); |
2717 map->AppendDescriptor(&d); | 2717 map->AppendDescriptor(&d); |
2718 } | 2718 } |
2719 | 2719 |
2720 STATIC_ASSERT(JSFunction::kNameDescriptorIndex == 1); | 2720 STATIC_ASSERT(JSFunction::kNameDescriptorIndex == 1); |
2721 { // Add name. | 2721 { // Add name. |
2722 Handle<AccessorInfo> name = | 2722 Handle<AccessorInfo> name = |
2723 Accessors::FunctionNameInfo(isolate(), roc_attribs); | 2723 Accessors::FunctionNameInfo(isolate(), roc_attribs); |
2724 AccessorConstantDescriptor d(handle(Name::cast(name->name())), name, | 2724 Descriptor d = Descriptor::AccessorConstant( |
2725 roc_attribs); | 2725 handle(Name::cast(name->name())), name, roc_attribs); |
2726 map->AppendDescriptor(&d); | 2726 map->AppendDescriptor(&d); |
2727 } | 2727 } |
2728 if (IsFunctionModeWithPrototype(function_mode)) { | 2728 if (IsFunctionModeWithPrototype(function_mode)) { |
2729 // Add prototype. | 2729 // Add prototype. |
2730 PropertyAttributes attribs = | 2730 PropertyAttributes attribs = |
2731 function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE ? rw_attribs | 2731 function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE ? rw_attribs |
2732 : ro_attribs; | 2732 : ro_attribs; |
2733 Handle<AccessorInfo> prototype = | 2733 Handle<AccessorInfo> prototype = |
2734 Accessors::FunctionPrototypeInfo(isolate(), attribs); | 2734 Accessors::FunctionPrototypeInfo(isolate(), attribs); |
2735 AccessorConstantDescriptor d(Handle<Name>(Name::cast(prototype->name())), | 2735 Descriptor d = Descriptor::AccessorConstant( |
2736 prototype, attribs); | 2736 Handle<Name>(Name::cast(prototype->name())), prototype, attribs); |
2737 map->AppendDescriptor(&d); | 2737 map->AppendDescriptor(&d); |
2738 } | 2738 } |
2739 } | 2739 } |
2740 | 2740 |
2741 Handle<Map> Factory::CreateClassFunctionMap(Handle<JSFunction> empty_function) { | 2741 Handle<Map> Factory::CreateClassFunctionMap(Handle<JSFunction> empty_function) { |
2742 Handle<Map> map = NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); | 2742 Handle<Map> map = NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); |
2743 SetClassFunctionInstanceDescriptor(map); | 2743 SetClassFunctionInstanceDescriptor(map); |
2744 map->set_is_constructor(true); | 2744 map->set_is_constructor(true); |
2745 map->set_is_callable(); | 2745 map->set_is_callable(); |
2746 Map::SetPrototype(map, empty_function); | 2746 Map::SetPrototype(map, empty_function); |
2747 return map; | 2747 return map; |
2748 } | 2748 } |
2749 | 2749 |
2750 void Factory::SetClassFunctionInstanceDescriptor(Handle<Map> map) { | 2750 void Factory::SetClassFunctionInstanceDescriptor(Handle<Map> map) { |
2751 Map::EnsureDescriptorSlack(map, 2); | 2751 Map::EnsureDescriptorSlack(map, 2); |
2752 | 2752 |
2753 PropertyAttributes rw_attribs = | 2753 PropertyAttributes rw_attribs = |
2754 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); | 2754 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); |
2755 PropertyAttributes roc_attribs = | 2755 PropertyAttributes roc_attribs = |
2756 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); | 2756 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); |
2757 | 2757 |
2758 STATIC_ASSERT(JSFunction::kLengthDescriptorIndex == 0); | 2758 STATIC_ASSERT(JSFunction::kLengthDescriptorIndex == 0); |
2759 { // Add length. | 2759 { // Add length. |
2760 Handle<AccessorInfo> length = | 2760 Handle<AccessorInfo> length = |
2761 Accessors::FunctionLengthInfo(isolate(), roc_attribs); | 2761 Accessors::FunctionLengthInfo(isolate(), roc_attribs); |
2762 AccessorConstantDescriptor d(handle(Name::cast(length->name())), length, | 2762 Descriptor d = Descriptor::AccessorConstant( |
2763 roc_attribs); | 2763 handle(Name::cast(length->name())), length, roc_attribs); |
2764 map->AppendDescriptor(&d); | 2764 map->AppendDescriptor(&d); |
2765 } | 2765 } |
2766 | 2766 |
2767 { | 2767 { |
2768 // Add prototype. | 2768 // Add prototype. |
2769 Handle<AccessorInfo> prototype = | 2769 Handle<AccessorInfo> prototype = |
2770 Accessors::FunctionPrototypeInfo(isolate(), rw_attribs); | 2770 Accessors::FunctionPrototypeInfo(isolate(), rw_attribs); |
2771 AccessorConstantDescriptor d(Handle<Name>(Name::cast(prototype->name())), | 2771 Descriptor d = Descriptor::AccessorConstant( |
2772 prototype, rw_attribs); | 2772 Handle<Name>(Name::cast(prototype->name())), prototype, rw_attribs); |
2773 map->AppendDescriptor(&d); | 2773 map->AppendDescriptor(&d); |
2774 } | 2774 } |
2775 } | 2775 } |
2776 | 2776 |
2777 } // namespace internal | 2777 } // namespace internal |
2778 } // namespace v8 | 2778 } // namespace v8 |
OLD | NEW |