mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 13:47:35 +00:00
LibJS: Remove implicit wrapping/unwrapping of completion records
This is an editorial change in the ECMA-262 spec, with similar changes in some proposals. See: -7575f74
-df899eb
-9eb5a12
-c81f527
This commit is contained in:
parent
15f32379bb
commit
9f3f3b0864
88 changed files with 792 additions and 735 deletions
|
@ -154,10 +154,10 @@ bool is_well_formed_unit_identifier(StringView unit_identifier)
|
|||
return true;
|
||||
}
|
||||
|
||||
// 2. Let i be ! StringIndexOf(unitIdentifier, "-per-", 0).
|
||||
// 2. Let i be StringIndexOf(unitIdentifier, "-per-", 0).
|
||||
auto indices = unit_identifier.find_all("-per-"sv);
|
||||
|
||||
// 3. If i is -1 or ! StringIndexOf(unitIdentifier, "-per-", i + 1) is not -1, then
|
||||
// 3. If i is -1 or StringIndexOf(unitIdentifier, "-per-", i + 1) is not -1, then
|
||||
if (indices.size() != 1) {
|
||||
// a. Return false.
|
||||
return false;
|
||||
|
@ -199,7 +199,7 @@ ThrowCompletionOr<Vector<String>> canonicalize_locale_list(GlobalObject& global_
|
|||
Object* object = nullptr;
|
||||
// 3. If Type(locales) is String or Type(locales) is Object and locales has an [[InitializedLocale]] internal slot, then
|
||||
if (locales.is_string() || (locales.is_object() && is<Locale>(locales.as_object()))) {
|
||||
// a. Let O be ! CreateArrayFromList(« locales »).
|
||||
// a. Let O be CreateArrayFromList(« locales »).
|
||||
object = Array::create_from(global_object, { locales });
|
||||
}
|
||||
// 4. Else,
|
||||
|
@ -586,7 +586,7 @@ ThrowCompletionOr<Array*> supported_locales(GlobalObject& global_object, Vector<
|
|||
supported_locales = lookup_supported_locales(requested_locales);
|
||||
}
|
||||
|
||||
// 5. Return ! CreateArrayFromList(supportedLocales).
|
||||
// 5. Return CreateArrayFromList(supportedLocales).
|
||||
return Array::create_from<String>(global_object, supported_locales, [&vm](auto& locale) { return js_string(vm, locale); });
|
||||
}
|
||||
|
||||
|
@ -595,7 +595,7 @@ ThrowCompletionOr<Object*> coerce_options_to_object(GlobalObject& global_object,
|
|||
{
|
||||
// 1. If options is undefined, then
|
||||
if (options.is_undefined()) {
|
||||
// a. Return ! OrdinaryObjectCreate(null).
|
||||
// a. Return OrdinaryObjectCreate(null).
|
||||
return Object::create(global_object, nullptr);
|
||||
}
|
||||
|
||||
|
@ -626,7 +626,7 @@ ThrowCompletionOr<Value> get_option(GlobalObject& global_object, Object const& o
|
|||
|
||||
// 5. If type is "boolean", then
|
||||
if (type == Value::Type::Boolean) {
|
||||
// a. Set value to ! ToBoolean(value).
|
||||
// a. Set value to ToBoolean(value).
|
||||
value = Value(value.to_boolean());
|
||||
}
|
||||
// 6. If type is "string", then
|
||||
|
@ -685,7 +685,7 @@ Vector<PatternPartition> partition_pattern(StringView pattern)
|
|||
// 1. Let result be a new empty List.
|
||||
Vector<PatternPartition> result;
|
||||
|
||||
// 2. Let beginIndex be ! StringIndexOf(pattern, "{", 0).
|
||||
// 2. Let beginIndex be StringIndexOf(pattern, "{", 0).
|
||||
auto begin_index = pattern.find('{', 0);
|
||||
|
||||
// 3. Let endIndex be 0.
|
||||
|
@ -697,7 +697,7 @@ Vector<PatternPartition> partition_pattern(StringView pattern)
|
|||
// 5. Let length be the number of code units in pattern.
|
||||
// 6. Repeat, while beginIndex is an integer index into pattern,
|
||||
while (begin_index.has_value()) {
|
||||
// a. Set endIndex to ! StringIndexOf(pattern, "}", beginIndex).
|
||||
// a. Set endIndex to StringIndexOf(pattern, "}", beginIndex).
|
||||
end_index = pattern.find('}', *begin_index).value();
|
||||
|
||||
// b. Assert: endIndex is greater than beginIndex.
|
||||
|
@ -721,7 +721,7 @@ Vector<PatternPartition> partition_pattern(StringView pattern)
|
|||
// f. Set nextIndex to endIndex + 1.
|
||||
next_index = end_index + 1;
|
||||
|
||||
// g. Set beginIndex to ! StringIndexOf(pattern, "{", nextIndex).
|
||||
// g. Set beginIndex to StringIndexOf(pattern, "{", nextIndex).
|
||||
begin_index = pattern.find('{', next_index);
|
||||
}
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ static ThrowCompletionOr<Collator*> initialize_collator(GlobalObject& global_obj
|
|||
|
||||
// 24. If relevantExtensionKeys contains "kn", then
|
||||
if (relevant_extension_keys.span().contains_slow("kn"sv) && result.kn.has_value()) {
|
||||
// a. Set collator.[[Numeric]] to ! SameValue(r.[[kn]], "true").
|
||||
// a. Set collator.[[Numeric]] to SameValue(r.[[kn]], "true").
|
||||
collator.set_numeric(same_value(js_string(vm, result.kn.release_value()), js_string(vm, "true"sv)));
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ JS_DEFINE_NATIVE_FUNCTION(CollatorPrototype::resolved_options)
|
|||
// 2. Perform ? RequireInternalSlot(collator, [[InitializedCollator]]).
|
||||
auto* collator = TRY(typed_this_object(global_object));
|
||||
|
||||
// 3. Let options be ! OrdinaryObjectCreate(%Object.prototype%).
|
||||
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto* options = Object::create(global_object, global_object.object_prototype());
|
||||
|
||||
// 4. For each row of Table 3, except the header row, in table order, do
|
||||
|
|
|
@ -72,7 +72,7 @@ ThrowCompletionOr<Object*> to_date_time_options(GlobalObject& global_object, Val
|
|||
if (!options_value.is_undefined())
|
||||
options = TRY(options_value.to_object(global_object));
|
||||
|
||||
// 2. Let options be ! OrdinaryObjectCreate(options).
|
||||
// 2. Let options be OrdinaryObjectCreate(options).
|
||||
options = Object::create(global_object, options);
|
||||
|
||||
// 3. Let needDefaults be true.
|
||||
|
@ -524,7 +524,7 @@ ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(GlobalObjec
|
|||
return static_cast<NumberFormat*>(number_format);
|
||||
};
|
||||
|
||||
// 4. Let nfOptions be ! OrdinaryObjectCreate(null).
|
||||
// 4. Let nfOptions be OrdinaryObjectCreate(null).
|
||||
auto* number_format_options = Object::create(global_object, nullptr);
|
||||
|
||||
// 5. Perform ! CreateDataPropertyOrThrow(nfOptions, "useGrouping", false).
|
||||
|
@ -533,7 +533,7 @@ ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(GlobalObjec
|
|||
// 6. Let nf be ? Construct(%NumberFormat%, « locale, nfOptions »).
|
||||
auto* number_format = TRY(construct_number_format(number_format_options));
|
||||
|
||||
// 7. Let nf2Options be ! OrdinaryObjectCreate(null).
|
||||
// 7. Let nf2Options be OrdinaryObjectCreate(null).
|
||||
auto* number_format_options2 = Object::create(global_object, nullptr);
|
||||
|
||||
// 8. Perform ! CreateDataPropertyOrThrow(nf2Options, "minimumIntegerDigits", 2).
|
||||
|
@ -553,7 +553,7 @@ ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(GlobalObjec
|
|||
if (date_time_format.has_fractional_second_digits()) {
|
||||
fractional_second_digits = date_time_format.fractional_second_digits();
|
||||
|
||||
// a. Let nf3Options be ! OrdinaryObjectCreate(null).
|
||||
// a. Let nf3Options be OrdinaryObjectCreate(null).
|
||||
auto* number_format_options3 = Object::create(global_object, nullptr);
|
||||
|
||||
// b. Perform ! CreateDataPropertyOrThrow(nf3Options, "minimumIntegerDigits", fractionalSecondDigits).
|
||||
|
@ -835,7 +835,7 @@ ThrowCompletionOr<Array*> format_date_time_to_parts(GlobalObject& global_object,
|
|||
|
||||
// 4. For each Record { [[Type]], [[Value]] } part in parts, do
|
||||
for (auto& part : parts) {
|
||||
// a. Let O be ! OrdinaryObjectCreate(%Object.prototype%).
|
||||
// a. Let O be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto* object = Object::create(global_object, global_object.object_prototype());
|
||||
|
||||
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
|
||||
|
@ -1155,7 +1155,7 @@ ThrowCompletionOr<Array*> format_date_time_range_to_parts(GlobalObject& global_o
|
|||
|
||||
// 4. For each Record { [[Type]], [[Value]], [[Source]] } part in parts, do
|
||||
for (auto& part : parts) {
|
||||
// a. Let O be ! OrdinaryObjectCreate(%ObjectPrototype%).
|
||||
// a. Let O be OrdinaryObjectCreate(%ObjectPrototype%).
|
||||
auto* object = Object::create(global_object, global_object.object_prototype());
|
||||
|
||||
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
|
||||
|
|
|
@ -146,7 +146,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::resolved_options)
|
|||
// 3. Perform ? RequireInternalSlot(dtf, [[InitializedDateTimeFormat]]).
|
||||
auto* date_time_format = TRY(typed_this_object(global_object));
|
||||
|
||||
// 4. Let options be ! OrdinaryObjectCreate(%Object.prototype%).
|
||||
// 4. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto* options = Object::create(global_object, global_object.object_prototype());
|
||||
|
||||
// 5. For each row of Table 5, except the header row, in table order, do
|
||||
|
|
|
@ -128,7 +128,7 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::resolved_options)
|
|||
// 2. Perform ? RequireInternalSlot(displayNames, [[InitializedDisplayNames]]).
|
||||
auto* display_names = TRY(typed_this_object(global_object));
|
||||
|
||||
// 3. Let options be ! OrdinaryObjectCreate(%Object.prototype%).
|
||||
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto* options = Object::create(global_object, global_object.object_prototype());
|
||||
|
||||
// 4. For each row of Table 8, except the header row, in table order, do
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -69,7 +69,7 @@ JS_DEFINE_NATIVE_FUNCTION(Intl::get_canonical_locales)
|
|||
for (auto& locale : locale_list)
|
||||
marked_locale_list.append(js_string(vm, move(locale)));
|
||||
|
||||
// 2. Return ! CreateArrayFromList(ll).
|
||||
// 2. Return CreateArrayFromList(ll).
|
||||
return Array::create_from(global_object, marked_locale_list);
|
||||
}
|
||||
|
||||
|
@ -150,7 +150,7 @@ JS_DEFINE_NATIVE_FUNCTION(Intl::supported_values_of)
|
|||
return vm.throw_completion<RangeError>(global_object, ErrorType::IntlInvalidKey, key);
|
||||
}
|
||||
|
||||
// 9. Return ! CreateArrayFromList( list ).
|
||||
// 9. Return CreateArrayFromList( list ).
|
||||
return Array::create_from<StringView>(global_object, list, [&](auto value) { return js_string(vm, value); });
|
||||
}
|
||||
|
||||
|
|
|
@ -216,7 +216,7 @@ Array* format_list_to_parts(GlobalObject& global_object, ListFormat const& list_
|
|||
|
||||
// 4. For each Record { [[Type]], [[Value]] } part in parts, do
|
||||
for (auto& part : parts) {
|
||||
// a. Let O be ! OrdinaryObjectCreate(%Object.prototype%).
|
||||
// a. Let O be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto* object = Object::create(global_object, global_object.object_prototype());
|
||||
|
||||
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
|
||||
|
|
|
@ -73,7 +73,7 @@ JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::resolved_options)
|
|||
// 2. Perform ? RequireInternalSlot(lf, [[InitializedListFormat]]).
|
||||
auto* list_format = TRY(typed_this_object(global_object));
|
||||
|
||||
// 3. Let options be ! OrdinaryObjectCreate(%Object.prototype%).
|
||||
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto* options = Object::create(global_object, global_object.object_prototype());
|
||||
|
||||
// 4. For each row of Table 10, except the header row, in table order, do
|
||||
|
|
|
@ -349,7 +349,7 @@ ThrowCompletionOr<Object*> LocaleConstructor::construct(FunctionObject& new_targ
|
|||
|
||||
// 35. If relevantExtensionKeys contains "kn", then
|
||||
if (relevant_extension_keys.span().contains_slow("kn"sv)) {
|
||||
// a. If ! SameValue(r.[[kn]], "true") is true or r.[[kn]] is the empty String, then
|
||||
// a. If SameValue(r.[[kn]], "true") is true or r.[[kn]] is the empty String, then
|
||||
if (result.kn.has_value() && (same_value(js_string(vm, *result.kn), js_string(vm, "true")) || result.kn->is_empty())) {
|
||||
// i. Set locale.[[Numeric]] to true.
|
||||
locale->set_numeric(true);
|
||||
|
|
|
@ -641,7 +641,7 @@ Vector<PatternPartition> partition_notation_sub_pattern(GlobalObject& global_obj
|
|||
// 2. Else use an implementation dependent algorithm to map n to the appropriate representation of n in the given numbering system.
|
||||
formatted_string = Unicode::replace_digits_for_number_system(number_format.numbering_system(), formatted_string);
|
||||
|
||||
// 3. Let decimalSepIndex be ! StringIndexOf(n, ".", 0).
|
||||
// 3. Let decimalSepIndex be StringIndexOf(n, ".", 0).
|
||||
auto decimal_sep_index = formatted_string.find('.');
|
||||
|
||||
StringView integer;
|
||||
|
@ -817,7 +817,7 @@ Array* format_numeric_to_parts(GlobalObject& global_object, NumberFormat& number
|
|||
|
||||
// 4. For each Record { [[Type]], [[Value]] } part in parts, do
|
||||
for (auto& part : parts) {
|
||||
// a. Let O be ! OrdinaryObjectCreate(%Object.prototype%).
|
||||
// a. Let O be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto* object = Object::create(global_object, global_object.object_prototype());
|
||||
|
||||
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
|
||||
|
|
|
@ -84,7 +84,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::resolved_options)
|
|||
// 3. Perform ? RequireInternalSlot(nf, [[InitializedNumberFormat]]).
|
||||
auto* number_format = TRY(typed_this_object(global_object));
|
||||
|
||||
// 4. Let options be ! OrdinaryObjectCreate(%Object.prototype%).
|
||||
// 4. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto* options = Object::create(global_object, global_object.object_prototype());
|
||||
|
||||
// 5. For each row of Table 11, except the header row, in table order, do
|
||||
|
|
|
@ -37,7 +37,7 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::resolved_options)
|
|||
// 2. Perform ? RequireInternalSlot(pr, [[InitializedPluralRules]]).
|
||||
auto* plural_rules = TRY(typed_this_object(global_object));
|
||||
|
||||
// 3. Let options be ! OrdinaryObjectCreate(%Object.prototype%).
|
||||
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto* options = Object::create(global_object, global_object.object_prototype());
|
||||
|
||||
// 4. For each row of Table 13, except the header row, in table order, do
|
||||
|
@ -61,7 +61,7 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::resolved_options)
|
|||
// FIXME: Implement this when the data is available in LibUnicode.
|
||||
MarkedVector<Value> plural_categories { vm.heap() };
|
||||
|
||||
// 6. Perform ! CreateDataProperty(options, "pluralCategories", ! CreateArrayFromList(pluralCategories)).
|
||||
// 6. Perform ! CreateDataProperty(options, "pluralCategories", CreateArrayFromList(pluralCategories)).
|
||||
MUST(options->create_data_property_or_throw(vm.names.pluralCategories, Array::create_from(global_object, plural_categories)));
|
||||
|
||||
// 7. Return options.
|
||||
|
|
|
@ -257,7 +257,7 @@ ThrowCompletionOr<Array*> format_relative_time_to_parts(GlobalObject& global_obj
|
|||
|
||||
// 4. For each Record { [[Type]], [[Value]], [[Unit]] } part in parts, do
|
||||
for (auto& part : parts) {
|
||||
// a. Let O be ! OrdinaryObjectCreate(%Object.prototype%).
|
||||
// a. Let O be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto* object = Object::create(global_object, global_object.object_prototype());
|
||||
|
||||
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
|
||||
|
|
|
@ -73,7 +73,7 @@ JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatPrototype::resolved_options)
|
|||
// 2. Perform ? RequireInternalSlot(relativeTimeFormat, [[InitializedRelativeTimeFormat]]).
|
||||
auto* relative_time_format = TRY(typed_this_object(global_object));
|
||||
|
||||
// 3. Let options be ! OrdinaryObjectCreate(%Object.prototype%).
|
||||
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto* options = Object::create(global_object, global_object.object_prototype());
|
||||
|
||||
// 4. For each row of Table 15, except the header row, in table order, do
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace JS::Intl {
|
|||
SegmentIterator* SegmentIterator::create(GlobalObject& global_object, Segmenter& segmenter, Utf16View const& string, Segments const& segments)
|
||||
{
|
||||
// 1. Let internalSlotsList be « [[IteratingSegmenter]], [[IteratedString]], [[IteratedStringNextSegmentCodeUnitIndex]] ».
|
||||
// 2. Let iterator be ! OrdinaryObjectCreate(%SegmentIteratorPrototype%, internalSlotsList).
|
||||
// 2. Let iterator be OrdinaryObjectCreate(%SegmentIteratorPrototype%, internalSlotsList).
|
||||
// 3. Set iterator.[[IteratingSegmenter]] to segmenter.
|
||||
// 4. Set iterator.[[IteratedString]] to string.
|
||||
// 5. Set iterator.[[IteratedStringNextSegmentCodeUnitIndex]] to 0.
|
||||
|
|
|
@ -52,7 +52,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmentIteratorPrototype::next)
|
|||
|
||||
// 7. If endIndex is not finite, then
|
||||
if (!Value(end_index).is_finite_number()) {
|
||||
// a. Return ! CreateIterResultObject(undefined, true).
|
||||
// a. Return CreateIterResultObject(undefined, true).
|
||||
return create_iterator_result_object(global_object, js_undefined(), true);
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmentIteratorPrototype::next)
|
|||
// 9. Let segmentData be ! CreateSegmentDataObject(segmenter, string, startIndex, endIndex).
|
||||
auto* segment_data = create_segment_data_object(global_object, segmenter, string, start_index, end_index);
|
||||
|
||||
// 10. Return ! CreateIterResultObject(segmentData, false).
|
||||
// 10. Return CreateIterResultObject(segmentData, false).
|
||||
return create_iterator_result_object(global_object, segment_data, false);
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ Object* create_segment_data_object(GlobalObject& global_object, Segmenter const&
|
|||
// 4. Assert: startIndex < endIndex.
|
||||
VERIFY(start_index < end_index);
|
||||
|
||||
// 5. Let result be ! OrdinaryObjectCreate(%Object.prototype%).
|
||||
// 5. Let result be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto* result = Object::create(global_object, global_object.object_prototype());
|
||||
|
||||
// 6. Let segment be the substring of string from startIndex to endIndex.
|
||||
|
|
|
@ -38,7 +38,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmenterPrototype::resolved_options)
|
|||
// 2. Perform ? RequireInternalSlot(segmenter, [[InitializedSegmenter]]).
|
||||
auto* segmenter = TRY(typed_this_object(global_object));
|
||||
|
||||
// 3. Let options be ! OrdinaryObjectCreate(%Object.prototype%).
|
||||
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
|
||||
auto* options = Object::create(global_object, global_object.object_prototype());
|
||||
|
||||
// 4. For each row of Table 16, except the header row, in table order, do
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace JS::Intl {
|
|||
Segments* Segments::create(GlobalObject& global_object, Segmenter& segmenter, Utf16String string)
|
||||
{
|
||||
// 1. Let internalSlotsList be « [[SegmentsSegmenter]], [[SegmentsString]] ».
|
||||
// 2. Let segments be ! OrdinaryObjectCreate(%SegmentsPrototype%, internalSlotsList).
|
||||
// 2. Let segments be OrdinaryObjectCreate(%SegmentsPrototype%, internalSlotsList).
|
||||
// 3. Set segments.[[SegmentsSegmenter]] to segmenter.
|
||||
// 4. Set segments.[[SegmentsString]] to string.
|
||||
// 5. Return segments.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue