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 "factory.h" | 5 #include "factory.h" |
6 | 6 |
7 #include "conversions.h" | 7 #include "conversions.h" |
8 #include "isolate-inl.h" | 8 #include "isolate-inl.h" |
9 #include "macro-assembler.h" | 9 #include "macro-assembler.h" |
10 | 10 |
(...skipping 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1064 | 1064 |
1065 Handle<Object> Factory::NewNumberFromInt(int32_t value, | 1065 Handle<Object> Factory::NewNumberFromInt(int32_t value, |
1066 PretenureFlag pretenure) { | 1066 PretenureFlag pretenure) { |
1067 if (Smi::IsValid(value)) return handle(Smi::FromInt(value), isolate()); | 1067 if (Smi::IsValid(value)) return handle(Smi::FromInt(value), isolate()); |
1068 // Bypass NumberFromDouble to avoid various redundant checks. | 1068 // Bypass NumberFromDouble to avoid various redundant checks. |
1069 return NewHeapNumber(FastI2D(value), pretenure); | 1069 return NewHeapNumber(FastI2D(value), pretenure); |
1070 } | 1070 } |
1071 | 1071 |
1072 | 1072 |
1073 Handle<Object> Factory::NewNumberFromUint(uint32_t value, | 1073 Handle<Object> Factory::NewNumberFromUint(uint32_t value, |
1074 PretenureFlag pretenure) { | 1074 PretenureFlag pretenure) { |
1075 CALL_HEAP_FUNCTION( | 1075 int32_t int32v = static_cast<int32_t>(value); |
1076 isolate(), | 1076 if (int32v >= 0 && Smi::IsValid(int32v)) { |
1077 isolate()->heap()->NumberFromUint32(value, pretenure), Object); | 1077 return handle(Smi::FromInt(int32v), isolate()); |
| 1078 } |
| 1079 return NewHeapNumber(FastUI2D(value), pretenure); |
1078 } | 1080 } |
1079 | 1081 |
1080 | 1082 |
1081 Handle<HeapNumber> Factory::NewHeapNumber(double value, | 1083 Handle<HeapNumber> Factory::NewHeapNumber(double value, |
1082 PretenureFlag pretenure) { | 1084 PretenureFlag pretenure) { |
1083 CALL_HEAP_FUNCTION( | 1085 CALL_HEAP_FUNCTION( |
1084 isolate(), | 1086 isolate(), |
1085 isolate()->heap()->AllocateHeapNumber(value, pretenure), HeapNumber); | 1087 isolate()->heap()->AllocateHeapNumber(value, pretenure), HeapNumber); |
1086 } | 1088 } |
1087 | 1089 |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1390 if (!self_ref.is_null()) *(self_ref.location()) = *code; | 1392 if (!self_ref.is_null()) *(self_ref.location()) = *code; |
1391 | 1393 |
1392 // Migrate generated code. | 1394 // Migrate generated code. |
1393 // The generated code can contain Object** values (typically from handles) | 1395 // The generated code can contain Object** values (typically from handles) |
1394 // that are dereferenced during the copy to point directly to the actual heap | 1396 // that are dereferenced during the copy to point directly to the actual heap |
1395 // objects. These pointers can include references to the code object itself, | 1397 // objects. These pointers can include references to the code object itself, |
1396 // through the self_reference parameter. | 1398 // through the self_reference parameter. |
1397 code->CopyFrom(desc); | 1399 code->CopyFrom(desc); |
1398 | 1400 |
1399 #ifdef VERIFY_HEAP | 1401 #ifdef VERIFY_HEAP |
1400 if (FLAG_verify_heap) { | 1402 if (FLAG_verify_heap) code->ObjectVerify(); |
1401 code->Verify(); | |
1402 } | |
1403 #endif | 1403 #endif |
1404 return code; | 1404 return code; |
1405 } | 1405 } |
1406 | 1406 |
1407 | 1407 |
1408 Handle<Code> Factory::CopyCode(Handle<Code> code) { | 1408 Handle<Code> Factory::CopyCode(Handle<Code> code) { |
1409 CALL_HEAP_FUNCTION(isolate(), | 1409 CALL_HEAP_FUNCTION(isolate(), |
1410 isolate()->heap()->CopyCode(*code), | 1410 isolate()->heap()->CopyCode(*code), |
1411 Code); | 1411 Code); |
1412 } | 1412 } |
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2303 return Handle<Object>::null(); | 2303 return Handle<Object>::null(); |
2304 } | 2304 } |
2305 | 2305 |
2306 | 2306 |
2307 Handle<Object> Factory::ToBoolean(bool value) { | 2307 Handle<Object> Factory::ToBoolean(bool value) { |
2308 return value ? true_value() : false_value(); | 2308 return value ? true_value() : false_value(); |
2309 } | 2309 } |
2310 | 2310 |
2311 | 2311 |
2312 } } // namespace v8::internal | 2312 } } // namespace v8::internal |
OLD | NEW |