Bug 1383436 - Part 3: Add ToIntegerPositiveZero as a new variant of ToInteger. r=jandem

ToIntegerPositiveZero has almost identical semantics as ToInteger with the sole
exception that negative zero is converted to positive zero.

The next patches will update callers to use this function instead of ToInteger
where possible and improve the inlining of this function.

Differential Revision: https://phabricator.services.mozilla.com/D37286

--HG--
extra : moz-landing-system : lando
This commit is contained in:
André Bargull 2019-10-22 09:34:54 +00:00
parent 7f0c09f323
commit 63b3c9f1ed

View File

@ -163,6 +163,18 @@ static bool intrinsic_ToInteger(JSContext* cx, unsigned argc, Value* vp) {
return true;
}
static bool intrinsic_ToIntegerPositiveZero(JSContext* cx, unsigned argc,
Value* vp) {
CallArgs args = CallArgsFromVp(argc, vp);
double result;
if (!ToInteger(cx, args[0], &result)) {
return false;
}
// Add zero to convert -0 to +0.
args.rval().setNumber(result + 0.0);
return true;
}
static bool intrinsic_ToString(JSContext* cx, unsigned argc, Value* vp) {
CallArgs args = CallArgsFromVp(argc, vp);
JSString* str = ToString<CanGC>(cx, args[0]);
@ -2134,6 +2146,7 @@ static const JSFunctionSpec intrinsic_functions[] = {
intrinsic_IsCrossRealmArrayConstructor, 1, 0,
IntrinsicIsCrossRealmArrayConstructor),
JS_INLINABLE_FN("ToInteger", intrinsic_ToInteger, 1, 0, IntrinsicToInteger),
JS_FN("ToIntegerPositiveZero", intrinsic_ToIntegerPositiveZero, 1, 0),
JS_INLINABLE_FN("ToString", intrinsic_ToString, 1, 0, IntrinsicToString),
JS_FN("ToSource", intrinsic_ToSource, 1, 0),
JS_FN("ToPropertyKey", intrinsic_ToPropertyKey, 1, 0),