Skip to content

Commit 6450c8d

Browse files
committed
Bug 1840374 - Part 35: Add SnapshotOwnProperties. r=spidermonkey-reviewers,dminor
Per <tc39/proposal-temporal#2586>. Differential Revision: https://phabricator.services.mozilla.com/D182055 UltraBlame original commit: 1a2a324c251824b802d2f635171b5223022dc671
1 parent 457a91a commit 6450c8d

9 files changed

+72
-55
lines changed

js/src/builtin/temporal/Calendar.cpp

+3-15
Original file line numberDiff line numberDiff line change
@@ -4379,37 +4379,25 @@ static bool Calendar_mergeFields(JSContext* cx, const CallArgs& args) {
43794379
return false;
43804380
}
43814381

4382-
4383-
Rooted<PlainObject*> fieldsCopy(cx, NewPlainObjectWithProto(cx, nullptr));
4382+
Rooted<PlainObject*> fieldsCopy(
4383+
cx, SnapshotOwnPropertiesIgnoreUndefined(cx, fields));
43844384
if (!fieldsCopy) {
43854385
return false;
43864386
}
43874387

43884388

4389-
if (!CopyDataPropertiesIgnoreUndefined(cx, fieldsCopy, fields)) {
4390-
return false;
4391-
}
4392-
4393-
43944389
Rooted<JSObject*> additionalFields(cx, JS::ToObject(cx, args.get(1)));
43954390
if (!additionalFields) {
43964391
return false;
43974392
}
43984393

4399-
44004394
Rooted<PlainObject*> additionalFieldsCopy(
4401-
cx, NewPlainObjectWithProto(cx, nullptr));
4395+
cx, SnapshotOwnPropertiesIgnoreUndefined(cx, additionalFields));
44024396
if (!additionalFieldsCopy) {
44034397
return false;
44044398
}
44054399

44064400

4407-
if (!CopyDataPropertiesIgnoreUndefined(cx, additionalFieldsCopy,
4408-
additionalFields)) {
4409-
return false;
4410-
}
4411-
4412-
44134401

44144402

44154403

js/src/builtin/temporal/Instant.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,8 @@ static bool DifferenceTemporalInstant(JSContext* cx,
10431043
}
10441044

10451045

1046-
Rooted<PlainObject*> resolvedOptions(cx, CopyOptions(cx, options));
1046+
Rooted<PlainObject*> resolvedOptions(cx,
1047+
SnapshotOwnProperties(cx, options));
10471048
if (!resolvedOptions) {
10481049
return false;
10491050
}

js/src/builtin/temporal/PlainDate.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,8 @@ static bool DifferenceTemporalPlainDate(JSContext* cx,
11981198
}
11991199

12001200

1201-
Rooted<PlainObject*> resolvedOptions(cx, CopyOptions(cx, options));
1201+
Rooted<PlainObject*> resolvedOptions(cx,
1202+
SnapshotOwnProperties(cx, options));
12021203
if (!resolvedOptions) {
12031204
return false;
12041205
}

js/src/builtin/temporal/PlainDateTime.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,8 @@ static bool DifferenceISODateTime(JSContext* cx, const PlainDateTime& one,
871871

872872

873873

874-
Rooted<PlainObject*> untilOptions(cx, CopyOptions(cx, maybeOptions));
874+
Rooted<PlainObject*> untilOptions(cx,
875+
SnapshotOwnProperties(cx, maybeOptions));
875876
if (!untilOptions) {
876877
return false;
877878
}
@@ -1014,7 +1015,8 @@ static bool DifferenceTemporalPlainDateTime(JSContext* cx,
10141015
}
10151016

10161017

1017-
Rooted<PlainObject*> resolvedOptions(cx, CopyOptions(cx, options));
1018+
Rooted<PlainObject*> resolvedOptions(cx,
1019+
SnapshotOwnProperties(cx, options));
10181020
if (!resolvedOptions) {
10191021
return false;
10201022
}

js/src/builtin/temporal/PlainTime.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1728,7 +1728,8 @@ static bool DifferenceTemporalPlainTime(JSContext* cx,
17281728
}
17291729

17301730

1731-
Rooted<PlainObject*> resolvedOptions(cx, CopyOptions(cx, options));
1731+
Rooted<PlainObject*> resolvedOptions(cx,
1732+
SnapshotOwnProperties(cx, options));
17321733
if (!resolvedOptions) {
17331734
return false;
17341735
}

js/src/builtin/temporal/PlainYearMonth.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ static bool DifferenceTemporalPlainYearMonth(JSContext* cx,
427427
}
428428

429429

430-
resolvedOptions = CopyOptions(cx, options);
430+
resolvedOptions = SnapshotOwnProperties(cx, options);
431431
if (!resolvedOptions) {
432432
return false;
433433
}
@@ -612,7 +612,7 @@ static bool AddDurationToOrSubtractDurationFromPlainYearMonth(
612612
}
613613

614614

615-
Rooted<PlainObject*> fieldsCopy(cx, CopyOptions(cx, fields));
615+
Rooted<PlainObject*> fieldsCopy(cx, SnapshotOwnProperties(cx, fields));
616616
if (!fieldsCopy) {
617617
return false;
618618
}
@@ -717,7 +717,7 @@ static bool AddDurationToOrSubtractDurationFromPlainYearMonth(
717717

718718

719719

720-
Rooted<PlainObject*> optionsCopy(cx, CopyOptions(cx, options));
720+
Rooted<PlainObject*> optionsCopy(cx, SnapshotOwnProperties(cx, options));
721721
if (!optionsCopy) {
722722
return false;
723723
}

js/src/builtin/temporal/Temporal.cpp

+48-25
Original file line numberDiff line numberDiff line change
@@ -1678,31 +1678,11 @@ bool js::temporal::GetMethodForCall(JSContext* cx, Handle<JSObject*> object,
16781678

16791679

16801680

1681-
PlainObject* js::temporal::CopyOptions(JSContext* cx,
1682-
JS::Handle<JSObject*> options) {
1683-
1684-
Rooted<PlainObject*> optionsCopy(cx, NewPlainObjectWithProto(cx, nullptr));
1685-
if (!optionsCopy) {
1686-
return nullptr;
1687-
}
1688-
1689-
1690-
if (!CopyDataProperties(cx, optionsCopy, options)) {
1691-
return nullptr;
1692-
}
1693-
1694-
1695-
return optionsCopy;
1696-
}
1697-
1698-
1699-
1700-
17011681

17021682

17031683
bool js::temporal::CopyDataProperties(JSContext* cx,
1704-
JS::Handle<PlainObject*> target,
1705-
JS::Handle<JSObject*> source) {
1684+
Handle<PlainObject*> target,
1685+
Handle<JSObject*> source) {
17061686

17071687
if (source->is<NativeObject>()) {
17081688
bool optimized = false;
@@ -1765,9 +1745,9 @@ bool js::temporal::CopyDataProperties(JSContext* cx,
17651745

17661746

17671747

1768-
bool js::temporal::CopyDataPropertiesIgnoreUndefined(
1769-
JSContext* cx, JS::Handle<PlainObject*> target,
1770-
JS::Handle<JSObject*> source) {
1748+
static bool CopyDataPropertiesIgnoreUndefined(JSContext* cx,
1749+
Handle<PlainObject*> target,
1750+
Handle<JSObject*> source) {
17711751

17721752

17731753

@@ -1818,6 +1798,49 @@ bool js::temporal::CopyDataPropertiesIgnoreUndefined(
18181798

18191799

18201800

1801+
PlainObject* js::temporal::SnapshotOwnProperties(JSContext* cx,
1802+
Handle<JSObject*> source) {
1803+
1804+
Rooted<PlainObject*> copy(cx, NewPlainObjectWithProto(cx, nullptr));
1805+
if (!copy) {
1806+
return nullptr;
1807+
}
1808+
1809+
1810+
if (!CopyDataProperties(cx, copy, source)) {
1811+
return nullptr;
1812+
}
1813+
1814+
1815+
return copy;
1816+
}
1817+
1818+
1819+
1820+
1821+
1822+
1823+
1824+
PlainObject* js::temporal::SnapshotOwnPropertiesIgnoreUndefined(
1825+
JSContext* cx, Handle<JSObject*> source) {
1826+
1827+
Rooted<PlainObject*> copy(cx, NewPlainObjectWithProto(cx, nullptr));
1828+
if (!copy) {
1829+
return nullptr;
1830+
}
1831+
1832+
1833+
if (!CopyDataPropertiesIgnoreUndefined(cx, copy, source)) {
1834+
return nullptr;
1835+
}
1836+
1837+
1838+
return copy;
1839+
}
1840+
1841+
1842+
1843+
18211844

18221845
bool js::temporal::GetDifferenceSettings(
18231846
JSContext* cx, TemporalDifference operation, Handle<JSObject*> options,

js/src/builtin/temporal/Temporal.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -357,20 +357,21 @@ bool GetMethodForCall(JSContext* cx, JS::Handle<JSObject*> object,
357357

358358

359359

360-
PlainObject* CopyOptions(JSContext* cx, JS::Handle<JSObject*> options);
360+
361+
PlainObject* SnapshotOwnProperties(JSContext* cx, JS::Handle<JSObject*> source);
361362

362363

363364

364365

365-
bool CopyDataProperties(JSContext* cx, JS::Handle<PlainObject*> target,
366-
JS::Handle<JSObject*> source);
367366

367+
PlainObject* SnapshotOwnPropertiesIgnoreUndefined(JSContext* cx,
368+
JS::Handle<JSObject*> source);
368369

369370

370371

371-
bool CopyDataPropertiesIgnoreUndefined(JSContext* cx,
372-
JS::Handle<PlainObject*> target,
373-
JS::Handle<JSObject*> source);
372+
373+
bool CopyDataProperties(JSContext* cx, JS::Handle<PlainObject*> target,
374+
JS::Handle<JSObject*> source);
374375

375376
enum class TemporalDifference { Since, Until };
376377

js/src/builtin/temporal/ZonedDateTime.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ static bool DifferenceTemporalZonedDateTime(JSContext* cx,
13401340
}
13411341

13421342

1343-
resolvedOptions = CopyOptions(cx, options);
1343+
resolvedOptions = SnapshotOwnProperties(cx, options);
13441344
if (!resolvedOptions) {
13451345
return false;
13461346
}

0 commit comments

Comments
 (0)