// Converts a string into an integer.
double StringToInt(UnicodeCache* unicode_cache, String* str, int radix);
-inline bool TryNumberToSize(Isolate* isolate,
- Object* number, size_t* result) {
+// Converts a number into size_t.
+inline size_t NumberToSize(Isolate* isolate,
+ Object* number) {
SealHandleScope shs(isolate);
if (number->IsSmi()) {
int value = Smi::cast(number)->value();
- ASSERT(Smi::kMaxValue <= std::numeric_limits<size_t>::max());
- if (value >= 0) {
- *result = static_cast<size_t>(value);
- return true;
- }
- return false;
+ CHECK_GE(value, 0);
+ ASSERT(
+ static_cast<unsigned>(Smi::kMaxValue)
+ <= std::numeric_limits<size_t>::max());
+ return static_cast<size_t>(value);
} else {
ASSERT(number->IsHeapNumber());
double value = HeapNumber::cast(number)->value();
- if (value >= 0 &&
- value <= std::numeric_limits<size_t>::max()) {
- *result = static_cast<size_t>(value);
- return true;
- } else {
- return false;
- }
+ CHECK(value >= 0 &&
+ value <= std::numeric_limits<size_t>::max());
+ return static_cast<size_t>(value);
}
}
-// Converts a number into size_t.
-inline size_t NumberToSize(Isolate* isolate,
- Object* number) {
- size_t result;
- bool is_valid = TryNumberToSize(isolate, number, &result);
- CHECK(is_valid);
- return result;
-}
-
} } // namespace v8::internal
#endif // V8_V8CONVERSIONS_H_
test(isTestingGet, "Int8", undefined, 0);
test(isTestingGet, "Int8", 8, -128);
test(isTestingGet, "Int8", 15, -1);
- test(isTestingGet, "Int8", 1e12, undefined);
test(isTestingGet, "Uint8", 0, 0);
test(isTestingGet, "Uint8", undefined, 0);
test(isTestingGet, "Uint8", 8, 128);
test(isTestingGet, "Uint8", 15, 255);
- test(isTestingGet, "Uint8", 1e12, undefined);
// Little endian.
test(isTestingGet, "Int16", 0, 256, true);
test(isTestingGet, "Int16", 5, 26213, true);
test(isTestingGet, "Int16", 9, -32127, true);
test(isTestingGet, "Int16", 14, -2, true);
- test(isTestingGet, "Int16", 1e12, undefined, true);
// Big endian.
test(isTestingGet, "Int16", 0, 1);
test(isTestingGet, "Int16", 5, 25958);
test(isTestingGet, "Int16", 9, -32382);
test(isTestingGet, "Int16", 14, -257);
- test(isTestingGet, "Int16", 1e12, undefined);
// Little endian.
test(isTestingGet, "Uint16", 0, 256, true);
test(isTestingGet, "Uint16", 5, 26213, true);
test(isTestingGet, "Uint16", 9, 33409, true);
test(isTestingGet, "Uint16", 14, 65534, true);
- test(isTestingGet, "Uint16", 1e12, undefined, true);
// Big endian.
test(isTestingGet, "Uint16", 0, 1);
test(isTestingGet, "Uint16", 5, 25958);
test(isTestingGet, "Uint16", 9, 33154);
test(isTestingGet, "Uint16", 14, 65279);
- test(isTestingGet, "Uint16", 1e12, undefined);
// Little endian.
test(isTestingGet, "Int32", 0, 50462976, true);
test(isTestingGet, "Int32", 6, -2122291354, true);
test(isTestingGet, "Int32", 9, -58490239, true);
test(isTestingGet, "Int32", 12,-66052, true);
- test(isTestingGet, "Int32", 1e12, undefined, true);
// Big endian.
test(isTestingGet, "Int32", 0, 66051);
test(isTestingGet, "Int32", 6, 1718059137);
test(isTestingGet, "Int32", 9, -2122152964);
test(isTestingGet, "Int32", 12, -50462977);
- test(isTestingGet, "Int32", 1e12, undefined);
// Little endian.
test(isTestingGet, "Uint32", 0, 50462976, true);
test(isTestingGet, "Uint32", 6, 2172675942, true);
test(isTestingGet, "Uint32", 9, 4236477057, true);
test(isTestingGet, "Uint32", 12,4294901244, true);
- test(isTestingGet, "Uint32", 1e12, undefined, true);
// Big endian.
test(isTestingGet, "Uint32", 0, 66051);
test(isTestingGet, "Uint32", 6, 1718059137);
test(isTestingGet, "Uint32", 9, 2172814332);
test(isTestingGet, "Uint32", 12, 4244504319);
- test(isTestingGet, "Uint32", 1e12, undefined);
}
function testFloat(isTestingGet, func, array, start, expected) {
test(isTestingGet, func, 7, expected, true);
createDataView(array, 10, true, start);
test(isTestingGet, func, 10, expected, true);
- test(isTestingGet, func, 1e12, undefined, true);
// Big endian.
createDataView(array, 0, false);
test(isTestingGet, func, 7, expected, false);
createDataView(array, 10, false);
test(isTestingGet, func, 10, expected, false);
- test(isTestingGet, func, 1e12, undefined, false);
}
function runFloatTestCases(isTestingGet, start) {