mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:47:35 +00:00
LibJS: Update spec numbers / text for the Change Array by Copy proposal
This proposal has been merged into the main ECMA-262 spec. See:
4a32716
Note this includes some editorial changes made when the proposal was
merged into the main spec, but are not in the proposal spec.
This commit is contained in:
parent
f794b08548
commit
e945994877
5 changed files with 133 additions and 128 deletions
|
@ -156,7 +156,60 @@ ThrowCompletionOr<bool> Array::set_length(PropertyDescriptor const& property_des
|
|||
return true;
|
||||
}
|
||||
|
||||
// 1.1.1.2 CompareArrayElements ( x, y, comparefn ), https://tc39.es/proposal-change-array-by-copy/#sec-comparearrayelements
|
||||
// 23.1.3.30.1 SortIndexedProperties ( obj, len, SortCompare, holes ), https://tc39.es/ecma262/#sec-sortindexedproperties
|
||||
ThrowCompletionOr<MarkedVector<Value>> sort_indexed_properties(VM& vm, Object const& object, size_t length, Function<ThrowCompletionOr<double>(Value, Value)> const& sort_compare, Holes holes)
|
||||
{
|
||||
// 1. Let items be a new empty List.
|
||||
auto items = MarkedVector<Value> { vm.heap() };
|
||||
|
||||
// 2. Let k be 0.
|
||||
// 3. Repeat, while k < len,
|
||||
for (size_t k = 0; k < length; ++k) {
|
||||
// a. Let Pk be ! ToString(𝔽(k)).
|
||||
auto property_key = PropertyKey { k };
|
||||
|
||||
bool k_read;
|
||||
|
||||
// b. If holes is skip-holes, then
|
||||
if (holes == Holes::SkipHoles) {
|
||||
// i. Let kRead be ? HasProperty(obj, Pk).
|
||||
k_read = TRY(object.has_property(property_key));
|
||||
}
|
||||
// c. Else,
|
||||
else {
|
||||
// i. Assert: holes is read-through-holes.
|
||||
VERIFY(holes == Holes::ReadThroughHoles);
|
||||
|
||||
// ii. Let kRead be true.
|
||||
k_read = true;
|
||||
}
|
||||
|
||||
// d. If kRead is true, then
|
||||
if (k_read) {
|
||||
// i. Let kValue be ? Get(obj, Pk).
|
||||
auto k_value = TRY(object.get(property_key));
|
||||
|
||||
// ii. Append kValue to items.
|
||||
items.append(k_value);
|
||||
}
|
||||
|
||||
// e. Set k to k + 1.
|
||||
}
|
||||
|
||||
// 4. Sort items using an implementation-defined sequence of calls to SortCompare. If any such call returns an abrupt completion, stop before performing any further calls to SortCompare or steps in this algorithm and return that Completion Record.
|
||||
|
||||
// Perform sorting by merge sort. This isn't as efficient compared to quick sort, but
|
||||
// quicksort can't be used in all cases because the spec requires Array.prototype.sort()
|
||||
// to be stable. FIXME: when initially scanning through the array, maintain a flag
|
||||
// for if an unstable sort would be indistinguishable from a stable sort (such as just
|
||||
// just strings or numbers), and in that case use quick sort instead for better performance.
|
||||
TRY(array_merge_sort(vm, sort_compare, items));
|
||||
|
||||
// 5. Return items.
|
||||
return items;
|
||||
}
|
||||
|
||||
// 23.1.3.30.2 CompareArrayElements ( x, y, comparefn ), https://tc39.es/ecma262/#sec-comparearrayelements
|
||||
ThrowCompletionOr<double> compare_array_elements(VM& vm, Value x, Value y, FunctionObject* comparefn)
|
||||
{
|
||||
// 1. If x and y are both undefined, return +0𝔽.
|
||||
|
@ -209,56 +262,6 @@ ThrowCompletionOr<double> compare_array_elements(VM& vm, Value x, Value y, Funct
|
|||
return 0;
|
||||
}
|
||||
|
||||
// 1.1.1.3 SortIndexedProperties ( obj, len, SortCompare, skipHoles ), https://tc39.es/proposal-change-array-by-copy/#sec-sortindexedproperties
|
||||
ThrowCompletionOr<MarkedVector<Value>> sort_indexed_properties(VM& vm, Object const& object, size_t length, Function<ThrowCompletionOr<double>(Value, Value)> const& sort_compare, bool skip_holes)
|
||||
{
|
||||
// 1. Let items be a new empty List.
|
||||
auto items = MarkedVector<Value> { vm.heap() };
|
||||
|
||||
// 2. Let k be 0.
|
||||
// 3. Repeat, while k < len,
|
||||
for (size_t k = 0; k < length; ++k) {
|
||||
// a. Let Pk be ! ToString(𝔽(k)).
|
||||
auto property_key = PropertyKey { k };
|
||||
|
||||
bool k_read;
|
||||
|
||||
// b. If skipHoles is true, then
|
||||
if (skip_holes) {
|
||||
// i. Let kRead be ? HasProperty(obj, Pk).
|
||||
k_read = TRY(object.has_property(property_key));
|
||||
}
|
||||
// c. Else,
|
||||
else {
|
||||
// i. Let kRead be true.
|
||||
k_read = true;
|
||||
}
|
||||
|
||||
// d. If kRead is true, then
|
||||
if (k_read) {
|
||||
// i. Let kValue be ? Get(obj, Pk).
|
||||
auto k_value = TRY(object.get(property_key));
|
||||
|
||||
// ii. Append kValue to items.
|
||||
items.append(k_value);
|
||||
}
|
||||
|
||||
// e. Set k to k + 1.
|
||||
}
|
||||
|
||||
// 4. Sort items using an implementation-defined sequence of calls to SortCompare. If any such call returns an abrupt completion, stop before performing any further calls to SortCompare or steps in this algorithm and return that Completion Record.
|
||||
|
||||
// Perform sorting by merge sort. This isn't as efficient compared to quick sort, but
|
||||
// quicksort can't be used in all cases because the spec requires Array.prototype.sort()
|
||||
// to be stable. FIXME: when initially scanning through the array, maintain a flag
|
||||
// for if an unstable sort would be indistinguishable from a stable sort (such as just
|
||||
// just strings or numbers), and in that case use quick sort instead for better performance.
|
||||
TRY(array_merge_sort(vm, sort_compare, items));
|
||||
|
||||
// 5. Return items.
|
||||
return items;
|
||||
}
|
||||
|
||||
// NON-STANDARD: Used to return the value of the ephemeral length property
|
||||
ThrowCompletionOr<Optional<PropertyDescriptor>> Array::internal_get_own_property(PropertyKey const& property_key) const
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue