mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:17:44 +00:00
LibJS: Move MergeLists into non-Temporal ECMA-262 amendments
This is an editorial change in the Temporal spec.
See: 4ce3db1
This commit is contained in:
parent
0c3d2b656e
commit
7a8e6cf6c6
5 changed files with 31 additions and 29 deletions
|
@ -136,6 +136,35 @@ ThrowCompletionOr<T*> ordinary_create_from_constructor(GlobalObject& global_obje
|
||||||
return global_object.heap().allocate<T>(global_object, forward<Args>(args)..., *prototype);
|
return global_object.heap().allocate<T>(global_object, forward<Args>(args)..., *prototype);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 14.1 MergeLists ( a, b ), https://tc39.es/proposal-temporal/#sec-temporal-mergelists
|
||||||
|
template<typename T>
|
||||||
|
Vector<T> merge_lists(Vector<T> const& a, Vector<T> const& b)
|
||||||
|
{
|
||||||
|
// 1. Let merged be a new empty List.
|
||||||
|
Vector<T> merged;
|
||||||
|
|
||||||
|
// 2. For each element element of a, do
|
||||||
|
for (auto const& element : a) {
|
||||||
|
// a. If merged does not contain element, then
|
||||||
|
if (!merged.contains_slow(element)) {
|
||||||
|
// i. Append element to merged.
|
||||||
|
merged.append(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. For each element element of b, do
|
||||||
|
for (auto const& element : b) {
|
||||||
|
// a. If merged does not contain element, then
|
||||||
|
if (!merged.contains_slow(element)) {
|
||||||
|
// i. Append element to merged.
|
||||||
|
merged.append(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Return merged.
|
||||||
|
return merged;
|
||||||
|
}
|
||||||
|
|
||||||
// x modulo y, https://tc39.es/ecma262/#eqn-modulo
|
// x modulo y, https://tc39.es/ecma262/#eqn-modulo
|
||||||
template<typename T, typename U>
|
template<typename T, typename U>
|
||||||
auto modulo(T x, U y) requires(IsArithmetic<T>, IsArithmetic<U>)
|
auto modulo(T x, U y) requires(IsArithmetic<T>, IsArithmetic<U>)
|
||||||
|
|
|
@ -997,32 +997,4 @@ ThrowCompletionOr<Object*> default_merge_calendar_fields(GlobalObject& global_ob
|
||||||
return merged;
|
return merged;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 12.2.41 MergeLists ( a, b ), https://tc39.es/proposal-temporal/#sec-temporal-mergelists
|
|
||||||
Vector<String> merge_lists(Vector<String> const& a, Vector<String> const& b)
|
|
||||||
{
|
|
||||||
// 1. Let merged be a new empty List.
|
|
||||||
Vector<String> merged;
|
|
||||||
|
|
||||||
// 2. For each element element of a, do
|
|
||||||
for (auto const& element : a) {
|
|
||||||
// a. If merged does not contain element, then
|
|
||||||
if (!merged.contains_slow(element)) {
|
|
||||||
// i. Append element to merged.
|
|
||||||
merged.append(element);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. For each element element of b, do
|
|
||||||
for (auto const& element : b) {
|
|
||||||
// a. If merged does not contain element, then
|
|
||||||
if (!merged.contains_slow(element)) {
|
|
||||||
// i. Append element to merged.
|
|
||||||
merged.append(element);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. Return merged.
|
|
||||||
return merged;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,5 @@ u8 iso_month(Object& temporal_object);
|
||||||
String iso_month_code(Object& temporal_object);
|
String iso_month_code(Object& temporal_object);
|
||||||
u8 iso_day(Object& temporal_object);
|
u8 iso_day(Object& temporal_object);
|
||||||
ThrowCompletionOr<Object*> default_merge_calendar_fields(GlobalObject&, Object const& fields, Object const& additional_fields);
|
ThrowCompletionOr<Object*> default_merge_calendar_fields(GlobalObject&, Object const& fields, Object const& additional_fields);
|
||||||
Vector<String> merge_lists(Vector<String> const& a, Vector<String> const& b);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/TypeCasts.h>
|
#include <AK/TypeCasts.h>
|
||||||
|
#include <LibJS/Runtime/AbstractOperations.h>
|
||||||
#include <LibJS/Runtime/GlobalObject.h>
|
#include <LibJS/Runtime/GlobalObject.h>
|
||||||
#include <LibJS/Runtime/Temporal/AbstractOperations.h>
|
#include <LibJS/Runtime/Temporal/AbstractOperations.h>
|
||||||
#include <LibJS/Runtime/Temporal/Calendar.h>
|
#include <LibJS/Runtime/Temporal/Calendar.h>
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/TypeCasts.h>
|
#include <AK/TypeCasts.h>
|
||||||
|
#include <LibJS/Runtime/AbstractOperations.h>
|
||||||
#include <LibJS/Runtime/Array.h>
|
#include <LibJS/Runtime/Array.h>
|
||||||
#include <LibJS/Runtime/GlobalObject.h>
|
#include <LibJS/Runtime/GlobalObject.h>
|
||||||
#include <LibJS/Runtime/Temporal/AbstractOperations.h>
|
#include <LibJS/Runtime/Temporal/AbstractOperations.h>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue