mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-28 20:55:39 +00:00
Bug 1317383 - Part 1: Move NonStandardToIndex to SIMD.cpp. r=evilpie
--HG-- extra : rebase_source : b96e0480c2210b6c07aaeb8d5d8354debc92a43b
This commit is contained in:
parent
40a6c939ee
commit
8f6bdbd19c
@ -156,6 +156,72 @@ ErrorBadIndex(JSContext* cx)
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Non-standard: convert and range check an index value for SIMD operations.
|
||||
*
|
||||
* 1. numericIndex = ToNumber(argument) (may throw TypeError)
|
||||
* 2. intIndex = ToInteger(numericIndex)
|
||||
* 3. if intIndex != numericIndex throw RangeError
|
||||
*
|
||||
* This function additionally bounds the range to the non-negative contiguous
|
||||
* integers:
|
||||
*
|
||||
* 4. if intIndex < 0 or intIndex > 2^53 throw RangeError
|
||||
*
|
||||
* Return true and set |*index| to the integer value if |argument| is a valid
|
||||
* array index argument. Otherwise report an TypeError or RangeError and return
|
||||
* false.
|
||||
*
|
||||
* The returned index will always be in the range 0 <= *index <= 2^53.
|
||||
*/
|
||||
static bool
|
||||
NonStandardToIndex(JSContext* cx, HandleValue v, uint64_t* index)
|
||||
{
|
||||
// Fast common case.
|
||||
if (v.isInt32()) {
|
||||
int32_t i = v.toInt32();
|
||||
if (i >= 0) {
|
||||
*index = i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Slow case. Use ToNumber() to coerce. This may throw a TypeError.
|
||||
double d;
|
||||
if (!ToNumber(cx, v, &d))
|
||||
return false;
|
||||
|
||||
// Check that |d| is an integer in the valid range.
|
||||
//
|
||||
// Not all floating point integers fit in the range of a uint64_t, so we
|
||||
// need a rough range check before the real range check in our caller. We
|
||||
// could limit indexes to UINT64_MAX, but this would mean that our callers
|
||||
// have to be very careful about integer overflow. The contiguous integer
|
||||
// floating point numbers end at 2^53, so make that our upper limit. If we
|
||||
// ever support arrays with more than 2^53 elements, this will need to
|
||||
// change.
|
||||
//
|
||||
// Reject infinities, NaNs, and numbers outside the contiguous integer range
|
||||
// with a RangeError.
|
||||
|
||||
// Write relation so NaNs throw a RangeError.
|
||||
if (!(0 <= d && d <= (uint64_t(1) << 53))) {
|
||||
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_BAD_INDEX);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check that d is an integer, throw a RangeError if not.
|
||||
// Note that this conversion could invoke undefined behaviour without the
|
||||
// range check above.
|
||||
uint64_t i(d);
|
||||
if (d != double(i)) {
|
||||
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_BAD_INDEX);
|
||||
return false;
|
||||
}
|
||||
|
||||
*index = i;
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static SimdTypeDescr*
|
||||
GetTypeDescr(JSContext* cx)
|
||||
|
@ -1796,55 +1796,6 @@ js::ToUint16Slow(JSContext* cx, const HandleValue v, uint16_t* out)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
js::NonStandardToIndex(JSContext* cx, HandleValue v, uint64_t* index)
|
||||
{
|
||||
// Fast common case.
|
||||
if (v.isInt32()) {
|
||||
int32_t i = v.toInt32();
|
||||
if (i >= 0) {
|
||||
*index = i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Slow case. Use ToNumber() to coerce. This may throw a TypeError.
|
||||
double d;
|
||||
if (!ToNumber(cx, v, &d))
|
||||
return false;
|
||||
|
||||
// Check that |d| is an integer in the valid range.
|
||||
//
|
||||
// Not all floating point integers fit in the range of a uint64_t, so we
|
||||
// need a rough range check before the real range check in our caller. We
|
||||
// could limit indexes to UINT64_MAX, but this would mean that our callers
|
||||
// have to be very careful about integer overflow. The contiguous integer
|
||||
// floating point numbers end at 2^53, so make that our upper limit. If we
|
||||
// ever support arrays with more than 2^53 elements, this will need to
|
||||
// change.
|
||||
//
|
||||
// Reject infinities, NaNs, and numbers outside the contiguous integer range
|
||||
// with a RangeError.
|
||||
|
||||
// Write relation so NaNs throw a RangeError.
|
||||
if (!(0 <= d && d <= (uint64_t(1) << 53))) {
|
||||
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_BAD_INDEX);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check that d is an integer, throw a RangeError if not.
|
||||
// Note that this conversion could invoke undefined behaviour without the
|
||||
// range check above.
|
||||
uint64_t i(d);
|
||||
if (d != double(i)) {
|
||||
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_BAD_INDEX);
|
||||
return false;
|
||||
}
|
||||
|
||||
*index = i;
|
||||
return true;
|
||||
}
|
||||
|
||||
// ES2017 draft 7.1.17 ToIndex
|
||||
bool
|
||||
js::ToIndex(JSContext* cx, JS::HandleValue v, uint64_t* index)
|
||||
|
@ -276,26 +276,6 @@ ToInteger(JSContext* cx, HandleValue v, double* dp)
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Non-standard convert and range check an index value as for SIMD, and Atomics
|
||||
* operations, eg ES7 24.2.1.1, DataView's GetViewValue():
|
||||
*
|
||||
* 1. numericIndex = ToNumber(argument) (may throw TypeError)
|
||||
* 2. intIndex = ToInteger(numericIndex)
|
||||
* 3. if intIndex != numericIndex throw RangeError
|
||||
*
|
||||
* This function additionally bounds the range to the non-negative contiguous
|
||||
* integers:
|
||||
*
|
||||
* 4. if intIndex < 0 or intIndex > 2^53 throw RangeError
|
||||
*
|
||||
* Return true and set |*index| to the integer value if |argument| is a valid
|
||||
* array index argument. Otherwise report an TypeError or RangeError and return
|
||||
* false.
|
||||
*
|
||||
* The returned index will always be in the range 0 <= *index <= 2^53.
|
||||
*/
|
||||
MOZ_MUST_USE bool NonStandardToIndex(JSContext* cx, JS::HandleValue v, uint64_t* index);
|
||||
|
||||
/* ES2017 draft 7.1.17 ToIndex
|
||||
*
|
||||
* Return true and set |*index| to the integer value if |v| is a valid
|
||||
|
Loading…
Reference in New Issue
Block a user