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/conversions.h" | 7 #include "src/conversions.h" |
8 #include "src/isolate-inl.h" | 8 #include "src/isolate-inl.h" |
9 #include "src/macro-assembler.h" | 9 #include "src/macro-assembler.h" |
10 | 10 |
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1001 isolate()->heap()->CopyConstantPoolArray(*array), | 1001 isolate()->heap()->CopyConstantPoolArray(*array), |
1002 ConstantPoolArray); | 1002 ConstantPoolArray); |
1003 } | 1003 } |
1004 | 1004 |
1005 | 1005 |
1006 Handle<Object> Factory::NewNumber(double value, | 1006 Handle<Object> Factory::NewNumber(double value, |
1007 PretenureFlag pretenure) { | 1007 PretenureFlag pretenure) { |
1008 // We need to distinguish the minus zero value and this cannot be | 1008 // We need to distinguish the minus zero value and this cannot be |
1009 // done after conversion to int. Doing this by comparing bit | 1009 // done after conversion to int. Doing this by comparing bit |
1010 // patterns is faster than using fpclassify() et al. | 1010 // patterns is faster than using fpclassify() et al. |
1011 if (IsMinusZero(value)) return NewHeapNumber(-0.0, IMMUTABLE, pretenure); | 1011 if (IsMinusZero(value)) return NewHeapNumber(-0.0, pretenure); |
1012 | 1012 |
1013 int int_value = FastD2I(value); | 1013 int int_value = FastD2I(value); |
1014 if (value == int_value && Smi::IsValid(int_value)) { | 1014 if (value == int_value && Smi::IsValid(int_value)) { |
1015 return handle(Smi::FromInt(int_value), isolate()); | 1015 return handle(Smi::FromInt(int_value), isolate()); |
1016 } | 1016 } |
1017 | 1017 |
1018 // Materialize the value in the heap. | 1018 // Materialize the value in the heap. |
1019 return NewHeapNumber(value, IMMUTABLE, pretenure); | 1019 return NewHeapNumber(value, pretenure); |
1020 } | 1020 } |
1021 | 1021 |
1022 | 1022 |
1023 Handle<Object> Factory::NewNumberFromInt(int32_t value, | 1023 Handle<Object> Factory::NewNumberFromInt(int32_t value, |
1024 PretenureFlag pretenure) { | 1024 PretenureFlag pretenure) { |
1025 if (Smi::IsValid(value)) return handle(Smi::FromInt(value), isolate()); | 1025 if (Smi::IsValid(value)) return handle(Smi::FromInt(value), isolate()); |
1026 // Bypass NewNumber to avoid various redundant checks. | 1026 // Bypass NumberFromDouble to avoid various redundant checks. |
1027 return NewHeapNumber(FastI2D(value), IMMUTABLE, pretenure); | 1027 return NewHeapNumber(FastI2D(value), pretenure); |
1028 } | 1028 } |
1029 | 1029 |
1030 | 1030 |
1031 Handle<Object> Factory::NewNumberFromUint(uint32_t value, | 1031 Handle<Object> Factory::NewNumberFromUint(uint32_t value, |
1032 PretenureFlag pretenure) { | 1032 PretenureFlag pretenure) { |
1033 int32_t int32v = static_cast<int32_t>(value); | 1033 int32_t int32v = static_cast<int32_t>(value); |
1034 if (int32v >= 0 && Smi::IsValid(int32v)) { | 1034 if (int32v >= 0 && Smi::IsValid(int32v)) { |
1035 return handle(Smi::FromInt(int32v), isolate()); | 1035 return handle(Smi::FromInt(int32v), isolate()); |
1036 } | 1036 } |
1037 return NewHeapNumber(FastUI2D(value), IMMUTABLE, pretenure); | 1037 return NewHeapNumber(FastUI2D(value), pretenure); |
1038 } | 1038 } |
1039 | 1039 |
1040 | 1040 |
1041 Handle<HeapNumber> Factory::NewHeapNumber(double value, | 1041 Handle<HeapNumber> Factory::NewHeapNumber(double value, |
1042 MutableMode mode, | |
1043 PretenureFlag pretenure) { | 1042 PretenureFlag pretenure) { |
1044 CALL_HEAP_FUNCTION( | 1043 CALL_HEAP_FUNCTION( |
1045 isolate(), | 1044 isolate(), |
1046 isolate()->heap()->AllocateHeapNumber(value, mode, pretenure), | 1045 isolate()->heap()->AllocateHeapNumber(value, pretenure), HeapNumber); |
1047 HeapNumber); | |
1048 } | 1046 } |
1049 | 1047 |
1050 | 1048 |
1051 Handle<Object> Factory::NewTypeError(const char* message, | 1049 Handle<Object> Factory::NewTypeError(const char* message, |
1052 Vector< Handle<Object> > args) { | 1050 Vector< Handle<Object> > args) { |
1053 return NewError("MakeTypeError", message, args); | 1051 return NewError("MakeTypeError", message, args); |
1054 } | 1052 } |
1055 | 1053 |
1056 | 1054 |
1057 Handle<Object> Factory::NewTypeError(Handle<String> message) { | 1055 Handle<Object> Factory::NewTypeError(Handle<String> message) { |
(...skipping 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2362 return Handle<Object>::null(); | 2360 return Handle<Object>::null(); |
2363 } | 2361 } |
2364 | 2362 |
2365 | 2363 |
2366 Handle<Object> Factory::ToBoolean(bool value) { | 2364 Handle<Object> Factory::ToBoolean(bool value) { |
2367 return value ? true_value() : false_value(); | 2365 return value ? true_value() : false_value(); |
2368 } | 2366 } |
2369 | 2367 |
2370 | 2368 |
2371 } } // namespace v8::internal | 2369 } } // namespace v8::internal |
OLD | NEW |