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

Side by Side Diff: src/factory.cc

Issue 2396353002: Revert "Add Smi::Zero and replace all Smi::FromInt(0) calls" (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « src/elements.cc ('k') | src/field-type.cc » ('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/base/bits.h" 9 #include "src/base/bits.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 Handle<Box> result = Handle<Box>::cast(NewStruct(BOX_TYPE)); 90 Handle<Box> result = Handle<Box>::cast(NewStruct(BOX_TYPE));
91 result->set_value(*value); 91 result->set_value(*value);
92 return result; 92 return result;
93 } 93 }
94 94
95 Handle<PrototypeInfo> Factory::NewPrototypeInfo() { 95 Handle<PrototypeInfo> Factory::NewPrototypeInfo() {
96 Handle<PrototypeInfo> result = 96 Handle<PrototypeInfo> result =
97 Handle<PrototypeInfo>::cast(NewStruct(PROTOTYPE_INFO_TYPE)); 97 Handle<PrototypeInfo>::cast(NewStruct(PROTOTYPE_INFO_TYPE));
98 result->set_prototype_users(WeakFixedArray::Empty()); 98 result->set_prototype_users(WeakFixedArray::Empty());
99 result->set_registry_slot(PrototypeInfo::UNREGISTERED); 99 result->set_registry_slot(PrototypeInfo::UNREGISTERED);
100 result->set_validity_cell(Smi::kZero); 100 result->set_validity_cell(Smi::FromInt(0));
101 result->set_bit_field(0); 101 result->set_bit_field(0);
102 return result; 102 return result;
103 } 103 }
104 104
105 Handle<ContextExtension> Factory::NewContextExtension( 105 Handle<ContextExtension> Factory::NewContextExtension(
106 Handle<ScopeInfo> scope_info, Handle<Object> extension) { 106 Handle<ScopeInfo> scope_info, Handle<Object> extension) {
107 Handle<ContextExtension> result = 107 Handle<ContextExtension> result =
108 Handle<ContextExtension>::cast(NewStruct(CONTEXT_EXTENSION_TYPE)); 108 Handle<ContextExtension>::cast(NewStruct(CONTEXT_EXTENSION_TYPE));
109 result->set_scope_info(*scope_info); 109 result->set_scope_info(*scope_info);
110 result->set_extension(*extension); 110 result->set_extension(*extension);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 } 172 }
173 } 173 }
174 return array; 174 return array;
175 } 175 }
176 176
177 Handle<FrameArray> Factory::NewFrameArray(int number_of_frames, 177 Handle<FrameArray> Factory::NewFrameArray(int number_of_frames,
178 PretenureFlag pretenure) { 178 PretenureFlag pretenure) {
179 DCHECK_LE(0, number_of_frames); 179 DCHECK_LE(0, number_of_frames);
180 Handle<FixedArray> result = 180 Handle<FixedArray> result =
181 NewFixedArrayWithHoles(FrameArray::LengthFor(number_of_frames)); 181 NewFixedArrayWithHoles(FrameArray::LengthFor(number_of_frames));
182 result->set(FrameArray::kFrameCountIndex, Smi::kZero); 182 result->set(FrameArray::kFrameCountIndex, Smi::FromInt(0));
183 return Handle<FrameArray>::cast(result); 183 return Handle<FrameArray>::cast(result);
184 } 184 }
185 185
186 Handle<OrderedHashSet> Factory::NewOrderedHashSet() { 186 Handle<OrderedHashSet> Factory::NewOrderedHashSet() {
187 return OrderedHashSet::Allocate(isolate(), OrderedHashSet::kMinCapacity); 187 return OrderedHashSet::Allocate(isolate(), OrderedHashSet::kMinCapacity);
188 } 188 }
189 189
190 190
191 Handle<OrderedHashMap> Factory::NewOrderedHashMap() { 191 Handle<OrderedHashMap> Factory::NewOrderedHashMap() {
192 return OrderedHashMap::Allocate(isolate(), OrderedHashMap::kMinCapacity); 192 return OrderedHashMap::Allocate(isolate(), OrderedHashMap::kMinCapacity);
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 return symbol; 772 return symbol;
773 } 773 }
774 774
775 775
776 Handle<Context> Factory::NewNativeContext() { 776 Handle<Context> Factory::NewNativeContext() {
777 Handle<FixedArray> array = 777 Handle<FixedArray> array =
778 NewFixedArray(Context::NATIVE_CONTEXT_SLOTS, TENURED); 778 NewFixedArray(Context::NATIVE_CONTEXT_SLOTS, TENURED);
779 array->set_map_no_write_barrier(*native_context_map()); 779 array->set_map_no_write_barrier(*native_context_map());
780 Handle<Context> context = Handle<Context>::cast(array); 780 Handle<Context> context = Handle<Context>::cast(array);
781 context->set_native_context(*context); 781 context->set_native_context(*context);
782 context->set_errors_thrown(Smi::kZero); 782 context->set_errors_thrown(Smi::FromInt(0));
783 Handle<WeakCell> weak_cell = NewWeakCell(context); 783 Handle<WeakCell> weak_cell = NewWeakCell(context);
784 context->set_self_weak_cell(*weak_cell); 784 context->set_self_weak_cell(*weak_cell);
785 DCHECK(context->IsNativeContext()); 785 DCHECK(context->IsNativeContext());
786 return context; 786 return context;
787 } 787 }
788 788
789 789
790 Handle<Context> Factory::NewScriptContext(Handle<JSFunction> function, 790 Handle<Context> Factory::NewScriptContext(Handle<JSFunction> function,
791 Handle<ScopeInfo> scope_info) { 791 Handle<ScopeInfo> scope_info) {
792 DCHECK_EQ(scope_info->scope_type(), SCRIPT_SCOPE); 792 DCHECK_EQ(scope_info->scope_type(), SCRIPT_SCOPE);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 script->set_name(heap->undefined_value()); 963 script->set_name(heap->undefined_value());
964 script->set_id(isolate()->heap()->NextScriptId()); 964 script->set_id(isolate()->heap()->NextScriptId());
965 script->set_line_offset(0); 965 script->set_line_offset(0);
966 script->set_column_offset(0); 966 script->set_column_offset(0);
967 script->set_context_data(heap->undefined_value()); 967 script->set_context_data(heap->undefined_value());
968 script->set_type(Script::TYPE_NORMAL); 968 script->set_type(Script::TYPE_NORMAL);
969 script->set_wrapper(heap->undefined_value()); 969 script->set_wrapper(heap->undefined_value());
970 script->set_line_ends(heap->undefined_value()); 970 script->set_line_ends(heap->undefined_value());
971 script->set_eval_from_shared(heap->undefined_value()); 971 script->set_eval_from_shared(heap->undefined_value());
972 script->set_eval_from_position(0); 972 script->set_eval_from_position(0);
973 script->set_shared_function_infos(Smi::kZero); 973 script->set_shared_function_infos(Smi::FromInt(0));
974 script->set_flags(0); 974 script->set_flags(0);
975 975
976 heap->set_script_list(*WeakFixedArray::Add(script_list(), script)); 976 heap->set_script_list(*WeakFixedArray::Add(script_list(), script));
977 return script; 977 return script;
978 } 978 }
979 979
980 980
981 Handle<Foreign> Factory::NewForeign(Address addr, PretenureFlag pretenure) { 981 Handle<Foreign> Factory::NewForeign(Address addr, PretenureFlag pretenure) {
982 CALL_HEAP_FUNCTION(isolate(), 982 CALL_HEAP_FUNCTION(isolate(),
983 isolate()->heap()->AllocateForeign(addr, pretenure), 983 isolate()->heap()->AllocateForeign(addr, pretenure),
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 1497
1498 Handle<Code> code = NewCodeRaw(obj_size, immovable); 1498 Handle<Code> code = NewCodeRaw(obj_size, immovable);
1499 DCHECK(!isolate()->heap()->memory_allocator()->code_range()->valid() || 1499 DCHECK(!isolate()->heap()->memory_allocator()->code_range()->valid() ||
1500 isolate()->heap()->memory_allocator()->code_range()->contains( 1500 isolate()->heap()->memory_allocator()->code_range()->contains(
1501 code->address()) || 1501 code->address()) ||
1502 obj_size <= isolate()->heap()->code_space()->AreaSize()); 1502 obj_size <= isolate()->heap()->code_space()->AreaSize());
1503 1503
1504 // The code object has not been fully initialized yet. We rely on the 1504 // The code object has not been fully initialized yet. We rely on the
1505 // fact that no allocation will happen from this point on. 1505 // fact that no allocation will happen from this point on.
1506 DisallowHeapAllocation no_gc; 1506 DisallowHeapAllocation no_gc;
1507 code->set_gc_metadata(Smi::kZero); 1507 code->set_gc_metadata(Smi::FromInt(0));
1508 code->set_ic_age(isolate()->heap()->global_ic_age()); 1508 code->set_ic_age(isolate()->heap()->global_ic_age());
1509 code->set_instruction_size(desc.instr_size); 1509 code->set_instruction_size(desc.instr_size);
1510 code->set_relocation_info(*reloc_info); 1510 code->set_relocation_info(*reloc_info);
1511 code->set_flags(flags); 1511 code->set_flags(flags);
1512 code->set_has_unwinding_info(has_unwinding_info); 1512 code->set_has_unwinding_info(has_unwinding_info);
1513 code->set_raw_kind_specific_flags1(0); 1513 code->set_raw_kind_specific_flags1(0);
1514 code->set_raw_kind_specific_flags2(0); 1514 code->set_raw_kind_specific_flags2(0);
1515 code->set_is_crankshafted(crankshafted); 1515 code->set_is_crankshafted(crankshafted);
1516 code->set_deoptimization_data(*empty_fixed_array(), SKIP_WRITE_BARRIER); 1516 code->set_deoptimization_data(*empty_fixed_array(), SKIP_WRITE_BARRIER);
1517 code->set_raw_type_feedback_info(Smi::kZero); 1517 code->set_raw_type_feedback_info(Smi::FromInt(0));
1518 code->set_next_code_link(*undefined_value(), SKIP_WRITE_BARRIER); 1518 code->set_next_code_link(*undefined_value(), SKIP_WRITE_BARRIER);
1519 code->set_handler_table(*empty_fixed_array(), SKIP_WRITE_BARRIER); 1519 code->set_handler_table(*empty_fixed_array(), SKIP_WRITE_BARRIER);
1520 code->set_source_position_table(*empty_byte_array(), SKIP_WRITE_BARRIER); 1520 code->set_source_position_table(*empty_byte_array(), SKIP_WRITE_BARRIER);
1521 code->set_prologue_offset(prologue_offset); 1521 code->set_prologue_offset(prologue_offset);
1522 code->set_constant_pool_offset(desc.instr_size - desc.constant_pool_size); 1522 code->set_constant_pool_offset(desc.instr_size - desc.constant_pool_size);
1523 code->set_builtin_index(-1); 1523 code->set_builtin_index(-1);
1524 1524
1525 if (code->kind() == Code::OPTIMIZED_FUNCTION) { 1525 if (code->kind() == Code::OPTIMIZED_FUNCTION) {
1526 code->set_marked_for_deoptimization(false); 1526 code->set_marked_for_deoptimization(false);
1527 } 1527 }
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1699 } 1699 }
1700 1700
1701 1701
1702 void Factory::NewJSArrayStorage(Handle<JSArray> array, 1702 void Factory::NewJSArrayStorage(Handle<JSArray> array,
1703 int length, 1703 int length,
1704 int capacity, 1704 int capacity,
1705 ArrayStorageAllocationMode mode) { 1705 ArrayStorageAllocationMode mode) {
1706 DCHECK(capacity >= length); 1706 DCHECK(capacity >= length);
1707 1707
1708 if (capacity == 0) { 1708 if (capacity == 0) {
1709 array->set_length(Smi::kZero); 1709 array->set_length(Smi::FromInt(0));
1710 array->set_elements(*empty_fixed_array()); 1710 array->set_elements(*empty_fixed_array());
1711 return; 1711 return;
1712 } 1712 }
1713 1713
1714 HandleScope inner_scope(isolate()); 1714 HandleScope inner_scope(isolate());
1715 Handle<FixedArrayBase> elms; 1715 Handle<FixedArrayBase> elms;
1716 ElementsKind elements_kind = array->GetElementsKind(); 1716 ElementsKind elements_kind = array->GetElementsKind();
1717 if (IsFastDoubleElementsKind(elements_kind)) { 1717 if (IsFastDoubleElementsKind(elements_kind)) {
1718 if (mode == DONT_INITIALIZE_ARRAY_ELEMENTS) { 1718 if (mode == DONT_INITIALIZE_ARRAY_ELEMENTS) {
1719 elms = NewFixedDoubleArray(capacity); 1719 elms = NewFixedDoubleArray(capacity);
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
2005 Handle<JSTypedArray> obj = NewJSTypedArray(elements_kind, pretenure); 2005 Handle<JSTypedArray> obj = NewJSTypedArray(elements_kind, pretenure);
2006 2006
2007 size_t element_size = GetFixedTypedArraysElementSize(elements_kind); 2007 size_t element_size = GetFixedTypedArraysElementSize(elements_kind);
2008 ExternalArrayType array_type = GetArrayTypeFromElementsKind(elements_kind); 2008 ExternalArrayType array_type = GetArrayTypeFromElementsKind(elements_kind);
2009 2009
2010 CHECK(number_of_elements <= 2010 CHECK(number_of_elements <=
2011 (std::numeric_limits<size_t>::max() / element_size)); 2011 (std::numeric_limits<size_t>::max() / element_size));
2012 CHECK(number_of_elements <= static_cast<size_t>(Smi::kMaxValue)); 2012 CHECK(number_of_elements <= static_cast<size_t>(Smi::kMaxValue));
2013 size_t byte_length = number_of_elements * element_size; 2013 size_t byte_length = number_of_elements * element_size;
2014 2014
2015 obj->set_byte_offset(Smi::kZero); 2015 obj->set_byte_offset(Smi::FromInt(0));
2016 i::Handle<i::Object> byte_length_object = 2016 i::Handle<i::Object> byte_length_object =
2017 NewNumberFromSize(byte_length, pretenure); 2017 NewNumberFromSize(byte_length, pretenure);
2018 obj->set_byte_length(*byte_length_object); 2018 obj->set_byte_length(*byte_length_object);
2019 Handle<Object> length_object = 2019 Handle<Object> length_object =
2020 NewNumberFromSize(number_of_elements, pretenure); 2020 NewNumberFromSize(number_of_elements, pretenure);
2021 obj->set_length(*length_object); 2021 obj->set_length(*length_object);
2022 2022
2023 Handle<JSArrayBuffer> buffer = 2023 Handle<JSArrayBuffer> buffer =
2024 NewJSArrayBuffer(SharedFlag::kNotShared, pretenure); 2024 NewJSArrayBuffer(SharedFlag::kNotShared, pretenure);
2025 JSArrayBuffer::Setup(buffer, isolate(), true, NULL, byte_length, 2025 JSArrayBuffer::Setup(buffer, isolate(), true, NULL, byte_length,
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
2452 int capture_count) { 2452 int capture_count) {
2453 Handle<FixedArray> store = NewFixedArray(JSRegExp::kIrregexpDataSize); 2453 Handle<FixedArray> store = NewFixedArray(JSRegExp::kIrregexpDataSize);
2454 Smi* uninitialized = Smi::FromInt(JSRegExp::kUninitializedValue); 2454 Smi* uninitialized = Smi::FromInt(JSRegExp::kUninitializedValue);
2455 store->set(JSRegExp::kTagIndex, Smi::FromInt(type)); 2455 store->set(JSRegExp::kTagIndex, Smi::FromInt(type));
2456 store->set(JSRegExp::kSourceIndex, *source); 2456 store->set(JSRegExp::kSourceIndex, *source);
2457 store->set(JSRegExp::kFlagsIndex, Smi::FromInt(flags)); 2457 store->set(JSRegExp::kFlagsIndex, Smi::FromInt(flags));
2458 store->set(JSRegExp::kIrregexpLatin1CodeIndex, uninitialized); 2458 store->set(JSRegExp::kIrregexpLatin1CodeIndex, uninitialized);
2459 store->set(JSRegExp::kIrregexpUC16CodeIndex, uninitialized); 2459 store->set(JSRegExp::kIrregexpUC16CodeIndex, uninitialized);
2460 store->set(JSRegExp::kIrregexpLatin1CodeSavedIndex, uninitialized); 2460 store->set(JSRegExp::kIrregexpLatin1CodeSavedIndex, uninitialized);
2461 store->set(JSRegExp::kIrregexpUC16CodeSavedIndex, uninitialized); 2461 store->set(JSRegExp::kIrregexpUC16CodeSavedIndex, uninitialized);
2462 store->set(JSRegExp::kIrregexpMaxRegisterCountIndex, Smi::kZero); 2462 store->set(JSRegExp::kIrregexpMaxRegisterCountIndex, Smi::FromInt(0));
2463 store->set(JSRegExp::kIrregexpCaptureCountIndex, 2463 store->set(JSRegExp::kIrregexpCaptureCountIndex,
2464 Smi::FromInt(capture_count)); 2464 Smi::FromInt(capture_count));
2465 store->set(JSRegExp::kIrregexpCaptureNameMapIndex, uninitialized); 2465 store->set(JSRegExp::kIrregexpCaptureNameMapIndex, uninitialized);
2466 regexp->set_data(*store); 2466 regexp->set_data(*store);
2467 } 2467 }
2468 2468
2469 2469
2470 Handle<Object> Factory::GlobalConstantFor(Handle<Name> name) { 2470 Handle<Object> Factory::GlobalConstantFor(Handle<Name> name) {
2471 if (Name::Equals(name, undefined_string())) return undefined_value(); 2471 if (Name::Equals(name, undefined_string())) return undefined_value();
2472 if (Name::Equals(name, nan_string())) return nan_value(); 2472 if (Name::Equals(name, nan_string())) return nan_value();
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
2603 Handle<AccessorInfo> prototype = 2603 Handle<AccessorInfo> prototype =
2604 Accessors::FunctionPrototypeInfo(isolate(), attribs); 2604 Accessors::FunctionPrototypeInfo(isolate(), attribs);
2605 AccessorConstantDescriptor d(Handle<Name>(Name::cast(prototype->name())), 2605 AccessorConstantDescriptor d(Handle<Name>(Name::cast(prototype->name())),
2606 prototype, attribs); 2606 prototype, attribs);
2607 map->AppendDescriptor(&d); 2607 map->AppendDescriptor(&d);
2608 } 2608 }
2609 } 2609 }
2610 2610
2611 } // namespace internal 2611 } // namespace internal
2612 } // namespace v8 2612 } // namespace v8
OLDNEW
« no previous file with comments | « src/elements.cc ('k') | src/field-type.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698