LibJS: Replace standalone js_string() with PrimitiveString::create()

Note that js_rope_string() has been folded into this, the old name was
misleading - it would not always create a rope string, only if both
sides are not empty strings. Use a three-argument create() overload
instead.
This commit is contained in:
Linus Groh 2022-12-06 22:17:27 +00:00
parent 5db38d7ba1
commit 525f22d018
Notes: sideshowbarker 2024-07-17 03:40:04 +09:00
144 changed files with 656 additions and 672 deletions

View file

@ -1412,7 +1412,7 @@ static void generate_wrap_statement(SourceGenerator& generator, DeprecatedString
if (type.is_string()) {
scoped_generator.append(R"~~~(
@result_expression@ JS::js_string(vm, @value@);
@result_expression@ JS::PrimitiveString::create(vm, @value@);
)~~~");
} else if (type.name() == "sequence") {
// https://webidl.spec.whatwg.org/#es-sequence
@ -1527,7 +1527,7 @@ static void generate_wrap_statement(SourceGenerator& generator, DeprecatedString
)~~~");
} else if (interface.enumerations.contains(type.name())) {
scoped_generator.append(R"~~~(
@result_expression@ JS::js_string(vm, Bindings::idl_enum_to_deprecated_string(@value@));
@result_expression@ JS::PrimitiveString::create(vm, Bindings::idl_enum_to_deprecated_string(@value@));
)~~~");
} else if (interface.callback_functions.contains(type.name())) {
// https://webidl.spec.whatwg.org/#es-callback-function
@ -2574,7 +2574,7 @@ void @prototype_class@::initialize(JS::Realm& realm)
}
generator.append(R"~~~(
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "@name@"), JS::Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), JS::PrimitiveString::create(vm, "@name@"), JS::Attribute::Configurable);
Object::initialize(realm);
}
@ -2735,7 +2735,7 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::to_string)
}
stringifier_generator.append(R"~~~(
return JS::js_string(vm, move(retval));
return JS::PrimitiveString::create(vm, move(retval));
}
)~~~");
}
@ -2893,7 +2893,7 @@ void @prototype_class@::initialize(JS::Realm& realm)
Object::initialize(realm);
define_native_function(realm, vm.names.next, next, 0, JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Iterator"), JS::Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), JS::PrimitiveString::create(vm, "Iterator"), JS::Attribute::Configurable);
}
static JS::ThrowCompletionOr<@fully_qualified_name@*> impl_from(JS::VM& vm)

View file

@ -103,7 +103,7 @@ void add_@global_object_snake_name@_exposed_interfaces(JS::Object& global, JS::R
auto& constructor = Bindings::ensure_web_constructor<Bindings::@constructor_class@>(realm, "@interface_name@");
global.define_direct_property("@interface_name@", &constructor, JS::Attribute::Writable | JS::Attribute::Configurable);
prototype.define_direct_property(vm.names.constructor, &constructor, JS::Attribute::Writable | JS::Attribute::Configurable);
constructor.define_direct_property(vm.names.name, js_string(vm, "@interface_name@"), JS::Attribute::Configurable);
constructor.define_direct_property(vm.names.name, JS::PrimitiveString::create(vm, "@interface_name@"), JS::Attribute::Configurable);
}
)~~~"); };

View file

@ -153,7 +153,8 @@ JS::Value Cell::js_data()
if (m_kind == Formula)
return m_evaluated_data;
return JS::js_string(m_sheet->interpreter().heap(), m_data);
auto& vm = m_sheet->interpreter().vm();
return JS::PrimitiveString::create(vm, m_data);
}
DeprecatedString Cell::source() const

View file

@ -27,8 +27,9 @@ JS::ThrowCompletionOr<DeprecatedString> StringCell::display(Cell& cell, CellType
JS::ThrowCompletionOr<JS::Value> StringCell::js_value(Cell& cell, CellTypeMetadata const& metadata) const
{
auto& vm = cell.sheet().interpreter().vm();
auto string = TRY(display(cell, metadata));
return JS::js_string(cell.sheet().interpreter().heap(), string);
return JS::PrimitiveString::create(vm, string);
}
DeprecatedString StringCell::metadata_hint(MetadataName metadata) const

View file

@ -178,7 +178,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::get_name)
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "SheetGlobalObject");
auto sheet_object = static_cast<SheetGlobalObject*>(this_object);
return JS::js_string(vm, sheet_object->m_sheet.name());
return JS::PrimitiveString::create(vm, sheet_object->m_sheet.name());
}
JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::get_real_cell_contents)
@ -205,9 +205,9 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::get_real_cell_contents)
return JS::js_undefined();
if (cell->kind() == Spreadsheet::Cell::Kind::Formula)
return JS::js_string(vm, DeprecatedString::formatted("={}", cell->data()));
return JS::PrimitiveString::create(vm, DeprecatedString::formatted("={}", cell->data()));
return JS::js_string(vm, cell->data());
return JS::PrimitiveString::create(vm, cell->data());
}
JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::set_real_cell_contents)
@ -260,7 +260,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::parse_cell_name)
return JS::js_undefined();
auto object = JS::Object::create(realm, realm.intrinsics().object_prototype());
object->define_direct_property("column", JS::js_string(vm, sheet_object->m_sheet.column(position.value().column)), JS::default_attributes);
object->define_direct_property("column", JS::PrimitiveString::create(vm, sheet_object->m_sheet.column(position.value().column)), JS::default_attributes);
object->define_direct_property("row", JS::Value((unsigned)position.value().row), JS::default_attributes);
return object;
@ -286,7 +286,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::current_cell_position)
auto position = current_cell->position();
auto object = JS::Object::create(realm, realm.intrinsics().object_prototype());
object->define_direct_property("column", JS::js_string(vm, sheet_object->m_sheet.column(position.column)), JS::default_attributes);
object->define_direct_property("column", JS::PrimitiveString::create(vm, sheet_object->m_sheet.column(position.column)), JS::default_attributes);
object->define_direct_property("row", JS::Value((unsigned)position.row), JS::default_attributes);
return object;
@ -342,7 +342,7 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::column_arithmetic)
if (!new_column.has_value())
return vm.throw_completion<JS::TypeError>(DeprecatedString::formatted("'{}' is not a valid column", column_name_str));
return JS::js_string(vm, new_column.release_value());
return JS::PrimitiveString::create(vm, new_column.release_value());
}
JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::get_column_bound)

View file

@ -426,7 +426,7 @@ RefPtr<Sheet> Sheet::from_json(JsonObject const& object, Workbook& workbook)
break;
case Cell::Formula: {
auto& vm = sheet->interpreter().vm();
auto value_or_error = JS::call(vm, parse_function, json, JS::js_string(vm, obj.get("value"sv).as_string()));
auto value_or_error = JS::call(vm, parse_function, json, JS::PrimitiveString::create(vm, obj.get("value"sv).as_string()));
if (value_or_error.is_error()) {
warnln("Failed to load previous value for cell {}, leaving as undefined", position.to_cell_identifier(sheet));
value_or_error = JS::js_undefined();

View file

@ -1538,7 +1538,7 @@ Completion UnaryExpression::execute(Interpreter& interpreter) const
case UnaryOp::Minus:
return TRY(unary_minus(vm, lhs_result));
case UnaryOp::Typeof:
return Value { js_string(vm, lhs_result.typeof()) };
return Value { PrimitiveString::create(vm, lhs_result.typeof()) };
case UnaryOp::Void:
return js_undefined();
case UnaryOp::Delete:
@ -3465,9 +3465,10 @@ Completion ImportCall::execute(Interpreter& interpreter) const
Completion StringLiteral::execute(Interpreter& interpreter) const
{
InterpreterNodeScope node_scope { interpreter, *this };
auto& vm = interpreter.vm();
// 1. Return the SV of StringLiteral as defined in 12.8.4.2.
return Value { js_string(interpreter.heap(), m_value) };
return Value { PrimitiveString::create(vm, m_value) };
}
// 13.2.3.1 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-literals-runtime-semantics-evaluation
@ -3627,7 +3628,7 @@ Completion TemplateLiteral::execute(Interpreter& interpreter) const
}
// 7. Return the string-concatenation of head, middle, and tail.
return Value { js_string(interpreter.heap(), string_builder.build()) };
return Value { PrimitiveString::create(vm, string_builder.build()) };
}
void TaggedTemplateLiteral::dump(int indent) const

View file

@ -150,7 +150,7 @@ static ThrowCompletionOr<Value> not_(VM&, Value value)
static ThrowCompletionOr<Value> typeof_(VM& vm, Value value)
{
return Value(js_string(vm, value.typeof()));
return Value(PrimitiveString::create(vm, value.typeof()));
}
#define JS_DEFINE_COMMON_UNARY_OP(OpTitleCase, op_snake_case) \
@ -296,7 +296,7 @@ ThrowCompletionOr<void> IteratorToArray::execute_impl(Bytecode::Interpreter& int
ThrowCompletionOr<void> NewString::execute_impl(Bytecode::Interpreter& interpreter) const
{
interpreter.accumulator() = js_string(interpreter.vm(), interpreter.current_executable().get_string(m_string));
interpreter.accumulator() = PrimitiveString::create(interpreter.vm(), interpreter.current_executable().get_string(m_string));
return {};
}
@ -316,7 +316,7 @@ ThrowCompletionOr<void> NewRegExp::execute_impl(Bytecode::Interpreter& interpret
auto source = interpreter.current_executable().get_string(m_source_index);
auto flags = interpreter.current_executable().get_string(m_flags_index);
interpreter.accumulator() = TRY(regexp_create(vm, js_string(vm, source), js_string(vm, flags)));
interpreter.accumulator() = TRY(regexp_create(vm, PrimitiveString::create(vm, source), PrimitiveString::create(vm, flags)));
return {};
}
@ -923,7 +923,7 @@ ThrowCompletionOr<void> GetObjectPropertyIterator::execute_impl(Bytecode::Interp
if (key.is_number())
result_object->define_direct_property(vm.names.value, JS::Value(key.as_number()), default_attributes);
else if (key.is_string())
result_object->define_direct_property(vm.names.value, js_string(vm, key.as_string()), default_attributes);
result_object->define_direct_property(vm.names.value, PrimitiveString::create(vm, key.as_string()), default_attributes);
else
VERIFY_NOT_REACHED(); // We should not have non-string/number keys.
@ -992,7 +992,7 @@ ThrowCompletionOr<void> TypeofVariable::execute_impl(Bytecode::Interpreter& inte
// 2. If val is a Reference Record, then
// a. If IsUnresolvableReference(val) is true, return "undefined".
if (reference.is_unresolvable()) {
interpreter.accumulator() = js_string(vm, "undefined"sv);
interpreter.accumulator() = PrimitiveString::create(vm, "undefined"sv);
return {};
}
@ -1001,7 +1001,7 @@ ThrowCompletionOr<void> TypeofVariable::execute_impl(Bytecode::Interpreter& inte
// 4. NOTE: This step is replaced in section B.3.6.3.
// 5. Return a String according to Table 41.
interpreter.accumulator() = js_string(vm, value.typeof());
interpreter.accumulator() = PrimitiveString::create(vm, value.typeof());
return {};
}

View file

@ -139,7 +139,7 @@ ThrowCompletionOr<Value> Console::count()
// 5. Perform Logger("count", « concat »).
MarkedVector<Value> concat_as_vector { vm.heap() };
concat_as_vector.append(js_string(vm, concat));
concat_as_vector.append(PrimitiveString::create(vm, concat));
if (m_client)
TRY(m_client->logger(LogLevel::Count, concat_as_vector));
return js_undefined();
@ -167,7 +167,7 @@ ThrowCompletionOr<Value> Console::count_reset()
auto message = DeprecatedString::formatted("\"{}\" doesn't have a count", label);
// 2. Perform Logger("countReset", « message »);
MarkedVector<Value> message_as_vector { vm.heap() };
message_as_vector.append(js_string(vm, message));
message_as_vector.append(PrimitiveString::create(vm, message));
if (m_client)
TRY(m_client->logger(LogLevel::CountReset, message_as_vector));
}
@ -186,7 +186,7 @@ ThrowCompletionOr<Value> Console::assert_()
return js_undefined();
// 2. Let message be a string without any formatting specifiers indicating generically an assertion failure (such as "Assertion failed").
auto message = js_string(vm, "Assertion failed");
auto message = PrimitiveString::create(vm, "Assertion failed");
// NOTE: Assemble `data` from the function arguments.
MarkedVector<Value> data { vm.heap() };
@ -212,7 +212,7 @@ ThrowCompletionOr<Value> Console::assert_()
// 3. Otherwise:
else {
// 1. Let concat be the concatenation of message, U+003A (:), U+0020 SPACE, and first.
auto concat = js_string(vm, DeprecatedString::formatted("{}: {}", message->deprecated_string(), first.to_string(vm).value()));
auto concat = PrimitiveString::create(vm, DeprecatedString::formatted("{}: {}", message->deprecated_string(), first.to_string(vm).value()));
// 2. Set data[0] to concat.
data[0] = concat;
}
@ -319,7 +319,7 @@ ThrowCompletionOr<Value> Console::time()
if (m_timer_table.contains(label)) {
if (m_client) {
MarkedVector<Value> timer_already_exists_warning_message_as_vector { vm.heap() };
timer_already_exists_warning_message_as_vector.append(js_string(vm, DeprecatedString::formatted("Timer '{}' already exists.", label)));
timer_already_exists_warning_message_as_vector.append(PrimitiveString::create(vm, DeprecatedString::formatted("Timer '{}' already exists.", label)));
TRY(m_client->printer(LogLevel::Warn, move(timer_already_exists_warning_message_as_vector)));
}
return js_undefined();
@ -347,7 +347,7 @@ ThrowCompletionOr<Value> Console::time_log()
if (maybe_start_time == m_timer_table.end()) {
if (m_client) {
MarkedVector<Value> timer_does_not_exist_warning_message_as_vector { vm.heap() };
timer_does_not_exist_warning_message_as_vector.append(js_string(vm, DeprecatedString::formatted("Timer '{}' does not exist.", label)));
timer_does_not_exist_warning_message_as_vector.append(PrimitiveString::create(vm, DeprecatedString::formatted("Timer '{}' does not exist.", label)));
TRY(m_client->printer(LogLevel::Warn, move(timer_does_not_exist_warning_message_as_vector)));
}
return js_undefined();
@ -363,7 +363,7 @@ ThrowCompletionOr<Value> Console::time_log()
// 5. Prepend concat to data.
MarkedVector<Value> data { vm.heap() };
data.ensure_capacity(vm.argument_count());
data.append(js_string(vm, concat));
data.append(PrimitiveString::create(vm, concat));
for (size_t i = 1; i < vm.argument_count(); ++i)
data.append(vm.argument(i));
@ -390,7 +390,7 @@ ThrowCompletionOr<Value> Console::time_end()
if (maybe_start_time == m_timer_table.end()) {
if (m_client) {
MarkedVector<Value> timer_does_not_exist_warning_message_as_vector { vm.heap() };
timer_does_not_exist_warning_message_as_vector.append(js_string(vm, DeprecatedString::formatted("Timer '{}' does not exist.", label)));
timer_does_not_exist_warning_message_as_vector.append(PrimitiveString::create(vm, DeprecatedString::formatted("Timer '{}' does not exist.", label)));
TRY(m_client->printer(LogLevel::Warn, move(timer_does_not_exist_warning_message_as_vector)));
}
return js_undefined();
@ -409,7 +409,7 @@ ThrowCompletionOr<Value> Console::time_end()
// 6. Perform Printer("timeEnd", « concat »).
if (m_client) {
MarkedVector<Value> concat_as_vector { vm.heap() };
concat_as_vector.append(js_string(vm, concat));
concat_as_vector.append(PrimitiveString::create(vm, concat));
TRY(m_client->printer(LogLevel::TimeEnd, move(concat_as_vector)));
}
return js_undefined();
@ -622,7 +622,7 @@ ThrowCompletionOr<MarkedVector<Value>> ConsoleClient::formatter(MarkedVector<Val
else if (specifier == "%c"sv) {
// NOTE: This has no spec yet. `%c` specifiers treat the argument as CSS styling for the log message.
add_css_style_to_current_message(TRY(current.to_string(vm)));
converted = js_string(vm, "");
converted = PrimitiveString::create(vm, "");
}
// 7. If any of the previous steps set converted, replace specifier in target with converted.
@ -633,7 +633,7 @@ ThrowCompletionOr<MarkedVector<Value>> ConsoleClient::formatter(MarkedVector<Val
// 7. Let result be a list containing target together with the elements of args starting from the third onward.
MarkedVector<Value> result { vm.heap() };
result.ensure_capacity(args.size() - 1);
result.empend(js_string(vm, target));
result.empend(PrimitiveString::create(vm, target));
for (size_t i = 2; i < args.size(); ++i)
result.unchecked_append(args[i]);

View file

@ -425,7 +425,7 @@ ErrorOr<void> print_temporal_calendar(JS::PrintContext& print_context, JS::Tempo
{
TRY(print_type(print_context, "Temporal.Calendar"));
TRY(js_out(print_context, " "));
TRY(print_value(print_context, JS::js_string(calendar.vm(), calendar.identifier()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(calendar.vm(), calendar.identifier()), seen_objects));
return {};
}
@ -496,7 +496,7 @@ ErrorOr<void> print_temporal_time_zone(JS::PrintContext& print_context, JS::Temp
{
TRY(print_type(print_context, "Temporal.TimeZone"));
TRY(js_out(print_context, " "));
TRY(print_value(print_context, JS::js_string(time_zone.vm(), time_zone.identifier()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(time_zone.vm(), time_zone.identifier()), seen_objects));
if (time_zone.offset_nanoseconds().has_value()) {
TRY(js_out(print_context, "\n offset (ns): "));
TRY(print_value(print_context, JS::Value(*time_zone.offset_nanoseconds()), seen_objects));
@ -520,16 +520,16 @@ ErrorOr<void> print_intl_display_names(JS::PrintContext& print_context, JS::Intl
{
TRY(print_type(print_context, "Intl.DisplayNames"));
TRY(js_out(print_context, "\n locale: "));
TRY(print_value(print_context, js_string(display_names.vm(), display_names.locale()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(display_names.vm(), display_names.locale()), seen_objects));
TRY(js_out(print_context, "\n type: "));
TRY(print_value(print_context, js_string(display_names.vm(), display_names.type_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(display_names.vm(), display_names.type_string()), seen_objects));
TRY(js_out(print_context, "\n style: "));
TRY(print_value(print_context, js_string(display_names.vm(), display_names.style_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(display_names.vm(), display_names.style_string()), seen_objects));
TRY(js_out(print_context, "\n fallback: "));
TRY(print_value(print_context, js_string(display_names.vm(), display_names.fallback_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(display_names.vm(), display_names.fallback_string()), seen_objects));
if (display_names.has_language_display()) {
TRY(js_out(print_context, "\n languageDisplay: "));
TRY(print_value(print_context, js_string(display_names.vm(), display_names.language_display_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(display_names.vm(), display_names.language_display_string()), seen_objects));
}
return {};
}
@ -538,26 +538,26 @@ ErrorOr<void> print_intl_locale(JS::PrintContext& print_context, JS::Intl::Local
{
TRY(print_type(print_context, "Intl.Locale"));
TRY(js_out(print_context, "\n locale: "));
TRY(print_value(print_context, js_string(locale.vm(), locale.locale()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(locale.vm(), locale.locale()), seen_objects));
if (locale.has_calendar()) {
TRY(js_out(print_context, "\n calendar: "));
TRY(print_value(print_context, js_string(locale.vm(), locale.calendar()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(locale.vm(), locale.calendar()), seen_objects));
}
if (locale.has_case_first()) {
TRY(js_out(print_context, "\n caseFirst: "));
TRY(print_value(print_context, js_string(locale.vm(), locale.case_first()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(locale.vm(), locale.case_first()), seen_objects));
}
if (locale.has_collation()) {
TRY(js_out(print_context, "\n collation: "));
TRY(print_value(print_context, js_string(locale.vm(), locale.collation()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(locale.vm(), locale.collation()), seen_objects));
}
if (locale.has_hour_cycle()) {
TRY(js_out(print_context, "\n hourCycle: "));
TRY(print_value(print_context, js_string(locale.vm(), locale.hour_cycle()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(locale.vm(), locale.hour_cycle()), seen_objects));
}
if (locale.has_numbering_system()) {
TRY(js_out(print_context, "\n numberingSystem: "));
TRY(print_value(print_context, js_string(locale.vm(), locale.numbering_system()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(locale.vm(), locale.numbering_system()), seen_objects));
}
TRY(js_out(print_context, "\n numeric: "));
TRY(print_value(print_context, JS::Value(locale.numeric()), seen_objects));
@ -568,11 +568,11 @@ ErrorOr<void> print_intl_list_format(JS::PrintContext& print_context, JS::Intl::
{
TRY(print_type(print_context, "Intl.ListFormat"));
TRY(js_out(print_context, "\n locale: "));
TRY(print_value(print_context, js_string(list_format.vm(), list_format.locale()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(list_format.vm(), list_format.locale()), seen_objects));
TRY(js_out(print_context, "\n type: "));
TRY(print_value(print_context, js_string(list_format.vm(), list_format.type_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(list_format.vm(), list_format.type_string()), seen_objects));
TRY(js_out(print_context, "\n style: "));
TRY(print_value(print_context, js_string(list_format.vm(), list_format.style_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(list_format.vm(), list_format.style_string()), seen_objects));
return {};
}
@ -580,32 +580,32 @@ ErrorOr<void> print_intl_number_format(JS::PrintContext& print_context, JS::Intl
{
TRY(print_type(print_context, "Intl.NumberFormat"));
TRY(js_out(print_context, "\n locale: "));
TRY(print_value(print_context, js_string(number_format.vm(), number_format.locale()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(number_format.vm(), number_format.locale()), seen_objects));
TRY(js_out(print_context, "\n dataLocale: "));
TRY(print_value(print_context, js_string(number_format.vm(), number_format.data_locale()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(number_format.vm(), number_format.data_locale()), seen_objects));
TRY(js_out(print_context, "\n numberingSystem: "));
TRY(print_value(print_context, js_string(number_format.vm(), number_format.numbering_system()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(number_format.vm(), number_format.numbering_system()), seen_objects));
TRY(js_out(print_context, "\n style: "));
TRY(print_value(print_context, js_string(number_format.vm(), number_format.style_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(number_format.vm(), number_format.style_string()), seen_objects));
if (number_format.has_currency()) {
TRY(js_out(print_context, "\n currency: "));
TRY(print_value(print_context, js_string(number_format.vm(), number_format.currency()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(number_format.vm(), number_format.currency()), seen_objects));
}
if (number_format.has_currency_display()) {
TRY(js_out(print_context, "\n currencyDisplay: "));
TRY(print_value(print_context, js_string(number_format.vm(), number_format.currency_display_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(number_format.vm(), number_format.currency_display_string()), seen_objects));
}
if (number_format.has_currency_sign()) {
TRY(js_out(print_context, "\n currencySign: "));
TRY(print_value(print_context, js_string(number_format.vm(), number_format.currency_sign_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(number_format.vm(), number_format.currency_sign_string()), seen_objects));
}
if (number_format.has_unit()) {
TRY(js_out(print_context, "\n unit: "));
TRY(print_value(print_context, js_string(number_format.vm(), number_format.unit()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(number_format.vm(), number_format.unit()), seen_objects));
}
if (number_format.has_unit_display()) {
TRY(js_out(print_context, "\n unitDisplay: "));
TRY(print_value(print_context, js_string(number_format.vm(), number_format.unit_display_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(number_format.vm(), number_format.unit_display_string()), seen_objects));
}
TRY(js_out(print_context, "\n minimumIntegerDigits: "));
TRY(print_value(print_context, JS::Value(number_format.min_integer_digits()), seen_objects));
@ -628,21 +628,21 @@ ErrorOr<void> print_intl_number_format(JS::PrintContext& print_context, JS::Intl
TRY(js_out(print_context, "\n useGrouping: "));
TRY(print_value(print_context, number_format.use_grouping_to_value(number_format.vm()), seen_objects));
TRY(js_out(print_context, "\n roundingType: "));
TRY(print_value(print_context, js_string(number_format.vm(), number_format.rounding_type_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(number_format.vm(), number_format.rounding_type_string()), seen_objects));
TRY(js_out(print_context, "\n roundingMode: "));
TRY(print_value(print_context, js_string(number_format.vm(), number_format.rounding_mode_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(number_format.vm(), number_format.rounding_mode_string()), seen_objects));
TRY(js_out(print_context, "\n roundingIncrement: "));
TRY(print_value(print_context, JS::Value(number_format.rounding_increment()), seen_objects));
TRY(js_out(print_context, "\n notation: "));
TRY(print_value(print_context, js_string(number_format.vm(), number_format.notation_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(number_format.vm(), number_format.notation_string()), seen_objects));
if (number_format.has_compact_display()) {
TRY(js_out(print_context, "\n compactDisplay: "));
TRY(print_value(print_context, js_string(number_format.vm(), number_format.compact_display_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(number_format.vm(), number_format.compact_display_string()), seen_objects));
}
TRY(js_out(print_context, "\n signDisplay: "));
TRY(print_value(print_context, js_string(number_format.vm(), number_format.sign_display_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(number_format.vm(), number_format.sign_display_string()), seen_objects));
TRY(js_out(print_context, "\n trailingZeroDisplay: "));
TRY(print_value(print_context, js_string(number_format.vm(), number_format.trailing_zero_display_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(number_format.vm(), number_format.trailing_zero_display_string()), seen_objects));
return {};
}
@ -650,26 +650,26 @@ ErrorOr<void> print_intl_date_time_format(JS::PrintContext& print_context, JS::I
{
TRY(print_type(print_context, "Intl.DateTimeFormat"));
TRY(js_out(print_context, "\n locale: "));
TRY(print_value(print_context, js_string(date_time_format.vm(), date_time_format.locale()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(date_time_format.vm(), date_time_format.locale()), seen_objects));
TRY(js_out(print_context, "\n pattern: "));
TRY(print_value(print_context, js_string(date_time_format.vm(), date_time_format.pattern()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(date_time_format.vm(), date_time_format.pattern()), seen_objects));
TRY(js_out(print_context, "\n calendar: "));
TRY(print_value(print_context, js_string(date_time_format.vm(), date_time_format.calendar()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(date_time_format.vm(), date_time_format.calendar()), seen_objects));
TRY(js_out(print_context, "\n numberingSystem: "));
TRY(print_value(print_context, js_string(date_time_format.vm(), date_time_format.numbering_system()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(date_time_format.vm(), date_time_format.numbering_system()), seen_objects));
if (date_time_format.has_hour_cycle()) {
TRY(js_out(print_context, "\n hourCycle: "));
TRY(print_value(print_context, js_string(date_time_format.vm(), date_time_format.hour_cycle_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(date_time_format.vm(), date_time_format.hour_cycle_string()), seen_objects));
}
TRY(js_out(print_context, "\n timeZone: "));
TRY(print_value(print_context, js_string(date_time_format.vm(), date_time_format.time_zone()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(date_time_format.vm(), date_time_format.time_zone()), seen_objects));
if (date_time_format.has_date_style()) {
TRY(js_out(print_context, "\n dateStyle: "));
TRY(print_value(print_context, js_string(date_time_format.vm(), date_time_format.date_style_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(date_time_format.vm(), date_time_format.date_style_string()), seen_objects));
}
if (date_time_format.has_time_style()) {
TRY(js_out(print_context, "\n timeStyle: "));
TRY(print_value(print_context, js_string(date_time_format.vm(), date_time_format.time_style_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(date_time_format.vm(), date_time_format.time_style_string()), seen_objects));
}
auto result = JS::Intl::for_each_calendar_field(date_time_format.vm(), date_time_format, [&](auto& option, auto const& property, auto const&) -> JS::ThrowCompletionOr<void> {
@ -688,7 +688,7 @@ ErrorOr<void> print_intl_date_time_format(JS::PrintContext& print_context, JS::I
return JS::throw_completion(JS::js_null());
} else {
auto name = Locale::calendar_pattern_style_to_string(*option);
if (print_value(print_context, js_string(date_time_format.vm(), name), seen_objects).is_error())
if (print_value(print_context, JS::PrimitiveString::create(date_time_format.vm(), name), seen_objects).is_error())
return JS::throw_completion(JS::js_null());
}
@ -705,13 +705,13 @@ ErrorOr<void> print_intl_relative_time_format(JS::PrintContext& print_context, J
{
TRY(print_type(print_context, "Intl.RelativeTimeFormat"));
TRY(js_out(print_context, "\n locale: "));
TRY(print_value(print_context, js_string(date_time_format.vm(), date_time_format.locale()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(date_time_format.vm(), date_time_format.locale()), seen_objects));
TRY(js_out(print_context, "\n numberingSystem: "));
TRY(print_value(print_context, js_string(date_time_format.vm(), date_time_format.numbering_system()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(date_time_format.vm(), date_time_format.numbering_system()), seen_objects));
TRY(js_out(print_context, "\n style: "));
TRY(print_value(print_context, js_string(date_time_format.vm(), date_time_format.style_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(date_time_format.vm(), date_time_format.style_string()), seen_objects));
TRY(js_out(print_context, "\n numeric: "));
TRY(print_value(print_context, js_string(date_time_format.vm(), date_time_format.numeric_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(date_time_format.vm(), date_time_format.numeric_string()), seen_objects));
return {};
}
@ -719,9 +719,9 @@ ErrorOr<void> print_intl_plural_rules(JS::PrintContext& print_context, JS::Intl:
{
TRY(print_type(print_context, "Intl.PluralRules"));
TRY(js_out(print_context, "\n locale: "));
TRY(print_value(print_context, js_string(plural_rules.vm(), plural_rules.locale()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(plural_rules.vm(), plural_rules.locale()), seen_objects));
TRY(js_out(print_context, "\n type: "));
TRY(print_value(print_context, js_string(plural_rules.vm(), plural_rules.type_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(plural_rules.vm(), plural_rules.type_string()), seen_objects));
TRY(js_out(print_context, "\n minimumIntegerDigits: "));
TRY(print_value(print_context, JS::Value(plural_rules.min_integer_digits()), seen_objects));
if (plural_rules.has_min_fraction_digits()) {
@ -741,7 +741,7 @@ ErrorOr<void> print_intl_plural_rules(JS::PrintContext& print_context, JS::Intl:
TRY(print_value(print_context, JS::Value(plural_rules.max_significant_digits()), seen_objects));
}
TRY(js_out(print_context, "\n roundingType: "));
TRY(print_value(print_context, js_string(plural_rules.vm(), plural_rules.rounding_type_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(plural_rules.vm(), plural_rules.rounding_type_string()), seen_objects));
return {};
}
@ -749,15 +749,15 @@ ErrorOr<void> print_intl_collator(JS::PrintContext& print_context, JS::Intl::Col
{
TRY(print_type(print_context, "Intl.Collator"));
out("\n locale: ");
TRY(print_value(print_context, js_string(collator.vm(), collator.locale()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(collator.vm(), collator.locale()), seen_objects));
out("\n usage: ");
TRY(print_value(print_context, js_string(collator.vm(), collator.usage_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(collator.vm(), collator.usage_string()), seen_objects));
out("\n sensitivity: ");
TRY(print_value(print_context, js_string(collator.vm(), collator.sensitivity_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(collator.vm(), collator.sensitivity_string()), seen_objects));
out("\n caseFirst: ");
TRY(print_value(print_context, js_string(collator.vm(), collator.case_first_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(collator.vm(), collator.case_first_string()), seen_objects));
out("\n collation: ");
TRY(print_value(print_context, js_string(collator.vm(), collator.collation()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(collator.vm(), collator.collation()), seen_objects));
out("\n ignorePunctuation: ");
TRY(print_value(print_context, JS::Value(collator.ignore_punctuation()), seen_objects));
out("\n numeric: ");
@ -769,9 +769,9 @@ ErrorOr<void> print_intl_segmenter(JS::PrintContext& print_context, JS::Intl::Se
{
TRY(print_type(print_context, "Intl.Segmenter"));
out("\n locale: ");
TRY(print_value(print_context, js_string(segmenter.vm(), segmenter.locale()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(segmenter.vm(), segmenter.locale()), seen_objects));
out("\n granularity: ");
TRY(print_value(print_context, js_string(segmenter.vm(), segmenter.segmenter_granularity_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(segmenter.vm(), segmenter.segmenter_granularity_string()), seen_objects));
return {};
}
@ -779,7 +779,7 @@ ErrorOr<void> print_intl_segments(JS::PrintContext& print_context, JS::Intl::Seg
{
TRY(print_type(print_context, "Segments"));
out("\n string: ");
TRY(print_value(print_context, js_string(segments.vm(), segments.segments_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(segments.vm(), segments.segments_string()), seen_objects));
out("\n segmenter: ");
TRY(print_value(print_context, &segments.segments_segmenter(), seen_objects));
return {};
@ -789,53 +789,53 @@ ErrorOr<void> print_intl_duration_format(JS::PrintContext& print_context, JS::In
{
TRY(print_type(print_context, "Intl.DurationFormat"));
out("\n locale: ");
TRY(print_value(print_context, js_string(duration_format.vm(), duration_format.locale()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.locale()), seen_objects));
out("\n dataLocale: ");
TRY(print_value(print_context, js_string(duration_format.vm(), duration_format.data_locale()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.data_locale()), seen_objects));
out("\n numberingSystem: ");
TRY(print_value(print_context, js_string(duration_format.vm(), duration_format.numbering_system()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.numbering_system()), seen_objects));
out("\n style: ");
TRY(print_value(print_context, js_string(duration_format.vm(), duration_format.style_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.style_string()), seen_objects));
out("\n years: ");
TRY(print_value(print_context, js_string(duration_format.vm(), duration_format.years_style_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.years_style_string()), seen_objects));
out("\n yearsDisplay: ");
TRY(print_value(print_context, js_string(duration_format.vm(), duration_format.years_display_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.years_display_string()), seen_objects));
out("\n months: ");
TRY(print_value(print_context, js_string(duration_format.vm(), duration_format.months_style_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.months_style_string()), seen_objects));
out("\n monthsDisplay: ");
TRY(print_value(print_context, js_string(duration_format.vm(), duration_format.months_display_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.months_display_string()), seen_objects));
out("\n weeks: ");
TRY(print_value(print_context, js_string(duration_format.vm(), duration_format.weeks_style_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.weeks_style_string()), seen_objects));
out("\n weeksDisplay: ");
TRY(print_value(print_context, js_string(duration_format.vm(), duration_format.weeks_display_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.weeks_display_string()), seen_objects));
out("\n days: ");
TRY(print_value(print_context, js_string(duration_format.vm(), duration_format.days_style_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.days_style_string()), seen_objects));
out("\n daysDisplay: ");
TRY(print_value(print_context, js_string(duration_format.vm(), duration_format.days_display_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.days_display_string()), seen_objects));
out("\n hours: ");
TRY(print_value(print_context, js_string(duration_format.vm(), duration_format.hours_style_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.hours_style_string()), seen_objects));
out("\n hoursDisplay: ");
TRY(print_value(print_context, js_string(duration_format.vm(), duration_format.hours_display_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.hours_display_string()), seen_objects));
out("\n minutes: ");
TRY(print_value(print_context, js_string(duration_format.vm(), duration_format.minutes_style_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.minutes_style_string()), seen_objects));
out("\n minutesDisplay: ");
TRY(print_value(print_context, js_string(duration_format.vm(), duration_format.minutes_display_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.minutes_display_string()), seen_objects));
out("\n seconds: ");
TRY(print_value(print_context, js_string(duration_format.vm(), duration_format.seconds_style_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.seconds_style_string()), seen_objects));
out("\n secondsDisplay: ");
TRY(print_value(print_context, js_string(duration_format.vm(), duration_format.seconds_display_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.seconds_display_string()), seen_objects));
out("\n milliseconds: ");
TRY(print_value(print_context, js_string(duration_format.vm(), duration_format.milliseconds_style_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.milliseconds_style_string()), seen_objects));
out("\n millisecondsDisplay: ");
TRY(print_value(print_context, js_string(duration_format.vm(), duration_format.milliseconds_display_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.milliseconds_display_string()), seen_objects));
out("\n microseconds: ");
TRY(print_value(print_context, js_string(duration_format.vm(), duration_format.microseconds_style_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.microseconds_style_string()), seen_objects));
out("\n microsecondsDisplay: ");
TRY(print_value(print_context, js_string(duration_format.vm(), duration_format.microseconds_display_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.microseconds_display_string()), seen_objects));
out("\n nanoseconds: ");
TRY(print_value(print_context, js_string(duration_format.vm(), duration_format.nanoseconds_style_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.nanoseconds_style_string()), seen_objects));
out("\n nanosecondsDisplay: ");
TRY(print_value(print_context, js_string(duration_format.vm(), duration_format.nanoseconds_display_string()), seen_objects));
TRY(print_value(print_context, JS::PrimitiveString::create(duration_format.vm(), duration_format.nanoseconds_display_string()), seen_objects));
if (duration_format.has_fractional_digits()) {
out("\n fractionalDigits: ");
TRY(print_value(print_context, JS::Value(duration_format.fractional_digits()), seen_objects));

View file

@ -46,7 +46,7 @@ ThrowCompletionOr<Object*> AggregateErrorConstructor::construct(FunctionObject&
if (!vm.argument(1).is_undefined()) {
auto message = TRY(vm.argument(1).to_string(vm));
aggregate_error->create_non_enumerable_data_property_or_throw(vm.names.message, js_string(vm, message));
aggregate_error->create_non_enumerable_data_property_or_throw(vm.names.message, PrimitiveString::create(vm, message));
}
TRY(aggregate_error->install_error_cause(vm.argument(2)));

View file

@ -20,8 +20,8 @@ void AggregateErrorPrototype::initialize(Realm& realm)
auto& vm = this->vm();
Object::initialize(realm);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_direct_property(vm.names.name, js_string(vm, "AggregateError"), attr);
define_direct_property(vm.names.message, js_string(vm, ""), attr);
define_direct_property(vm.names.name, PrimitiveString::create(vm, "AggregateError"), attr);
define_direct_property(vm.names.message, PrimitiveString::create(vm, ""), attr);
}
}

View file

@ -186,10 +186,10 @@ ThrowCompletionOr<double> compare_array_elements(VM& vm, Value x, Value y, Funct
}
// 5. Let xString be ? ToString(x).
auto* x_string = js_string(vm, TRY(x.to_string(vm)));
auto x_string = PrimitiveString::create(vm, TRY(x.to_string(vm)));
// 6. Let yString be ? ToString(y).
auto* y_string = js_string(vm, TRY(y.to_string(vm)));
auto y_string = PrimitiveString::create(vm, TRY(y.to_string(vm)));
// 7. Let xSmaller be ! IsLessThan(xString, yString, true).
auto x_smaller = MUST(is_less_than(vm, x_string, y_string, true));
@ -330,7 +330,7 @@ ThrowCompletionOr<MarkedVector<Value>> Array::internal_own_property_keys() const
auto& vm = this->vm();
auto keys = TRY(Object::internal_own_property_keys());
// FIXME: This is pretty expensive, find a better way to do this
keys.insert(indexed_properties().real_size(), js_string(vm, vm.names.length.as_string()));
keys.insert(indexed_properties().real_size(), PrimitiveString::create(vm, vm.names.length.as_string()));
return { move(keys) };
}

View file

@ -28,7 +28,7 @@ void ArrayBufferPrototype::initialize(Realm& realm)
define_native_accessor(realm, vm.names.byteLength, byte_length_getter, {}, Attribute::Configurable);
// 25.1.5.4 ArrayBuffer.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-arraybuffer.prototype-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, vm.names.ArrayBuffer.as_string()), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, vm.names.ArrayBuffer.as_string()), Attribute::Configurable);
}
// 25.1.5.3 ArrayBuffer.prototype.slice ( start, end ), https://tc39.es/ecma262/#sec-arraybuffer.prototype.slice

View file

@ -27,7 +27,7 @@ void ArrayIteratorPrototype::initialize(Realm& realm)
define_native_function(realm, vm.names.next, next, 0, Attribute::Configurable | Attribute::Writable);
// 23.1.5.2.2 %ArrayIteratorPrototype% [ @@toStringTag ], https://tc39.es/ecma262/#sec-%arrayiteratorprototype%-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Array Iterator"), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Array Iterator"), Attribute::Configurable);
}
// 23.1.5.2.1 %ArrayIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%arrayiteratorprototype%.next

View file

@ -991,7 +991,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::join)
// FWIW: engine262, a "100% spec compliant" ECMA-262 impl, aborts with "too much recursion".
// Same applies to Array.prototype.toLocaleString().
if (s_array_join_seen_objects.contains(this_object))
return js_string(vm, "");
return PrimitiveString::create(vm, "");
s_array_join_seen_objects.set(this_object);
ArmedScopeGuard unsee_object_guard = [&] {
s_array_join_seen_objects.remove(this_object);
@ -1012,7 +1012,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::join)
builder.append(string);
}
return js_string(vm, builder.to_deprecated_string());
return PrimitiveString::create(vm, builder.to_deprecated_string());
}
// 23.1.3.19 Array.prototype.keys ( ), https://tc39.es/ecma262/#sec-array.prototype.keys
@ -1702,7 +1702,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_locale_string)
auto* this_object = TRY(vm.this_value().to_object(vm));
if (s_array_join_seen_objects.contains(this_object))
return js_string(vm, "");
return PrimitiveString::create(vm, "");
s_array_join_seen_objects.set(this_object);
ArmedScopeGuard unsee_object_guard = [&] {
s_array_join_seen_objects.remove(this_object);
@ -1743,7 +1743,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_locale_string)
}
// 7. Return R.
return js_string(vm, builder.to_deprecated_string());
return PrimitiveString::create(vm, builder.to_deprecated_string());
}
// 1.1.1.4 Array.prototype.toReversed ( ), https://tc39.es/proposal-change-array-by-copy/#sec-array.prototype.toReversed

View file

@ -20,7 +20,7 @@ void AsyncFunctionPrototype::initialize(Realm& realm)
Object::initialize(realm);
// 27.7.3.2 AsyncFunction.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-async-function-prototype-properties-toStringTag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, vm.names.AsyncFunction.as_string()), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, vm.names.AsyncFunction.as_string()), Attribute::Configurable);
}
}

View file

@ -27,7 +27,7 @@ void AsyncGeneratorFunctionPrototype::initialize(Realm& realm)
define_direct_property(vm.names.prototype, realm.intrinsics().async_generator_prototype(), Attribute::Configurable);
// 27.4.3.3 AsyncGeneratorFunction.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-asyncgeneratorfunction-prototype-tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, vm.names.AsyncGeneratorFunction.as_string()), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, vm.names.AsyncGeneratorFunction.as_string()), Attribute::Configurable);
}
}

View file

@ -20,7 +20,7 @@ void AsyncGeneratorPrototype::initialize(Realm& realm)
Object::initialize(realm);
// 27.6.1.5 AsyncGenerator.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-asyncgenerator-prototype-tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "AsyncGenerator"), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "AsyncGenerator"), Attribute::Configurable);
}
}

View file

@ -147,7 +147,7 @@ void AtomicsObject::initialize(Realm& realm)
define_native_function(realm, vm.names.xor_, xor_, 3, attr);
// 25.4.15 Atomics [ @@toStringTag ], https://tc39.es/ecma262/#sec-atomics-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Atomics"), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Atomics"), Attribute::Configurable);
}
// 25.4.3 Atomics.add ( typedArray, index, value ), https://tc39.es/ecma262/#sec-atomics.add

View file

@ -32,7 +32,7 @@ void BigIntPrototype::initialize(Realm& realm)
define_native_function(realm, vm.names.valueOf, value_of, 0, attr);
// 21.2.3.5 BigInt.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-bigint.prototype-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, vm.names.BigInt.as_string()), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, vm.names.BigInt.as_string()), Attribute::Configurable);
}
// thisBigIntValue ( value ), https://tc39.es/ecma262/#thisbigintvalue
@ -55,7 +55,7 @@ JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::to_string)
if (radix < 2 || radix > 36)
return vm.throw_completion<RangeError>(ErrorType::InvalidRadix);
}
return js_string(vm, bigint->big_integer().to_base(radix));
return PrimitiveString::create(vm, bigint->big_integer().to_base(radix));
}
// 21.2.3.2 BigInt.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ), https://tc39.es/ecma262/#sec-bigint.prototype.tolocalestring
@ -75,7 +75,7 @@ JS_DEFINE_NATIVE_FUNCTION(BigIntPrototype::to_locale_string)
// 3. Return ? FormatNumeric(numberFormat, x).
auto formatted = Intl::format_numeric(vm, *number_format, Value(bigint));
return js_string(vm, move(formatted));
return PrimitiveString::create(vm, move(formatted));
}
// 21.2.3.4 BigInt.prototype.valueOf ( ), https://tc39.es/ecma262/#sec-bigint.prototype.valueof

View file

@ -31,12 +31,12 @@ JS_DEFINE_NATIVE_FUNCTION(BooleanPrototype::to_string)
{
auto this_value = vm.this_value();
if (this_value.is_boolean())
return js_string(vm, this_value.as_bool() ? "true" : "false");
return PrimitiveString::create(vm, this_value.as_bool() ? "true" : "false");
if (!this_value.is_object() || !is<BooleanObject>(this_value.as_object()))
return vm.throw_completion<TypeError>(ErrorType::NotAnObjectOfType, "Boolean");
bool bool_value = static_cast<BooleanObject const&>(this_value.as_object()).boolean();
return js_string(vm, bool_value ? "true" : "false");
return PrimitiveString::create(vm, bool_value ? "true" : "false");
}
// 20.3.3.3 Boolean.prototype.valueOf ( ), https://tc39.es/ecma262/#sec-boolean.prototype.valueof

View file

@ -47,7 +47,7 @@ void DataViewPrototype::initialize(Realm& realm)
define_native_accessor(realm, vm.names.byteOffset, byte_offset_getter, {}, Attribute::Configurable);
// 25.3.4.25 DataView.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-dataview.prototype-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, vm.names.DataView.as_string()), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, vm.names.DataView.as_string()), Attribute::Configurable);
}
// 25.3.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ), https://tc39.es/ecma262/#sec-getviewvalue

View file

@ -202,7 +202,7 @@ ThrowCompletionOr<Value> DateConstructor::call()
auto now = AK::Time::now_realtime().to_milliseconds();
// b. Return ToDateString(now).
return js_string(vm(), to_date_string(now));
return PrimitiveString::create(vm(), to_date_string(now));
}
// 21.4.2.1 Date ( ...values ), https://tc39.es/ecma262/#sec-date

View file

@ -951,11 +951,11 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_date_string)
// 3. If tv is NaN, return "Invalid Date".
if (isnan(time))
return js_string(vm, "Invalid Date"sv);
return PrimitiveString::create(vm, "Invalid Date"sv);
// 4. Let t be LocalTime(tv).
// 5. Return DateString(t).
return js_string(vm, date_string(local_time(time)));
return PrimitiveString::create(vm, date_string(local_time(time)));
}
// 21.4.4.36 Date.prototype.toISOString ( ), https://tc39.es/ecma262/#sec-date.prototype.toisostring
@ -967,7 +967,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_iso_string)
return vm.throw_completion<RangeError>(ErrorType::InvalidTimeValue);
auto string = this_object->iso_date_string();
return js_string(vm, move(string));
return PrimitiveString::create(vm, move(string));
}
// 21.4.4.37 Date.prototype.toJSON ( key ), https://tc39.es/ecma262/#sec-date.prototype.tojson
@ -1002,7 +1002,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_locale_date_string)
// 2. If x is NaN, return "Invalid Date".
if (isnan(time))
return js_string(vm, "Invalid Date"sv);
return PrimitiveString::create(vm, "Invalid Date"sv);
// 3. Let options be ? ToDateTimeOptions(options, "date", "date").
options = Value(TRY(Intl::to_date_time_options(vm, options, Intl::OptionRequired::Date, Intl::OptionDefaults::Date)));
@ -1012,7 +1012,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_locale_date_string)
// 5. Return ? FormatDateTime(dateFormat, x).
auto formatted = TRY(Intl::format_date_time(vm, *date_format, time));
return js_string(vm, move(formatted));
return PrimitiveString::create(vm, move(formatted));
}
// 21.4.4.39 Date.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ), https://tc39.es/ecma262/#sec-date.prototype.tolocalestring
@ -1027,7 +1027,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_locale_string)
// 2. If x is NaN, return "Invalid Date".
if (isnan(time))
return js_string(vm, "Invalid Date"sv);
return PrimitiveString::create(vm, "Invalid Date"sv);
// 3. Let options be ? ToDateTimeOptions(options, "any", "all").
options = Value(TRY(Intl::to_date_time_options(vm, options, Intl::OptionRequired::Any, Intl::OptionDefaults::All)));
@ -1037,7 +1037,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_locale_string)
// 5. Return ? FormatDateTime(dateFormat, x).
auto formatted = TRY(Intl::format_date_time(vm, *date_format, time));
return js_string(vm, move(formatted));
return PrimitiveString::create(vm, move(formatted));
}
// 21.4.4.40 Date.prototype.toLocaleTimeString ( [ reserved1 [ , reserved2 ] ] ), https://tc39.es/ecma262/#sec-date.prototype.tolocaletimestring
@ -1052,7 +1052,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_locale_time_string)
// 2. If x is NaN, return "Invalid Date".
if (isnan(time))
return js_string(vm, "Invalid Date"sv);
return PrimitiveString::create(vm, "Invalid Date"sv);
// 3. Let options be ? ToDateTimeOptions(options, "time", "time").
options = Value(TRY(Intl::to_date_time_options(vm, options, Intl::OptionRequired::Time, Intl::OptionDefaults::Time)));
@ -1062,7 +1062,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_locale_time_string)
// 5. Return ? FormatDateTime(dateFormat, x).
auto formatted = TRY(Intl::format_date_time(vm, *time_format, time));
return js_string(vm, move(formatted));
return PrimitiveString::create(vm, move(formatted));
}
// 21.4.4.41 Date.prototype.toString ( ), https://tc39.es/ecma262/#sec-date.prototype.tostring
@ -1072,7 +1072,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_string)
auto time = TRY(this_time_value(vm, vm.this_value()));
// 2. Return ToDateString(tv).
return js_string(vm, JS::to_date_string(time));
return PrimitiveString::create(vm, JS::to_date_string(time));
}
// 21.4.4.41.1 TimeString ( tv ), https://tc39.es/ecma262/#sec-timestring
@ -1209,12 +1209,12 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_time_string)
// 3. If tv is NaN, return "Invalid Date".
if (isnan(time))
return js_string(vm, "Invalid Date"sv);
return PrimitiveString::create(vm, "Invalid Date"sv);
// 4. Let t be LocalTime(tv).
// 5. Return the string-concatenation of TimeString(t) and TimeZoneString(tv).
auto string = DeprecatedString::formatted("{}{}", time_string(local_time(time)), time_zone_string(time));
return js_string(vm, move(string));
return PrimitiveString::create(vm, move(string));
}
// 21.4.4.43 Date.prototype.toUTCString ( ), https://tc39.es/ecma262/#sec-date.prototype.toutcstring
@ -1226,7 +1226,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_utc_string)
// 3. If tv is NaN, return "Invalid Date".
if (isnan(time))
return js_string(vm, "Invalid Date"sv);
return PrimitiveString::create(vm, "Invalid Date"sv);
// 4. Let weekday be the Name of the entry in Table 62 with the Number WeekDay(tv).
auto weekday = short_day_names[week_day(time)];
@ -1246,7 +1246,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_utc_string)
// 9. Let paddedYear be ToZeroPaddedDecimalString(abs((yv)), 4).
// 10. Return the string-concatenation of weekday, ",", the code unit 0x0020 (SPACE), day, the code unit 0x0020 (SPACE), month, the code unit 0x0020 (SPACE), yearSign, paddedYear, the code unit 0x0020 (SPACE), and TimeString(tv).
auto string = DeprecatedString::formatted("{}, {:02} {} {}{:04} {}", weekday, day, month, year_sign, abs(year), time_string(time));
return js_string(vm, move(string));
return PrimitiveString::create(vm, move(string));
}
// 21.4.4.45 Date.prototype [ @@toPrimitive ] ( hint ), https://tc39.es/ecma262/#sec-date.prototype-@@toprimitive

View file

@ -108,7 +108,7 @@ void ECMAScriptFunctionObject::initialize(Realm& realm)
// are defined in the spec.
MUST(define_property_or_throw(vm.names.length, { .value = Value(m_function_length), .writable = false, .enumerable = false, .configurable = true }));
MUST(define_property_or_throw(vm.names.name, { .value = js_string(vm, m_name.is_null() ? "" : m_name), .writable = false, .enumerable = false, .configurable = true }));
MUST(define_property_or_throw(vm.names.name, { .value = PrimitiveString::create(vm, m_name.is_null() ? "" : m_name), .writable = false, .enumerable = false, .configurable = true }));
if (!m_is_arrow_function) {
Object* prototype = nullptr;
@ -911,7 +911,7 @@ void ECMAScriptFunctionObject::set_name(FlyString const& name)
VERIFY(!name.is_null());
auto& vm = this->vm();
m_name = name;
MUST(define_property_or_throw(vm.names.name, { .value = js_string(vm, m_name), .writable = false, .enumerable = false, .configurable = true }));
MUST(define_property_or_throw(vm.names.name, { .value = PrimitiveString::create(vm, m_name), .writable = false, .enumerable = false, .configurable = true }));
}
}

View file

@ -24,7 +24,7 @@ Error* Error::create(Realm& realm, DeprecatedString const& message)
auto& vm = realm.vm();
auto* error = Error::create(realm);
u8 attr = Attribute::Writable | Attribute::Configurable;
error->define_direct_property(vm.names.message, js_string(vm, message), attr);
error->define_direct_property(vm.names.message, PrimitiveString::create(vm, message), attr);
return error;
}
@ -109,7 +109,7 @@ DeprecatedString Error::stack_string() const
auto& vm = realm.vm(); \
auto* error = ClassName::create(realm); \
u8 attr = Attribute::Writable | Attribute::Configurable; \
error->define_direct_property(vm.names.message, js_string(vm, message), attr); \
error->define_direct_property(vm.names.message, PrimitiveString::create(vm, message), attr); \
return error; \
} \
\

View file

@ -51,7 +51,7 @@ ThrowCompletionOr<Object*> ErrorConstructor::construct(FunctionObject& new_targe
auto msg = TRY(message.to_string(vm));
// b. Perform CreateNonEnumerableDataPropertyOrThrow(O, "message", msg).
error->create_non_enumerable_data_property_or_throw(vm.names.message, js_string(vm, move(msg)));
error->create_non_enumerable_data_property_or_throw(vm.names.message, PrimitiveString::create(vm, move(msg)));
}
// 4. Perform ? InstallErrorCause(O, options).
@ -104,7 +104,7 @@ ThrowCompletionOr<Object*> ErrorConstructor::construct(FunctionObject& new_targe
auto msg = TRY(message.to_string(vm)); \
\
/* b. Perform CreateNonEnumerableDataPropertyOrThrow(O, "message", msg). */ \
error->create_non_enumerable_data_property_or_throw(vm.names.message, js_string(vm, move(msg))); \
error->create_non_enumerable_data_property_or_throw(vm.names.message, PrimitiveString::create(vm, move(msg))); \
} \
\
/* 4. Perform ? InstallErrorCause(O, options). */ \

View file

@ -24,8 +24,8 @@ void ErrorPrototype::initialize(Realm& realm)
auto& vm = this->vm();
Object::initialize(realm);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_direct_property(vm.names.name, js_string(vm, "Error"), attr);
define_direct_property(vm.names.message, js_string(vm, ""), attr);
define_direct_property(vm.names.name, PrimitiveString::create(vm, "Error"), attr);
define_direct_property(vm.names.message, PrimitiveString::create(vm, ""), attr);
define_native_function(realm, vm.names.toString, to_string, 0, attr);
// Non standard property "stack"
// Every other engine seems to have this in some way or another, and the spec
@ -58,14 +58,14 @@ JS_DEFINE_NATIVE_FUNCTION(ErrorPrototype::to_string)
// 7. If name is the empty String, return msg.
if (name.is_empty())
return js_string(vm, message);
return PrimitiveString::create(vm, message);
// 8. If msg is the empty String, return name.
if (message.is_empty())
return js_string(vm, name);
return PrimitiveString::create(vm, name);
// 9. Return the string-concatenation of name, the code unit 0x003A (COLON), the code unit 0x0020 (SPACE), and msg.
return js_string(vm, DeprecatedString::formatted("{}: {}", name, message));
return PrimitiveString::create(vm, DeprecatedString::formatted("{}: {}", name, message));
}
// B.1.1 get Error.prototype.stack ( ), https://tc39.es/proposal-error-stacks/#sec-get-error.prototype-stack
@ -98,7 +98,7 @@ JS_DEFINE_NATIVE_FUNCTION(ErrorPrototype::stack_getter)
if (!message.is_empty())
header = DeprecatedString::formatted("{}: {}", name, message);
return js_string(vm, DeprecatedString::formatted("{}\n{}", header, error.stack_string()));
return PrimitiveString::create(vm, DeprecatedString::formatted("{}\n{}", header, error.stack_string()));
}
// B.1.2 set Error.prototype.stack ( value ), https://tc39.es/proposal-error-stacks/#sec-set-error.prototype-stack
@ -122,19 +122,19 @@ JS_DEFINE_NATIVE_FUNCTION(ErrorPrototype::stack_setter)
return TRY(this_object.create_data_property_or_throw(vm.names.stack, vm.argument(0)));
}
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
PrototypeName::PrototypeName(Realm& realm) \
: PrototypeObject(*realm.intrinsics().error_prototype()) \
{ \
} \
\
void PrototypeName::initialize(Realm& realm) \
{ \
auto& vm = this->vm(); \
Object::initialize(realm); \
u8 attr = Attribute::Writable | Attribute::Configurable; \
define_direct_property(vm.names.name, js_string(vm, #ClassName), attr); \
define_direct_property(vm.names.message, js_string(vm, ""), attr); \
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
PrototypeName::PrototypeName(Realm& realm) \
: PrototypeObject(*realm.intrinsics().error_prototype()) \
{ \
} \
\
void PrototypeName::initialize(Realm& realm) \
{ \
auto& vm = this->vm(); \
Object::initialize(realm); \
u8 attr = Attribute::Writable | Attribute::Configurable; \
define_direct_property(vm.names.name, PrimitiveString::create(vm, #ClassName), attr); \
define_direct_property(vm.names.message, PrimitiveString::create(vm, ""), attr); \
}
JS_ENUMERATE_NATIVE_ERRORS

View file

@ -26,7 +26,7 @@ void FinalizationRegistryPrototype::initialize(Realm& realm)
define_native_function(realm, vm.names.unregister, unregister, 1, attr);
// 26.2.3.4 FinalizationRegistry.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-finalization-registry.prototype-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, vm.names.FinalizationRegistry.as_string()), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, vm.names.FinalizationRegistry.as_string()), Attribute::Configurable);
}
// @STAGE 2@ FinalizationRegistry.prototype.cleanupSome ( [ callback ] ), https://github.com/tc39/proposal-cleanup-some/blob/master/spec/finalization-registry.html

View file

@ -119,7 +119,7 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> FunctionConstructor::create_dynamic
// 10. If argCount = 0, let bodyArg be the empty String.
if (arg_count == 0) {
// Optimization: Instead of creating a js_string() here, we just check if body_arg is empty in step 16.
// Optimization: Instead of creating a PrimitiveString here, we just check if body_arg is empty in step 16.
}
// 11. Else if argCount = 1, let bodyArg be args[0].
else if (arg_count == 1) {

View file

@ -75,7 +75,7 @@ void FunctionObject::set_function_name(Variant<PropertyKey, PrivateName> const&
}
// 6. Perform ! DefinePropertyOrThrow(F, "name", PropertyDescriptor { [[Value]]: name, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }).
MUST(define_property_or_throw(vm.names.name, PropertyDescriptor { .value = js_string(vm, move(name)), .writable = false, .enumerable = false, .configurable = true }));
MUST(define_property_or_throw(vm.names.name, PropertyDescriptor { .value = PrimitiveString::create(vm, move(name)), .writable = false, .enumerable = false, .configurable = true }));
// 7. Return unused.
}

View file

@ -36,7 +36,7 @@ void FunctionPrototype::initialize(Realm& realm)
define_native_function(realm, vm.names.toString, to_string, 0, attr);
define_native_function(realm, *vm.well_known_symbol_has_instance(), symbol_has_instance, 1, 0);
define_direct_property(vm.names.length, Value(0), Attribute::Configurable);
define_direct_property(vm.names.name, js_string(heap(), ""), Attribute::Configurable);
define_direct_property(vm.names.name, PrimitiveString::create(vm, ""), Attribute::Configurable);
}
ThrowCompletionOr<Value> FunctionPrototype::internal_call(Value, MarkedVector<Value>)
@ -156,7 +156,7 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::to_string)
// 2. If Type(func) is Object and func has a [[SourceText]] internal slot and func.[[SourceText]] is a sequence of Unicode code points and HostHasSourceTextAvailable(func) is true, then
if (is<ECMAScriptFunctionObject>(function)) {
// a. Return CodePointsToString(func.[[SourceText]]).
return js_string(vm, static_cast<ECMAScriptFunctionObject&>(function).source_text());
return PrimitiveString::create(vm, static_cast<ECMAScriptFunctionObject&>(function).source_text());
}
// 3. If func is a built-in function object, return an implementation-defined String source code representation of func. The representation must have the syntax of a NativeFunction. Additionally, if func has an [[InitialName]] internal slot and func.[[InitialName]] is a String, the portion of the returned String that would be matched by NativeFunctionAccessor[opt] PropertyName must be the value of func.[[InitialName]].
@ -164,12 +164,12 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::to_string)
// NOTE: once we remove name(), the fallback here can simply be an empty string.
auto const& native_function = static_cast<NativeFunction&>(function);
auto const name = native_function.initial_name().value_or(native_function.name());
return js_string(vm, DeprecatedString::formatted("function {}() {{ [native code] }}", name));
return PrimitiveString::create(vm, DeprecatedString::formatted("function {}() {{ [native code] }}", name));
}
// 4. If Type(func) is Object and IsCallable(func) is true, return an implementation-defined String source code representation of func. The representation must have the syntax of a NativeFunction.
// NOTE: ProxyObject, BoundFunction, WrappedFunction
return js_string(vm, "function () { [native code] }");
return PrimitiveString::create(vm, "function () { [native code] }");
}
// 20.2.3.6 Function.prototype [ @@hasInstance ] ( V ), https://tc39.es/ecma262/#sec-function.prototype-@@hasinstance

View file

@ -23,7 +23,7 @@ void GeneratorFunctionPrototype::initialize(Realm& realm)
// 27.3.3.2 GeneratorFunction.prototype.prototype, https://tc39.es/ecma262/#sec-generatorfunction.prototype.prototype
define_direct_property(vm.names.prototype, realm.intrinsics().generator_prototype(), Attribute::Configurable);
// 27.3.3.3 GeneratorFunction.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-generatorfunction.prototype-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "GeneratorFunction"), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "GeneratorFunction"), Attribute::Configurable);
}
}

View file

@ -24,7 +24,7 @@ void GeneratorPrototype::initialize(Realm& realm)
define_native_function(realm, vm.names.throw_, throw_, 1, attr);
// 27.5.1.5 Generator.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-generator.prototype-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Generator"), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Generator"), Attribute::Configurable);
}
// 27.5.1.2 Generator.prototype.next ( value ), https://tc39.es/ecma262/#sec-generator.prototype.next

View file

@ -226,7 +226,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::parse_float)
if (vm.argument(0).is_number())
return vm.argument(0);
auto input_string = TRY(vm.argument(0).to_string(vm));
auto trimmed_string = MUST(trim_string(vm, js_string(vm, input_string), TrimMode::Left));
auto trimmed_string = MUST(trim_string(vm, PrimitiveString::create(vm, input_string), TrimMode::Left));
if (trimmed_string.is_empty())
return js_nan();
@ -253,7 +253,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::parse_int)
auto input_string = TRY(vm.argument(0).to_string(vm));
// 2. Let S be ! TrimString(inputString, start).
auto string = MUST(trim_string(vm, js_string(vm, input_string), TrimMode::Left));
auto string = MUST(trim_string(vm, PrimitiveString::create(vm, input_string), TrimMode::Left));
// 3. Let sign be 1.
auto sign = 1;
@ -458,7 +458,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::encode_uri)
{
auto uri_string = TRY(vm.argument(0).to_string(vm));
auto encoded = TRY(encode(vm, uri_string, ";/?:@&=+$,abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.!~*'()#"sv));
return js_string(vm, move(encoded));
return PrimitiveString::create(vm, move(encoded));
}
// 19.2.6.2 decodeURI ( encodedURI ), https://tc39.es/ecma262/#sec-decodeuri-encodeduri
@ -466,7 +466,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::decode_uri)
{
auto uri_string = TRY(vm.argument(0).to_string(vm));
auto decoded = TRY(decode(vm, uri_string, ";/?:@&=+$,#"sv));
return js_string(vm, move(decoded));
return PrimitiveString::create(vm, move(decoded));
}
// 19.2.6.5 encodeURIComponent ( uriComponent ), https://tc39.es/ecma262/#sec-encodeuricomponent-uricomponent
@ -474,7 +474,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::encode_uri_component)
{
auto uri_string = TRY(vm.argument(0).to_string(vm));
auto encoded = TRY(encode(vm, uri_string, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.!~*'()"sv));
return js_string(vm, move(encoded));
return PrimitiveString::create(vm, move(encoded));
}
// 19.2.6.3 decodeURIComponent ( encodedURIComponent ), https://tc39.es/ecma262/#sec-decodeuricomponent-encodeduricomponent
@ -482,7 +482,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::decode_uri_component)
{
auto uri_string = TRY(vm.argument(0).to_string(vm));
auto decoded = TRY(decode(vm, uri_string, ""sv));
return js_string(vm, move(decoded));
return PrimitiveString::create(vm, move(decoded));
}
// B.2.1.1 escape ( string ), https://tc39.es/ecma262/#sec-escape-string
@ -500,7 +500,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::escape)
}
escaped.appendff("%u{:04X}", code_point);
}
return js_string(vm, escaped.build());
return PrimitiveString::create(vm, escaped.build());
}
// B.2.1.2 unescape ( string ), https://tc39.es/ecma262/#sec-unescape-string
@ -522,7 +522,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::unescape)
}
unescaped.append_code_point(code_point);
}
return js_string(vm, unescaped.build());
return PrimitiveString::create(vm, unescaped.build());
}
}

View file

@ -589,7 +589,7 @@ ThrowCompletionOr<Array*> supported_locales(VM& vm, Vector<DeprecatedString> con
}
// 5. Return CreateArrayFromList(supportedLocales).
return Array::create_from<DeprecatedString>(realm, supported_locales, [&vm](auto& locale) { return js_string(vm, locale); });
return Array::create_from<DeprecatedString>(realm, supported_locales, [&vm](auto& locale) { return PrimitiveString::create(vm, locale); });
}
// 9.2.12 CoerceOptionsToObject ( options ), https://tc39.es/ecma402/#sec-coerceoptionstoobject

View file

@ -26,7 +26,7 @@ void CollatorCompareFunction::initialize(Realm&)
{
auto& vm = this->vm();
define_direct_property(vm.names.length, Value(2), Attribute::Configurable);
define_direct_property(vm.names.name, js_string(vm, DeprecatedString::empty()), Attribute::Configurable);
define_direct_property(vm.names.name, PrimitiveString::create(vm, DeprecatedString::empty()), Attribute::Configurable);
}
// 10.3.3.2 CompareStrings ( collator, x, y ), https://tc39.es/ecma402/#sec-collator-comparestrings

View file

@ -88,7 +88,7 @@ static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collat
// 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").
collator.set_numeric(same_value(js_string(vm, result.kn.release_value()), js_string(vm, "true"sv)));
collator.set_numeric(same_value(PrimitiveString::create(vm, result.kn.release_value()), PrimitiveString::create(vm, "true"sv)));
}
// 25. If relevantExtensionKeys contains "kf", then
@ -105,14 +105,14 @@ static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collat
// a. If usage is "sort", then
if (collator.usage() == Collator::Usage::Sort) {
// i. Let sensitivity be "variant".
sensitivity = js_string(vm, "variant"sv);
sensitivity = PrimitiveString::create(vm, "variant"sv);
}
// b. Else,
else {
// i. Let dataLocale be r.[[dataLocale]].
// ii. Let dataLocaleData be localeData.[[<dataLocale>]].
// iii. Let sensitivity be dataLocaleData.[[sensitivity]].
sensitivity = js_string(vm, "base"sv);
sensitivity = PrimitiveString::create(vm, "base"sv);
}
}

View file

@ -24,7 +24,7 @@ void CollatorPrototype::initialize(Realm& realm)
auto& vm = this->vm();
// 10.3.2 Intl.Collator.prototype [ @@toStringTag ], https://tc39.es/ecma402/#sec-intl.collator.prototype-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Intl.Collator"), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Intl.Collator"), Attribute::Configurable);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_accessor(realm, vm.names.compare, compare_getter, {}, attr);
@ -75,13 +75,13 @@ JS_DEFINE_NATIVE_FUNCTION(CollatorPrototype::resolved_options)
// 1. Let v be undefined.
// d. If v is not undefined, then
// i. Perform ! CreateDataPropertyOrThrow(options, p, v).
MUST(options->create_data_property_or_throw(vm.names.locale, js_string(vm, collator->locale())));
MUST(options->create_data_property_or_throw(vm.names.usage, js_string(vm, collator->usage_string())));
MUST(options->create_data_property_or_throw(vm.names.sensitivity, js_string(vm, collator->sensitivity_string())));
MUST(options->create_data_property_or_throw(vm.names.locale, PrimitiveString::create(vm, collator->locale())));
MUST(options->create_data_property_or_throw(vm.names.usage, PrimitiveString::create(vm, collator->usage_string())));
MUST(options->create_data_property_or_throw(vm.names.sensitivity, PrimitiveString::create(vm, collator->sensitivity_string())));
MUST(options->create_data_property_or_throw(vm.names.ignorePunctuation, Value(collator->ignore_punctuation())));
MUST(options->create_data_property_or_throw(vm.names.collation, js_string(vm, collator->collation())));
MUST(options->create_data_property_or_throw(vm.names.collation, PrimitiveString::create(vm, collator->collation())));
MUST(options->create_data_property_or_throw(vm.names.numeric, Value(collator->numeric())));
MUST(options->create_data_property_or_throw(vm.names.caseFirst, js_string(vm, collator->case_first_string())));
MUST(options->create_data_property_or_throw(vm.names.caseFirst, PrimitiveString::create(vm, collator->case_first_string())));
// 5. Return options.
return options;

View file

@ -135,7 +135,7 @@ ThrowCompletionOr<Object*> to_date_time_options(VM& vm, Value options_value, Opt
// a. For each property name prop of « "year", "month", "day" », do
for (auto const& property : AK::Array { vm.names.year, vm.names.month, vm.names.day }) {
// i. Perform ? CreateDataPropertyOrThrow(options, prop, "numeric").
TRY(options->create_data_property_or_throw(property, js_string(vm, "numeric"sv)));
TRY(options->create_data_property_or_throw(property, PrimitiveString::create(vm, "numeric"sv)));
}
}
@ -144,7 +144,7 @@ ThrowCompletionOr<Object*> to_date_time_options(VM& vm, Value options_value, Opt
// a. For each property name prop of « "hour", "minute", "second" », do
for (auto const& property : AK::Array { vm.names.hour, vm.names.minute, vm.names.second }) {
// i. Perform ? CreateDataPropertyOrThrow(options, prop, "numeric").
TRY(options->create_data_property_or_throw(property, js_string(vm, "numeric"sv)));
TRY(options->create_data_property_or_throw(property, PrimitiveString::create(vm, "numeric"sv)));
}
}
@ -548,7 +548,7 @@ ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(VM& vm, Dat
auto const& data_locale = date_time_format.data_locale();
auto construct_number_format = [&](auto* options) -> ThrowCompletionOr<NumberFormat*> {
auto* number_format = TRY(construct(vm, *realm.intrinsics().intl_number_format_constructor(), js_string(vm, locale), options));
auto* number_format = TRY(construct(vm, *realm.intrinsics().intl_number_format_constructor(), PrimitiveString::create(vm, locale), options));
return static_cast<NumberFormat*>(number_format);
};
@ -868,10 +868,10 @@ ThrowCompletionOr<Array*> format_date_time_to_parts(VM& vm, DateTimeFormat& date
auto* object = Object::create(realm, realm.intrinsics().object_prototype());
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));
MUST(object->create_data_property_or_throw(vm.names.type, PrimitiveString::create(vm, part.type)));
// c. Perform ! CreateDataPropertyOrThrow(O, "value", part.[[Value]]).
MUST(object->create_data_property_or_throw(vm.names.value, js_string(vm, move(part.value))));
MUST(object->create_data_property_or_throw(vm.names.value, PrimitiveString::create(vm, move(part.value))));
// d. Perform ! CreateDataProperty(result, ! ToString(n), O).
MUST(result->create_data_property_or_throw(n, object));
@ -1184,13 +1184,13 @@ ThrowCompletionOr<Array*> format_date_time_range_to_parts(VM& vm, DateTimeFormat
auto* object = Object::create(realm, realm.intrinsics().object_prototype());
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));
MUST(object->create_data_property_or_throw(vm.names.type, PrimitiveString::create(vm, part.type)));
// c. Perform ! CreateDataPropertyOrThrow(O, "value", part.[[Value]]).
MUST(object->create_data_property_or_throw(vm.names.value, js_string(vm, move(part.value))));
MUST(object->create_data_property_or_throw(vm.names.value, PrimitiveString::create(vm, move(part.value))));
// d. Perform ! CreateDataPropertyOrThrow(O, "source", part.[[Source]]).
MUST(object->create_data_property_or_throw(vm.names.source, js_string(vm, part.source)));
MUST(object->create_data_property_or_throw(vm.names.source, PrimitiveString::create(vm, part.source)));
// e. Perform ! CreateDataProperty(result, ! ToString(n), O).
MUST(result->create_data_property_or_throw(n, object));

View file

@ -31,7 +31,7 @@ void DateTimeFormatFunction::initialize(Realm& realm)
Base::initialize(realm);
define_direct_property(vm.names.length, Value(1), Attribute::Configurable);
define_direct_property(vm.names.name, js_string(vm, DeprecatedString::empty()), Attribute::Configurable);
define_direct_property(vm.names.name, PrimitiveString::create(vm, DeprecatedString::empty()), Attribute::Configurable);
}
ThrowCompletionOr<Value> DateTimeFormatFunction::call()
@ -59,7 +59,7 @@ ThrowCompletionOr<Value> DateTimeFormatFunction::call()
// 5. Return ? FormatDateTime(dtf, x).
auto formatted = TRY(format_date_time(vm, m_date_time_format, date_value));
return js_string(vm, move(formatted));
return PrimitiveString::create(vm, move(formatted));
}
void DateTimeFormatFunction::visit_edges(Cell::Visitor& visitor)

View file

@ -26,7 +26,7 @@ void DateTimeFormatPrototype::initialize(Realm& realm)
auto& vm = this->vm();
// 11.3.2 Intl.DateTimeFormat.prototype [ @@toStringTag ], https://tc39.es/ecma402/#sec-intl.datetimeformat.prototype-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Intl.DateTimeFormat"), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Intl.DateTimeFormat"), Attribute::Configurable);
define_native_accessor(realm, vm.names.format, format, nullptr, Attribute::Configurable);
@ -114,7 +114,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format_range)
// 6. Return ? FormatDateTimeRange(dtf, x, y).
auto formatted = TRY(format_date_time_range(vm, *date_time_format, start_date_number, end_date_number));
return js_string(vm, move(formatted));
return PrimitiveString::create(vm, move(formatted));
}
// 11.3.6 Intl.DateTimeFormat.prototype.formatRangeToParts ( startDate, endDate ), https://tc39.es/ecma402/#sec-Intl.DateTimeFormat.prototype.formatRangeToParts
@ -171,13 +171,13 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::resolved_options)
// 1. Let v be undefined.
// e. If v is not undefined, then
// i. Perform ! CreateDataPropertyOrThrow(options, p, v).
MUST(options->create_data_property_or_throw(vm.names.locale, js_string(vm, date_time_format->locale())));
MUST(options->create_data_property_or_throw(vm.names.calendar, js_string(vm, date_time_format->calendar())));
MUST(options->create_data_property_or_throw(vm.names.numberingSystem, js_string(vm, date_time_format->numbering_system())));
MUST(options->create_data_property_or_throw(vm.names.timeZone, js_string(vm, date_time_format->time_zone())));
MUST(options->create_data_property_or_throw(vm.names.locale, PrimitiveString::create(vm, date_time_format->locale())));
MUST(options->create_data_property_or_throw(vm.names.calendar, PrimitiveString::create(vm, date_time_format->calendar())));
MUST(options->create_data_property_or_throw(vm.names.numberingSystem, PrimitiveString::create(vm, date_time_format->numbering_system())));
MUST(options->create_data_property_or_throw(vm.names.timeZone, PrimitiveString::create(vm, date_time_format->time_zone())));
if (date_time_format->has_hour_cycle()) {
MUST(options->create_data_property_or_throw(vm.names.hourCycle, js_string(vm, date_time_format->hour_cycle_string())));
MUST(options->create_data_property_or_throw(vm.names.hourCycle, PrimitiveString::create(vm, date_time_format->hour_cycle_string())));
switch (date_time_format->hour_cycle()) {
case ::Locale::HourCycle::H11:
@ -202,7 +202,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::resolved_options)
TRY(options->create_data_property_or_throw(property, Value(*option)));
} else {
auto name = ::Locale::calendar_pattern_style_to_string(*option);
TRY(options->create_data_property_or_throw(property, js_string(vm, name)));
TRY(options->create_data_property_or_throw(property, PrimitiveString::create(vm, name)));
}
return {};
@ -210,9 +210,9 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::resolved_options)
}
if (date_time_format->has_date_style())
MUST(options->create_data_property_or_throw(vm.names.dateStyle, js_string(vm, date_time_format->date_style_string())));
MUST(options->create_data_property_or_throw(vm.names.dateStyle, PrimitiveString::create(vm, date_time_format->date_style_string())));
if (date_time_format->has_time_style())
MUST(options->create_data_property_or_throw(vm.names.timeStyle, js_string(vm, date_time_format->time_style_string())));
MUST(options->create_data_property_or_throw(vm.names.timeStyle, PrimitiveString::create(vm, date_time_format->time_style_string())));
// 6. Return options.
return options;

View file

@ -116,7 +116,7 @@ ThrowCompletionOr<Value> canonical_code_for_display_names(VM& vm, DisplayNames::
// c. Return ! CanonicalizeUnicodeLocaleId(code).
auto canonicalized_tag = JS::Intl::canonicalize_unicode_locale_id(*locale_id);
return js_string(vm, move(canonicalized_tag));
return PrimitiveString::create(vm, move(canonicalized_tag));
}
// 2. If type is "region", then
@ -126,7 +126,7 @@ ThrowCompletionOr<Value> canonical_code_for_display_names(VM& vm, DisplayNames::
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, code, "region"sv);
// b. Return the ASCII-uppercase of code.
return js_string(vm, code.to_uppercase_string());
return PrimitiveString::create(vm, code.to_uppercase_string());
}
// 3. If type is "script", then
@ -142,7 +142,7 @@ ThrowCompletionOr<Value> canonical_code_for_display_names(VM& vm, DisplayNames::
// c. Let first be the ASCII-uppercase of the substring of code from 0 to 1.
// d. Let rest be the ASCII-lowercase of the substring of code from 1.
// e. Return the string-concatenation of first and rest.
return js_string(vm, code.to_titlecase_string());
return PrimitiveString::create(vm, code.to_titlecase_string());
}
// 4. If type is "calendar", then
@ -156,7 +156,7 @@ ThrowCompletionOr<Value> canonical_code_for_display_names(VM& vm, DisplayNames::
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, code, "calendar"sv);
// c. Return the ASCII-lowercase of code.
return js_string(vm, code.to_lowercase_string());
return PrimitiveString::create(vm, code.to_lowercase_string());
}
// 5. If type is "dateTimeField", then
@ -166,7 +166,7 @@ ThrowCompletionOr<Value> canonical_code_for_display_names(VM& vm, DisplayNames::
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, code, "dateTimeField"sv);
// b. Return code.
return js_string(vm, code);
return PrimitiveString::create(vm, code);
}
// 6. Assert: type is "currency".
@ -177,7 +177,7 @@ ThrowCompletionOr<Value> canonical_code_for_display_names(VM& vm, DisplayNames::
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, code, "currency"sv);
// 8. Return the ASCII-uppercase of code.
return js_string(vm, code.to_uppercase_string());
return PrimitiveString::create(vm, code.to_uppercase_string());
}
// 12.5.2 IsValidDateTimeFieldCode ( field ), https://tc39.es/ecma402/#sec-isvaliddatetimefieldcode

View file

@ -26,7 +26,7 @@ void DisplayNamesPrototype::initialize(Realm& realm)
auto& vm = this->vm();
// 12.3.2 Intl.DisplayNames.prototype[ @@toStringTag ], https://tc39.es/ecma402/#sec-Intl.DisplayNames.prototype-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Intl.DisplayNames"), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Intl.DisplayNames"), Attribute::Configurable);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(realm, vm.names.of, of, 1, attr);
@ -44,7 +44,7 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::of)
// 3. Let code be ? ToString(code).
auto code_string = TRY(code.to_string(vm));
code = js_string(vm, move(code_string));
code = PrimitiveString::create(vm, move(code_string));
// 4. Let code be ? CanonicalCodeForDisplayNames(displayNames.[[Type]], code).
code = TRY(canonical_code_for_display_names(vm, display_names->type(), code.as_string().deprecated_string()));
@ -109,9 +109,9 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::of)
}
if (result.has_value())
return js_string(vm, result.release_value());
return PrimitiveString::create(vm, result.release_value());
if (formatted_result.has_value())
return js_string(vm, formatted_result.release_value());
return PrimitiveString::create(vm, formatted_result.release_value());
// 7. If displayNames.[[Fallback]] is "code", return code.
if (display_names->fallback() == DisplayNames::Fallback::Code)
@ -138,14 +138,14 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::resolved_options)
// b. Let v be the value of displayNames's internal slot whose name is the Internal Slot value of the current row.
// c. Assert: v is not undefined.
// d. Perform ! CreateDataPropertyOrThrow(options, p, v).
MUST(options->create_data_property_or_throw(vm.names.locale, js_string(vm, display_names->locale())));
MUST(options->create_data_property_or_throw(vm.names.style, js_string(vm, display_names->style_string())));
MUST(options->create_data_property_or_throw(vm.names.type, js_string(vm, display_names->type_string())));
MUST(options->create_data_property_or_throw(vm.names.fallback, js_string(vm, display_names->fallback_string())));
MUST(options->create_data_property_or_throw(vm.names.locale, PrimitiveString::create(vm, display_names->locale())));
MUST(options->create_data_property_or_throw(vm.names.style, PrimitiveString::create(vm, display_names->style_string())));
MUST(options->create_data_property_or_throw(vm.names.type, PrimitiveString::create(vm, display_names->type_string())));
MUST(options->create_data_property_or_throw(vm.names.fallback, PrimitiveString::create(vm, display_names->fallback_string())));
// NOTE: Step 4c indicates languageDisplay must not be undefined, but it is only set when the type option is language.
if (display_names->has_language_display())
MUST(options->create_data_property_or_throw(vm.names.languageDisplay, js_string(vm, display_names->language_display_string())));
MUST(options->create_data_property_or_throw(vm.names.languageDisplay, PrimitiveString::create(vm, display_names->language_display_string())));
// 5. Return options.
return options;

View file

@ -401,7 +401,7 @@ Vector<PatternPartition> partition_duration_format_pattern(VM& vm, DurationForma
// i. If style is "2-digit" or "numeric", then
if (style == DurationFormat::ValueStyle::TwoDigit || style == DurationFormat::ValueStyle::Numeric) {
// 1. Let nf be ! Construct(%NumberFormat%, « durationFormat.[[Locale]], nfOpts »).
auto* number_format = static_cast<NumberFormat*>(MUST(construct(vm, *realm.intrinsics().intl_number_format_constructor(), js_string(vm, duration_format.locale()), number_format_options)));
auto* number_format = static_cast<NumberFormat*>(MUST(construct(vm, *realm.intrinsics().intl_number_format_constructor(), PrimitiveString::create(vm, duration_format.locale()), number_format_options)));
// 2. Let dataLocale be durationFormat.[[DataLocale]].
auto const& data_locale = duration_format.data_locale();
@ -455,17 +455,17 @@ Vector<PatternPartition> partition_duration_format_pattern(VM& vm, DurationForma
// ii. Else,
else {
// 1. Perform ! CreateDataPropertyOrThrow(nfOpts, "style", "unit").
MUST(number_format_options->create_data_property_or_throw(vm.names.style, js_string(vm, "unit"sv)));
MUST(number_format_options->create_data_property_or_throw(vm.names.style, PrimitiveString::create(vm, "unit"sv)));
// 2. Perform ! CreateDataPropertyOrThrow(nfOpts, "unit", numberFormatUnit).
MUST(number_format_options->create_data_property_or_throw(vm.names.unit, js_string(vm, number_format_unit)));
MUST(number_format_options->create_data_property_or_throw(vm.names.unit, PrimitiveString::create(vm, number_format_unit)));
// 3. Perform ! CreateDataPropertyOrThrow(nfOpts, "unitDisplay", style).
auto unicode_style = ::Locale::style_to_string(static_cast<::Locale::Style>(style));
MUST(number_format_options->create_data_property_or_throw(vm.names.unitDisplay, js_string(vm, unicode_style)));
MUST(number_format_options->create_data_property_or_throw(vm.names.unitDisplay, PrimitiveString::create(vm, unicode_style)));
// 4. Let nf be ! Construct(%NumberFormat%, « durationFormat.[[Locale]], nfOpts »).
auto* number_format = static_cast<NumberFormat*>(MUST(construct(vm, *realm.intrinsics().intl_number_format_constructor(), js_string(vm, duration_format.locale()), number_format_options)));
auto* number_format = static_cast<NumberFormat*>(MUST(construct(vm, *realm.intrinsics().intl_number_format_constructor(), PrimitiveString::create(vm, duration_format.locale()), number_format_options)));
// 5. Let parts be ! PartitionNumberPattern(nf, 𝔽(value)).
auto parts = partition_number_pattern(vm, *number_format, MathematicalValue(value));
@ -489,7 +489,7 @@ Vector<PatternPartition> partition_duration_format_pattern(VM& vm, DurationForma
auto* list_format_options = Object::create(realm, nullptr);
// 5. Perform ! CreateDataPropertyOrThrow(lfOpts, "type", "unit").
MUST(list_format_options->create_data_property_or_throw(vm.names.type, js_string(vm, "unit"sv)));
MUST(list_format_options->create_data_property_or_throw(vm.names.type, PrimitiveString::create(vm, "unit"sv)));
// 6. Let listStyle be durationFormat.[[Style]].
auto list_style = duration_format.style();
@ -503,10 +503,10 @@ Vector<PatternPartition> partition_duration_format_pattern(VM& vm, DurationForma
auto unicode_list_style = ::Locale::style_to_string(static_cast<::Locale::Style>(list_style));
// 8. Perform ! CreateDataPropertyOrThrow(lfOpts, "style", listStyle).
MUST(list_format_options->create_data_property_or_throw(vm.names.style, js_string(vm, unicode_list_style)));
MUST(list_format_options->create_data_property_or_throw(vm.names.style, PrimitiveString::create(vm, unicode_list_style)));
// 9. Let lf be ! Construct(%ListFormat%, « durationFormat.[[Locale]], lfOpts »).
auto* list_format = static_cast<ListFormat*>(MUST(construct(vm, *realm.intrinsics().intl_list_format_constructor(), js_string(vm, duration_format.locale()), list_format_options)));
auto* list_format = static_cast<ListFormat*>(MUST(construct(vm, *realm.intrinsics().intl_list_format_constructor(), PrimitiveString::create(vm, duration_format.locale()), list_format_options)));
// FIXME: CreatePartsFromList expects a list of strings and creates a list of Pattern Partition records, but we already created a list of Pattern Partition records
// so we try to hack something together from it that looks mostly right

View file

@ -24,7 +24,7 @@ void DurationFormatPrototype::initialize(Realm& realm)
auto& vm = this->vm();
// 1.4.2 Intl.DurationFormat.prototype [ @@toStringTag ], https://tc39.es/proposal-intl-duration-format/#sec-Intl.DurationFormat.prototype-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Intl.DurationFormat"), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Intl.DurationFormat"), Attribute::Configurable);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(realm, vm.names.format, format, 1, attr);
@ -59,7 +59,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format)
}
// 8. Return result.
return js_string(vm, result.build());
return PrimitiveString::create(vm, result.build());
}
// 1.4.4 Intl.DurationFormat.prototype.formatToParts ( duration ), https://tc39.es/proposal-intl-duration-format/#sec-Intl.DurationFormat.prototype.formatToParts
@ -93,10 +93,10 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts)
auto* object = Object::create(realm, realm.intrinsics().object_prototype());
// b. Perform ! CreateDataPropertyOrThrow(obj, "type", part.[[Type]]).
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));
MUST(object->create_data_property_or_throw(vm.names.type, PrimitiveString::create(vm, part.type)));
// c. Perform ! CreateDataPropertyOrThrow(obj, "value", part.[[Value]]).
MUST(object->create_data_property_or_throw(vm.names.value, js_string(vm, part.value)));
MUST(object->create_data_property_or_throw(vm.names.value, PrimitiveString::create(vm, part.value)));
// d. Perform ! CreateDataPropertyOrThrow(result, ! ToString(n), obj).
MUST(result->create_data_property_or_throw(n, object));
@ -125,30 +125,30 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::resolved_options)
// b. Let v be the value of df's internal slot whose name is the Internal Slot value of the current row.
// c. Assert: v is not undefined.
// d. Perform ! CreateDataPropertyOrThrow(options, p, v).
MUST(options->create_data_property_or_throw(vm.names.locale, js_string(vm, duration_format->locale())));
MUST(options->create_data_property_or_throw(vm.names.style, js_string(vm, duration_format->style_string())));
MUST(options->create_data_property_or_throw(vm.names.years, js_string(vm, duration_format->years_style_string())));
MUST(options->create_data_property_or_throw(vm.names.yearsDisplay, js_string(vm, duration_format->years_display_string())));
MUST(options->create_data_property_or_throw(vm.names.months, js_string(vm, duration_format->months_style_string())));
MUST(options->create_data_property_or_throw(vm.names.monthsDisplay, js_string(vm, duration_format->months_display_string())));
MUST(options->create_data_property_or_throw(vm.names.weeks, js_string(vm, duration_format->weeks_style_string())));
MUST(options->create_data_property_or_throw(vm.names.weeksDisplay, js_string(vm, duration_format->weeks_display_string())));
MUST(options->create_data_property_or_throw(vm.names.days, js_string(vm, duration_format->days_style_string())));
MUST(options->create_data_property_or_throw(vm.names.daysDisplay, js_string(vm, duration_format->days_display_string())));
MUST(options->create_data_property_or_throw(vm.names.hours, js_string(vm, duration_format->hours_style_string())));
MUST(options->create_data_property_or_throw(vm.names.hoursDisplay, js_string(vm, duration_format->hours_display_string())));
MUST(options->create_data_property_or_throw(vm.names.minutes, js_string(vm, duration_format->minutes_style_string())));
MUST(options->create_data_property_or_throw(vm.names.minutesDisplay, js_string(vm, duration_format->minutes_display_string())));
MUST(options->create_data_property_or_throw(vm.names.seconds, js_string(vm, duration_format->seconds_style_string())));
MUST(options->create_data_property_or_throw(vm.names.secondsDisplay, js_string(vm, duration_format->seconds_display_string())));
MUST(options->create_data_property_or_throw(vm.names.milliseconds, js_string(vm, duration_format->milliseconds_style_string())));
MUST(options->create_data_property_or_throw(vm.names.millisecondsDisplay, js_string(vm, duration_format->milliseconds_display_string())));
MUST(options->create_data_property_or_throw(vm.names.microseconds, js_string(vm, duration_format->microseconds_style_string())));
MUST(options->create_data_property_or_throw(vm.names.microsecondsDisplay, js_string(vm, duration_format->microseconds_display_string())));
MUST(options->create_data_property_or_throw(vm.names.nanoseconds, js_string(vm, duration_format->nanoseconds_style_string())));
MUST(options->create_data_property_or_throw(vm.names.nanosecondsDisplay, js_string(vm, duration_format->nanoseconds_display_string())));
MUST(options->create_data_property_or_throw(vm.names.locale, PrimitiveString::create(vm, duration_format->locale())));
MUST(options->create_data_property_or_throw(vm.names.style, PrimitiveString::create(vm, duration_format->style_string())));
MUST(options->create_data_property_or_throw(vm.names.years, PrimitiveString::create(vm, duration_format->years_style_string())));
MUST(options->create_data_property_or_throw(vm.names.yearsDisplay, PrimitiveString::create(vm, duration_format->years_display_string())));
MUST(options->create_data_property_or_throw(vm.names.months, PrimitiveString::create(vm, duration_format->months_style_string())));
MUST(options->create_data_property_or_throw(vm.names.monthsDisplay, PrimitiveString::create(vm, duration_format->months_display_string())));
MUST(options->create_data_property_or_throw(vm.names.weeks, PrimitiveString::create(vm, duration_format->weeks_style_string())));
MUST(options->create_data_property_or_throw(vm.names.weeksDisplay, PrimitiveString::create(vm, duration_format->weeks_display_string())));
MUST(options->create_data_property_or_throw(vm.names.days, PrimitiveString::create(vm, duration_format->days_style_string())));
MUST(options->create_data_property_or_throw(vm.names.daysDisplay, PrimitiveString::create(vm, duration_format->days_display_string())));
MUST(options->create_data_property_or_throw(vm.names.hours, PrimitiveString::create(vm, duration_format->hours_style_string())));
MUST(options->create_data_property_or_throw(vm.names.hoursDisplay, PrimitiveString::create(vm, duration_format->hours_display_string())));
MUST(options->create_data_property_or_throw(vm.names.minutes, PrimitiveString::create(vm, duration_format->minutes_style_string())));
MUST(options->create_data_property_or_throw(vm.names.minutesDisplay, PrimitiveString::create(vm, duration_format->minutes_display_string())));
MUST(options->create_data_property_or_throw(vm.names.seconds, PrimitiveString::create(vm, duration_format->seconds_style_string())));
MUST(options->create_data_property_or_throw(vm.names.secondsDisplay, PrimitiveString::create(vm, duration_format->seconds_display_string())));
MUST(options->create_data_property_or_throw(vm.names.milliseconds, PrimitiveString::create(vm, duration_format->milliseconds_style_string())));
MUST(options->create_data_property_or_throw(vm.names.millisecondsDisplay, PrimitiveString::create(vm, duration_format->milliseconds_display_string())));
MUST(options->create_data_property_or_throw(vm.names.microseconds, PrimitiveString::create(vm, duration_format->microseconds_style_string())));
MUST(options->create_data_property_or_throw(vm.names.microsecondsDisplay, PrimitiveString::create(vm, duration_format->microseconds_display_string())));
MUST(options->create_data_property_or_throw(vm.names.nanoseconds, PrimitiveString::create(vm, duration_format->nanoseconds_style_string())));
MUST(options->create_data_property_or_throw(vm.names.nanosecondsDisplay, PrimitiveString::create(vm, duration_format->nanoseconds_display_string())));
MUST(options->create_data_property_or_throw(vm.names.fractionalDigits, duration_format->has_fractional_digits() ? Value(duration_format->fractional_digits()) : js_undefined()));
MUST(options->create_data_property_or_throw(vm.names.numberingSystem, js_string(vm, duration_format->numbering_system())));
MUST(options->create_data_property_or_throw(vm.names.numberingSystem, PrimitiveString::create(vm, duration_format->numbering_system())));
// 5. Return options.
return options;

View file

@ -39,7 +39,7 @@ void Intl::initialize(Realm& realm)
auto& vm = this->vm();
// 8.1.1 Intl[ @@toStringTag ], https://tc39.es/ecma402/#sec-Intl-toStringTag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Intl"), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Intl"), Attribute::Configurable);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_intrinsic_accessor(vm.names.Collator, attr, [](auto& realm) -> Value { return realm.intrinsics().intl_collator_constructor(); });
@ -70,7 +70,7 @@ JS_DEFINE_NATIVE_FUNCTION(Intl::get_canonical_locales)
MarkedVector<Value> marked_locale_list { vm.heap() };
marked_locale_list.ensure_capacity(locale_list.size());
for (auto& locale : locale_list)
marked_locale_list.append(js_string(vm, move(locale)));
marked_locale_list.append(PrimitiveString::create(vm, move(locale)));
// 2. Return CreateArrayFromList(ll).
return Array::create_from(realm, marked_locale_list);
@ -154,7 +154,7 @@ JS_DEFINE_NATIVE_FUNCTION(Intl::supported_values_of)
}
// 9. Return CreateArrayFromList( list ).
return Array::create_from<StringView>(realm, list, [&](auto value) { return js_string(vm, value); });
return Array::create_from<StringView>(realm, list, [&](auto value) { return PrimitiveString::create(vm, value); });
}
}

View file

@ -220,10 +220,10 @@ Array* format_list_to_parts(VM& vm, ListFormat const& list_format, Vector<Deprec
auto* object = Object::create(realm, realm.intrinsics().object_prototype());
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));
MUST(object->create_data_property_or_throw(vm.names.type, PrimitiveString::create(vm, part.type)));
// c. Perform ! CreateDataPropertyOrThrow(O, "value", part.[[Value]]).
MUST(object->create_data_property_or_throw(vm.names.value, js_string(vm, move(part.value))));
MUST(object->create_data_property_or_throw(vm.names.value, PrimitiveString::create(vm, move(part.value))));
// d. Perform ! CreateDataPropertyOrThrow(result, ! ToString(n), O).
MUST(result->create_data_property_or_throw(n, object));

View file

@ -25,7 +25,7 @@ void ListFormatPrototype::initialize(Realm& realm)
auto& vm = this->vm();
// 13.3.2 Intl.ListFormat.prototype [ @@toStringTag ], https://tc39.es/ecma402/#sec-Intl.ListFormat.prototype-toStringTag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Intl.ListFormat"), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Intl.ListFormat"), Attribute::Configurable);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(realm, vm.names.format, format, 1, attr);
@ -47,7 +47,7 @@ JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::format)
// 4. Return ! FormatList(lf, stringList).
auto formatted = format_list(*list_format, string_list);
return js_string(vm, move(formatted));
return PrimitiveString::create(vm, move(formatted));
}
// 13.3.4 Intl.ListFormat.prototype.formatToParts ( list ), https://tc39.es/ecma402/#sec-Intl.ListFormat.prototype.formatToParts
@ -83,9 +83,9 @@ JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::resolved_options)
// b. Let v be the value of lf's internal slot whose name is the Internal Slot value of the current row.
// c. Assert: v is not undefined.
// d. Perform ! CreateDataPropertyOrThrow(options, p, v).
MUST(options->create_data_property_or_throw(vm.names.locale, js_string(vm, list_format->locale())));
MUST(options->create_data_property_or_throw(vm.names.type, js_string(vm, list_format->type_string())));
MUST(options->create_data_property_or_throw(vm.names.style, js_string(vm, list_format->style_string())));
MUST(options->create_data_property_or_throw(vm.names.locale, PrimitiveString::create(vm, list_format->locale())));
MUST(options->create_data_property_or_throw(vm.names.type, PrimitiveString::create(vm, list_format->type_string())));
MUST(options->create_data_property_or_throw(vm.names.style, PrimitiveString::create(vm, list_format->style_string())));
// 5. Return options.
return options;

View file

@ -67,7 +67,7 @@ static Array* create_array_from_list_or_restricted(VM& vm, Vector<StringView> li
// 2. Return ! CreateArrayFromList( list ).
return Array::create_from<StringView>(realm, list, [&vm](auto value) {
return js_string(vm, value);
return PrimitiveString::create(vm, value);
});
}
@ -163,7 +163,7 @@ Array* time_zones_of_locale(VM& vm, StringView region)
// 5. Return ! CreateArrayFromList( list ).
return Array::create_from<StringView>(realm, list, [&vm](auto value) {
return js_string(vm, value);
return PrimitiveString::create(vm, value);
});
}

View file

@ -346,7 +346,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
if (result.kn.has_value() && (same_value(js_string(vm, *result.kn), js_string(vm, "true")) || result.kn->is_empty())) {
if (result.kn.has_value() && (same_value(PrimitiveString::create(vm, *result.kn), PrimitiveString::create(vm, "true")) || result.kn->is_empty())) {
// i. Set locale.[[Numeric]] to true.
locale->set_numeric(true);
}

View file

@ -31,7 +31,7 @@ void LocalePrototype::initialize(Realm& realm)
define_native_function(realm, vm.names.toString, to_string, 0, attr);
// 14.3.2 Intl.Locale.prototype[ @@toStringTag ], https://tc39.es/ecma402/#sec-Intl.Locale.prototype-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Intl.Locale"), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Intl.Locale"), Attribute::Configurable);
define_native_accessor(realm, vm.names.baseName, base_name, {}, Attribute::Configurable);
define_native_accessor(realm, vm.names.calendar, calendar, {}, Attribute::Configurable);
@ -100,7 +100,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::to_string)
auto* locale_object = TRY(typed_this_object(vm));
// 3. Return loc.[[Locale]].
return js_string(vm, locale_object->locale());
return PrimitiveString::create(vm, locale_object->locale());
}
// 14.3.6 get Intl.Locale.prototype.baseName, https://tc39.es/ecma402/#sec-Intl.Locale.prototype.baseName
@ -115,7 +115,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::base_name)
VERIFY(locale.has_value());
// 4. Return the substring of locale corresponding to the unicode_language_id production.
return js_string(vm, locale->language_id.to_deprecated_string());
return PrimitiveString::create(vm, locale->language_id.to_deprecated_string());
}
#define JS_ENUMERATE_LOCALE_KEYWORD_PROPERTIES \
@ -130,13 +130,13 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::base_name)
// 14.3.9 get Intl.Locale.prototype.collation, https://tc39.es/ecma402/#sec-Intl.Locale.prototype.collation
// 14.3.10 get Intl.Locale.prototype.hourCycle, https://tc39.es/ecma402/#sec-Intl.Locale.prototype.hourCycle
// 14.3.12 get Intl.Locale.prototype.numberingSystem, https://tc39.es/ecma402/#sec-Intl.Locale.prototype.numberingSystem
#define __JS_ENUMERATE(keyword) \
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::keyword) \
{ \
auto* locale_object = TRY(typed_this_object(vm)); \
if (!locale_object->has_##keyword()) \
return js_undefined(); \
return js_string(vm, locale_object->keyword()); \
#define __JS_ENUMERATE(keyword) \
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::keyword) \
{ \
auto* locale_object = TRY(typed_this_object(vm)); \
if (!locale_object->has_##keyword()) \
return js_undefined(); \
return PrimitiveString::create(vm, locale_object->keyword()); \
}
JS_ENUMERATE_LOCALE_KEYWORD_PROPERTIES
#undef __JS_ENUMERATE
@ -166,7 +166,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::language)
VERIFY(locale.has_value());
// 5. Return the substring of locale corresponding to the unicode_language_subtag production of the unicode_language_id.
return js_string(vm, *locale->language_id.language);
return PrimitiveString::create(vm, *locale->language_id.language);
}
// 14.3.14 get Intl.Locale.prototype.script, https://tc39.es/ecma402/#sec-Intl.Locale.prototype.script
@ -187,7 +187,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::script)
return js_undefined();
// 6. Return the substring of locale corresponding to the unicode_script_subtag production of the unicode_language_id.
return js_string(vm, *locale->language_id.script);
return PrimitiveString::create(vm, *locale->language_id.script);
}
// 14.3.15 get Intl.Locale.prototype.region, https://tc39.es/ecma402/#sec-Intl.Locale.prototype.region
@ -208,7 +208,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::region)
return js_undefined();
// 6. Return the substring of locale corresponding to the unicode_region_subtag production of the unicode_language_id.
return js_string(vm, *locale->language_id.region);
return PrimitiveString::create(vm, *locale->language_id.region);
}
#define JS_ENUMERATE_LOCALE_INFO_PROPERTIES \
@ -264,7 +264,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::text_info)
auto direction = character_direction_of_locale(*locale_object);
// 5. Perform ! CreateDataPropertyOrThrow(info, "direction", dir).
MUST(info->create_data_property_or_throw(vm.names.direction, js_string(vm, direction)));
MUST(info->create_data_property_or_throw(vm.names.direction, PrimitiveString::create(vm, direction)));
// 6. Return info.
return info;

View file

@ -246,11 +246,11 @@ Value NumberFormat::use_grouping_to_value(VM& vm) const
{
switch (m_use_grouping) {
case UseGrouping::Always:
return js_string(vm, "always"sv);
return PrimitiveString::create(vm, "always"sv);
case UseGrouping::Auto:
return js_string(vm, "auto"sv);
return PrimitiveString::create(vm, "auto"sv);
case UseGrouping::Min2:
return js_string(vm, "min2"sv);
return PrimitiveString::create(vm, "min2"sv);
case UseGrouping::False:
return Value(false);
default:
@ -925,10 +925,10 @@ Array* format_numeric_to_parts(VM& vm, NumberFormat& number_format, Mathematical
auto* object = Object::create(realm, realm.intrinsics().object_prototype());
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));
MUST(object->create_data_property_or_throw(vm.names.type, PrimitiveString::create(vm, part.type)));
// c. Perform ! CreateDataPropertyOrThrow(O, "value", part.[[Value]]).
MUST(object->create_data_property_or_throw(vm.names.value, js_string(vm, move(part.value))));
MUST(object->create_data_property_or_throw(vm.names.value, PrimitiveString::create(vm, move(part.value))));
// d. Perform ! CreateDataPropertyOrThrow(result, ! ToString(n), O).
MUST(result->create_data_property_or_throw(n, object));
@ -1835,13 +1835,13 @@ ThrowCompletionOr<Array*> format_numeric_range_to_parts(VM& vm, NumberFormat& nu
auto* object = Object::create(realm, realm.intrinsics().object_prototype());
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));
MUST(object->create_data_property_or_throw(vm.names.type, PrimitiveString::create(vm, part.type)));
// c. Perform ! CreateDataPropertyOrThrow(O, "value", part.[[Value]]).
MUST(object->create_data_property_or_throw(vm.names.value, js_string(vm, move(part.value))));
MUST(object->create_data_property_or_throw(vm.names.value, PrimitiveString::create(vm, move(part.value))));
// d. Perform ! CreateDataPropertyOrThrow(O, "source", part.[[Source]]).
MUST(object->create_data_property_or_throw(vm.names.source, js_string(vm, part.source)));
MUST(object->create_data_property_or_throw(vm.names.source, PrimitiveString::create(vm, part.source)));
// e. Perform ! CreateDataPropertyOrThrow(result, ! ToString(n), O).
MUST(result->create_data_property_or_throw(n, object));

View file

@ -29,7 +29,7 @@ void NumberFormatFunction::initialize(Realm& realm)
Base::initialize(realm);
define_direct_property(vm.names.length, Value(1), Attribute::Configurable);
define_direct_property(vm.names.name, js_string(vm, DeprecatedString::empty()), Attribute::Configurable);
define_direct_property(vm.names.name, PrimitiveString::create(vm, DeprecatedString::empty()), Attribute::Configurable);
}
ThrowCompletionOr<Value> NumberFormatFunction::call()
@ -47,7 +47,7 @@ ThrowCompletionOr<Value> NumberFormatFunction::call()
// 5. Return ? FormatNumeric(nf, x).
// Note: Our implementation of FormatNumeric does not throw.
auto formatted = format_numeric(vm, m_number_format, move(mathematical_value));
return js_string(vm, move(formatted));
return PrimitiveString::create(vm, move(formatted));
}
void NumberFormatFunction::visit_edges(Cell::Visitor& visitor)

View file

@ -26,7 +26,7 @@ void NumberFormatPrototype::initialize(Realm& realm)
auto& vm = this->vm();
// 15.3.2 Intl.NumberFormat.prototype [ @@toStringTag ], https://tc39.es/ecma402/#sec-intl.numberformat.prototype-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Intl.NumberFormat"), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Intl.NumberFormat"), Attribute::Configurable);
define_native_accessor(realm, vm.names.format, format, nullptr, Attribute::Configurable);
@ -104,7 +104,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::format_range)
// 6. Return ? FormatNumericRange(nf, x, y).
auto formatted = TRY(format_numeric_range(vm, *number_format, move(x), move(y)));
return js_string(vm, move(formatted));
return PrimitiveString::create(vm, move(formatted));
}
// 1.4.6 Intl.NumberFormat.prototype.formatRangeToParts ( start, end ), https://tc39.es/proposal-intl-numberformat-v3/out/numberformat/proposed.html#sec-intl.numberformat.prototype.formatrangetoparts
@ -152,19 +152,19 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::resolved_options)
// b. Let v be the value of nf's internal slot whose name is the Internal Slot value of the current row.
// c. If v is not undefined, then
// i. Perform ! CreateDataPropertyOrThrow(options, p, v).
MUST(options->create_data_property_or_throw(vm.names.locale, js_string(vm, number_format->locale())));
MUST(options->create_data_property_or_throw(vm.names.numberingSystem, js_string(vm, number_format->numbering_system())));
MUST(options->create_data_property_or_throw(vm.names.style, js_string(vm, number_format->style_string())));
MUST(options->create_data_property_or_throw(vm.names.locale, PrimitiveString::create(vm, number_format->locale())));
MUST(options->create_data_property_or_throw(vm.names.numberingSystem, PrimitiveString::create(vm, number_format->numbering_system())));
MUST(options->create_data_property_or_throw(vm.names.style, PrimitiveString::create(vm, number_format->style_string())));
if (number_format->has_currency())
MUST(options->create_data_property_or_throw(vm.names.currency, js_string(vm, number_format->currency())));
MUST(options->create_data_property_or_throw(vm.names.currency, PrimitiveString::create(vm, number_format->currency())));
if (number_format->has_currency_display())
MUST(options->create_data_property_or_throw(vm.names.currencyDisplay, js_string(vm, number_format->currency_display_string())));
MUST(options->create_data_property_or_throw(vm.names.currencyDisplay, PrimitiveString::create(vm, number_format->currency_display_string())));
if (number_format->has_currency_sign())
MUST(options->create_data_property_or_throw(vm.names.currencySign, js_string(vm, number_format->currency_sign_string())));
MUST(options->create_data_property_or_throw(vm.names.currencySign, PrimitiveString::create(vm, number_format->currency_sign_string())));
if (number_format->has_unit())
MUST(options->create_data_property_or_throw(vm.names.unit, js_string(vm, number_format->unit())));
MUST(options->create_data_property_or_throw(vm.names.unit, PrimitiveString::create(vm, number_format->unit())));
if (number_format->has_unit_display())
MUST(options->create_data_property_or_throw(vm.names.unitDisplay, js_string(vm, number_format->unit_display_string())));
MUST(options->create_data_property_or_throw(vm.names.unitDisplay, PrimitiveString::create(vm, number_format->unit_display_string())));
MUST(options->create_data_property_or_throw(vm.names.minimumIntegerDigits, Value(number_format->min_integer_digits())));
if (number_format->has_min_fraction_digits())
MUST(options->create_data_property_or_throw(vm.names.minimumFractionDigits, Value(number_format->min_fraction_digits())));
@ -175,29 +175,29 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::resolved_options)
if (number_format->has_max_significant_digits())
MUST(options->create_data_property_or_throw(vm.names.maximumSignificantDigits, Value(number_format->max_significant_digits())));
MUST(options->create_data_property_or_throw(vm.names.useGrouping, number_format->use_grouping_to_value(vm)));
MUST(options->create_data_property_or_throw(vm.names.notation, js_string(vm, number_format->notation_string())));
MUST(options->create_data_property_or_throw(vm.names.notation, PrimitiveString::create(vm, number_format->notation_string())));
if (number_format->has_compact_display())
MUST(options->create_data_property_or_throw(vm.names.compactDisplay, js_string(vm, number_format->compact_display_string())));
MUST(options->create_data_property_or_throw(vm.names.signDisplay, js_string(vm, number_format->sign_display_string())));
MUST(options->create_data_property_or_throw(vm.names.roundingMode, js_string(vm, number_format->rounding_mode_string())));
MUST(options->create_data_property_or_throw(vm.names.compactDisplay, PrimitiveString::create(vm, number_format->compact_display_string())));
MUST(options->create_data_property_or_throw(vm.names.signDisplay, PrimitiveString::create(vm, number_format->sign_display_string())));
MUST(options->create_data_property_or_throw(vm.names.roundingMode, PrimitiveString::create(vm, number_format->rounding_mode_string())));
MUST(options->create_data_property_or_throw(vm.names.roundingIncrement, Value(number_format->rounding_increment())));
MUST(options->create_data_property_or_throw(vm.names.trailingZeroDisplay, js_string(vm, number_format->trailing_zero_display_string())));
MUST(options->create_data_property_or_throw(vm.names.trailingZeroDisplay, PrimitiveString::create(vm, number_format->trailing_zero_display_string())));
switch (number_format->rounding_type()) {
// 6. If nf.[[RoundingType]] is morePrecision, then
case NumberFormatBase::RoundingType::MorePrecision:
// a. Perform ! CreateDataPropertyOrThrow(options, "roundingPriority", "morePrecision").
MUST(options->create_data_property_or_throw(vm.names.roundingPriority, js_string(vm, "morePrecision"sv)));
MUST(options->create_data_property_or_throw(vm.names.roundingPriority, PrimitiveString::create(vm, "morePrecision"sv)));
break;
// 7. Else if nf.[[RoundingType]] is lessPrecision, then
case NumberFormatBase::RoundingType::LessPrecision:
// a. Perform ! CreateDataPropertyOrThrow(options, "roundingPriority", "lessPrecision").
MUST(options->create_data_property_or_throw(vm.names.roundingPriority, js_string(vm, "lessPrecision"sv)));
MUST(options->create_data_property_or_throw(vm.names.roundingPriority, PrimitiveString::create(vm, "lessPrecision"sv)));
break;
// 8. Else,
default:
// a. Perform ! CreateDataPropertyOrThrow(options, "roundingPriority", "auto").
MUST(options->create_data_property_or_throw(vm.names.roundingPriority, js_string(vm, "auto"sv)));
MUST(options->create_data_property_or_throw(vm.names.roundingPriority, PrimitiveString::create(vm, "auto"sv)));
break;
}

View file

@ -25,7 +25,7 @@ void PluralRulesPrototype::initialize(Realm& realm)
auto& vm = this->vm();
// 16.3.2 Intl.PluralRules.prototype [ @@toStringTag ], https://tc39.es/ecma402/#sec-intl.pluralrules.prototype-tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Intl.PluralRules"sv), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Intl.PluralRules"sv), Attribute::Configurable);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(realm, vm.names.select, select, 1, attr);
@ -45,7 +45,7 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::select)
// 4. Return ! ResolvePlural(pr, n).
auto plurality = resolve_plural(*plural_rules, number);
return js_string(vm, ::Locale::plural_category_to_string(plurality));
return PrimitiveString::create(vm, ::Locale::plural_category_to_string(plurality));
}
// 1.4.4 Intl.PluralRules.prototype.selectRange ( start, end ), https://tc39.es/proposal-intl-numberformat-v3/out/pluralrules/proposed.html#sec-intl.pluralrules.prototype.selectrange
@ -72,7 +72,7 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::select_range)
// 6. Return ? ResolvePluralRange(pr, x, y).
auto plurality = TRY(resolve_plural_range(vm, *plural_rules, x, y));
return js_string(vm, ::Locale::plural_category_to_string(plurality));
return PrimitiveString::create(vm, ::Locale::plural_category_to_string(plurality));
}
// 16.3.4 Intl.PluralRules.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.pluralrules.prototype.resolvedoptions
@ -93,8 +93,8 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::resolved_options)
// b. Let v be the value of pr's internal slot whose name is the Internal Slot value of the current row.
// c. If v is not undefined, then
// i. Perform ! CreateDataPropertyOrThrow(options, p, v).
MUST(options->create_data_property_or_throw(vm.names.locale, js_string(vm, plural_rules->locale())));
MUST(options->create_data_property_or_throw(vm.names.type, js_string(vm, plural_rules->type_string())));
MUST(options->create_data_property_or_throw(vm.names.locale, PrimitiveString::create(vm, plural_rules->locale())));
MUST(options->create_data_property_or_throw(vm.names.type, PrimitiveString::create(vm, plural_rules->type_string())));
MUST(options->create_data_property_or_throw(vm.names.minimumIntegerDigits, Value(plural_rules->min_integer_digits())));
if (plural_rules->has_min_fraction_digits())
MUST(options->create_data_property_or_throw(vm.names.minimumFractionDigits, Value(plural_rules->min_fraction_digits())));
@ -109,7 +109,7 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::resolved_options)
auto available_categories = ::Locale::available_plural_categories(plural_rules->locale(), plural_rules->type());
auto* plural_categories = Array::create_from<::Locale::PluralCategory>(realm, available_categories, [&](auto category) {
return js_string(vm, ::Locale::plural_category_to_string(category));
return PrimitiveString::create(vm, ::Locale::plural_category_to_string(category));
});
// 6. Perform ! CreateDataProperty(options, "pluralCategories", CreateArrayFromList(pluralCategories)).
@ -119,17 +119,17 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::resolved_options)
// 7. If pr.[[RoundingType]] is morePrecision, then
case NumberFormatBase::RoundingType::MorePrecision:
// a. Perform ! CreateDataPropertyOrThrow(options, "roundingPriority", "morePrecision").
MUST(options->create_data_property_or_throw(vm.names.roundingPriority, js_string(vm, "morePrecision"sv)));
MUST(options->create_data_property_or_throw(vm.names.roundingPriority, PrimitiveString::create(vm, "morePrecision"sv)));
break;
// 8. Else if pr.[[RoundingType]] is lessPrecision, then
case NumberFormatBase::RoundingType::LessPrecision:
// a. Perform ! CreateDataPropertyOrThrow(options, "roundingPriority", "lessPrecision").
MUST(options->create_data_property_or_throw(vm.names.roundingPriority, js_string(vm, "lessPrecision"sv)));
MUST(options->create_data_property_or_throw(vm.names.roundingPriority, PrimitiveString::create(vm, "lessPrecision"sv)));
break;
// 9. Else,
default:
// a. Perform ! CreateDataPropertyOrThrow(options, "roundingPriority", "auto").
MUST(options->create_data_property_or_throw(vm.names.roundingPriority, js_string(vm, "auto"sv)));
MUST(options->create_data_property_or_throw(vm.names.roundingPriority, PrimitiveString::create(vm, "auto"sv)));
break;
}

View file

@ -260,15 +260,15 @@ ThrowCompletionOr<Array*> format_relative_time_to_parts(VM& vm, RelativeTimeForm
auto* object = Object::create(realm, realm.intrinsics().object_prototype());
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));
MUST(object->create_data_property_or_throw(vm.names.type, PrimitiveString::create(vm, part.type)));
// c. Perform ! CreateDataPropertyOrThrow(O, "value", part.[[Value]]).
MUST(object->create_data_property_or_throw(vm.names.value, js_string(vm, move(part.value))));
MUST(object->create_data_property_or_throw(vm.names.value, PrimitiveString::create(vm, move(part.value))));
// d. If part.[[Unit]] is not empty, then
if (!part.unit.is_empty()) {
// i. Perform ! CreateDataPropertyOrThrow(O, "unit", part.[[Unit]]).
MUST(object->create_data_property_or_throw(vm.names.unit, js_string(vm, part.unit)));
MUST(object->create_data_property_or_throw(vm.names.unit, PrimitiveString::create(vm, part.unit)));
}
// e. Perform ! CreateDataPropertyOrThrow(result, ! ToString(n), O).

View file

@ -138,11 +138,11 @@ ThrowCompletionOr<RelativeTimeFormat*> initialize_relative_time_format(VM& vm, R
relative_time_format.set_numeric(numeric.as_string().deprecated_string());
// 19. Let relativeTimeFormat.[[NumberFormat]] be ! Construct(%NumberFormat%, « locale »).
auto* number_format = MUST(construct(vm, *realm.intrinsics().intl_number_format_constructor(), js_string(vm, locale)));
auto* number_format = MUST(construct(vm, *realm.intrinsics().intl_number_format_constructor(), PrimitiveString::create(vm, locale)));
relative_time_format.set_number_format(static_cast<NumberFormat*>(number_format));
// 20. Let relativeTimeFormat.[[PluralRules]] be ! Construct(%PluralRules%, « locale »).
auto* plural_rules = MUST(construct(vm, *realm.intrinsics().intl_plural_rules_constructor(), js_string(vm, locale)));
auto* plural_rules = MUST(construct(vm, *realm.intrinsics().intl_plural_rules_constructor(), PrimitiveString::create(vm, locale)));
relative_time_format.set_plural_rules(static_cast<PluralRules*>(plural_rules));
// 21. Return relativeTimeFormat.

View file

@ -23,7 +23,7 @@ void RelativeTimeFormatPrototype::initialize(Realm& realm)
auto& vm = this->vm();
// 17.3.2 Intl.RelativeTimeFormat.prototype[ @@toStringTag ], https://tc39.es/ecma402/#sec-Intl.RelativeTimeFormat.prototype-toStringTag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Intl.RelativeTimeFormat"sv), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Intl.RelativeTimeFormat"sv), Attribute::Configurable);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(realm, vm.names.format, format, 2, attr);
@ -46,7 +46,7 @@ JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatPrototype::format)
// 5. Return ? FormatRelativeTime(relativeTimeFormat, value, unit).
auto formatted = TRY(format_relative_time(vm, *relative_time_format, value.as_double(), unit));
return js_string(vm, move(formatted));
return PrimitiveString::create(vm, move(formatted));
}
// 17.3.4 Intl.RelativeTimeFormat.prototype.formatToParts ( value, unit ), https://tc39.es/ecma402/#sec-Intl.RelativeTimeFormat.prototype.formatToParts
@ -83,10 +83,10 @@ JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatPrototype::resolved_options)
// b. Let v be the value of relativeTimeFormat's internal slot whose name is the Internal Slot value of the current row.
// c. Assert: v is not undefined.
// d. Perform ! CreateDataPropertyOrThrow(options, p, v).
MUST(options->create_data_property_or_throw(vm.names.locale, js_string(vm, relative_time_format->locale())));
MUST(options->create_data_property_or_throw(vm.names.style, js_string(vm, relative_time_format->style_string())));
MUST(options->create_data_property_or_throw(vm.names.numeric, js_string(vm, relative_time_format->numeric_string())));
MUST(options->create_data_property_or_throw(vm.names.numberingSystem, js_string(vm, relative_time_format->numbering_system())));
MUST(options->create_data_property_or_throw(vm.names.locale, PrimitiveString::create(vm, relative_time_format->locale())));
MUST(options->create_data_property_or_throw(vm.names.style, PrimitiveString::create(vm, relative_time_format->style_string())));
MUST(options->create_data_property_or_throw(vm.names.numeric, PrimitiveString::create(vm, relative_time_format->numeric_string())));
MUST(options->create_data_property_or_throw(vm.names.numberingSystem, PrimitiveString::create(vm, relative_time_format->numbering_system())));
// 5. Return options.
return options;

View file

@ -25,7 +25,7 @@ void SegmentIteratorPrototype::initialize(Realm& realm)
auto& vm = this->vm();
// 18.6.2.2 %SegmentIteratorPrototype% [ @@toStringTag ], https://tc39.es/ecma402/#sec-%segmentiteratorprototype%.@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Segmenter String Iterator"), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Segmenter String Iterator"), Attribute::Configurable);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(realm, vm.names.next, next, 0, attr);

View file

@ -68,13 +68,13 @@ Object* create_segment_data_object(VM& vm, Segmenter const& segmenter, Utf16View
auto segment = string.substring_view(start_index, end_index - start_index);
// 7. Perform ! CreateDataPropertyOrThrow(result, "segment", segment).
MUST(result->create_data_property_or_throw(vm.names.segment, js_string(vm, segment)));
MUST(result->create_data_property_or_throw(vm.names.segment, PrimitiveString::create(vm, segment)));
// 8. Perform ! CreateDataPropertyOrThrow(result, "index", 𝔽(startIndex)).
MUST(result->create_data_property_or_throw(vm.names.index, Value(start_index)));
// 9. Perform ! CreateDataPropertyOrThrow(result, "input", string).
MUST(result->create_data_property_or_throw(vm.names.input, js_string(vm, string)));
MUST(result->create_data_property_or_throw(vm.names.input, PrimitiveString::create(vm, string)));
// 10. Let granularity be segmenter.[[SegmenterGranularity]].
auto granularity = segmenter.segmenter_granularity();

View file

@ -24,7 +24,7 @@ void SegmenterPrototype::initialize(Realm& realm)
auto& vm = this->vm();
// 18.3.2 Intl.Segmenter.prototype [ @@toStringTag ], https://tc39.es/ecma402/#sec-intl.segmenter.prototype-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Intl.Segmenter"), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Intl.Segmenter"), Attribute::Configurable);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(realm, vm.names.resolvedOptions, resolved_options, 0, attr);
@ -48,8 +48,8 @@ JS_DEFINE_NATIVE_FUNCTION(SegmenterPrototype::resolved_options)
// b. Let v be the value of segmenter's internal slot whose name is the Internal Slot value of the current row.
// c. Assert: v is not undefined.
// d. Perform ! CreateDataPropertyOrThrow(options, p, v).
MUST(options->create_data_property_or_throw(vm.names.locale, js_string(vm, segmenter->locale())));
MUST(options->create_data_property_or_throw(vm.names.granularity, js_string(vm, segmenter->segmenter_granularity_string())));
MUST(options->create_data_property_or_throw(vm.names.locale, PrimitiveString::create(vm, segmenter->locale())));
MUST(options->create_data_property_or_throw(vm.names.granularity, PrimitiveString::create(vm, segmenter->segmenter_granularity_string())));
// 5. Return options.
return options;

View file

@ -126,7 +126,7 @@ namespace JS {
static void initialize_constructor(VM& vm, PropertyKey const& property_key, Object& constructor, Object* prototype, PropertyAttributes constructor_property_attributes = Attribute::Writable | Attribute::Configurable)
{
constructor.define_direct_property(vm.names.name, js_string(vm, property_key.as_string()), Attribute::Configurable);
constructor.define_direct_property(vm.names.name, PrimitiveString::create(vm, property_key.as_string()), Attribute::Configurable);
if (prototype)
prototype->define_direct_property(vm.names.constructor, &constructor, constructor_property_attributes);
}
@ -228,7 +228,7 @@ void Intrinsics::initialize_intrinsics(Realm& realm)
},
0, "", &realm);
m_throw_type_error_function->define_direct_property(vm.names.length, Value(0), 0);
m_throw_type_error_function->define_direct_property(vm.names.name, js_string(vm, ""), 0);
m_throw_type_error_function->define_direct_property(vm.names.name, PrimitiveString::create(vm, ""), 0);
MUST(m_throw_type_error_function->internal_prevent_extensions());
#define __JS_ENUMERATE(ClassName, snake_name) \

View file

@ -40,7 +40,7 @@ void JSONObject::initialize(Realm& realm)
define_native_function(realm, vm.names.parse, parse, 2, attr);
// 25.5.3 JSON [ @@toStringTag ], https://tc39.es/ecma262/#sec-json-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "JSON"), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "JSON"), Attribute::Configurable);
}
// 25.5.2 JSON.stringify ( value [ , replacer [ , space ] ] ), https://tc39.es/ecma262/#sec-json.stringify
@ -121,7 +121,7 @@ JS_DEFINE_NATIVE_FUNCTION(JSONObject::stringify)
if (string.is_null())
return js_undefined();
return js_string(vm, string);
return PrimitiveString::create(vm, string);
}
// 25.5.2.1 SerializeJSONProperty ( state, key, holder ), https://tc39.es/ecma262/#sec-serializejsonproperty
@ -138,14 +138,14 @@ ThrowCompletionOr<DeprecatedString> JSONObject::serialize_json_property(VM& vm,
// b. If IsCallable(toJSON) is true, then
if (to_json.is_function()) {
// i. Set value to ? Call(toJSON, value, « key »).
value = TRY(call(vm, to_json.as_function(), value, js_string(vm, key.to_string())));
value = TRY(call(vm, to_json.as_function(), value, PrimitiveString::create(vm, key.to_string())));
}
}
// 3. If state.[[ReplacerFunction]] is not undefined, then
if (state.replacer_function) {
// a. Set value to ? Call(state.[[ReplacerFunction]], holder, « key, value »).
value = TRY(call(vm, *state.replacer_function, holder, js_string(vm, key.to_string()), value));
value = TRY(call(vm, *state.replacer_function, holder, PrimitiveString::create(vm, key.to_string()), value));
}
// 4. If Type(value) is Object, then
@ -422,7 +422,7 @@ Value JSONObject::parse_json_value(VM& vm, JsonValue const& value)
if (value.is_number())
return Value(value.to_double(0));
if (value.is_string())
return js_string(vm, value.to_deprecated_string());
return PrimitiveString::create(vm, value.to_deprecated_string());
if (value.is_bool())
return Value(static_cast<bool>(value.as_bool()));
VERIFY_NOT_REACHED();
@ -477,7 +477,7 @@ ThrowCompletionOr<Value> JSONObject::internalize_json_property(VM& vm, Object* h
}
}
return TRY(call(vm, reviver, holder, js_string(vm, name.to_string()), value));
return TRY(call(vm, reviver, holder, PrimitiveString::create(vm, name.to_string()), value));
}
}

View file

@ -24,7 +24,7 @@ void MapIteratorPrototype::initialize(Realm& realm)
Object::initialize(realm);
define_native_function(realm, vm.names.next, next, 0, Attribute::Configurable | Attribute::Writable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Map Iterator"), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Map Iterator"), Attribute::Configurable);
}
// 24.1.5.2.1 %MapIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%mapiteratorprototype%.next

View file

@ -36,7 +36,7 @@ void MapPrototype::initialize(Realm& realm)
define_native_accessor(realm, vm.names.size, size_getter, {}, Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_iterator(), get_without_side_effects(vm.names.entries), attr);
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, vm.names.Map.as_string()), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, vm.names.Map.as_string()), Attribute::Configurable);
}
// 24.1.3.1 Map.prototype.clear ( ), https://tc39.es/ecma262/#sec-map.prototype.clear

View file

@ -72,7 +72,7 @@ void MathObject::initialize(Realm& realm)
define_direct_property(vm.names.SQRT2, Value(M_SQRT2), 0);
// 21.3.1.9 Math [ @@toStringTag ], https://tc39.es/ecma262/#sec-math-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, vm.names.Math.as_string()), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, vm.names.Math.as_string()), Attribute::Configurable);
}
// 21.3.2.1 Math.abs ( x ), https://tc39.es/ecma262/#sec-math.abs

View file

@ -27,7 +27,7 @@ void ModuleNamespaceObject::initialize(Realm& realm)
Object::initialize(realm);
// 28.3.1 @@toStringTag, https://tc39.es/ecma262/#sec-@@tostringtag
define_direct_property(*vm().well_known_symbol_to_string_tag(), js_string(vm(), "Module"sv), 0);
define_direct_property(*vm().well_known_symbol_to_string_tag(), PrimitiveString::create(vm(), "Module"sv), 0);
}
// 10.4.6.1 [[GetPrototypeOf]] ( ), https://tc39.es/ecma262/#sec-module-namespace-exotic-objects-getprototypeof
@ -219,7 +219,7 @@ ThrowCompletionOr<MarkedVector<Value>> ModuleNamespaceObject::internal_own_prope
// 3. Return the list-concatenation of exports and symbolKeys.
exports.ensure_capacity(m_exports.size() + symbol_keys.size());
for (auto const& export_name : m_exports)
exports.unchecked_append(js_string(vm(), export_name));
exports.unchecked_append(PrimitiveString::create(vm(), export_name));
exports.extend(symbol_keys);
return exports;

View file

@ -90,7 +90,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_exponential)
// 4. If x is not finite, return Number::toString(x).
if (!number_value.is_finite_number())
return js_string(vm, MUST(number_value.to_string(vm)));
return PrimitiveString::create(vm, MUST(number_value.to_string(vm)));
// 5. If f < 0 or f > 100, throw a RangeError exception.
if (fraction_digits < 0 || fraction_digits > 100)
@ -195,7 +195,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_exponential)
// 14. Set m to the string-concatenation of m, "e", c, and d.
// 15. Return the string-concatenation of s and m.
return js_string(vm, DeprecatedString::formatted("{}{}e{}{}", sign, number_string, exponent_sign, exponent_string));
return PrimitiveString::create(vm, DeprecatedString::formatted("{}{}e{}{}", sign, number_string, exponent_sign, exponent_string));
}
// 21.1.3.3 Number.prototype.toFixed ( fractionDigits ), https://tc39.es/ecma262/#sec-number.prototype.tofixed
@ -218,7 +218,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_fixed)
// 6. If x is not finite, return Number::toString(x).
if (!number_value.is_finite_number())
return js_string(vm, TRY(number_value.to_string(vm)));
return PrimitiveString::create(vm, TRY(number_value.to_string(vm)));
// 7. Set x to (x).
auto number = number_value.as_double();
@ -233,7 +233,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_fixed)
// 10. If x ≥ 10^21, then
if (fabs(number) >= 1e+21)
return js_string(vm, MUST(number_value.to_string(vm)));
return PrimitiveString::create(vm, MUST(number_value.to_string(vm)));
// 11. Else,
// a. Let n be an integer for which n / (10^f) - x is as close to zero as possible. If there are two such n, pick the larger n.
@ -269,7 +269,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_fixed)
}
// 12. Return the string-concatenation of s and m.
return js_string(vm, DeprecatedString::formatted("{}{}", s, m));
return PrimitiveString::create(vm, DeprecatedString::formatted("{}{}", s, m));
}
// 19.2.1 Number.prototype.toLocaleString ( [ locales [ , options ] ] ), https://tc39.es/ecma402/#sup-number.prototype.tolocalestring
@ -289,7 +289,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_locale_string)
// 3. Return ? FormatNumeric(numberFormat, x).
// Note: Our implementation of FormatNumeric does not throw.
auto formatted = Intl::format_numeric(vm, *number_format, number_value);
return js_string(vm, move(formatted));
return PrimitiveString::create(vm, move(formatted));
}
// 21.1.3.5 Number.prototype.toPrecision ( precision ), https://tc39.es/ecma262/#sec-number.prototype.toprecision
@ -302,14 +302,14 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_precision)
// 2. If precision is undefined, return ! ToString(x).
if (precision_value.is_undefined())
return js_string(vm, MUST(number_value.to_string(vm)));
return PrimitiveString::create(vm, MUST(number_value.to_string(vm)));
// 3. Let p be ? ToIntegerOrInfinity(precision).
auto precision = TRY(precision_value.to_integer_or_infinity(vm));
// 4. If x is not finite, return Number::toString(x).
if (!number_value.is_finite_number())
return js_string(vm, MUST(number_value.to_string(vm)));
return PrimitiveString::create(vm, MUST(number_value.to_string(vm)));
// 5. If p < 1 or p > 100, throw a RangeError exception.
if ((precision < 1) || (precision > 100))
@ -391,13 +391,13 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_precision)
auto exponent_string = DeprecatedString::number(exponent);
// vi. Return the string-concatenation of s, m, the code unit 0x0065 (LATIN SMALL LETTER E), c, and d.
return js_string(vm, DeprecatedString::formatted("{}{}e{}{}", sign, number_string, exponent_sign, exponent_string));
return PrimitiveString::create(vm, DeprecatedString::formatted("{}{}e{}{}", sign, number_string, exponent_sign, exponent_string));
}
}
// 11. If e = p - 1, return the string-concatenation of s and m.
if (exponent == precision - 1)
return js_string(vm, DeprecatedString::formatted("{}{}", sign, number_string));
return PrimitiveString::create(vm, DeprecatedString::formatted("{}{}", sign, number_string));
// 12. If e ≥ 0, then
if (exponent >= 0) {
@ -417,7 +417,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_precision)
}
// 14. Return the string-concatenation of s and m.
return js_string(vm, DeprecatedString::formatted("{}{}", sign, number_string));
return PrimitiveString::create(vm, DeprecatedString::formatted("{}{}", sign, number_string));
}
// 21.1.3.6 Number.prototype.toString ( [ radix ] ), https://tc39.es/ecma262/#sec-number.prototype.tostring
@ -441,17 +441,17 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_string)
// 5. If radixMV = 10, return ! ToString(x).
if (radix_mv == 10)
return js_string(vm, MUST(number_value.to_string(vm)));
return PrimitiveString::create(vm, MUST(number_value.to_string(vm)));
// 6. Return the String representation of this Number value using the radix specified by radixMV. Letters a-z are used for digits with values 10 through 35. The precise algorithm is implementation-defined, however the algorithm should be a generalization of that specified in 6.1.6.1.20.
if (number_value.is_positive_infinity())
return js_string(vm, "Infinity");
return PrimitiveString::create(vm, "Infinity");
if (number_value.is_negative_infinity())
return js_string(vm, "-Infinity");
return PrimitiveString::create(vm, "-Infinity");
if (number_value.is_nan())
return js_string(vm, "NaN");
return PrimitiveString::create(vm, "NaN");
if (number_value.is_positive_zero() || number_value.is_negative_zero())
return js_string(vm, "0");
return PrimitiveString::create(vm, "0");
double number = number_value.as_double();
bool negative = number < 0;
@ -499,7 +499,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_string)
characters.take_last();
}
return js_string(vm, DeprecatedString(characters.data(), characters.size()));
return PrimitiveString::create(vm, DeprecatedString(characters.data(), characters.size()));
}
// 21.1.3.7 Number.prototype.valueOf ( ), https://tc39.es/ecma262/#sec-number.prototype.valueof

View file

@ -961,7 +961,7 @@ ThrowCompletionOr<MarkedVector<Value>> Object::internal_own_property_keys() cons
// 2. For each own property key P of O such that P is an array index, in ascending numeric index order, do
for (auto& entry : m_indexed_properties) {
// a. Add P as the last element of keys.
keys.append(js_string(vm, DeprecatedString::number(entry.index())));
keys.append(PrimitiveString::create(vm, DeprecatedString::number(entry.index())));
}
// 3. For each own property key P of O such that Type(P) is String and P is not an array index, in ascending chronological order of property creation, do

View file

@ -70,11 +70,11 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::to_string)
// 1. If the this value is undefined, return "[object Undefined]".
if (this_value.is_undefined())
return js_string(vm, "[object Undefined]");
return PrimitiveString::create(vm, "[object Undefined]");
// 2. If the this value is null, return "[object Null]".
if (this_value.is_null())
return js_string(vm, "[object Null]");
return PrimitiveString::create(vm, "[object Null]");
// 3. Let O be ! ToObject(this value).
auto* object = MUST(this_value.to_object(vm));
@ -128,7 +128,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::to_string)
tag = to_string_tag.as_string().deprecated_string();
// 17. Return the string-concatenation of "[object ", tag, and "]".
return js_string(vm, DeprecatedString::formatted("[object {}]", tag));
return PrimitiveString::create(vm, DeprecatedString::formatted("[object {}]", tag));
}
// 20.1.3.5 Object.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] ), https://tc39.es/ecma262/#sec-object.prototype.tolocalestring

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -105,65 +106,50 @@ Optional<Value> PrimitiveString::get(VM& vm, PropertyKey const& property_key) co
auto length = str.length_in_code_units();
if (length <= index.as_index())
return {};
return js_string(vm, str.substring_view(index.as_index(), 1));
return create(vm, str.substring_view(index.as_index(), 1));
}
PrimitiveString* js_string(Heap& heap, Utf16View const& view)
NonnullGCPtr<PrimitiveString> PrimitiveString::create(VM& vm, Utf16View const& view)
{
return js_string(heap, Utf16String(view));
return create(vm, Utf16String(view));
}
PrimitiveString* js_string(VM& vm, Utf16View const& view)
{
return js_string(vm.heap(), view);
}
PrimitiveString* js_string(Heap& heap, Utf16String string)
NonnullGCPtr<PrimitiveString> PrimitiveString::create(VM& vm, Utf16String string)
{
if (string.is_empty())
return &heap.vm().empty_string();
return vm.empty_string();
if (string.length_in_code_units() == 1) {
u16 code_unit = string.code_unit_at(0);
if (is_ascii(code_unit))
return &heap.vm().single_ascii_character_string(static_cast<u8>(code_unit));
return vm.single_ascii_character_string(static_cast<u8>(code_unit));
}
return heap.allocate_without_realm<PrimitiveString>(move(string));
return *vm.heap().allocate_without_realm<PrimitiveString>(move(string));
}
PrimitiveString* js_string(VM& vm, Utf16String string)
{
return js_string(vm.heap(), move(string));
}
PrimitiveString* js_string(Heap& heap, DeprecatedString string)
NonnullGCPtr<PrimitiveString> PrimitiveString::create(VM& vm, DeprecatedString string)
{
if (string.is_empty())
return &heap.vm().empty_string();
return vm.empty_string();
if (string.length() == 1) {
auto ch = static_cast<u8>(string.characters()[0]);
if (is_ascii(ch))
return &heap.vm().single_ascii_character_string(ch);
return vm.single_ascii_character_string(ch);
}
auto& string_cache = heap.vm().string_cache();
auto& string_cache = vm.string_cache();
auto it = string_cache.find(string);
if (it == string_cache.end()) {
auto* new_string = heap.allocate_without_realm<PrimitiveString>(string);
auto* new_string = vm.heap().allocate_without_realm<PrimitiveString>(string);
string_cache.set(move(string), new_string);
return new_string;
return *new_string;
}
return it->value;
return *it->value;
}
PrimitiveString* js_string(VM& vm, DeprecatedString string)
{
return js_string(vm.heap(), move(string));
}
PrimitiveString* js_rope_string(VM& vm, PrimitiveString& lhs, PrimitiveString& rhs)
NonnullGCPtr<PrimitiveString> PrimitiveString::create(VM& vm, PrimitiveString& lhs, PrimitiveString& rhs)
{
// We're here to concatenate two strings into a new rope string.
// However, if any of them are empty, no rope is required.
@ -172,15 +158,15 @@ PrimitiveString* js_rope_string(VM& vm, PrimitiveString& lhs, PrimitiveString& r
bool rhs_empty = rhs.is_empty();
if (lhs_empty && rhs_empty)
return &vm.empty_string();
return vm.empty_string();
if (lhs_empty)
return &rhs;
return rhs;
if (rhs_empty)
return &lhs;
return lhs;
return vm.heap().allocate_without_realm<PrimitiveString>(lhs, rhs);
return *vm.heap().allocate_without_realm<PrimitiveString>(lhs, rhs);
}
void PrimitiveString::resolve_rope_if_needed() const

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -19,6 +20,11 @@ class PrimitiveString final : public Cell {
JS_CELL(PrimitiveString, Cell);
public:
[[nodiscard]] static NonnullGCPtr<PrimitiveString> create(VM&, Utf16View const&);
[[nodiscard]] static NonnullGCPtr<PrimitiveString> create(VM&, Utf16String);
[[nodiscard]] static NonnullGCPtr<PrimitiveString> create(VM&, DeprecatedString);
[[nodiscard]] static NonnullGCPtr<PrimitiveString> create(VM&, PrimitiveString&, PrimitiveString&);
virtual ~PrimitiveString();
PrimitiveString(PrimitiveString const&) = delete;
@ -56,15 +62,4 @@ private:
mutable Utf16String m_utf16_string;
};
PrimitiveString* js_string(Heap&, Utf16View const&);
PrimitiveString* js_string(VM&, Utf16View const&);
PrimitiveString* js_string(Heap&, Utf16String);
PrimitiveString* js_string(VM&, Utf16String);
PrimitiveString* js_string(Heap&, DeprecatedString);
PrimitiveString* js_string(VM&, DeprecatedString);
PrimitiveString* js_rope_string(VM&, PrimitiveString&, PrimitiveString&);
}

View file

@ -157,7 +157,7 @@ Promise::ResolvingFunctions Promise::create_resolving_functions()
// 16. Return undefined.
return js_undefined();
});
resolve_function->define_direct_property(vm.names.name, js_string(vm, DeprecatedString::empty()), Attribute::Configurable);
resolve_function->define_direct_property(vm.names.name, PrimitiveString::create(vm, DeprecatedString::empty()), Attribute::Configurable);
// 7. Let stepsReject be the algorithm steps defined in Promise Reject Functions.
// 8. Let lengthReject be the number of non-optional parameters of the function definition in Promise Reject Functions.
@ -189,7 +189,7 @@ Promise::ResolvingFunctions Promise::create_resolving_functions()
// 8. Return undefined.
return js_undefined();
});
reject_function->define_direct_property(vm.names.name, js_string(vm, DeprecatedString::empty()), Attribute::Configurable);
reject_function->define_direct_property(vm.names.name, PrimitiveString::create(vm, DeprecatedString::empty()), Attribute::Configurable);
// 12. Return the Record { [[Resolve]]: resolve, [[Reject]]: reject }.
return { *resolve_function, *reject_function };

View file

@ -139,7 +139,7 @@ static ThrowCompletionOr<Value> perform_promise_all(VM& vm, Iterator& iterator_r
// p. Set onFulfilled.[[Capability]] to resultCapability.
// q. Set onFulfilled.[[RemainingElements]] to remainingElementsCount.
auto* on_fulfilled = PromiseAllResolveElementFunction::create(realm, index, values, result_capability, remaining_elements_count);
on_fulfilled->define_direct_property(vm.names.name, js_string(vm, DeprecatedString::empty()), Attribute::Configurable);
on_fulfilled->define_direct_property(vm.names.name, PrimitiveString::create(vm, DeprecatedString::empty()), Attribute::Configurable);
// s. Perform ? Invoke(nextPromise, "then", « onFulfilled, resultCapability.[[Reject]] »).
return next_promise.invoke(vm, vm.names.then, on_fulfilled, result_capability.reject());
@ -171,7 +171,7 @@ static ThrowCompletionOr<Value> perform_promise_all_settled(VM& vm, Iterator& it
// q. Set onFulfilled.[[Capability]] to resultCapability.
// r. Set onFulfilled.[[RemainingElements]] to remainingElementsCount.
auto* on_fulfilled = PromiseAllSettledResolveElementFunction::create(realm, index, values, result_capability, remaining_elements_count);
on_fulfilled->define_direct_property(vm.names.name, js_string(vm, DeprecatedString::empty()), Attribute::Configurable);
on_fulfilled->define_direct_property(vm.names.name, PrimitiveString::create(vm, DeprecatedString::empty()), Attribute::Configurable);
// s. Let stepsRejected be the algorithm steps defined in Promise.allSettled Reject Element Functions.
// t. Let lengthRejected be the number of non-optional parameters of the function definition in Promise.allSettled Reject Element Functions.
@ -182,7 +182,7 @@ static ThrowCompletionOr<Value> perform_promise_all_settled(VM& vm, Iterator& it
// y. Set onRejected.[[Capability]] to resultCapability.
// z. Set onRejected.[[RemainingElements]] to remainingElementsCount.
auto* on_rejected = PromiseAllSettledRejectElementFunction::create(realm, index, values, result_capability, remaining_elements_count);
on_rejected->define_direct_property(vm.names.name, js_string(vm, DeprecatedString::empty()), Attribute::Configurable);
on_rejected->define_direct_property(vm.names.name, PrimitiveString::create(vm, DeprecatedString::empty()), Attribute::Configurable);
// ab. Perform ? Invoke(nextPromise, "then", « onFulfilled, onRejected »).
return next_promise.invoke(vm, vm.names.then, on_fulfilled, on_rejected);
@ -217,7 +217,7 @@ static ThrowCompletionOr<Value> perform_promise_any(VM& vm, Iterator& iterator_r
// p. Set onRejected.[[Capability]] to resultCapability.
// q. Set onRejected.[[RemainingElements]] to remainingElementsCount.
auto* on_rejected = PromiseAnyRejectElementFunction::create(realm, index, errors, result_capability, remaining_elements_count);
on_rejected->define_direct_property(vm.names.name, js_string(vm, DeprecatedString::empty()), Attribute::Configurable);
on_rejected->define_direct_property(vm.names.name, PrimitiveString::create(vm, DeprecatedString::empty()), Attribute::Configurable);
// s. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], onRejected »).
return next_promise.invoke(vm, vm.names.then, result_capability.resolve(), on_rejected);

View file

@ -32,7 +32,7 @@ void PromisePrototype::initialize(Realm& realm)
define_native_function(realm, vm.names.finally, finally, 1, attr);
// 27.2.5.5 Promise.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-promise.prototype-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, vm.names.Promise.as_string()), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, vm.names.Promise.as_string()), Attribute::Configurable);
}
// 27.2.5.4 Promise.prototype.then ( onFulfilled, onRejected ), https://tc39.es/ecma262/#sec-promise.prototype.then

View file

@ -104,7 +104,7 @@ ThrowCompletionOr<Value> PromiseAllSettledResolveElementFunction::resolve_elemen
auto* object = Object::create(realm, realm.intrinsics().object_prototype());
// 10. Perform ! CreateDataPropertyOrThrow(obj, "status", "fulfilled").
MUST(object->create_data_property_or_throw(vm.names.status, js_string(vm, "fulfilled"sv)));
MUST(object->create_data_property_or_throw(vm.names.status, PrimitiveString::create(vm, "fulfilled"sv)));
// 11. Perform ! CreateDataPropertyOrThrow(obj, "value", x).
MUST(object->create_data_property_or_throw(vm.names.value, vm.argument(0)));
@ -145,7 +145,7 @@ ThrowCompletionOr<Value> PromiseAllSettledRejectElementFunction::resolve_element
auto* object = Object::create(realm, realm.intrinsics().object_prototype());
// 10. Perform ! CreateDataPropertyOrThrow(obj, "status", "rejected").
MUST(object->create_data_property_or_throw(vm.names.status, js_string(vm, "rejected"sv)));
MUST(object->create_data_property_or_throw(vm.names.status, PrimitiveString::create(vm, "rejected"sv)));
// 11. Perform ! CreateDataPropertyOrThrow(obj, "reason", x).
MUST(object->create_data_property_or_throw(vm.names.reason, vm.argument(0)));

View file

@ -34,10 +34,10 @@ static Value property_key_to_value(VM& vm, PropertyKey const& property_key)
return property_key.as_symbol();
if (property_key.is_string())
return js_string(vm, property_key.as_string());
return PrimitiveString::create(vm, property_key.as_string());
VERIFY(property_key.is_number());
return js_string(vm, DeprecatedString::number(property_key.as_number()));
return PrimitiveString::create(vm, DeprecatedString::number(property_key.as_number()));
}
// 10.5.1 [[GetPrototypeOf]] ( ), https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-getprototypeof

View file

@ -40,7 +40,7 @@ void ReflectObject::initialize(Realm& realm)
define_native_function(realm, vm.names.setPrototypeOf, set_prototype_of, 2, attr);
// 28.1.14 Reflect [ @@toStringTag ], https://tc39.es/ecma262/#sec-reflect-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, vm.names.Reflect.as_string()), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, vm.names.Reflect.as_string()), Attribute::Configurable);
}
// 28.1.1 Reflect.apply ( target, thisArgument, argumentsList ), https://tc39.es/ecma262/#sec-reflect.apply

View file

@ -100,11 +100,11 @@ ThrowCompletionOr<Object*> RegExpConstructor::construct(FunctionObject& new_targ
if (pattern.is_object() && is<RegExpObject>(pattern.as_object())) {
// a. Let P be pattern.[[OriginalSource]].
auto& regexp_pattern = static_cast<RegExpObject&>(pattern.as_object());
pattern_value = js_string(vm, regexp_pattern.pattern());
pattern_value = PrimitiveString::create(vm, regexp_pattern.pattern());
// b. If flags is undefined, let F be pattern.[[OriginalFlags]].
if (flags.is_undefined())
flags_value = js_string(vm, regexp_pattern.flags());
flags_value = PrimitiveString::create(vm, regexp_pattern.flags());
// c. Else, let F be flags.
else
flags_value = flags;

View file

@ -46,7 +46,7 @@ ThrowCompletionOr<Value> get_legacy_regexp_static_property(VM& vm, RegExpConstru
return vm.throw_completion<TypeError>(ErrorType::GetLegacyRegExpStaticPropertyValueEmpty);
// 5. Return val.
return js_string(vm, val.release_value());
return PrimitiveString::create(vm, val.release_value());
}
// SetLegacyRegExpStaticProperty( C, thisValue, internalSlotName, val ), https://github.com/tc39/proposal-regexp-legacy-features#setlegacyregexpstaticproperty-c-thisvalue-internalslotname-val-

View file

@ -275,7 +275,7 @@ static ThrowCompletionOr<Value> regexp_builtin_exec(VM& vm, RegExpObject& regexp
// 27. Let matchedValue be ! GetMatchString(S, match).
// 28. Perform ! CreateDataPropertyOrThrow(A, "0", matchedValue).
MUST(array->create_data_property_or_throw(0, js_string(vm, match.view.u16_view())));
MUST(array->create_data_property_or_throw(0, PrimitiveString::create(vm, match.view.u16_view())));
// 29. If R contains any GroupName, then
// a. Let groups be OrdinaryObjectCreate(null).
@ -312,7 +312,7 @@ static ThrowCompletionOr<Value> regexp_builtin_exec(VM& vm, RegExpObject& regexp
// iv. Let capture be the Match { [[StartIndex]]: captureStart, [[EndIndex]: captureEnd }.
// v. Let capturedValue be ! GetMatchString(S, capture).
auto capture_as_utf16_string = Utf16String(capture.view.u16_view());
captured_value = js_string(vm, capture_as_utf16_string);
captured_value = PrimitiveString::create(vm, capture_as_utf16_string);
// vi. Append capture to indices.
indices.append(Match::create(capture));
// vii. Append capturedValue to the end of capturedValues.
@ -375,8 +375,8 @@ static ThrowCompletionOr<Value> regexp_builtin_exec(VM& vm, RegExpObject& regexp
}
// 22. Perform ! CreateDataPropertyOrThrow(A, "input", S).
// NOTE: This step is performed last to allow the string to be moved into the js_string invocation.
MUST(array->create_data_property_or_throw(vm.names.input, js_string(vm, move(string))));
// NOTE: This step is performed last to allow the string to be moved into the PrimitiveString::create() invocation.
MUST(array->create_data_property_or_throw(vm.names.input, PrimitiveString::create(vm, move(string))));
// 34. Return A.
return array;
@ -391,7 +391,7 @@ ThrowCompletionOr<Value> regexp_exec(VM& vm, Object& regexp_object, Utf16String
// 2. If IsCallable(exec) is true, then
if (exec.is_function()) {
// a. Let result be ? Call(exec, R, « S »).
auto result = TRY(call(vm, exec.as_function(), &regexp_object, js_string(vm, move(string))));
auto result = TRY(call(vm, exec.as_function(), &regexp_object, PrimitiveString::create(vm, move(string))));
// b. If Type(result) is neither Object nor Null, throw a TypeError exception.
if (!result.is_object() && !result.is_null())
@ -510,7 +510,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::flags)
#undef __JS_ENUMERATE
// 18. Return result.
return js_string(vm, builder.to_deprecated_string());
return PrimitiveString::create(vm, builder.to_deprecated_string());
}
// 22.2.5.8 RegExp.prototype [ @@match ] ( string ), https://tc39.es/ecma262/#sec-regexp.prototype-@@match
@ -576,7 +576,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match)
auto match_str = TRY(match_value.to_string(vm));
// 2. Perform ! CreateDataPropertyOrThrow(A, ! ToString(𝔽(n)), matchStr).
MUST(array->create_data_property_or_throw(n, js_string(vm, match_str)));
MUST(array->create_data_property_or_throw(n, PrimitiveString::create(vm, match_str)));
// 3. If matchStr is the empty String, then
if (match_str.is_empty()) {
@ -620,7 +620,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match_all)
bool full_unicode = flags.contains('u') || flags.contains('v');
// 6. Let matcher be ? Construct(C, « R, flags »).
auto* matcher = TRY(construct(vm, *constructor, regexp_object, js_string(vm, move(flags))));
auto* matcher = TRY(construct(vm, *constructor, regexp_object, PrimitiveString::create(vm, move(flags))));
// 7. Let lastIndex be ? ToLength(? Get(R, "lastIndex")).
auto last_index_value = TRY(regexp_object->get(vm.names.lastIndex));
@ -654,7 +654,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_replace)
if (!replace_value.is_function()) {
// a. Set replaceValue to ? ToString(replaceValue).
auto replace_string = TRY(replace_value.to_string(vm));
replace_value = js_string(vm, move(replace_string));
replace_value = PrimitiveString::create(vm, move(replace_string));
}
// 7. Let flags be ? ToString(? Get(rx, "flags")).
@ -752,7 +752,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_replace)
// ii. If capN is not undefined, then
if (!capture.is_undefined()) {
// 1. Set capN to ? ToString(capN).
capture = js_string(vm, TRY(capture.to_string(vm)));
capture = PrimitiveString::create(vm, TRY(capture.to_string(vm)));
}
// iii. Append capN as the last element of captures.
@ -771,14 +771,14 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_replace)
if (replace_value.is_function()) {
// i. Let replacerArgs be « matched ».
MarkedVector<Value> replacer_args(vm.heap());
replacer_args.append(js_string(vm, move(matched)));
replacer_args.append(PrimitiveString::create(vm, move(matched)));
// ii. Append in List order the elements of captures to the end of the List replacerArgs.
replacer_args.extend(move(captures));
// iii. Append 𝔽(position) and S to replacerArgs.
replacer_args.append(Value(position));
replacer_args.append(js_string(vm, string));
replacer_args.append(PrimitiveString::create(vm, string));
// iv. If namedCaptures is not undefined, then
if (!named_captures.is_undefined()) {
@ -820,13 +820,13 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_replace)
// 15. If nextSourcePosition ≥ lengthS, return accumulatedResult.
if (next_source_position >= string.length_in_code_units())
return js_string(vm, accumulated_result.build());
return PrimitiveString::create(vm, accumulated_result.build());
// 16. Return the string-concatenation of accumulatedResult and the substring of S from nextSourcePosition.
auto substring = string.substring_view(next_source_position);
accumulated_result.append(substring);
return js_string(vm, accumulated_result.build());
return PrimitiveString::create(vm, accumulated_result.build());
}
// 22.2.5.12 RegExp.prototype [ @@search ] ( string ), https://tc39.es/ecma262/#sec-regexp.prototype-@@search
@ -881,7 +881,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::source)
if (!is<RegExpObject>(regexp_object)) {
// a. If SameValue(R, %RegExp.prototype%) is true, return "(?:)".
if (same_value(regexp_object, realm.intrinsics().regexp_prototype()))
return js_string(vm, "(?:)");
return PrimitiveString::create(vm, "(?:)");
// b. Otherwise, throw a TypeError exception.
return vm.throw_completion<TypeError>(ErrorType::NotAnObjectOfType, "RegExp");
@ -891,7 +891,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::source)
// 5. Let src be R.[[OriginalSource]].
// 6. Let flags be R.[[OriginalFlags]].
// 7. Return EscapeRegExpPattern(src, flags).
return js_string(vm, static_cast<RegExpObject&>(*regexp_object).escape_regexp_pattern());
return PrimitiveString::create(vm, static_cast<RegExpObject&>(*regexp_object).escape_regexp_pattern());
}
// 22.2.5.14 RegExp.prototype [ @@split ] ( string, limit ), https://tc39.es/ecma262/#sec-regexp.prototype-@@split
@ -923,7 +923,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_split)
auto new_flags = flags.find('y').has_value() ? move(flags) : DeprecatedString::formatted("{}y", flags);
// 10. Let splitter be ? Construct(C, « rx, newFlags »).
auto* splitter = TRY(construct(vm, *constructor, regexp_object, js_string(vm, move(new_flags))));
auto* splitter = TRY(construct(vm, *constructor, regexp_object, PrimitiveString::create(vm, move(new_flags))));
// 11. Let A be ! ArrayCreate(0).
auto* array = MUST(Array::create(realm, 0));
@ -951,7 +951,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_split)
return array;
// c. Perform ! CreateDataPropertyOrThrow(A, "0", S).
MUST(array->create_data_property_or_throw(0, js_string(vm, move(string))));
MUST(array->create_data_property_or_throw(0, PrimitiveString::create(vm, move(string))));
// d. Return A.
return array;
@ -998,7 +998,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_split)
auto substring = string.substring_view(last_match_end, next_search_from - last_match_end);
// 2. Perform ! CreateDataPropertyOrThrow(A, ! ToString(𝔽(lengthA)), T).
MUST(array->create_data_property_or_throw(array_length, js_string(vm, substring)));
MUST(array->create_data_property_or_throw(array_length, PrimitiveString::create(vm, substring)));
// 3. Set lengthA to lengthA + 1.
++array_length;
@ -1045,7 +1045,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_split)
auto substring = string.substring_view(last_match_end);
// 21. Perform ! CreateDataPropertyOrThrow(A, ! ToString(𝔽(lengthA)), T).
MUST(array->create_data_property_or_throw(array_length, js_string(vm, substring)));
MUST(array->create_data_property_or_throw(array_length, PrimitiveString::create(vm, substring)));
// 22. Return A.
return array;
@ -1085,7 +1085,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::to_string)
// 5. Let result be the string-concatenation of "/", pattern, "/", and flags.
// 6. Return result.
return js_string(vm, DeprecatedString::formatted("/{}/{}", pattern, flags));
return PrimitiveString::create(vm, DeprecatedString::formatted("/{}/{}", pattern, flags));
}
// B.2.4.1 RegExp.prototype.compile ( pattern, flags ), https://tc39.es/ecma262/#sec-regexp.prototype.compile
@ -1122,10 +1122,10 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::compile)
auto& regexp_pattern = static_cast<RegExpObject&>(pattern.as_object());
// b. Let P be pattern.[[OriginalSource]].
pattern = js_string(vm, regexp_pattern.pattern());
pattern = PrimitiveString::create(vm, regexp_pattern.pattern());
// c. Let F be pattern.[[OriginalFlags]].
flags = js_string(vm, regexp_pattern.flags());
flags = PrimitiveString::create(vm, regexp_pattern.flags());
}
// 8. Else,
// a. Let P be pattern.

View file

@ -26,7 +26,7 @@ void RegExpStringIteratorPrototype::initialize(Realm& realm)
define_native_function(realm, vm.names.next, next, 0, attr);
// 22.2.7.2.2 %RegExpStringIteratorPrototype% [ @@toStringTag ], https://tc39.es/ecma262/#sec-%regexpstringiteratorprototype%-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "RegExp String Iterator"), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "RegExp String Iterator"), Attribute::Configurable);
}
// 22.2.7.2.1 %RegExpStringIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%regexpstringiteratorprototype%.next

View file

@ -26,7 +26,7 @@ void SetIteratorPrototype::initialize(Realm& realm)
define_native_function(realm, vm.names.next, next, 0, Attribute::Configurable | Attribute::Writable);
// 24.2.5.2.2 %SetIteratorPrototype% [ @@toStringTag ], https://tc39.es/ecma262/#sec-%setiteratorprototype%-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Set Iterator"), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Set Iterator"), Attribute::Configurable);
}
// 24.2.5.2.1 %SetIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%setiteratorprototype%.next

View file

@ -47,7 +47,7 @@ void SetPrototype::initialize(Realm& realm)
define_direct_property(*vm.well_known_symbol_iterator(), get_without_side_effects(vm.names.values), attr);
// 24.2.3.12 Set.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-set.prototype-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, vm.names.Set.as_string()), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, vm.names.Set.as_string()), Attribute::Configurable);
}
// 24.2.3.1 Set.prototype.add ( value ), https://tc39.es/ecma262/#sec-set.prototype.add

View file

@ -83,7 +83,7 @@ ThrowCompletionOr<void> copy_name_and_length(VM& vm, FunctionObject& function, F
// 7. If Type(targetName) is not String, set targetName to the empty String.
if (!target_name.is_string())
target_name = js_string(vm, DeprecatedString::empty());
target_name = PrimitiveString::create(vm, DeprecatedString::empty());
// 8. Perform SetFunctionName(F, targetName, prefix).
function.set_function_name({ target_name.as_string().deprecated_string() }, move(prefix));

View file

@ -26,7 +26,7 @@ void ShadowRealmPrototype::initialize(Realm& realm)
define_native_function(realm, vm.names.importValue, import_value, 2, attr);
// 3.4.3 ShadowRealm.prototype [ @@toStringTag ], https://tc39.es/proposal-shadowrealm/#sec-shadowrealm.prototype-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, vm.names.ShadowRealm.as_string()), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, vm.names.ShadowRealm.as_string()), Attribute::Configurable);
}
// 3.4.1 ShadowRealm.prototype.evaluate ( sourceText ), https://tc39.es/proposal-shadowrealm/#sec-shadowrealm.prototype.evaluate

View file

@ -43,9 +43,9 @@ ThrowCompletionOr<Value> StringConstructor::call()
{
auto& vm = this->vm();
if (!vm.argument_count())
return js_string(heap(), "");
return PrimitiveString::create(vm, "");
if (vm.argument(0).is_symbol())
return js_string(vm, vm.argument(0).as_symbol().to_deprecated_string());
return PrimitiveString::create(vm, vm.argument(0).as_symbol().to_deprecated_string());
return TRY(vm.argument(0).to_primitive_string(vm));
}
@ -57,7 +57,7 @@ ThrowCompletionOr<Object*> StringConstructor::construct(FunctionObject& new_targ
PrimitiveString* primitive_string;
if (!vm.argument_count())
primitive_string = js_string(vm, "");
primitive_string = PrimitiveString::create(vm, "");
else
primitive_string = TRY(vm.argument(0).to_primitive_string(vm));
auto* prototype = TRY(get_prototype_from_constructor(vm, new_target, &Intrinsics::string_prototype));
@ -73,7 +73,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringConstructor::raw)
auto literal_segments = TRY(length_of_array_like(vm, *raw));
if (literal_segments == 0)
return js_string(vm, "");
return PrimitiveString::create(vm, "");
auto const number_of_substituions = vm.argument_count() - 1;
@ -94,7 +94,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringConstructor::raw)
builder.append(next_sub);
}
}
return js_string(vm, builder.build());
return PrimitiveString::create(vm, builder.build());
}
// 22.1.2.1 String.fromCharCode ( ...codeUnits ), https://tc39.es/ecma262/#sec-string.fromcharcode
@ -106,7 +106,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringConstructor::from_char_code)
for (size_t i = 0; i < vm.argument_count(); ++i)
string.append(TRY(vm.argument(i).to_u16(vm)));
return js_string(vm, Utf16String(move(string)));
return PrimitiveString::create(vm, Utf16String(move(string)));
}
// 22.1.2.2 String.fromCodePoint ( ...codePoints ), https://tc39.es/ecma262/#sec-string.fromcodepoint
@ -126,7 +126,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringConstructor::from_code_point)
AK::code_point_to_utf16(string, static_cast<u32>(code_point));
}
return js_string(vm, Utf16String(move(string)));
return PrimitiveString::create(vm, Utf16String(move(string)));
}
}

View file

@ -25,7 +25,7 @@ void StringIteratorPrototype::initialize(Realm& realm)
define_native_function(realm, vm.names.next, next, 0, Attribute::Configurable | Attribute::Writable);
// 22.1.5.1.2 %StringIteratorPrototype% [ @@toStringTag ], https://tc39.es/ecma262/#sec-%stringiteratorprototype%-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "String Iterator"), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "String Iterator"), Attribute::Configurable);
}
// 22.1.5.1.1 %StringIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%stringiteratorprototype%.next
@ -46,7 +46,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringIteratorPrototype::next)
builder.append_code_point(*utf8_iterator);
++utf8_iterator;
return create_iterator_result_object(vm, js_string(vm, builder.to_deprecated_string()), false);
return create_iterator_result_object(vm, PrimitiveString::create(vm, builder.to_deprecated_string()), false);
}
}

View file

@ -71,7 +71,7 @@ static Optional<PropertyDescriptor> string_get_own_property(StringObject const&
return {};
// 10. Let resultStr be the String value of length 1, containing one code unit from str, specifically the code unit at index (index).
auto result_str = js_string(string.vm(), str.substring_view(index.as_index(), 1));
auto result_str = PrimitiveString::create(string.vm(), str.substring_view(index.as_index(), 1));
// 11. Return the PropertyDescriptor { [[Value]]: resultStr, [[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false }.
return PropertyDescriptor {
@ -138,14 +138,14 @@ ThrowCompletionOr<MarkedVector<Value>> StringObject::internal_own_property_keys(
// 5. For each integer i starting with 0 such that i < len, in ascending order, do
for (size_t i = 0; i < length; ++i) {
// a. Add ! ToString(𝔽(i)) as the last element of keys.
keys.append(js_string(vm, DeprecatedString::number(i)));
keys.append(PrimitiveString::create(vm, DeprecatedString::number(i)));
}
// 6. For each own property key P of O such that P is an array index and ! ToIntegerOrInfinity(P) ≥ len, in ascending numeric index order, do
for (auto& entry : indexed_properties()) {
if (entry.index() >= length) {
// a. Add P as the last element of keys.
keys.append(js_string(vm, DeprecatedString::number(entry.index())));
keys.append(PrimitiveString::create(vm, DeprecatedString::number(entry.index())));
}
}

View file

@ -86,7 +86,7 @@ public:
Value to_value(VM& vm) const
{
if (is_string())
return js_string(vm, as_string());
return PrimitiveString::create(vm, as_string());
if (is_symbol())
return const_cast<Symbol*>(as_symbol());
return {};

View file

@ -131,7 +131,7 @@ CodePoint code_point_at(Utf16View const& string, size_t position)
}
StringPrototype::StringPrototype(Realm& realm)
: StringObject(*js_string(realm.vm(), DeprecatedString::empty()), *realm.intrinsics().object_prototype())
: StringObject(*PrimitiveString::create(realm.vm(), DeprecatedString::empty()), *realm.intrinsics().object_prototype())
{
}
@ -237,7 +237,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::at)
return js_undefined();
// 7. Return ? Get(O, ! ToString(𝔽(k))).
return js_string(vm, string.substring_view(index.value(), 1));
return PrimitiveString::create(vm, string.substring_view(index.value(), 1));
}
// 22.1.3.2 String.prototype.charAt ( pos ), https://tc39.es/ecma262/#sec-string.prototype.charat
@ -246,9 +246,9 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::char_at)
auto string = TRY(utf16_string_from(vm));
auto position = TRY(vm.argument(0).to_integer_or_infinity(vm));
if (position < 0 || position >= string.length_in_code_units())
return js_string(vm, DeprecatedString::empty());
return PrimitiveString::create(vm, DeprecatedString::empty());
return js_string(vm, string.substring_view(position, 1));
return PrimitiveString::create(vm, string.substring_view(position, 1));
}
// 22.1.3.3 String.prototype.charCodeAt ( pos ), https://tc39.es/ecma262/#sec-string.prototype.charcodeat
@ -292,7 +292,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::concat)
auto* next_string = TRY(vm.argument(i).to_primitive_string(vm));
// b. Set R to the string-concatenation of R and nextString.
result = js_rope_string(vm, *result, *next_string);
result = PrimitiveString::create(vm, *result, *next_string);
}
// 5. Return R.
@ -451,7 +451,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::match)
auto string = TRY(this_object.to_utf16_string(vm));
auto rx = TRY(regexp_create(vm, regexp, js_undefined()));
return TRY(Value(rx).invoke(vm, *vm.well_known_symbol_match(), js_string(vm, move(string))));
return TRY(Value(rx).invoke(vm, *vm.well_known_symbol_match(), PrimitiveString::create(vm, move(string))));
}
// 22.1.3.13 String.prototype.matchAll ( regexp ), https://tc39.es/ecma262/#sec-string.prototype.matchall
@ -474,8 +474,8 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::match_all)
auto string = TRY(this_object.to_utf16_string(vm));
auto rx = TRY(regexp_create(vm, regexp, js_string(vm, "g")));
return TRY(Value(rx).invoke(vm, *vm.well_known_symbol_match_all(), js_string(vm, move(string))));
auto rx = TRY(regexp_create(vm, regexp, PrimitiveString::create(vm, "g")));
return TRY(Value(rx).invoke(vm, *vm.well_known_symbol_match_all(), PrimitiveString::create(vm, move(string))));
}
// 22.1.3.14 String.prototype.normalize ( [ form ] ), https://tc39.es/ecma262/#sec-string.prototype.normalize
@ -501,7 +501,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::normalize)
auto ns = Unicode::normalize(string, unicode_form);
// 7. return ns.
return js_string(vm, move(ns));
return PrimitiveString::create(vm, move(ns));
}
enum class PadPlacement {
@ -516,13 +516,13 @@ static ThrowCompletionOr<Value> pad_string(VM& vm, Utf16String string, PadPlacem
auto max_length = TRY(vm.argument(0).to_length(vm));
if (max_length <= string_length)
return js_string(vm, move(string));
return PrimitiveString::create(vm, move(string));
Utf16String fill_string(Vector<u16, 1> { 0x20 });
if (!vm.argument(1).is_undefined()) {
fill_string = TRY(vm.argument(1).to_utf16_string(vm));
if (fill_string.is_empty())
return js_string(vm, move(string));
return PrimitiveString::create(vm, move(string));
}
auto fill_code_units = fill_string.length_in_code_units();
@ -538,7 +538,7 @@ static ThrowCompletionOr<Value> pad_string(VM& vm, Utf16String string, PadPlacem
auto formatted = placement == PadPlacement::Start
? DeprecatedString::formatted("{}{}", filler, string.view())
: DeprecatedString::formatted("{}{}", string.view(), filler);
return js_string(vm, move(formatted));
return PrimitiveString::create(vm, move(formatted));
}
// 22.1.3.15 String.prototype.padEnd ( maxLength [ , fillString ] ), https://tc39.es/ecma262/#sec-string.prototype.padend
@ -569,16 +569,16 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::repeat)
return vm.throw_completion<RangeError>(ErrorType::StringRepeatCountMustBe, "finite");
if (n == 0)
return js_string(vm, DeprecatedString::empty());
return PrimitiveString::create(vm, DeprecatedString::empty());
// NOTE: This is an optimization, it is not required by the specification but it produces equivalent behavior
if (string.is_empty())
return js_string(vm, DeprecatedString::empty());
return PrimitiveString::create(vm, DeprecatedString::empty());
StringBuilder builder;
for (size_t i = 0; i < n; ++i)
builder.append(string);
return js_string(vm, builder.to_deprecated_string());
return PrimitiveString::create(vm, builder.to_deprecated_string());
}
// 22.1.3.18 String.prototype.replace ( searchValue, replaceValue ), https://tc39.es/ecma262/#sec-string.prototype.replace
@ -598,18 +598,18 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::replace)
if (!replace_value.is_function()) {
auto replace_string = TRY(replace_value.to_utf16_string(vm));
replace_value = js_string(vm, move(replace_string));
replace_value = PrimitiveString::create(vm, move(replace_string));
}
Optional<size_t> position = string_index_of(string.view(), search_string.view(), 0);
if (!position.has_value())
return js_string(vm, move(string));
return PrimitiveString::create(vm, move(string));
auto preserved = string.substring_view(0, position.value());
DeprecatedString replacement;
if (replace_value.is_function()) {
auto result = TRY(call(vm, replace_value.as_function(), js_undefined(), js_string(vm, search_string), Value(position.value()), js_string(vm, string)));
auto result = TRY(call(vm, replace_value.as_function(), js_undefined(), PrimitiveString::create(vm, search_string), Value(position.value()), PrimitiveString::create(vm, string)));
replacement = TRY(result.to_string(vm));
} else {
replacement = TRY(get_substitution(vm, search_string.view(), string.view(), *position, {}, js_undefined(), replace_value));
@ -620,7 +620,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::replace)
builder.append(replacement);
builder.append(string.substring_view(*position + search_string.length_in_code_units()));
return js_string(vm, builder.build());
return PrimitiveString::create(vm, builder.build());
}
// 22.1.3.19 String.prototype.replaceAll ( searchValue, replaceValue ), https://tc39.es/ecma262/#sec-string.prototype.replaceall
@ -651,7 +651,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::replace_all)
if (!replace_value.is_function()) {
auto replace_string = TRY(replace_value.to_utf16_string(vm));
replace_value = js_string(vm, move(replace_string));
replace_value = PrimitiveString::create(vm, move(replace_string));
}
auto string_length = string.length_in_code_units();
@ -674,7 +674,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::replace_all)
DeprecatedString replacement;
if (replace_value.is_function()) {
auto result = TRY(call(vm, replace_value.as_function(), js_undefined(), js_string(vm, search_string), Value(position), js_string(vm, string)));
auto result = TRY(call(vm, replace_value.as_function(), js_undefined(), PrimitiveString::create(vm, search_string), Value(position), PrimitiveString::create(vm, string)));
replacement = TRY(result.to_string(vm));
} else {
replacement = TRY(get_substitution(vm, search_string.view(), string.view(), position, {}, js_undefined(), replace_value));
@ -689,7 +689,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::replace_all)
if (end_of_last_match < string_length)
result.append(string.substring_view(end_of_last_match));
return js_string(vm, result.build());
return PrimitiveString::create(vm, result.build());
}
// 22.1.3.20 String.prototype.search ( regexp ), https://tc39.es/ecma262/#sec-string.prototype.search
@ -705,7 +705,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::search)
auto string = TRY(this_object.to_utf16_string(vm));
auto rx = TRY(regexp_create(vm, regexp, js_undefined()));
return TRY(Value(rx).invoke(vm, *vm.well_known_symbol_search(), js_string(vm, move(string))));
return TRY(Value(rx).invoke(vm, *vm.well_known_symbol_search(), PrimitiveString::create(vm, move(string))));
}
// 22.1.3.21 String.prototype.slice ( start, end ), https://tc39.es/ecma262/#sec-string.prototype.slice
@ -734,9 +734,9 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::slice)
}
if (int_start >= int_end)
return js_string(vm, DeprecatedString::empty());
return PrimitiveString::create(vm, DeprecatedString::empty());
return js_string(vm, string.substring_view(int_start, int_end - int_start));
return PrimitiveString::create(vm, string.substring_view(int_start, int_end - int_start));
}
// 22.1.3.22 String.prototype.split ( separator, limit ), https://tc39.es/ecma262/#sec-string.prototype.split
@ -773,13 +773,13 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::split)
auto separator_length = separator.length_in_code_units();
if (separator_argument.is_undefined()) {
MUST(array->create_data_property_or_throw(0, js_string(vm, move(string))));
MUST(array->create_data_property_or_throw(0, PrimitiveString::create(vm, move(string))));
return array;
}
if (string_length == 0) {
if (separator_length > 0)
MUST(array->create_data_property_or_throw(0, js_string(vm, move(string))));
MUST(array->create_data_property_or_throw(0, PrimitiveString::create(vm, move(string))));
return array;
}
@ -793,7 +793,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::split)
}
auto segment = string.substring_view(start, position - start);
MUST(array->create_data_property_or_throw(array_length, js_string(vm, segment)));
MUST(array->create_data_property_or_throw(array_length, PrimitiveString::create(vm, segment)));
++array_length;
if (array_length == limit)
return array;
@ -802,7 +802,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::split)
}
auto rest = string.substring_view(start);
MUST(array->create_data_property_or_throw(array_length, js_string(vm, rest)));
MUST(array->create_data_property_or_throw(array_length, PrimitiveString::create(vm, rest)));
return array;
}
@ -867,7 +867,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::substring)
size_t to = max(final_start, final_end);
// 10. Return the substring of S from from to to.
return js_string(vm, string.substring_view(from, to - from));
return PrimitiveString::create(vm, string.substring_view(from, to - from));
}
enum class TargetCase {
@ -942,7 +942,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_locale_lowercase)
auto string = TRY(ak_string_from(vm));
// 3. Return ? TransformCase(S, locales, lower).
return js_string(vm, TRY(transform_case(vm, string, locales, TargetCase::Lower)));
return PrimitiveString::create(vm, TRY(transform_case(vm, string, locales, TargetCase::Lower)));
}
// 22.1.3.26 String.prototype.toLocaleUpperCase ( [ reserved1 [ , reserved2 ] ] ), https://tc39.es/ecma262/#sec-string.prototype.tolocaleuppercase
@ -956,7 +956,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_locale_uppercase)
auto string = TRY(ak_string_from(vm));
// 3. Return ? TransformCase(S, locales, upper).
return js_string(vm, TRY(transform_case(vm, string, locales, TargetCase::Upper)));
return PrimitiveString::create(vm, TRY(transform_case(vm, string, locales, TargetCase::Upper)));
}
// 22.1.3.27 String.prototype.toLowerCase ( ), https://tc39.es/ecma262/#sec-string.prototype.tolowercase
@ -964,7 +964,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_lowercase)
{
auto string = TRY(ak_string_from(vm));
auto lowercase = Unicode::to_unicode_lowercase_full(string);
return js_string(vm, move(lowercase));
return PrimitiveString::create(vm, move(lowercase));
}
// 22.1.3.28 String.prototype.toString ( ), https://tc39.es/ecma262/#sec-string.prototype.tostring
@ -978,7 +978,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_uppercase)
{
auto string = TRY(ak_string_from(vm));
auto uppercase = Unicode::to_unicode_uppercase_full(string);
return js_string(vm, move(uppercase));
return PrimitiveString::create(vm, move(uppercase));
}
// 22.1.3.11 String.prototype.toWellFormed ( ), https://tc39.es/proposal-is-usv-string/#sec-string.prototype.towellformed
@ -1018,7 +1018,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::to_well_formed)
}
// 7. Return result.
return js_string(vm, result.build());
return PrimitiveString::create(vm, result.build());
}
ThrowCompletionOr<DeprecatedString> trim_string(VM& vm, Value input_value, TrimMode where)
@ -1043,19 +1043,19 @@ ThrowCompletionOr<DeprecatedString> trim_string(VM& vm, Value input_value, TrimM
// 22.1.3.30 String.prototype.trim ( ), https://tc39.es/ecma262/#sec-string.prototype.trim
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::trim)
{
return js_string(vm, TRY(trim_string(vm, vm.this_value(), TrimMode::Both)));
return PrimitiveString::create(vm, TRY(trim_string(vm, vm.this_value(), TrimMode::Both)));
}
// 22.1.3.31 String.prototype.trimEnd ( ), https://tc39.es/ecma262/#sec-string.prototype.trimend
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::trim_end)
{
return js_string(vm, TRY(trim_string(vm, vm.this_value(), TrimMode::Right)));
return PrimitiveString::create(vm, TRY(trim_string(vm, vm.this_value(), TrimMode::Right)));
}
// 22.1.3.32 String.prototype.trimStart ( ), https://tc39.es/ecma262/#sec-string.prototype.trimstart
JS_DEFINE_NATIVE_FUNCTION(StringPrototype::trim_start)
{
return js_string(vm, TRY(trim_string(vm, vm.this_value(), TrimMode::Left)));
return PrimitiveString::create(vm, TRY(trim_string(vm, vm.this_value(), TrimMode::Left)));
}
// 22.1.3.33 String.prototype.valueOf ( ), https://tc39.es/ecma262/#sec-string.prototype.valueof
@ -1108,10 +1108,10 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::substr)
auto int_end = min((i32)(int_start + int_length), size);
if (int_start >= int_end)
return js_string(vm, DeprecatedString::empty());
return PrimitiveString::create(vm, DeprecatedString::empty());
// 11. Return the substring of S from intStart to intEnd.
return js_string(vm, string.substring_view(int_start, int_end - int_start));
return PrimitiveString::create(vm, string.substring_view(int_start, int_end - int_start));
}
// B.2.2.2.1 CreateHTML ( string, tag, attribute, value ), https://tc39.es/ecma262/#sec-createhtml
@ -1135,7 +1135,7 @@ static ThrowCompletionOr<Value> create_html(VM& vm, Value string, DeprecatedStri
builder.append("</"sv);
builder.append(tag);
builder.append('>');
return js_string(vm, builder.build());
return PrimitiveString::create(vm, builder.build());
}
// B.2.2.2 String.prototype.anchor ( name ), https://tc39.es/ecma262/#sec-string.prototype.anchor

View file

@ -85,7 +85,7 @@ JS_DEFINE_NATIVE_FUNCTION(SymbolConstructor::key_for)
auto& symbol = argument.as_symbol();
if (symbol.is_global())
return js_string(vm, symbol.description());
return PrimitiveString::create(vm, symbol.description());
return js_undefined();
}

View file

@ -34,7 +34,7 @@ void SymbolPrototype::initialize(Realm& realm)
define_native_function(realm, *vm.well_known_symbol_to_primitive(), symbol_to_primitive, 1, Attribute::Configurable);
// 20.4.3.6 Symbol.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-symbol.prototype-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Symbol"), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Symbol"), Attribute::Configurable);
}
// thisSymbolValue ( value ), https://tc39.es/ecma262/#thissymbolvalue
@ -54,14 +54,14 @@ JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::description_getter)
auto& description = symbol->raw_description();
if (!description.has_value())
return js_undefined();
return js_string(vm, *description);
return PrimitiveString::create(vm, *description);
}
// 20.4.3.3 Symbol.prototype.toString ( ), https://tc39.es/ecma262/#sec-symbol.prototype.tostring
JS_DEFINE_NATIVE_FUNCTION(SymbolPrototype::to_string)
{
auto* symbol = TRY(this_symbol_value(vm, vm.this_value()));
return js_string(vm, symbol->to_deprecated_string());
return PrimitiveString::create(vm, symbol->to_deprecated_string());
}
// 20.4.3.4 Symbol.prototype.valueOf ( ), https://tc39.es/ecma262/#sec-symbol.prototype.valueof

View file

@ -117,7 +117,7 @@ ThrowCompletionOr<Value> get_option(VM& vm, Object const& options, PropertyKey c
[](Empty) { return js_undefined(); },
[](bool b) { return Value(b); },
[](double d) { return Value(d); },
[&vm](StringView s) { return Value(js_string(vm, s)); });
[&vm](StringView s) { return Value(PrimitiveString::create(vm, s)); });
}
// 5. If type is "boolean", then
@ -603,7 +603,7 @@ ThrowCompletionOr<Value> to_relative_temporal_object(VM& vm, Object const& optio
auto* date_options = Object::create(realm, nullptr);
// g. Perform ! CreateDataPropertyOrThrow(dateOptions, "overflow", "constrain").
MUST(date_options->create_data_property_or_throw(vm.names.overflow, js_string(vm, "constrain"sv)));
MUST(date_options->create_data_property_or_throw(vm.names.overflow, PrimitiveString::create(vm, "constrain"sv)));
// h. Let result be ? InterpretTemporalDateTimeFields(calendar, fields, dateOptions).
result = TRY(interpret_temporal_date_time_fields(vm, *calendar, *fields, *date_options));
@ -635,10 +635,10 @@ ThrowCompletionOr<Value> to_relative_temporal_object(VM& vm, Object const& optio
result = TRY(parse_temporal_relative_to_string(vm, string));
// c. Let calendar be ? ToTemporalCalendarWithISODefault(result.[[Calendar]]).
calendar = TRY(to_temporal_calendar_with_iso_default(vm, result.calendar.has_value() ? js_string(vm, *result.calendar) : js_undefined()));
calendar = TRY(to_temporal_calendar_with_iso_default(vm, result.calendar.has_value() ? PrimitiveString::create(vm, *result.calendar) : js_undefined()));
// d. Let offsetString be result.[[TimeZone]].[[OffsetString]].
offset_string = result.time_zone.offset_string.has_value() ? js_string(vm, *result.time_zone.offset_string) : js_undefined();
offset_string = result.time_zone.offset_string.has_value() ? PrimitiveString::create(vm, *result.time_zone.offset_string) : js_undefined();
// e. Let timeZoneName be result.[[TimeZone]].[[Name]].
auto time_zone_name = result.time_zone.name;
@ -757,7 +757,7 @@ ThrowCompletionOr<Object*> merge_largest_unit_option(VM& vm, Object const& optio
}
// 4. Perform ! CreateDataPropertyOrThrow(merged, "largestUnit", largestUnit).
MUST(merged->create_data_property_or_throw(vm.names.largestUnit, js_string(vm, move(largest_unit))));
MUST(merged->create_data_property_or_throw(vm.names.largestUnit, PrimitiveString::create(vm, move(largest_unit))));
// 5. Return merged.
return merged;

View file

@ -119,7 +119,7 @@ ThrowCompletionOr<Vector<DeprecatedString>> calendar_fields(VM& vm, Object& cale
}
// 3. Let fieldsArray be ? Call(fields, calendar, « CreateArrayFromList(fieldNames) »).
auto fields_array = TRY(call(vm, *fields, &calendar, Array::create_from<StringView>(realm, field_names, [&](auto value) { return js_string(vm, value); })));
auto fields_array = TRY(call(vm, *fields, &calendar, Array::create_from<StringView>(realm, field_names, [&](auto value) { return PrimitiveString::create(vm, value); })));
// 4. Return ? IterableToListOfType(fieldsArray, « String »).
auto list = TRY(iterable_to_list_of_type(vm, fields_array, { OptionType::String }));
@ -397,7 +397,7 @@ ThrowCompletionOr<Value> calendar_era(VM& vm, Object& calendar, Object& date_lik
// 3. If result is not undefined, set result to ? ToString(result).
if (!result.is_undefined())
result = js_string(vm, TRY(result.to_string(vm)));
result = PrimitiveString::create(vm, TRY(result.to_string(vm)));
// 4. Return result.
return result;
@ -811,7 +811,7 @@ ThrowCompletionOr<double> resolve_iso_month(VM& vm, Object const& fields)
return vm.throw_completion<RangeError>(ErrorType::TemporalInvalidMonthCode);
// 11. Let monthCodeNumber be ! ToIntegerOrInfinity(monthCodeDigits).
auto month_code_number = MUST(Value(js_string(vm, move(month_code_digits))).to_integer_or_infinity(vm));
auto month_code_number = MUST(Value(PrimitiveString::create(vm, move(month_code_digits))).to_integer_or_infinity(vm));
// 12. Assert: SameValue(monthCode, ISOMonthCode(monthCodeNumber)) is true.
VERIFY(month_code_string == iso_month_code(month_code_number));

View file

@ -36,7 +36,7 @@ void CalendarPrototype::initialize(Realm& realm)
auto& vm = this->vm();
// 12.4.2 Temporal.Calendar.prototype[ @@toStringTag ], https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Temporal.Calendar"), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Temporal.Calendar"), Attribute::Configurable);
define_native_accessor(realm, vm.names.id, id_getter, {}, Attribute::Configurable);
@ -74,7 +74,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::id_getter)
auto* calendar = TRY(typed_this_object(vm));
// 3. Return calendar.[[Identifier]].
return { js_string(vm, calendar->identifier()) };
return { PrimitiveString::create(vm, calendar->identifier()) };
}
// 12.4.4 Temporal.Calendar.prototype.dateFromFields ( fields [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.datefromfields
@ -300,7 +300,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::month_code)
// NOTE: The assertion happens in iso_month() call.
// 6. Return ISOMonthCode(temporalDateLike.[[ISOMonth]]).
return js_string(vm, iso_month_code(iso_month(temporal_date_like.as_object())));
return PrimitiveString::create(vm, iso_month_code(iso_month(temporal_date_like.as_object())));
}
// 12.4.12 Temporal.Calendar.prototype.day ( temporalDateLike ), https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.day
@ -589,7 +589,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::to_string)
auto* calendar = TRY(typed_this_object(vm));
// 3. Return calendar.[[Identifier]].
return js_string(vm, calendar->identifier());
return PrimitiveString::create(vm, calendar->identifier());
}
// 12.4.24 Temporal.Calendar.prototype.toJSON ( ), https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.tojson
@ -600,7 +600,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::to_json)
auto* calendar = TRY(typed_this_object(vm));
// 3. Return ? ToString(calendar).
return js_string(vm, TRY(Value(calendar).to_string(vm)));
return PrimitiveString::create(vm, TRY(Value(calendar).to_string(vm)));
}
// 15.6.2.6 Temporal.Calendar.prototype.era ( temporalDateLike ), https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype.era

View file

@ -692,7 +692,7 @@ ThrowCompletionOr<DateDurationRecord> unbalance_duration_relative(VM& vm, double
auto* until_options = Object::create(realm, nullptr);
// iii. Perform ! CreateDataPropertyOrThrow(untilOptions, "largestUnit", "month").
MUST(until_options->create_data_property_or_throw(vm.names.largestUnit, js_string(vm, "month"sv)));
MUST(until_options->create_data_property_or_throw(vm.names.largestUnit, PrimitiveString::create(vm, "month"sv)));
// iv. Let untilResult be ? CalendarDateUntil(calendar, relativeTo, newRelativeTo, untilOptions, dateUntil).
auto* until_result = TRY(calendar_date_until(vm, *calendar, relative_to, new_relative_to, *until_options, date_until));
@ -928,7 +928,7 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(VM& vm, double y
auto* until_options = Object::create(realm, nullptr);
// m. Perform ! CreateDataPropertyOrThrow(untilOptions, "largestUnit", "month").
MUST(until_options->create_data_property_or_throw(vm.names.largestUnit, js_string(vm, "month"sv)));
MUST(until_options->create_data_property_or_throw(vm.names.largestUnit, PrimitiveString::create(vm, "month"sv)));
// n. Let untilResult be ? CalendarDateUntil(calendar, relativeTo, newRelativeTo, untilOptions, dateUntil).
auto* until_result = TRY(calendar_date_until(vm, calendar, relative_to, new_relative_to, *until_options, date_until));
@ -954,7 +954,7 @@ ThrowCompletionOr<DateDurationRecord> balance_duration_relative(VM& vm, double y
until_options = Object::create(realm, nullptr);
// vi. Perform ! CreateDataPropertyOrThrow(untilOptions, "largestUnit", "month").
MUST(until_options->create_data_property_or_throw(vm.names.largestUnit, js_string(vm, "month"sv)));
MUST(until_options->create_data_property_or_throw(vm.names.largestUnit, PrimitiveString::create(vm, "month"sv)));
// vii. Set untilResult to ? CalendarDateUntil(calendar, relativeTo, newRelativeTo, untilOptions, dateUntil).
until_result = TRY(calendar_date_until(vm, calendar, relative_to, new_relative_to, *until_options, date_until));
@ -1109,7 +1109,7 @@ ThrowCompletionOr<DurationRecord> add_duration(VM& vm, double years1, double mon
auto* difference_options = Object::create(realm, nullptr);
// i. Perform ! CreateDataPropertyOrThrow(differenceOptions, "largestUnit", dateLargestUnit).
MUST(difference_options->create_data_property_or_throw(vm.names.largestUnit, js_string(vm, date_largest_unit)));
MUST(difference_options->create_data_property_or_throw(vm.names.largestUnit, PrimitiveString::create(vm, date_largest_unit)));
// j. Let dateDifference be ? CalendarDateUntil(calendar, relativeTo, end, differenceOptions).
auto* date_difference = TRY(calendar_date_until(vm, calendar, &relative_to, end, *difference_options));
@ -1312,7 +1312,7 @@ ThrowCompletionOr<RoundedDuration> round_duration(VM& vm, double years, double m
auto* until_options = Object::create(realm, nullptr);
// l. Perform ! CreateDataPropertyOrThrow(untilOptions, "largestUnit", "year").
MUST(until_options->create_data_property_or_throw(vm.names.largestUnit, js_string(vm, "year"sv)));
MUST(until_options->create_data_property_or_throw(vm.names.largestUnit, PrimitiveString::create(vm, "year"sv)));
// m. Let timePassed be ? CalendarDateUntil(calendar, relativeTo, daysLater, untilOptions).
auto* time_passed = TRY(calendar_date_until(vm, *calendar, relative_to, days_later, *until_options));

View file

@ -27,7 +27,7 @@ void DurationPrototype::initialize(Realm& realm)
auto& vm = this->vm();
// 7.3.2 Temporal.Duration.prototype[ @@toStringTag ], https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Temporal.Duration"), Attribute::Configurable);
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Temporal.Duration"), Attribute::Configurable);
define_native_accessor(realm, vm.names.years, years_getter, {}, Attribute::Configurable);
define_native_accessor(realm, vm.names.months, months_getter, {}, Attribute::Configurable);
@ -586,7 +586,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::to_string)
auto result = TRY(round_duration(vm, duration->years(), duration->months(), duration->weeks(), duration->days(), duration->hours(), duration->minutes(), duration->seconds(), duration->milliseconds(), duration->microseconds(), duration->nanoseconds(), precision.increment, precision.unit, rounding_mode)).duration_record;
// 8. Return ! TemporalDurationToString(result.[[Years]], result.[[Months]], result.[[Weeks]], result.[[Days]], result.[[Hours]], result.[[Minutes]], result.[[Seconds]], result.[[Milliseconds]], result.[[Microseconds]], result.[[Nanoseconds]], precision.[[Precision]]).
return js_string(vm, temporal_duration_to_string(result.years, result.months, result.weeks, result.days, result.hours, result.minutes, result.seconds, result.milliseconds, result.microseconds, result.nanoseconds, precision.precision));
return PrimitiveString::create(vm, temporal_duration_to_string(result.years, result.months, result.weeks, result.days, result.hours, result.minutes, result.seconds, result.milliseconds, result.microseconds, result.nanoseconds, precision.precision));
}
// 7.3.23 Temporal.Duration.prototype.toJSON ( ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.tojson
@ -597,7 +597,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::to_json)
auto* duration = TRY(typed_this_object(vm));
// 3. Return ! TemporalDurationToString(duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]], "auto").
return js_string(vm, temporal_duration_to_string(duration->years(), duration->months(), duration->weeks(), duration->days(), duration->hours(), duration->minutes(), duration->seconds(), duration->milliseconds(), duration->microseconds(), duration->nanoseconds(), "auto"sv));
return PrimitiveString::create(vm, temporal_duration_to_string(duration->years(), duration->months(), duration->weeks(), duration->days(), duration->hours(), duration->minutes(), duration->seconds(), duration->milliseconds(), duration->microseconds(), duration->nanoseconds(), "auto"sv));
}
// 7.3.24 Temporal.Duration.prototype.toLocaleString ( [ locales [ , options ] ] ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.tolocalestring
@ -609,7 +609,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::to_locale_string)
auto* duration = TRY(typed_this_object(vm));
// 3. Return ! TemporalDurationToString(duration.[[Years]], duration.[[Months]], duration.[[Weeks]], duration.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]], "auto").
return js_string(vm, temporal_duration_to_string(duration->years(), duration->months(), duration->weeks(), duration->days(), duration->hours(), duration->minutes(), duration->seconds(), duration->milliseconds(), duration->microseconds(), duration->nanoseconds(), "auto"sv));
return PrimitiveString::create(vm, temporal_duration_to_string(duration->years(), duration->months(), duration->weeks(), duration->days(), duration->hours(), duration->minutes(), duration->seconds(), duration->milliseconds(), duration->microseconds(), duration->nanoseconds(), "auto"sv));
}
// 7.3.25 Temporal.Duration.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.valueof

Some files were not shown because too many files have changed in this diff Show more