Skip to content

Commit d82bf08

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 UltraBlame original commit: de7fc134aa463dddcc4f75ff9ef2ba2b9b670a6f
1 parent 9c5106d commit d82bf08

File tree

2 files changed

+9
-57
lines changed

2 files changed

+9
-57
lines changed

js/src/builtin/temporal/Duration.cpp

+9-45
Original file line numberDiff line numberDiff line change
@@ -1154,38 +1154,12 @@ bool js::temporal::ToTemporalDurationRecord(JSContext* cx,
11541154

11551155

11561156

1157-
Wrapped<DurationObject*> js::temporal::ToTemporalDuration(JSContext* cx,
1158-
Handle<Value> item) {
1157+
static bool ToTemporalDuration(JSContext* cx, Handle<Value> item,
1158+
Duration* result) {
11591159

1160-
if (item.isObject()) {
1161-
JSObject* itemObj = &item.toObject();
1162-
if (itemObj->canUnwrapAs<DurationObject>()) {
1163-
return itemObj;
1164-
}
1165-
}
1166-
1167-
1168-
Duration result;
1169-
if (!ToTemporalDurationRecord(cx, item, &result)) {
1170-
return nullptr;
1171-
}
11721160

11731161

1174-
return CreateTemporalDuration(cx, result);
1175-
}
1176-
1177-
1178-
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-
}
1186-
1187-
*result = ToDuration(&obj.unwrap());
1188-
return true;
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-
33713343

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-
}
3344+
Duration result;
3345+
if (!ToTemporalDuration(cx, args.get(0), &result)) {
3346+
return false;
33823347
}
33833348

3384-
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
@@ -264,18 +264,6 @@ DurationObject* CreateTemporalDuration(JSContext* cx, const Duration& duration);
264264

265265

266266

267-
Wrapped<DurationObject*> ToTemporalDuration(JSContext* cx,
268-
JS::Handle<JS::Value> item);
269-
270-
271-
272-
273-
bool ToTemporalDuration(JSContext* cx, JS::Handle<JS::Value> item,
274-
Duration* result);
275-
276-
277-
278-
279267
bool ToTemporalDurationRecord(JSContext* cx,
280268
JS::Handle<JS::Value> temporalDurationLike,
281269
Duration* result);

0 commit comments

Comments
 (0)