Skip to content

Commit dfb6a45

Browse files
committed
Bug 1920955 - Part 48: Simplify ToTemporalDuration. r=sfink
<tc39/proposal-temporal#2943> should address the fixme note. Differential Revision: https://phabricator.services.mozilla.com/D223554
1 parent e72de65 commit dfb6a45

File tree

2 files changed

+12
-60
lines changed

2 files changed

+12
-60
lines changed

js/src/builtin/temporal/Duration.cpp

+12-48
Original file line numberDiff line numberDiff line change
@@ -1154,38 +1154,12 @@ bool js::temporal::ToTemporalDurationRecord(JSContext* cx,
11541154
/**
11551155
* ToTemporalDuration ( item )
11561156
*/
1157-
Wrapped<DurationObject*> js::temporal::ToTemporalDuration(JSContext* cx,
1158-
Handle<Value> item) {
1159-
// Step 1.
1160-
if (item.isObject()) {
1161-
JSObject* itemObj = &item.toObject();
1162-
if (itemObj->canUnwrapAs<DurationObject>()) {
1163-
return itemObj;
1164-
}
1165-
}
1166-
1167-
// Step 2.
1168-
Duration result;
1169-
if (!ToTemporalDurationRecord(cx, item, &result)) {
1170-
return nullptr;
1171-
}
1172-
1173-
// Step 3.
1174-
return CreateTemporalDuration(cx, result);
1175-
}
1176-
1177-
/**
1178-
* ToTemporalDuration ( item )
1179-
*/
1180-
bool js::temporal::ToTemporalDuration(JSContext* cx, Handle<Value> item,
1181-
Duration* result) {
1182-
auto obj = ToTemporalDuration(cx, item);
1183-
if (!obj) {
1184-
return false;
1185-
}
1157+
static bool ToTemporalDuration(JSContext* cx, Handle<Value> item,
1158+
Duration* result) {
1159+
// FIXME: spec issue - Merge with ToTemporalDurationRecord.
11861160

1187-
*result = ToDuration(&obj.unwrap());
1188-
return true;
1161+
// Steps 1-3.
1162+
return ToTemporalDurationRecord(cx, item, result);
11891163
}
11901164

11911165
/**
@@ -3366,28 +3340,18 @@ static bool DurationConstructor(JSContext* cx, unsigned argc, Value* vp) {
33663340
static bool Duration_from(JSContext* cx, unsigned argc, Value* vp) {
33673341
CallArgs args = CallArgsFromVp(argc, vp);
33683342

3369-
Handle<Value> item = args.get(0);
3370-
3371-
// Step 1.
3372-
if (item.isObject()) {
3373-
if (auto* duration = item.toObject().maybeUnwrapIf<DurationObject>()) {
3374-
auto* result = CreateTemporalDuration(cx, ToDuration(duration));
3375-
if (!result) {
3376-
return false;
3377-
}
3378-
3379-
args.rval().setObject(*result);
3380-
return true;
3381-
}
3343+
// Steps 1-2.
3344+
Duration result;
3345+
if (!ToTemporalDuration(cx, args.get(0), &result)) {
3346+
return false;
33823347
}
33833348

3384-
// Step 2.
3385-
auto result = ToTemporalDuration(cx, item);
3386-
if (!result) {
3349+
auto* obj = CreateTemporalDuration(cx, result);
3350+
if (!obj) {
33873351
return false;
33883352
}
33893353

3390-
args.rval().setObject(*result);
3354+
args.rval().setObject(*obj);
33913355
return true;
33923356
}
33933357

js/src/builtin/temporal/Duration.h

-12
Original file line numberDiff line numberDiff line change
@@ -261,18 +261,6 @@ NormalizedTimeDuration NormalizedTimeDurationFromEpochNanosecondsDifference(
261261
*/
262262
DurationObject* CreateTemporalDuration(JSContext* cx, const Duration& duration);
263263

264-
/**
265-
* ToTemporalDuration ( item )
266-
*/
267-
Wrapped<DurationObject*> ToTemporalDuration(JSContext* cx,
268-
JS::Handle<JS::Value> item);
269-
270-
/**
271-
* ToTemporalDuration ( item )
272-
*/
273-
bool ToTemporalDuration(JSContext* cx, JS::Handle<JS::Value> item,
274-
Duration* result);
275-
276264
/**
277265
* ToTemporalDurationRecord ( temporalDurationLike )
278266
*/

0 commit comments

Comments
 (0)