LibJS: Change PropertyKey(ByteString) to PropertyKey(String)

...and deal with the fallout.
This commit is contained in:
Andreas Kling 2025-03-16 20:45:02 -05:00 committed by Andreas Kling
commit d7908dbff5
Notes: github-actions[bot] 2025-03-24 22:28:48 +00:00
17 changed files with 78 additions and 78 deletions

View file

@ -1363,7 +1363,7 @@ ThrowCompletionOr<String> get_substitution(VM& vm, Utf16View const& matched, Utf
// 2. Let groupName be the substring of templateRemainder from 2 to gtPos. // 2. Let groupName be the substring of templateRemainder from 2 to gtPos.
auto group_name_view = template_remainder.substring_view(2, *greater_than_position - 2); auto group_name_view = template_remainder.substring_view(2, *greater_than_position - 2);
auto group_name = MUST(group_name_view.to_byte_string(Utf16View::AllowInvalidCodeUnits::Yes)); auto group_name = MUST(group_name_view.to_utf8(Utf16View::AllowInvalidCodeUnits::Yes));
// 3. Assert: namedCaptures is an Object. // 3. Assert: namedCaptures is an Object.
VERIFY(named_captures.is_object()); VERIFY(named_captures.is_object());

View file

@ -264,7 +264,7 @@ ThrowCompletionOr<DurationFormat::DurationUnitOptions> get_duration_unit_options
auto display_field = MUST(String::formatted("{}Display", unit_property_key)); auto display_field = MUST(String::formatted("{}Display", unit_property_key));
// 6. Let display be ? GetOption(options, displayField, STRING, « "auto", "always" », displayDefault). // 6. Let display be ? GetOption(options, displayField, STRING, « "auto", "always" », displayDefault).
auto display_value = TRY(get_option(vm, options, display_field.to_byte_string(), OptionType::String, { "auto"sv, "always"sv }, display_default)); auto display_value = TRY(get_option(vm, options, display_field, OptionType::String, { "auto"sv, "always"sv }, display_default));
auto display = DurationFormat::display_from_string(display_value.as_string().utf8_string()); auto display = DurationFormat::display_from_string(display_value.as_string().utf8_string());
// 7. Perform ? ValidateDurationUnitStyle(unit, style, display, prevStyle). // 7. Perform ? ValidateDurationUnitStyle(unit, style, display, prevStyle).

View file

@ -47,7 +47,7 @@ void JSONObject::initialize(Realm& realm)
} }
// 25.5.2 JSON.stringify ( value [ , replacer [ , space ] ] ), https://tc39.es/ecma262/#sec-json.stringify // 25.5.2 JSON.stringify ( value [ , replacer [ , space ] ] ), https://tc39.es/ecma262/#sec-json.stringify
ThrowCompletionOr<Optional<ByteString>> JSONObject::stringify_impl(VM& vm, Value value, Value replacer, Value space) ThrowCompletionOr<Optional<String>> JSONObject::stringify_impl(VM& vm, Value value, Value replacer, Value space)
{ {
auto& realm = *vm.current_realm(); auto& realm = *vm.current_realm();
@ -61,18 +61,18 @@ ThrowCompletionOr<Optional<ByteString>> JSONObject::stringify_impl(VM& vm, Value
if (is_array) { if (is_array) {
auto& replacer_object = replacer.as_object(); auto& replacer_object = replacer.as_object();
auto replacer_length = TRY(length_of_array_like(vm, replacer_object)); auto replacer_length = TRY(length_of_array_like(vm, replacer_object));
Vector<ByteString> list; Vector<String> list;
for (size_t i = 0; i < replacer_length; ++i) { for (size_t i = 0; i < replacer_length; ++i) {
auto replacer_value = TRY(replacer_object.get(i)); auto replacer_value = TRY(replacer_object.get(i));
Optional<ByteString> item; Optional<String> item;
if (replacer_value.is_string()) { if (replacer_value.is_string()) {
item = replacer_value.as_string().byte_string(); item = replacer_value.as_string().utf8_string();
} else if (replacer_value.is_number()) { } else if (replacer_value.is_number()) {
item = MUST(replacer_value.to_byte_string(vm)); item = MUST(replacer_value.to_string(vm));
} else if (replacer_value.is_object()) { } else if (replacer_value.is_object()) {
auto& value_object = replacer_value.as_object(); auto& value_object = replacer_value.as_object();
if (is<StringObject>(value_object) || is<NumberObject>(value_object)) if (is<StringObject>(value_object) || is<NumberObject>(value_object))
item = TRY(replacer_value.to_byte_string(vm)); item = TRY(replacer_value.to_string(vm));
} }
if (item.has_value() && !list.contains_slow(*item)) { if (item.has_value() && !list.contains_slow(*item)) {
list.append(*item); list.append(*item);
@ -94,20 +94,20 @@ ThrowCompletionOr<Optional<ByteString>> JSONObject::stringify_impl(VM& vm, Value
if (space.is_number()) { if (space.is_number()) {
auto space_mv = MUST(space.to_integer_or_infinity(vm)); auto space_mv = MUST(space.to_integer_or_infinity(vm));
space_mv = min(10, space_mv); space_mv = min(10, space_mv);
state.gap = space_mv < 1 ? ByteString::empty() : ByteString::repeated(' ', space_mv); state.gap = space_mv < 1 ? String {} : MUST(String::repeated(' ', space_mv));
} else if (space.is_string()) { } else if (space.is_string()) {
auto string = space.as_string().byte_string(); auto string = space.as_string().utf8_string();
if (string.length() <= 10) if (string.bytes().size() <= 10)
state.gap = string; state.gap = string;
else else
state.gap = string.substring(0, 10); state.gap = MUST(string.substring_from_byte_offset(0, 10));
} else { } else {
state.gap = ByteString::empty(); state.gap = String {};
} }
auto wrapper = Object::create(realm, realm.intrinsics().object_prototype()); auto wrapper = Object::create(realm, realm.intrinsics().object_prototype());
MUST(wrapper->create_data_property_or_throw(ByteString::empty(), value)); MUST(wrapper->create_data_property_or_throw(String {}, value));
return serialize_json_property(vm, state, ByteString::empty(), wrapper); return serialize_json_property(vm, state, String {}, wrapper);
} }
// 25.5.2 JSON.stringify ( value [ , replacer [ , space ] ] ), https://tc39.es/ecma262/#sec-json.stringify // 25.5.2 JSON.stringify ( value [ , replacer [ , space ] ] ), https://tc39.es/ecma262/#sec-json.stringify
@ -128,7 +128,7 @@ JS_DEFINE_NATIVE_FUNCTION(JSONObject::stringify)
} }
// 25.5.2.1 SerializeJSONProperty ( state, key, holder ), https://tc39.es/ecma262/#sec-serializejsonproperty // 25.5.2.1 SerializeJSONProperty ( state, key, holder ), https://tc39.es/ecma262/#sec-serializejsonproperty
ThrowCompletionOr<Optional<ByteString>> JSONObject::serialize_json_property(VM& vm, StringifyState& state, PropertyKey const& key, Object* holder) ThrowCompletionOr<Optional<String>> JSONObject::serialize_json_property(VM& vm, StringifyState& state, PropertyKey const& key, Object* holder)
{ {
// 1. Let value be ? Get(holder, key). // 1. Let value be ? Get(holder, key).
auto value = TRY(holder->get(key)); auto value = TRY(holder->get(key));
@ -179,25 +179,25 @@ ThrowCompletionOr<Optional<ByteString>> JSONObject::serialize_json_property(VM&
// 5. If value is null, return "null". // 5. If value is null, return "null".
if (value.is_null()) if (value.is_null())
return "null"sv; return "null"_string;
// 6. If value is true, return "true". // 6. If value is true, return "true".
// 7. If value is false, return "false". // 7. If value is false, return "false".
if (value.is_boolean()) if (value.is_boolean())
return value.as_bool() ? "true"sv : "false"sv; return value.as_bool() ? "true"_string : "false"_string;
// 8. If Type(value) is String, return QuoteJSONString(value). // 8. If Type(value) is String, return QuoteJSONString(value).
if (value.is_string()) if (value.is_string())
return quote_json_string(value.as_string().byte_string()); return quote_json_string(value.as_string().utf8_string());
// 9. If Type(value) is Number, then // 9. If Type(value) is Number, then
if (value.is_number()) { if (value.is_number()) {
// a. If value is finite, return ! ToString(value). // a. If value is finite, return ! ToString(value).
if (value.is_finite_number()) if (value.is_finite_number())
return MUST(value.to_byte_string(vm)); return MUST(value.to_string(vm));
// b. Return "null". // b. Return "null".
return "null"sv; return "null"_string;
} }
// 10. If Type(value) is BigInt, throw a TypeError exception. // 10. If Type(value) is BigInt, throw a TypeError exception.
@ -218,30 +218,30 @@ ThrowCompletionOr<Optional<ByteString>> JSONObject::serialize_json_property(VM&
} }
// 12. Return undefined. // 12. Return undefined.
return Optional<ByteString> {}; return Optional<String> {};
} }
// 25.5.2.4 SerializeJSONObject ( state, value ), https://tc39.es/ecma262/#sec-serializejsonobject // 25.5.2.4 SerializeJSONObject ( state, value ), https://tc39.es/ecma262/#sec-serializejsonobject
ThrowCompletionOr<ByteString> JSONObject::serialize_json_object(VM& vm, StringifyState& state, Object& object) ThrowCompletionOr<String> JSONObject::serialize_json_object(VM& vm, StringifyState& state, Object& object)
{ {
if (state.seen_objects.contains(&object)) if (state.seen_objects.contains(&object))
return vm.throw_completion<TypeError>(ErrorType::JsonCircular); return vm.throw_completion<TypeError>(ErrorType::JsonCircular);
state.seen_objects.set(&object); state.seen_objects.set(&object);
ByteString previous_indent = state.indent; String previous_indent = state.indent;
state.indent = ByteString::formatted("{}{}", state.indent, state.gap); state.indent = MUST(String::formatted("{}{}", state.indent, state.gap));
Vector<ByteString> property_strings; Vector<String> property_strings;
auto process_property = [&](PropertyKey const& key) -> ThrowCompletionOr<void> { auto process_property = [&](PropertyKey const& key) -> ThrowCompletionOr<void> {
if (key.is_symbol()) if (key.is_symbol())
return {}; return {};
auto serialized_property_string = TRY(serialize_json_property(vm, state, key, &object)); auto serialized_property_string = TRY(serialize_json_property(vm, state, key, &object));
if (serialized_property_string.has_value()) { if (serialized_property_string.has_value()) {
property_strings.append(ByteString::formatted( property_strings.append(MUST(String::formatted(
"{}:{}{}", "{}:{}{}",
quote_json_string(key.to_string()), quote_json_string(MUST(String::from_byte_string(key.to_string()))),
state.gap.is_empty() ? "" : " ", state.gap.is_empty() ? "" : " ",
serialized_property_string)); serialized_property_string)));
} }
return {}; return {};
}; };
@ -253,7 +253,7 @@ ThrowCompletionOr<ByteString> JSONObject::serialize_json_object(VM& vm, Stringif
} else { } else {
auto property_list = TRY(object.enumerable_own_property_names(PropertyKind::Key)); auto property_list = TRY(object.enumerable_own_property_names(PropertyKind::Key));
for (auto& property : property_list) for (auto& property : property_list)
TRY(process_property(property.as_string().byte_string())); TRY(process_property(property.as_string().utf8_string()));
} }
StringBuilder builder; StringBuilder builder;
if (property_strings.is_empty()) { if (property_strings.is_empty()) {
@ -271,7 +271,7 @@ ThrowCompletionOr<ByteString> JSONObject::serialize_json_object(VM& vm, Stringif
} else { } else {
builder.append('\n'); builder.append('\n');
builder.append(state.indent); builder.append(state.indent);
auto separator = ByteString::formatted(",\n{}", state.indent); auto separator = MUST(String::formatted(",\n{}", state.indent));
for (auto& property_string : property_strings) { for (auto& property_string : property_strings) {
if (!first) if (!first)
builder.append(separator); builder.append(separator);
@ -286,19 +286,19 @@ ThrowCompletionOr<ByteString> JSONObject::serialize_json_object(VM& vm, Stringif
state.seen_objects.remove(&object); state.seen_objects.remove(&object);
state.indent = previous_indent; state.indent = previous_indent;
return builder.to_byte_string(); return builder.to_string_without_validation();
} }
// 25.5.2.5 SerializeJSONArray ( state, value ), https://tc39.es/ecma262/#sec-serializejsonarray // 25.5.2.5 SerializeJSONArray ( state, value ), https://tc39.es/ecma262/#sec-serializejsonarray
ThrowCompletionOr<ByteString> JSONObject::serialize_json_array(VM& vm, StringifyState& state, Object& object) ThrowCompletionOr<String> JSONObject::serialize_json_array(VM& vm, StringifyState& state, Object& object)
{ {
if (state.seen_objects.contains(&object)) if (state.seen_objects.contains(&object))
return vm.throw_completion<TypeError>(ErrorType::JsonCircular); return vm.throw_completion<TypeError>(ErrorType::JsonCircular);
state.seen_objects.set(&object); state.seen_objects.set(&object);
ByteString previous_indent = state.indent; String previous_indent = state.indent;
state.indent = ByteString::formatted("{}{}", state.indent, state.gap); state.indent = MUST(String::formatted("{}{}", state.indent, state.gap));
Vector<ByteString> property_strings; Vector<String> property_strings;
auto length = TRY(length_of_array_like(vm, object)); auto length = TRY(length_of_array_like(vm, object));
@ -308,7 +308,7 @@ ThrowCompletionOr<ByteString> JSONObject::serialize_json_array(VM& vm, Stringify
for (size_t i = 0; i < length; ++i) { for (size_t i = 0; i < length; ++i) {
auto serialized_property_string = TRY(serialize_json_property(vm, state, i, &object)); auto serialized_property_string = TRY(serialize_json_property(vm, state, i, &object));
if (!serialized_property_string.has_value()) { if (!serialized_property_string.has_value()) {
property_strings.append("null"sv); property_strings.append("null"_string);
} else { } else {
property_strings.append(serialized_property_string.release_value()); property_strings.append(serialized_property_string.release_value());
} }
@ -331,7 +331,7 @@ ThrowCompletionOr<ByteString> JSONObject::serialize_json_array(VM& vm, Stringify
} else { } else {
builder.append("[\n"sv); builder.append("[\n"sv);
builder.append(state.indent); builder.append(state.indent);
auto separator = ByteString::formatted(",\n{}", state.indent); auto separator = MUST(String::formatted(",\n{}", state.indent));
bool first = true; bool first = true;
for (auto& property_string : property_strings) { for (auto& property_string : property_strings) {
if (!first) if (!first)
@ -347,11 +347,11 @@ ThrowCompletionOr<ByteString> JSONObject::serialize_json_array(VM& vm, Stringify
state.seen_objects.remove(&object); state.seen_objects.remove(&object);
state.indent = previous_indent; state.indent = previous_indent;
return builder.to_byte_string(); return builder.to_string_without_validation();
} }
// 25.5.2.2 QuoteJSONString ( value ), https://tc39.es/ecma262/#sec-quotejsonstring // 25.5.2.2 QuoteJSONString ( value ), https://tc39.es/ecma262/#sec-quotejsonstring
ByteString JSONObject::quote_json_string(ByteString string) String JSONObject::quote_json_string(String string)
{ {
// 1. Let product be the String value consisting solely of the code unit 0x0022 (QUOTATION MARK). // 1. Let product be the String value consisting solely of the code unit 0x0022 (QUOTATION MARK).
StringBuilder builder; StringBuilder builder;
@ -402,7 +402,7 @@ ByteString JSONObject::quote_json_string(ByteString string)
builder.append('"'); builder.append('"');
// 4. Return product. // 4. Return product.
return builder.to_byte_string(); return builder.to_string_without_validation();
} }
// 25.5.1 JSON.parse ( text [ , reviver ] ), https://tc39.es/ecma262/#sec-json.parse // 25.5.1 JSON.parse ( text [ , reviver ] ), https://tc39.es/ecma262/#sec-json.parse
@ -410,7 +410,7 @@ JS_DEFINE_NATIVE_FUNCTION(JSONObject::parse)
{ {
auto& realm = *vm.current_realm(); auto& realm = *vm.current_realm();
auto string = TRY(vm.argument(0).to_byte_string(vm)); auto string = TRY(vm.argument(0).to_string(vm));
auto reviver = vm.argument(1); auto reviver = vm.argument(1);
auto json = JsonValue::from_string(string); auto json = JsonValue::from_string(string);
@ -419,7 +419,7 @@ JS_DEFINE_NATIVE_FUNCTION(JSONObject::parse)
Value unfiltered = parse_json_value(vm, json.value()); Value unfiltered = parse_json_value(vm, json.value());
if (reviver.is_function()) { if (reviver.is_function()) {
auto root = Object::create(realm, realm.intrinsics().object_prototype()); auto root = Object::create(realm, realm.intrinsics().object_prototype());
auto root_name = ByteString::empty(); auto root_name = String {};
MUST(root->create_data_property_or_throw(root_name, unfiltered)); MUST(root->create_data_property_or_throw(root_name, unfiltered));
return internalize_json_property(vm, root, root_name, reviver.as_function()); return internalize_json_property(vm, root, root_name, reviver.as_function());
} }
@ -448,7 +448,7 @@ Object* JSONObject::parse_json_object(VM& vm, JsonObject const& json_object)
auto& realm = *vm.current_realm(); auto& realm = *vm.current_realm();
auto object = Object::create(realm, realm.intrinsics().object_prototype()); auto object = Object::create(realm, realm.intrinsics().object_prototype());
json_object.for_each_member([&](auto& key, auto& value) { json_object.for_each_member([&](auto& key, auto& value) {
object->define_direct_property(key.to_byte_string(), parse_json_value(vm, value), default_attributes); object->define_direct_property(key, parse_json_value(vm, value), default_attributes);
}); });
return object; return object;
} }
@ -488,7 +488,7 @@ ThrowCompletionOr<Value> JSONObject::internalize_json_property(VM& vm, Object* h
} else { } else {
auto property_list = TRY(value_object.enumerable_own_property_names(Object::PropertyKind::Key)); auto property_list = TRY(value_object.enumerable_own_property_names(Object::PropertyKind::Key));
for (auto& property_key : property_list) for (auto& property_key : property_list)
TRY(process_property(property_key.as_string().byte_string())); TRY(process_property(property_key.as_string().utf8_string()));
} }
} }

View file

@ -20,7 +20,7 @@ public:
// The base implementation of stringify is exposed because it is used by // The base implementation of stringify is exposed because it is used by
// test-js to communicate between the JS tests and the C++ test runner. // test-js to communicate between the JS tests and the C++ test runner.
static ThrowCompletionOr<Optional<ByteString>> stringify_impl(VM&, Value value, Value replacer, Value space); static ThrowCompletionOr<Optional<String>> stringify_impl(VM&, Value value, Value replacer, Value space);
static Value parse_json_value(VM&, JsonValue const&); static Value parse_json_value(VM&, JsonValue const&);
@ -30,16 +30,16 @@ private:
struct StringifyState { struct StringifyState {
GC::Ptr<FunctionObject> replacer_function; GC::Ptr<FunctionObject> replacer_function;
HashTable<GC::Ptr<Object>> seen_objects; HashTable<GC::Ptr<Object>> seen_objects;
ByteString indent { ByteString::empty() }; String indent;
ByteString gap; String gap;
Optional<Vector<ByteString>> property_list; Optional<Vector<String>> property_list;
}; };
// Stringify helpers // Stringify helpers
static ThrowCompletionOr<Optional<ByteString>> serialize_json_property(VM&, StringifyState&, PropertyKey const& key, Object* holder); static ThrowCompletionOr<Optional<String>> serialize_json_property(VM&, StringifyState&, PropertyKey const& key, Object* holder);
static ThrowCompletionOr<ByteString> serialize_json_object(VM&, StringifyState&, Object&); static ThrowCompletionOr<String> serialize_json_object(VM&, StringifyState&, Object&);
static ThrowCompletionOr<ByteString> serialize_json_array(VM&, StringifyState&, Object&); static ThrowCompletionOr<String> serialize_json_array(VM&, StringifyState&, Object&);
static ByteString quote_json_string(ByteString); static String quote_json_string(String);
// Parse helpers // Parse helpers
static Object* parse_json_object(VM&, JsonObject const&); static Object* parse_json_object(VM&, JsonObject const&);

View file

@ -56,8 +56,8 @@ public:
{ {
} }
PropertyKey(ByteString const& string) PropertyKey(String const& string)
: PropertyKey(DeprecatedFlyString(string)) : PropertyKey(DeprecatedFlyString(string.to_byte_string()))
{ {
} }

View file

@ -87,7 +87,7 @@ ThrowCompletionOr<void> copy_name_and_length(VM& vm, FunctionObject& function, F
target_name = PrimitiveString::create(vm, String {}); target_name = PrimitiveString::create(vm, String {});
// 8. Perform SetFunctionName(F, targetName, prefix). // 8. Perform SetFunctionName(F, targetName, prefix).
function.set_function_name({ target_name.as_string().byte_string() }, move(prefix)); function.set_function_name({ target_name.as_string().utf8_string() }, move(prefix));
return {}; return {};
} }
@ -190,7 +190,7 @@ ThrowCompletionOr<Value> perform_shadow_realm_eval(VM& vm, StringView source_tex
} }
// 3.1.4 ShadowRealmImportValue ( specifierString: a String, exportNameString: a String, callerRealm: a Realm Record, evalRealm: a Realm Record, evalContext: an execution context, ), https://tc39.es/proposal-shadowrealm/#sec-shadowrealmimportvalue // 3.1.4 ShadowRealmImportValue ( specifierString: a String, exportNameString: a String, callerRealm: a Realm Record, evalRealm: a Realm Record, evalContext: an execution context, ), https://tc39.es/proposal-shadowrealm/#sec-shadowrealmimportvalue
ThrowCompletionOr<Value> shadow_realm_import_value(VM& vm, ByteString specifier_string, ByteString export_name_string, Realm& caller_realm, Realm& eval_realm) ThrowCompletionOr<Value> shadow_realm_import_value(VM& vm, String specifier_string, String export_name_string, Realm& caller_realm, Realm& eval_realm)
{ {
auto& realm = *vm.current_realm(); auto& realm = *vm.current_realm();
@ -211,7 +211,7 @@ ThrowCompletionOr<Value> shadow_realm_import_value(VM& vm, ByteString specifier_
auto referrer = GC::Ref { *eval_context->realm }; auto referrer = GC::Ref { *eval_context->realm };
// 7. Perform HostLoadImportedModule(referrer, specifierString, empty, innerCapability). // 7. Perform HostLoadImportedModule(referrer, specifierString, empty, innerCapability).
vm.host_load_imported_module(referrer, ModuleRequest { specifier_string }, nullptr, inner_capability); vm.host_load_imported_module(referrer, ModuleRequest { specifier_string.to_byte_string() }, nullptr, inner_capability);
// 7. Suspend evalContext and remove it from the execution context stack. // 7. Suspend evalContext and remove it from the execution context stack.
// NOTE: We don't support this concept yet. // NOTE: We don't support this concept yet.

View file

@ -35,7 +35,7 @@ private:
ThrowCompletionOr<void> copy_name_and_length(VM&, FunctionObject& function, FunctionObject& target, Optional<StringView> prefix = {}, Optional<unsigned> arg_count = {}); ThrowCompletionOr<void> copy_name_and_length(VM&, FunctionObject& function, FunctionObject& target, Optional<StringView> prefix = {}, Optional<unsigned> arg_count = {});
ThrowCompletionOr<Value> perform_shadow_realm_eval(VM&, StringView source_text, Realm& caller_realm, Realm& eval_realm); ThrowCompletionOr<Value> perform_shadow_realm_eval(VM&, StringView source_text, Realm& caller_realm, Realm& eval_realm);
ThrowCompletionOr<Value> shadow_realm_import_value(VM&, ByteString specifier_string, ByteString export_name_string, Realm& caller_realm, Realm& eval_realm); ThrowCompletionOr<Value> shadow_realm_import_value(VM&, String specifier_string, String export_name_string, Realm& caller_realm, Realm& eval_realm);
ThrowCompletionOr<Value> get_wrapped_value(VM&, Realm& caller_realm, Value); ThrowCompletionOr<Value> get_wrapped_value(VM&, Realm& caller_realm, Value);
NonnullOwnPtr<ExecutionContext> get_shadow_realm_context(Realm& shadow_realm, bool strict_eval); NonnullOwnPtr<ExecutionContext> get_shadow_realm_context(Realm& shadow_realm, bool strict_eval);

View file

@ -65,7 +65,7 @@ JS_DEFINE_NATIVE_FUNCTION(ShadowRealmPrototype::import_value)
auto object = TRY(typed_this_object(vm)); auto object = TRY(typed_this_object(vm));
// 3. Let specifierString be ? ToString(specifier). // 3. Let specifierString be ? ToString(specifier).
auto specifier_string = TRY(specifier.to_byte_string(vm)); auto specifier_string = TRY(specifier.to_string(vm));
// 4. If Type(exportName) is not String, throw a TypeError exception. // 4. If Type(exportName) is not String, throw a TypeError exception.
if (!export_name.is_string()) if (!export_name.is_string())
@ -78,7 +78,7 @@ JS_DEFINE_NATIVE_FUNCTION(ShadowRealmPrototype::import_value)
auto& eval_realm = object->shadow_realm(); auto& eval_realm = object->shadow_realm();
// 7. Return ShadowRealmImportValue(specifierString, exportName, callerRealm, evalRealm). // 7. Return ShadowRealmImportValue(specifierString, exportName, callerRealm, evalRealm).
return shadow_realm_import_value(vm, move(specifier_string), export_name.as_string().byte_string(), *caller_realm, eval_realm); return shadow_realm_import_value(vm, move(specifier_string), export_name.as_string().utf8_string(), *caller_realm, eval_realm);
} }
} }

View file

@ -60,7 +60,7 @@
#define TESTJS_GLOBAL_FUNCTION(function, exposed_name, ...) \ #define TESTJS_GLOBAL_FUNCTION(function, exposed_name, ...) \
JS_DECLARE_NATIVE_FUNCTION(function); \ JS_DECLARE_NATIVE_FUNCTION(function); \
__TESTJS_REGISTER_GLOBAL_FUNCTION(#exposed_name, function, ##__VA_ARGS__); \ __TESTJS_REGISTER_GLOBAL_FUNCTION(#exposed_name##_string, function, ##__VA_ARGS__); \
JS_DEFINE_NATIVE_FUNCTION(function) JS_DEFINE_NATIVE_FUNCTION(function)
#define TESTJS_MAIN_HOOK() \ #define TESTJS_MAIN_HOOK() \
@ -117,7 +117,7 @@ struct FunctionWithLength {
JS::ThrowCompletionOr<JS::Value> (*function)(JS::VM&); JS::ThrowCompletionOr<JS::Value> (*function)(JS::VM&);
size_t length { 0 }; size_t length { 0 };
}; };
extern HashMap<ByteString, FunctionWithLength> s_exposed_global_functions; extern HashMap<String, FunctionWithLength> s_exposed_global_functions;
extern ByteString g_test_root_fragment; extern ByteString g_test_root_fragment;
extern ByteString g_test_root; extern ByteString g_test_root;
extern int g_test_argc; extern int g_test_argc;

View file

@ -21,7 +21,7 @@ namespace JS {
RefPtr<::JS::VM> g_vm; RefPtr<::JS::VM> g_vm;
bool g_collect_on_every_allocation = false; bool g_collect_on_every_allocation = false;
ByteString g_currently_running_test; ByteString g_currently_running_test;
HashMap<ByteString, FunctionWithLength> s_exposed_global_functions; HashMap<String, FunctionWithLength> s_exposed_global_functions;
Function<void()> g_main_hook; Function<void()> g_main_hook;
HashMap<bool*, Tuple<ByteString, ByteString, char>> g_extra_args; HashMap<bool*, Tuple<ByteString, ByteString, char>> g_extra_args;
IntermediateRunFileResult (*g_run_file)(ByteString const&, JS::Realm&, JS::ExecutionContext&) = nullptr; IntermediateRunFileResult (*g_run_file)(ByteString const&, JS::Realm&, JS::ExecutionContext&) = nullptr;

View file

@ -843,7 +843,7 @@ GC::Ref<WebIDL::Promise> SubtleCrypto::wrap_key(Bindings::KeyFormat format, GC::
} }
// 3. Let bytes be the result of UTF-8 encoding json. // 3. Let bytes be the result of UTF-8 encoding json.
bytes = maybe_json.release_value()->to_byte_buffer(); bytes = MUST(ByteBuffer::copy(maybe_json.value()->bytes()));
} else { } else {
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }

View file

@ -1018,7 +1018,7 @@ public:
auto deserialized_value = TRY(deserialize()); auto deserialized_value = TRY(deserialize());
// 2. Let result be ! CreateDataProperty(value, entry.[[Key]], deserializedValue). // 2. Let result be ! CreateDataProperty(value, entry.[[Key]], deserializedValue).
auto result = MUST(object.create_data_property(key.to_byte_string(), deserialized_value)); auto result = MUST(object.create_data_property(key, deserialized_value));
// 3. Assert: result is true. // 3. Assert: result is true.
VERIFY(result); VERIFY(result);

View file

@ -58,7 +58,7 @@ void Instance::initialize(JS::Realm& realm)
m_function_instances.set(address, *object); m_function_instances.set(address, *object);
} }
m_exports->define_direct_property(export_.name(), *object, JS::default_attributes); m_exports->define_direct_property(MUST(String::from_byte_string(export_.name())), *object, JS::default_attributes);
}, },
[&](Wasm::GlobalAddress const& address) { [&](Wasm::GlobalAddress const& address) {
Optional<GC::Ptr<Global>> object = cache.get_global_instance(address); Optional<GC::Ptr<Global>> object = cache.get_global_instance(address);
@ -66,7 +66,7 @@ void Instance::initialize(JS::Realm& realm)
object = realm.create<Global>(realm, address); object = realm.create<Global>(realm, address);
} }
m_exports->define_direct_property(export_.name(), *object, JS::default_attributes); m_exports->define_direct_property(MUST(String::from_byte_string(export_.name())), *object, JS::default_attributes);
}, },
[&](Wasm::MemoryAddress const& address) { [&](Wasm::MemoryAddress const& address) {
Optional<GC::Ptr<Memory>> object = m_memory_instances.get(address); Optional<GC::Ptr<Memory>> object = m_memory_instances.get(address);
@ -75,7 +75,7 @@ void Instance::initialize(JS::Realm& realm)
m_memory_instances.set(address, *object); m_memory_instances.set(address, *object);
} }
m_exports->define_direct_property(export_.name(), *object, JS::default_attributes); m_exports->define_direct_property(MUST(String::from_byte_string(export_.name())), *object, JS::default_attributes);
}, },
[&](Wasm::TableAddress const& address) { [&](Wasm::TableAddress const& address) {
Optional<GC::Ptr<Table>> object = m_table_instances.get(address); Optional<GC::Ptr<Table>> object = m_table_instances.get(address);
@ -84,7 +84,7 @@ void Instance::initialize(JS::Realm& realm)
m_table_instances.set(address, *object); m_table_instances.set(address, *object);
} }
m_exports->define_direct_property(export_.name(), *object, JS::default_attributes); m_exports->define_direct_property(MUST(String::from_byte_string(export_.name())), *object, JS::default_attributes);
}); });
} }

View file

@ -172,7 +172,7 @@ JS::ThrowCompletionOr<NonnullOwnPtr<Wasm::ModuleInstance>> instantiate_module(JS
for (Wasm::Linker::Name const& import_name : linker.unresolved_imports()) { for (Wasm::Linker::Name const& import_name : linker.unresolved_imports()) {
dbgln_if(LIBWEB_WASM_DEBUG, "Trying to resolve {}::{}", import_name.module, import_name.name); dbgln_if(LIBWEB_WASM_DEBUG, "Trying to resolve {}::{}", import_name.module, import_name.name);
// 3.1. Let o be ? Get(importObject, moduleName). // 3.1. Let o be ? Get(importObject, moduleName).
auto value_or_error = import_object->get(import_name.module); auto value_or_error = import_object->get(MUST(String::from_byte_string(import_name.module)));
if (value_or_error.is_error()) if (value_or_error.is_error())
break; break;
auto value = value_or_error.release_value(); auto value = value_or_error.release_value();
@ -182,7 +182,7 @@ JS::ThrowCompletionOr<NonnullOwnPtr<Wasm::ModuleInstance>> instantiate_module(JS
break; break;
auto object = object_or_error.release_value(); auto object = object_or_error.release_value();
// 3.3. Let v be ? Get(o, componentName). // 3.3. Let v be ? Get(o, componentName).
auto import_or_error = object->get(import_name.name); auto import_or_error = object->get(MUST(String::from_byte_string(import_name.name)));
if (import_or_error.is_error()) if (import_or_error.is_error())
break; break;
auto import_ = import_or_error.release_value(); auto import_ = import_or_error.release_value();

View file

@ -171,7 +171,7 @@ JS::Completion call_user_object_operation(WebIDL::CallbackType& callback, String
// 9. If ! IsCallable(O) is false, then: // 9. If ! IsCallable(O) is false, then:
if (!object->is_function()) { if (!object->is_function()) {
// 1. Let getResult be Get(O, opName). // 1. Let getResult be Get(O, opName).
auto get_result = object->get(operation_name.to_byte_string()); auto get_result = object->get(operation_name);
// 2. If getResult is an abrupt completion, set completion to getResult and jump to the step labeled return. // 2. If getResult is an abrupt completion, set completion to getResult and jump to the step labeled return.
if (get_result.is_throw_completion()) { if (get_result.is_throw_completion()) {

View file

@ -1342,7 +1342,7 @@ Messages::WebDriverClient::GetElementPropertyResponse WebDriverConnection::get_e
// 5. Let property be the result of calling the Object.[[GetProperty]](name) on element. // 5. Let property be the result of calling the Object.[[GetProperty]](name) on element.
Web::HTML::TemporaryExecutionContext execution_context { current_browsing_context().active_document()->realm() }; Web::HTML::TemporaryExecutionContext execution_context { current_browsing_context().active_document()->realm() };
if (auto property_or_error = element->get(name.to_byte_string()); !property_or_error.is_throw_completion()) { if (auto property_or_error = element->get(name); !property_or_error.is_throw_completion()) {
auto property = property_or_error.release_value(); auto property = property_or_error.release_value();
// 6. Let result be the value of property if not undefined, or null. // 6. Let result be the value of property if not undefined, or null.

View file

@ -294,9 +294,9 @@ static JS::ThrowCompletionOr<JS::Value> load_ini_impl(JS::VM& vm)
auto group_object = JS::Object::create(realm, realm.intrinsics().object_prototype()); auto group_object = JS::Object::create(realm, realm.intrinsics().object_prototype());
for (auto const& key : config_file->keys(group)) { for (auto const& key : config_file->keys(group)) {
auto entry = config_file->read_entry(group, key); auto entry = config_file->read_entry(group, key);
group_object->define_direct_property(key, JS::PrimitiveString::create(vm, move(entry)), JS::Attribute::Enumerable | JS::Attribute::Configurable | JS::Attribute::Writable); group_object->define_direct_property(MUST(String::from_byte_string(key)), JS::PrimitiveString::create(vm, move(entry)), JS::Attribute::Enumerable | JS::Attribute::Configurable | JS::Attribute::Writable);
} }
object->define_direct_property(group, group_object, JS::Attribute::Enumerable | JS::Attribute::Configurable | JS::Attribute::Writable); object->define_direct_property(MUST(String::from_byte_string(group)), group_object, JS::Attribute::Enumerable | JS::Attribute::Configurable | JS::Attribute::Writable);
} }
return object; return object;
} }