From 6df34674355d508cf99c0e56ddd31e710dcf8596 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Bargull?= Date: Mon, 15 Apr 2024 18:27:18 +0000 Subject: [PATCH] Bug 1874684 - Part 5: Directly convert to DurationObject this-value to Duration value. r=dminor This matches other methods and makes the code a bit smaller. Differential Revision: https://phabricator.services.mozilla.com/D198538 --- js/src/builtin/temporal/Duration.cpp | 41 ++++++++++++++---------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/js/src/builtin/temporal/Duration.cpp b/js/src/builtin/temporal/Duration.cpp index 7d3e82e2a2c9..a25252afbbfd 100644 --- a/js/src/builtin/temporal/Duration.cpp +++ b/js/src/builtin/temporal/Duration.cpp @@ -4914,10 +4914,10 @@ static bool Duration_nanoseconds(JSContext* cx, unsigned argc, Value* vp) { * get Temporal.Duration.prototype.sign */ static bool Duration_sign(JSContext* cx, const CallArgs& args) { + auto duration = ToDuration(&args.thisv().toObject().as()); + // Step 3. - auto* duration = &args.thisv().toObject().as(); - int32_t sign = DurationSign(ToDuration(duration)); - args.rval().setInt32(sign); + args.rval().setInt32(DurationSign(duration)); return true; } @@ -4934,12 +4934,10 @@ static bool Duration_sign(JSContext* cx, unsigned argc, Value* vp) { * get Temporal.Duration.prototype.blank */ static bool Duration_blank(JSContext* cx, const CallArgs& args) { - // Step 3. - auto* duration = &args.thisv().toObject().as(); - int32_t sign = DurationSign(ToDuration(duration)); + auto duration = ToDuration(&args.thisv().toObject().as()); - // Steps 4-5. - args.rval().setBoolean(sign == 0); + // Steps 3-5. + args.rval().setBoolean(duration == Duration{}); return true; } @@ -4958,10 +4956,8 @@ static bool Duration_blank(JSContext* cx, unsigned argc, Value* vp) { * ToPartialDuration ( temporalDurationLike ) */ static bool Duration_with(JSContext* cx, const CallArgs& args) { - auto* durationObj = &args.thisv().toObject().as(); - // Absent values default to the corresponding values of |this| object. - auto duration = ToDuration(durationObj); + auto duration = ToDuration(&args.thisv().toObject().as()); // Steps 3-23. Rooted temporalDurationLike( @@ -4996,8 +4992,7 @@ static bool Duration_with(JSContext* cx, unsigned argc, Value* vp) { * Temporal.Duration.prototype.negated ( ) */ static bool Duration_negated(JSContext* cx, const CallArgs& args) { - auto* durationObj = &args.thisv().toObject().as(); - auto duration = ToDuration(durationObj); + auto duration = ToDuration(&args.thisv().toObject().as()); // Step 3. auto* result = CreateTemporalDuration(cx, duration.negate()); @@ -5022,8 +5017,7 @@ static bool Duration_negated(JSContext* cx, unsigned argc, Value* vp) { * Temporal.Duration.prototype.abs ( ) */ static bool Duration_abs(JSContext* cx, const CallArgs& args) { - auto* durationObj = &args.thisv().toObject().as(); - auto duration = ToDuration(durationObj); + auto duration = ToDuration(&args.thisv().toObject().as()); // Step 3. auto* result = CreateTemporalDuration(cx, AbsoluteDuration(duration)); @@ -5082,8 +5076,7 @@ static bool Duration_subtract(JSContext* cx, unsigned argc, Value* vp) { * Temporal.Duration.prototype.round ( roundTo ) */ static bool Duration_round(JSContext* cx, const CallArgs& args) { - auto* durationObj = &args.thisv().toObject().as(); - auto duration = ToDuration(durationObj); + auto duration = ToDuration(&args.thisv().toObject().as()); // Step 18. (Reordered) auto existingLargestUnit = DefaultTemporalLargestUnit(duration); @@ -5785,14 +5778,13 @@ static bool Duration_toString(JSContext* cx, unsigned argc, Value* vp) { } /** - * Temporal.Duration.prototype.toJSON ( ) + * Temporal.Duration.prototype.toJSON ( ) */ static bool Duration_toJSON(JSContext* cx, const CallArgs& args) { - auto* duration = &args.thisv().toObject().as(); + auto duration = ToDuration(&args.thisv().toObject().as()); // Steps 3-4. - JSString* str = - TemporalDurationToString(cx, ToDuration(duration), Precision::Auto()); + JSString* str = TemporalDurationToString(cx, duration, Precision::Auto()); if (!str) { return false; } @@ -5802,7 +5794,7 @@ static bool Duration_toJSON(JSContext* cx, const CallArgs& args) { } /** - * Temporal.Duration.prototype.toJSON ( ) + * Temporal.Duration.prototype.toJSON ( ) */ static bool Duration_toJSON(JSContext* cx, unsigned argc, Value* vp) { // Steps 1-2. @@ -5814,11 +5806,10 @@ static bool Duration_toJSON(JSContext* cx, unsigned argc, Value* vp) { * Temporal.Duration.prototype.toLocaleString ( [ locales [ , options ] ] ) */ static bool Duration_toLocaleString(JSContext* cx, const CallArgs& args) { - auto* duration = &args.thisv().toObject().as(); + auto duration = ToDuration(&args.thisv().toObject().as()); // Steps 3-4. - JSString* str = - TemporalDurationToString(cx, ToDuration(duration), Precision::Auto()); + JSString* str = TemporalDurationToString(cx, duration, Precision::Auto()); if (!str) { return false; } -- 2.11.4.GIT