LibJS: Use FlyString in PropertyKey instead of DeprecatedFlyString

This required dealing with *substantial* fallout.
This commit is contained in:
Andreas Kling 2025-03-18 18:08:02 -05:00 committed by Andreas Kling
commit 46a5710238
Notes: github-actions[bot] 2025-03-24 22:28:26 +00:00
110 changed files with 985 additions and 987 deletions

View file

@ -206,7 +206,7 @@ ThrowCompletionOr<Realm*> get_function_realm(VM& vm, FunctionObject const& funct
}
// 8.5.2.1 InitializeBoundName ( name, value, environment ), https://tc39.es/ecma262/#sec-initializeboundname
ThrowCompletionOr<void> initialize_bound_name(VM& vm, DeprecatedFlyString const& name, Value value, Environment* environment)
ThrowCompletionOr<void> initialize_bound_name(VM& vm, FlyString const& name, Value value, Environment* environment)
{
// 1. If environment is not undefined, then
if (environment) {
@ -692,7 +692,7 @@ ThrowCompletionOr<Value> perform_eval(VM& vm, Value x, CallerMode strict_caller,
return vm.throw_completion<InternalError>(ErrorType::NotImplemented, TRY_OR_THROW_OOM(vm, executable_result.error().to_string()));
auto executable = executable_result.release_value();
executable->name = "eval"sv;
executable->name = "eval"_fly_string;
if (Bytecode::g_dump_bytecode)
executable->dump();
auto result_or_error = vm.bytecode_interpreter().run_executable(*executable, {});
@ -779,7 +779,7 @@ ThrowCompletionOr<void> eval_declaration_instantiation(VM& vm, Program const& pr
Vector<FunctionDeclaration const&> functions_to_initialize;
// 9. Let declaredFunctionNames be a new empty List.
HashTable<DeprecatedFlyString> declared_function_names;
HashTable<FlyString> declared_function_names;
// 10. For each element d of varDeclarations, in reverse List order, do
TRY(program.for_each_var_function_declaration_in_reverse_order([&](FunctionDeclaration const& function) -> ThrowCompletionOr<void> {
@ -820,7 +820,7 @@ ThrowCompletionOr<void> eval_declaration_instantiation(VM& vm, Program const& pr
if (!strict) {
// a. Let declaredFunctionOrVarNames be the list-concatenation of declaredFunctionNames and declaredVarNames.
// The spec here uses 'declaredVarNames' but that has not been declared yet.
HashTable<DeprecatedFlyString> hoisted_functions;
HashTable<FlyString> hoisted_functions;
// b. For each FunctionDeclaration f that is directly contained in the StatementList of a Block, CaseClause, or DefaultClause Contained within body, do
TRY(program.for_each_function_hoistable_with_annexB_extension([&](FunctionDeclaration& function_declaration) -> ThrowCompletionOr<void> {
@ -911,7 +911,7 @@ ThrowCompletionOr<void> eval_declaration_instantiation(VM& vm, Program const& pr
}
// 12. Let declaredVarNames be a new empty List.
HashTable<DeprecatedFlyString> declared_var_names;
HashTable<FlyString> declared_var_names;
// 13. For each element d of varDeclarations, do
TRY(program.for_each_var_scoped_variable_declaration([&](VariableDeclaration const& declaration) {
@ -1109,7 +1109,7 @@ Object* create_mapped_arguments_object(VM& vm, FunctionObject& function, Vector<
MUST(object->define_property_or_throw(vm.names.length, { .value = Value(length), .writable = true, .enumerable = false, .configurable = true }));
// 17. Let mappedNames be a new empty List.
HashTable<DeprecatedFlyString> mapped_names;
HashTable<FlyString> mapped_names;
// 18. Set index to numberOfParameters - 1.
// 19. Repeat, while index ≥ 0,
@ -1178,19 +1178,21 @@ CanonicalIndex canonical_numeric_index_string(PropertyKey const& property_key, C
if (argument.is_empty())
return CanonicalIndex(CanonicalIndex::Type::Undefined, 0);
u32 current_index = 0;
if (argument.characters()[current_index] == '-') {
auto const* characters = argument.bytes_as_string_view().characters_without_null_termination();
auto const length = argument.bytes_as_string_view().length();
if (characters[current_index] == '-') {
current_index++;
if (current_index == argument.length())
if (current_index == length)
return CanonicalIndex(CanonicalIndex::Type::Undefined, 0);
}
if (argument.characters()[current_index] == '0') {
if (characters[current_index] == '0') {
current_index++;
if (current_index == argument.length())
if (current_index == length)
return CanonicalIndex(CanonicalIndex::Type::Numeric, 0);
if (argument.characters()[current_index] != '.')
if (characters[current_index] != '.')
return CanonicalIndex(CanonicalIndex::Type::Undefined, 0);
current_index++;
if (current_index == argument.length())
if (current_index == length)
return CanonicalIndex(CanonicalIndex::Type::Undefined, 0);
}
@ -1199,17 +1201,17 @@ CanonicalIndex canonical_numeric_index_string(PropertyKey const& property_key, C
return CanonicalIndex(CanonicalIndex::Type::Numeric, 0);
// Short circuit any string that doesn't start with digits
if (char first_non_zero = argument.characters()[current_index]; first_non_zero < '0' || first_non_zero > '9')
if (char first_non_zero = characters[current_index]; first_non_zero < '0' || first_non_zero > '9')
return CanonicalIndex(CanonicalIndex::Type::Undefined, 0);
// 2. Let n be ! ToNumber(argument).
auto maybe_double = argument.to_number<double>(AK::TrimWhitespace::No);
auto maybe_double = argument.bytes_as_string_view().to_number<double>(AK::TrimWhitespace::No);
if (!maybe_double.has_value())
return CanonicalIndex(CanonicalIndex::Type::Undefined, 0);
// FIXME: We return 0 instead of n but it might not observable?
// 3. If SameValue(! ToString(n), argument) is true, return n.
if (number_to_string(*maybe_double) == argument.view())
if (number_to_string(*maybe_double) == argument)
return CanonicalIndex(CanonicalIndex::Type::Numeric, 0);
// 4. Return undefined.
@ -1724,7 +1726,7 @@ ThrowCompletionOr<Value> perform_import_call(VM& vm, Value specifier, Value opti
// 8. Let specifierString be Completion(ToString(specifier)).
// 9. IfAbruptRejectPromise(specifierString, promiseCapability).
auto specifier_string = TRY_OR_REJECT_WITH_VALUE(vm, promise_capability, specifier.to_byte_string(vm));
auto specifier_string = TRY_OR_REJECT_WITH_VALUE(vm, promise_capability, specifier.to_string(vm));
// 10. Let attributes be a new empty List.
Vector<ImportAttribute> attributes;
@ -1780,7 +1782,7 @@ ThrowCompletionOr<Value> perform_import_call(VM& vm, Value specifier, Value opti
}
// 4. Append the ImportAttribute Record { [[Key]]: key, [[Value]]: value } to attributes.
attributes.empend(key.as_string().byte_string(), value.as_string().byte_string());
attributes.empend(key.as_string().utf8_string(), value.as_string().utf8_string());
}
}

View file

@ -38,7 +38,7 @@ ThrowCompletionOr<size_t> length_of_array_like(VM&, Object const&);
ThrowCompletionOr<GC::RootVector<Value>> create_list_from_array_like(VM&, Value, Function<ThrowCompletionOr<void>(Value)> = {});
ThrowCompletionOr<FunctionObject*> species_constructor(VM&, Object const&, FunctionObject& default_constructor);
ThrowCompletionOr<Realm*> get_function_realm(VM&, FunctionObject const&);
ThrowCompletionOr<void> initialize_bound_name(VM&, DeprecatedFlyString const&, Value, Environment*);
ThrowCompletionOr<void> initialize_bound_name(VM&, FlyString const&, Value, Environment*);
bool is_compatible_property_descriptor(bool extensible, PropertyDescriptor const&, Optional<PropertyDescriptor> const& current);
bool validate_and_apply_property_descriptor(Object*, PropertyKey const&, bool extensible, PropertyDescriptor const&, Optional<PropertyDescriptor> const& current);
ThrowCompletionOr<Object*> get_prototype_from_constructor(VM&, FunctionObject const& constructor, GC::Ref<Object> (Intrinsics::*intrinsic_default_prototype)());

View file

@ -40,7 +40,7 @@ BoundFunction::BoundFunction(Realm& realm, FunctionObject& bound_target_function
, m_bound_this(bound_this)
, m_bound_arguments(move(bound_arguments))
// FIXME: Non-standard and redundant, remove.
, m_name(ByteString::formatted("bound {}", bound_target_function.name()))
, m_name(MUST(String::formatted("bound {}", bound_target_function.name())))
{
}

View file

@ -23,7 +23,7 @@ public:
virtual ThrowCompletionOr<Value> internal_call(Value this_argument, ReadonlySpan<Value> arguments_list) override;
virtual ThrowCompletionOr<GC::Ref<Object>> internal_construct(ReadonlySpan<Value> arguments_list, FunctionObject& new_target) override;
virtual DeprecatedFlyString const& name() const override { return m_name; }
virtual FlyString const& name() const override { return m_name; }
virtual bool is_strict_mode() const override { return m_bound_target_function->is_strict_mode(); }
virtual bool has_constructor() const override { return m_bound_target_function->has_constructor(); }
@ -40,7 +40,7 @@ private:
Value m_bound_this; // [[BoundThis]]
Vector<Value> m_bound_arguments; // [[BoundArguments]]
DeprecatedFlyString m_name;
FlyString m_name;
};
}

View file

@ -608,35 +608,35 @@ namespace JS {
P(zonedDateTimeISO)
struct CommonPropertyNames {
PropertyKey and_ { "and", PropertyKey::StringMayBeNumber::No };
PropertyKey catch_ { "catch", PropertyKey::StringMayBeNumber::No };
PropertyKey delete_ { "delete", PropertyKey::StringMayBeNumber::No };
PropertyKey for_ { "for", PropertyKey::StringMayBeNumber::No };
PropertyKey or_ { "or", PropertyKey::StringMayBeNumber::No };
PropertyKey register_ { "register", PropertyKey::StringMayBeNumber::No };
PropertyKey return_ { "return", PropertyKey::StringMayBeNumber::No };
PropertyKey throw_ { "throw", PropertyKey::StringMayBeNumber::No };
PropertyKey try_ { "try", PropertyKey::StringMayBeNumber::No };
PropertyKey union_ { "union", PropertyKey::StringMayBeNumber::No };
PropertyKey xor_ { "xor", PropertyKey::StringMayBeNumber::No };
PropertyKey inputAlias { "$_", PropertyKey::StringMayBeNumber::No };
PropertyKey lastMatchAlias { "$&", PropertyKey::StringMayBeNumber::No };
PropertyKey lastParenAlias { "$+", PropertyKey::StringMayBeNumber::No };
PropertyKey leftContextAlias { "$`", PropertyKey::StringMayBeNumber::No };
PropertyKey rightContextAlias { "$'", PropertyKey::StringMayBeNumber::No };
#define __ENUMERATE(x) PropertyKey x { #x, PropertyKey::StringMayBeNumber::No };
PropertyKey and_ { "and"_fly_string, PropertyKey::StringMayBeNumber::No };
PropertyKey catch_ { "catch"_fly_string, PropertyKey::StringMayBeNumber::No };
PropertyKey delete_ { "delete"_fly_string, PropertyKey::StringMayBeNumber::No };
PropertyKey for_ { "for"_fly_string, PropertyKey::StringMayBeNumber::No };
PropertyKey or_ { "or"_fly_string, PropertyKey::StringMayBeNumber::No };
PropertyKey register_ { "register"_fly_string, PropertyKey::StringMayBeNumber::No };
PropertyKey return_ { "return"_fly_string, PropertyKey::StringMayBeNumber::No };
PropertyKey throw_ { "throw"_fly_string, PropertyKey::StringMayBeNumber::No };
PropertyKey try_ { "try"_fly_string, PropertyKey::StringMayBeNumber::No };
PropertyKey union_ { "union"_fly_string, PropertyKey::StringMayBeNumber::No };
PropertyKey xor_ { "xor"_fly_string, PropertyKey::StringMayBeNumber::No };
PropertyKey inputAlias { "$_"_fly_string, PropertyKey::StringMayBeNumber::No };
PropertyKey lastMatchAlias { "$&"_fly_string, PropertyKey::StringMayBeNumber::No };
PropertyKey lastParenAlias { "$+"_fly_string, PropertyKey::StringMayBeNumber::No };
PropertyKey leftContextAlias { "$`"_fly_string, PropertyKey::StringMayBeNumber::No };
PropertyKey rightContextAlias { "$'"_fly_string, PropertyKey::StringMayBeNumber::No };
#define __ENUMERATE(x) PropertyKey x { #x##_fly_string, PropertyKey::StringMayBeNumber::No };
ENUMERATE_STANDARD_PROPERTY_NAMES(__ENUMERATE)
#undef __ENUMERATE
#define __JS_ENUMERATE(x, a, b, c, t) PropertyKey x { #x, PropertyKey::StringMayBeNumber::No };
#define __JS_ENUMERATE(x, a, b, c, t) PropertyKey x { #x##_fly_string, PropertyKey::StringMayBeNumber::No };
JS_ENUMERATE_BUILTIN_TYPES
#undef __JS_ENUMERATE
#define __JS_ENUMERATE(x, a, b, c) PropertyKey x { #x, PropertyKey::StringMayBeNumber::No };
#define __JS_ENUMERATE(x, a, b, c) PropertyKey x { #x##_fly_string, PropertyKey::StringMayBeNumber::No };
JS_ENUMERATE_INTL_OBJECTS
#undef __JS_ENUMERATE
#define __JS_ENUMERATE(x, a, b, c) PropertyKey x { #x, PropertyKey::StringMayBeNumber::No };
#define __JS_ENUMERATE(x, a, b, c) PropertyKey x { #x##_fly_string, PropertyKey::StringMayBeNumber::No };
JS_ENUMERATE_TEMPORAL_OBJECTS
#undef __JS_ENUMERATE
#define __JS_ENUMERATE(x, a) PropertyKey x { #x, PropertyKey::StringMayBeNumber::No };
#define __JS_ENUMERATE(x, a) PropertyKey x { #x##_fly_string, PropertyKey::StringMayBeNumber::No };
JS_ENUMERATE_WELL_KNOWN_SYMBOLS
#undef __JS_ENUMERATE
};

View file

@ -52,7 +52,7 @@ void DeclarativeEnvironment::visit_edges(Visitor& visitor)
}
// 9.1.1.1.1 HasBinding ( N ), https://tc39.es/ecma262/#sec-declarative-environment-records-hasbinding-n
ThrowCompletionOr<bool> DeclarativeEnvironment::has_binding(DeprecatedFlyString const& name, Optional<size_t>* out_index) const
ThrowCompletionOr<bool> DeclarativeEnvironment::has_binding(FlyString const& name, Optional<size_t>* out_index) const
{
auto binding_and_index = find_binding_and_index(name);
if (!binding_and_index.has_value())
@ -63,7 +63,7 @@ ThrowCompletionOr<bool> DeclarativeEnvironment::has_binding(DeprecatedFlyString
}
// 9.1.1.1.2 CreateMutableBinding ( N, D ), https://tc39.es/ecma262/#sec-declarative-environment-records-createmutablebinding-n-d
ThrowCompletionOr<void> DeclarativeEnvironment::create_mutable_binding(VM&, DeprecatedFlyString const& name, bool can_be_deleted)
ThrowCompletionOr<void> DeclarativeEnvironment::create_mutable_binding(VM&, FlyString const& name, bool can_be_deleted)
{
// 1. Assert: envRec does not already have a binding for N.
// NOTE: We skip this to avoid O(n) traversal of m_bindings.
@ -86,7 +86,7 @@ ThrowCompletionOr<void> DeclarativeEnvironment::create_mutable_binding(VM&, Depr
}
// 9.1.1.1.3 CreateImmutableBinding ( N, S ), https://tc39.es/ecma262/#sec-declarative-environment-records-createimmutablebinding-n-s
ThrowCompletionOr<void> DeclarativeEnvironment::create_immutable_binding(VM&, DeprecatedFlyString const& name, bool strict)
ThrowCompletionOr<void> DeclarativeEnvironment::create_immutable_binding(VM&, FlyString const& name, bool strict)
{
// 1. Assert: envRec does not already have a binding for N.
// NOTE: We skip this to avoid O(n) traversal of m_bindings.
@ -110,7 +110,7 @@ ThrowCompletionOr<void> DeclarativeEnvironment::create_immutable_binding(VM&, De
// 9.1.1.1.4 InitializeBinding ( N, V ), https://tc39.es/ecma262/#sec-declarative-environment-records-initializebinding-n-v
// 4.1.1.1.1 InitializeBinding ( N, V, hint ), https://tc39.es/proposal-explicit-resource-management/#sec-declarative-environment-records
ThrowCompletionOr<void> DeclarativeEnvironment::initialize_binding(VM& vm, DeprecatedFlyString const& name, Value value, Environment::InitializeBindingHint hint)
ThrowCompletionOr<void> DeclarativeEnvironment::initialize_binding(VM& vm, FlyString const& name, Value value, Environment::InitializeBindingHint hint)
{
return initialize_binding_direct(vm, find_binding_and_index(name)->index().value(), value, hint);
}
@ -137,7 +137,7 @@ ThrowCompletionOr<void> DeclarativeEnvironment::initialize_binding_direct(VM& vm
}
// 9.1.1.1.5 SetMutableBinding ( N, V, S ), https://tc39.es/ecma262/#sec-declarative-environment-records-setmutablebinding-n-v-s
ThrowCompletionOr<void> DeclarativeEnvironment::set_mutable_binding(VM& vm, DeprecatedFlyString const& name, Value value, bool strict)
ThrowCompletionOr<void> DeclarativeEnvironment::set_mutable_binding(VM& vm, FlyString const& name, Value value, bool strict)
{
// 1. If envRec does not have a binding for N, then
auto binding_and_index = find_binding_and_index(name);
@ -187,7 +187,7 @@ ThrowCompletionOr<void> DeclarativeEnvironment::set_mutable_binding_direct(VM& v
}
// 9.1.1.1.6 GetBindingValue ( N, S ), https://tc39.es/ecma262/#sec-declarative-environment-records-getbindingvalue-n-s
ThrowCompletionOr<Value> DeclarativeEnvironment::get_binding_value(VM& vm, DeprecatedFlyString const& name, [[maybe_unused]] bool strict)
ThrowCompletionOr<Value> DeclarativeEnvironment::get_binding_value(VM& vm, FlyString const& name, [[maybe_unused]] bool strict)
{
// 1. Assert: envRec has a binding for N.
auto binding_and_index = find_binding_and_index(name);
@ -198,7 +198,7 @@ ThrowCompletionOr<Value> DeclarativeEnvironment::get_binding_value(VM& vm, Depre
}
// 9.1.1.1.7 DeleteBinding ( N ), https://tc39.es/ecma262/#sec-declarative-environment-records-deletebinding-n
ThrowCompletionOr<bool> DeclarativeEnvironment::delete_binding(VM&, DeprecatedFlyString const& name)
ThrowCompletionOr<bool> DeclarativeEnvironment::delete_binding(VM&, FlyString const& name)
{
// 1. Assert: envRec has a binding for the name that is the value of N.
auto binding_and_index = find_binding_and_index(name);
@ -218,7 +218,7 @@ ThrowCompletionOr<bool> DeclarativeEnvironment::delete_binding(VM&, DeprecatedFl
return true;
}
ThrowCompletionOr<void> DeclarativeEnvironment::initialize_or_set_mutable_binding(VM& vm, DeprecatedFlyString const& name, Value value)
ThrowCompletionOr<void> DeclarativeEnvironment::initialize_or_set_mutable_binding(VM& vm, FlyString const& name, Value value)
{
auto binding_and_index = find_binding_and_index(name);
VERIFY(binding_and_index.has_value());
@ -230,7 +230,7 @@ ThrowCompletionOr<void> DeclarativeEnvironment::initialize_or_set_mutable_bindin
return {};
}
void DeclarativeEnvironment::initialize_or_set_mutable_binding(Badge<ScopeNode>, VM& vm, DeprecatedFlyString const& name, Value value)
void DeclarativeEnvironment::initialize_or_set_mutable_binding(Badge<ScopeNode>, VM& vm, FlyString const& name, Value value)
{
MUST(initialize_or_set_mutable_binding(vm, name, value));
}

View file

@ -6,7 +6,7 @@
#pragma once
#include <AK/DeprecatedFlyString.h>
#include <AK/FlyString.h>
#include <AK/HashMap.h>
#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/Completion.h>
@ -20,7 +20,7 @@ class DeclarativeEnvironment : public Environment {
GC_DECLARE_ALLOCATOR(DeclarativeEnvironment);
struct Binding {
DeprecatedFlyString name;
FlyString name;
Value value;
bool strict { false };
bool mutable_ { false };
@ -33,21 +33,21 @@ public:
virtual ~DeclarativeEnvironment() override = default;
virtual ThrowCompletionOr<bool> has_binding(DeprecatedFlyString const& name, Optional<size_t>* = nullptr) const override final;
virtual ThrowCompletionOr<void> create_mutable_binding(VM&, DeprecatedFlyString const& name, bool can_be_deleted) override final;
virtual ThrowCompletionOr<void> create_immutable_binding(VM&, DeprecatedFlyString const& name, bool strict) override final;
virtual ThrowCompletionOr<void> initialize_binding(VM&, DeprecatedFlyString const& name, Value, InitializeBindingHint) override final;
virtual ThrowCompletionOr<void> set_mutable_binding(VM&, DeprecatedFlyString const& name, Value, bool strict) override final;
virtual ThrowCompletionOr<Value> get_binding_value(VM&, DeprecatedFlyString const& name, bool strict) override;
virtual ThrowCompletionOr<bool> delete_binding(VM&, DeprecatedFlyString const& name) override;
virtual ThrowCompletionOr<bool> has_binding(FlyString const& name, Optional<size_t>* = nullptr) const override final;
virtual ThrowCompletionOr<void> create_mutable_binding(VM&, FlyString const& name, bool can_be_deleted) override final;
virtual ThrowCompletionOr<void> create_immutable_binding(VM&, FlyString const& name, bool strict) override final;
virtual ThrowCompletionOr<void> initialize_binding(VM&, FlyString const& name, Value, InitializeBindingHint) override final;
virtual ThrowCompletionOr<void> set_mutable_binding(VM&, FlyString const& name, Value, bool strict) override final;
virtual ThrowCompletionOr<Value> get_binding_value(VM&, FlyString const& name, bool strict) override;
virtual ThrowCompletionOr<bool> delete_binding(VM&, FlyString const& name) override;
void initialize_or_set_mutable_binding(Badge<ScopeNode>, VM&, DeprecatedFlyString const& name, Value value);
ThrowCompletionOr<void> initialize_or_set_mutable_binding(VM&, DeprecatedFlyString const& name, Value value);
void initialize_or_set_mutable_binding(Badge<ScopeNode>, VM&, FlyString const& name, Value value);
ThrowCompletionOr<void> initialize_or_set_mutable_binding(VM&, FlyString const& name, Value value);
// This is not a method defined in the spec! Do not use this in any LibJS (or other spec related) code.
[[nodiscard]] Vector<DeprecatedFlyString> bindings() const
[[nodiscard]] Vector<FlyString> bindings() const
{
Vector<DeprecatedFlyString> names;
Vector<FlyString> names;
names.ensure_capacity(m_bindings.size());
for (auto const& binding : m_bindings)
@ -113,7 +113,7 @@ protected:
friend class ModuleEnvironment;
virtual Optional<BindingAndIndex> find_binding_and_index(DeprecatedFlyString const& name) const
virtual Optional<BindingAndIndex> find_binding_and_index(FlyString const& name) const
{
if (auto it = m_bindings_assoc.find(name); it != m_bindings_assoc.end()) {
return BindingAndIndex { const_cast<Binding*>(&m_bindings.at(it->value)), it->value };
@ -124,7 +124,7 @@ protected:
private:
Vector<Binding> m_bindings;
HashMap<DeprecatedFlyString, size_t> m_bindings_assoc;
HashMap<FlyString, size_t> m_bindings_assoc;
DisposeCapability m_dispose_capability;
u64 m_environment_serial_number { 0 };

View file

@ -33,7 +33,7 @@ namespace JS {
GC_DEFINE_ALLOCATOR(ECMAScriptFunctionObject);
GC::Ref<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create(Realm& realm, DeprecatedFlyString name, ByteString source_text, Statement const& ecmascript_code, Vector<FunctionParameter> parameters, i32 m_function_length, Vector<DeprecatedFlyString> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind kind, bool is_strict, FunctionParsingInsights parsing_insights, bool is_arrow_function, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name)
GC::Ref<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create(Realm& realm, FlyString name, ByteString source_text, Statement const& ecmascript_code, Vector<FunctionParameter> parameters, i32 m_function_length, Vector<FlyString> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind kind, bool is_strict, FunctionParsingInsights parsing_insights, bool is_arrow_function, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name)
{
Object* prototype = nullptr;
switch (kind) {
@ -53,12 +53,12 @@ GC::Ref<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create(Realm& realm,
return realm.create<ECMAScriptFunctionObject>(move(name), move(source_text), ecmascript_code, move(parameters), m_function_length, move(local_variables_names), parent_environment, private_environment, *prototype, kind, is_strict, parsing_insights, is_arrow_function, move(class_field_initializer_name));
}
GC::Ref<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create(Realm& realm, DeprecatedFlyString name, Object& prototype, ByteString source_text, Statement const& ecmascript_code, Vector<FunctionParameter> parameters, i32 m_function_length, Vector<DeprecatedFlyString> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind kind, bool is_strict, FunctionParsingInsights parsing_insights, bool is_arrow_function, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name)
GC::Ref<ECMAScriptFunctionObject> ECMAScriptFunctionObject::create(Realm& realm, FlyString name, Object& prototype, ByteString source_text, Statement const& ecmascript_code, Vector<FunctionParameter> parameters, i32 m_function_length, Vector<FlyString> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind kind, bool is_strict, FunctionParsingInsights parsing_insights, bool is_arrow_function, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name)
{
return realm.create<ECMAScriptFunctionObject>(move(name), move(source_text), ecmascript_code, move(parameters), m_function_length, move(local_variables_names), parent_environment, private_environment, prototype, kind, is_strict, parsing_insights, is_arrow_function, move(class_field_initializer_name));
}
ECMAScriptFunctionObject::ECMAScriptFunctionObject(DeprecatedFlyString name, ByteString source_text, Statement const& ecmascript_code, Vector<FunctionParameter> formal_parameters, i32 function_length, Vector<DeprecatedFlyString> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, Object& prototype, FunctionKind kind, bool strict, FunctionParsingInsights parsing_insights, bool is_arrow_function, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name)
ECMAScriptFunctionObject::ECMAScriptFunctionObject(FlyString name, ByteString source_text, Statement const& ecmascript_code, Vector<FunctionParameter> formal_parameters, i32 function_length, Vector<FlyString> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, Object& prototype, FunctionKind kind, bool strict, FunctionParsingInsights parsing_insights, bool is_arrow_function, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name)
: FunctionObject(prototype)
, m_name(move(name))
, m_function_length(function_length)
@ -161,7 +161,7 @@ ECMAScriptFunctionObject::ECMAScriptFunctionObject(DeprecatedFlyString name, Byt
m_arguments_object_needed = false;
}
HashTable<DeprecatedFlyString> function_names;
HashTable<FlyString> function_names;
// 18. Else if hasParameterExpressions is false, then
// a. If functionNames contains "arguments" or lexicalNames contains "arguments", then
@ -210,7 +210,7 @@ ECMAScriptFunctionObject::ECMAScriptFunctionObject(DeprecatedFlyString name, Byt
*environment_size += parameters_in_environment;
HashMap<DeprecatedFlyString, ParameterIsLocal> parameter_bindings;
HashMap<FlyString, ParameterIsLocal> parameter_bindings;
auto arguments_object_needs_binding = m_arguments_object_needed && !m_local_variables_names.contains_slow(vm().names.arguments.as_string());
@ -227,7 +227,7 @@ ECMAScriptFunctionObject::ECMAScriptFunctionObject(DeprecatedFlyString name, Byt
// a. Let parameterBindings be parameterNames.
}
HashMap<DeprecatedFlyString, ParameterIsLocal> instantiated_var_names;
HashMap<FlyString, ParameterIsLocal> instantiated_var_names;
size_t* var_environment_size = nullptr;
@ -721,7 +721,7 @@ void async_block_start(VM& vm, T const& async_body, PromiseCapability const& pro
auto& running_context = vm.running_execution_context();
// 2. Let closure be a new Abstract Closure with no parameters that captures promiseCapability and asyncBody and performs the following steps when called:
auto closure = NativeFunction::create(realm, "", [&async_body, &promise_capability](auto& vm) -> ThrowCompletionOr<Value> {
auto closure = NativeFunction::create(realm, ""_fly_string, [&async_body, &promise_capability](auto& vm) -> ThrowCompletionOr<Value> {
Completion result;
// a. Let acAsyncContext be the running execution context.
@ -729,7 +729,7 @@ void async_block_start(VM& vm, T const& async_body, PromiseCapability const& pro
// b. If asyncBody is a Parse Node, then
if constexpr (!IsSame<T, GC::Function<Completion()>>) {
// i. Let result be Completion(Evaluation of asyncBody).
auto maybe_executable = Bytecode::compile(vm, async_body, FunctionKind::Async, "AsyncBlockStart"sv);
auto maybe_executable = Bytecode::compile(vm, async_body, FunctionKind::Async, "AsyncBlockStart"_fly_string);
if (maybe_executable.is_error())
result = maybe_executable.release_error();
else
@ -840,7 +840,7 @@ Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body()
return { Completion::Type::Return, generator_object };
}
void ECMAScriptFunctionObject::set_name(DeprecatedFlyString const& name)
void ECMAScriptFunctionObject::set_name(FlyString const& name)
{
auto& vm = this->vm();
m_name = name;

View file

@ -39,8 +39,8 @@ public:
Global,
};
static GC::Ref<ECMAScriptFunctionObject> create(Realm&, DeprecatedFlyString name, ByteString source_text, Statement const& ecmascript_code, Vector<FunctionParameter> parameters, i32 m_function_length, Vector<DeprecatedFlyString> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind, bool is_strict, FunctionParsingInsights, bool is_arrow_function = false, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name = {});
static GC::Ref<ECMAScriptFunctionObject> create(Realm&, DeprecatedFlyString name, Object& prototype, ByteString source_text, Statement const& ecmascript_code, Vector<FunctionParameter> parameters, i32 m_function_length, Vector<DeprecatedFlyString> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind, bool is_strict, FunctionParsingInsights, bool is_arrow_function = false, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name = {});
static GC::Ref<ECMAScriptFunctionObject> create(Realm&, FlyString name, ByteString source_text, Statement const& ecmascript_code, Vector<FunctionParameter> parameters, i32 m_function_length, Vector<FlyString> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind, bool is_strict, FunctionParsingInsights, bool is_arrow_function = false, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name = {});
static GC::Ref<ECMAScriptFunctionObject> create(Realm&, FlyString name, Object& prototype, ByteString source_text, Statement const& ecmascript_code, Vector<FunctionParameter> parameters, i32 m_function_length, Vector<FlyString> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, FunctionKind, bool is_strict, FunctionParsingInsights, bool is_arrow_function = false, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name = {});
virtual void initialize(Realm&) override;
virtual ~ECMAScriptFunctionObject() override = default;
@ -56,8 +56,8 @@ public:
Statement const& ecmascript_code() const { return m_ecmascript_code; }
Vector<FunctionParameter> const& formal_parameters() const override { return m_formal_parameters; }
virtual DeprecatedFlyString const& name() const override { return m_name; }
void set_name(DeprecatedFlyString const& name);
virtual FlyString const& name() const override { return m_name; }
void set_name(FlyString const& name);
void set_is_class_constructor() { m_is_class_constructor = true; }
@ -89,7 +89,7 @@ public:
// Equivalent to absence of [[Construct]]
virtual bool has_constructor() const override { return m_kind == FunctionKind::Normal && !m_is_arrow_function; }
virtual Vector<DeprecatedFlyString> const& local_variables_names() const override { return m_local_variables_names; }
virtual Vector<FlyString> const& local_variables_names() const override { return m_local_variables_names; }
FunctionKind kind() const { return m_kind; }
@ -109,7 +109,7 @@ protected:
virtual Completion ordinary_call_evaluate_body();
private:
ECMAScriptFunctionObject(DeprecatedFlyString name, ByteString source_text, Statement const& ecmascript_code, Vector<FunctionParameter> parameters, i32 m_function_length, Vector<DeprecatedFlyString> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, Object& prototype, FunctionKind, bool is_strict, FunctionParsingInsights, bool is_arrow_function, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name);
ECMAScriptFunctionObject(FlyString name, ByteString source_text, Statement const& ecmascript_code, Vector<FunctionParameter> parameters, i32 m_function_length, Vector<FlyString> local_variables_names, Environment* parent_environment, PrivateEnvironment* private_environment, Object& prototype, FunctionKind, bool is_strict, FunctionParsingInsights, bool is_arrow_function, Variant<PropertyKey, PrivateName, Empty> class_field_initializer_name);
virtual bool is_ecmascript_function_object() const override { return true; }
virtual void visit_edges(Visitor&) override;
@ -117,12 +117,12 @@ private:
ThrowCompletionOr<void> prepare_for_ordinary_call(ExecutionContext& callee_context, Object* new_target);
void ordinary_call_bind_this(ExecutionContext&, Value this_argument);
DeprecatedFlyString m_name;
FlyString m_name;
GC::Ptr<PrimitiveString> m_name_string;
GC::Ptr<Bytecode::Executable> m_bytecode_executable;
i32 m_function_length { 0 };
Vector<DeprecatedFlyString> m_local_variables_names;
Vector<FlyString> m_local_variables_names;
// Internal Slots of ECMAScript Function Objects, https://tc39.es/ecma262/#table-internal-slots-of-ecmascript-function-objects
GC::Ptr<Environment> m_environment; // [[Environment]]
@ -159,14 +159,14 @@ private:
No,
Yes,
};
HashMap<DeprecatedFlyString, ParameterIsLocal> m_parameter_names;
HashMap<FlyString, ParameterIsLocal> m_parameter_names;
Vector<FunctionDeclaration const&> m_functions_to_initialize;
bool m_arguments_object_needed { false };
bool m_is_module_wrapper { false };
bool m_function_environment_needed { false };
bool m_uses_this { false };
Vector<VariableNameToInitialize> m_var_names_to_initialize_binding;
Vector<DeprecatedFlyString> m_function_names_to_initialize_binding;
Vector<FlyString> m_function_names_to_initialize_binding;
size_t m_function_environment_bindings_count { 0 };
size_t m_var_environment_bindings_count { 0 };

View file

@ -34,13 +34,13 @@ public:
virtual Object* with_base_object() const { return nullptr; }
virtual ThrowCompletionOr<bool> has_binding([[maybe_unused]] DeprecatedFlyString const& name, [[maybe_unused]] Optional<size_t>* out_index = nullptr) const { return false; }
virtual ThrowCompletionOr<void> create_mutable_binding(VM&, [[maybe_unused]] DeprecatedFlyString const& name, [[maybe_unused]] bool can_be_deleted) { return {}; }
virtual ThrowCompletionOr<void> create_immutable_binding(VM&, [[maybe_unused]] DeprecatedFlyString const& name, [[maybe_unused]] bool strict) { return {}; }
virtual ThrowCompletionOr<void> initialize_binding(VM&, [[maybe_unused]] DeprecatedFlyString const& name, Value, InitializeBindingHint) { return {}; }
virtual ThrowCompletionOr<void> set_mutable_binding(VM&, [[maybe_unused]] DeprecatedFlyString const& name, Value, [[maybe_unused]] bool strict) { return {}; }
virtual ThrowCompletionOr<Value> get_binding_value(VM&, [[maybe_unused]] DeprecatedFlyString const& name, [[maybe_unused]] bool strict) { return Value {}; }
virtual ThrowCompletionOr<bool> delete_binding(VM&, [[maybe_unused]] DeprecatedFlyString const& name) { return false; }
virtual ThrowCompletionOr<bool> has_binding([[maybe_unused]] FlyString const& name, [[maybe_unused]] Optional<size_t>* out_index = nullptr) const { return false; }
virtual ThrowCompletionOr<void> create_mutable_binding(VM&, [[maybe_unused]] FlyString const& name, [[maybe_unused]] bool can_be_deleted) { return {}; }
virtual ThrowCompletionOr<void> create_immutable_binding(VM&, [[maybe_unused]] FlyString const& name, [[maybe_unused]] bool strict) { return {}; }
virtual ThrowCompletionOr<void> initialize_binding(VM&, [[maybe_unused]] FlyString const& name, Value, InitializeBindingHint) { return {}; }
virtual ThrowCompletionOr<void> set_mutable_binding(VM&, [[maybe_unused]] FlyString const& name, Value, [[maybe_unused]] bool strict) { return {}; }
virtual ThrowCompletionOr<Value> get_binding_value(VM&, [[maybe_unused]] FlyString const& name, [[maybe_unused]] bool strict) { return Value {}; }
virtual ThrowCompletionOr<bool> delete_binding(VM&, [[maybe_unused]] FlyString const& name) { return false; }
// [[OuterEnv]]
Environment* outer_environment() { return m_outer_environment; }

View file

@ -84,7 +84,7 @@ void Error::populate_stack()
for (auto& element : stack_trace) {
auto* context = element.execution_context;
TracebackFrame frame {
.function_name = context->function_name ? context->function_name->byte_string() : "",
.function_name = context->function_name ? context->function_name->utf8_string() : ""_string,
.cached_source_range = element.source_range,
};
@ -111,7 +111,7 @@ String Error::stack_string(CompactTraceback compact) const
else
stack_string_builder.appendff(" at {} ({}:{}:{})\n", function_name, source_range.filename(), source_range.start.line, source_range.start.column);
} else {
stack_string_builder.appendff(" at {}\n", function_name.is_empty() ? "<unknown>"sv : function_name.view());
stack_string_builder.appendff(" at {}\n", function_name.is_empty() ? "<unknown>"sv : function_name);
}
};

View file

@ -7,7 +7,6 @@
#pragma once
#include <AK/DeprecatedFlyString.h>
#include <AK/String.h>
#include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/Object.h>
@ -16,7 +15,7 @@
namespace JS {
struct TracebackFrame {
DeprecatedFlyString function_name;
FlyString function_name;
[[nodiscard]] SourceRange const& source_range() const;
RefPtr<CachedSourceRange> cached_source_range;

View file

@ -6,6 +6,7 @@
#pragma once
#include <AK/String.h>
#include <AK/StringView.h>
#define JS_ENUMERATE_ERROR_TYPES(M) \
@ -309,18 +310,18 @@ public:
JS_ENUMERATE_ERROR_TYPES(__ENUMERATE_JS_ERROR)
#undef __ENUMERATE_JS_ERROR
StringView message() const
String message() const
{
return m_message;
}
private:
explicit ErrorType(StringView message)
: m_message(message)
: m_message(MUST(String::from_utf8(message)))
{
}
StringView m_message;
String m_message;
};
}

View file

@ -218,7 +218,7 @@ ThrowCompletionOr<GC::Ref<ECMAScriptFunctionObject>> FunctionConstructor::create
// 28. Let F be OrdinaryFunctionCreate(proto, sourceText, parameters, body, non-lexical-this, env, privateEnv).
parsing_insights.might_need_arguments_object = true;
auto function = ECMAScriptFunctionObject::create(realm, "anonymous", *prototype, move(source_text), expr->body(), expr->parameters(), expr->function_length(), expr->local_variables_names(), &environment, private_environment, expr->kind(), expr->is_strict_mode(), parsing_insights);
auto function = ECMAScriptFunctionObject::create(realm, "anonymous"_fly_string, *prototype, move(source_text), expr->body(), expr->parameters(), expr->function_length(), expr->local_variables_names(), &environment, private_environment, expr->kind(), expr->is_strict_mode(), parsing_insights);
// FIXME: Remove the name argument from create() and do this instead.
// 29. Perform SetFunctionName(F, "anonymous").

View file

@ -32,7 +32,7 @@ void FunctionObject::set_function_name(Variant<PropertyKey, PrivateName> const&
VERIFY(m_is_extensible);
VERIFY(!storage_has(vm.names.name));
ByteString name;
String name;
// 2. If Type(name) is Symbol, then
if (auto const* property_key = name_arg.get_pointer<PropertyKey>(); property_key && property_key->is_symbol()) {
@ -41,15 +41,15 @@ void FunctionObject::set_function_name(Variant<PropertyKey, PrivateName> const&
// b. If description is undefined, set name to the empty String.
if (!description.has_value())
name = ByteString::empty();
name = ""_string;
// c. Else, set name to the string-concatenation of "[", description, and "]".
else
name = ByteString::formatted("[{}]", *description);
name = MUST(String::formatted("[{}]", *description));
}
// 3. Else if name is a Private Name, then
else if (auto const* private_name = name_arg.get_pointer<PrivateName>()) {
// a. Set name to name.[[Description]].
name = private_name->description;
name = private_name->description.to_string();
}
// NOTE: This is necessary as we use a different parameter name.
else {
@ -65,7 +65,7 @@ void FunctionObject::set_function_name(Variant<PropertyKey, PrivateName> const&
// 5. If prefix is present, then
if (prefix.has_value()) {
// a. Set name to the string-concatenation of prefix, the code unit 0x0020 (SPACE), and name.
name = ByteString::formatted("{} {}", *prefix, name);
name = MUST(String::formatted("{} {}", *prefix, name));
// b. If F has an [[InitialName]] internal slot, then
if (is<NativeFunction>(this)) {

View file

@ -26,7 +26,7 @@ public:
virtual ThrowCompletionOr<Value> internal_call(Value this_argument, ReadonlySpan<Value> arguments_list) = 0;
virtual ThrowCompletionOr<GC::Ref<Object>> internal_construct([[maybe_unused]] ReadonlySpan<Value> arguments_list, [[maybe_unused]] FunctionObject& new_target) { VERIFY_NOT_REACHED(); }
virtual DeprecatedFlyString const& name() const = 0;
virtual FlyString const& name() const = 0;
void set_function_name(Variant<PropertyKey, PrivateName> const& name_arg, Optional<StringView> const& prefix = {});
void set_function_length(double length);
@ -38,7 +38,7 @@ public:
// [[Realm]]
virtual Realm* realm() const { return nullptr; }
virtual Vector<DeprecatedFlyString> const& local_variables_names() const { VERIFY_NOT_REACHED(); }
virtual Vector<FlyString> const& local_variables_names() const { VERIFY_NOT_REACHED(); }
virtual Vector<FunctionParameter> const& formal_parameters() const { VERIFY_NOT_REACHED(); }

View file

@ -19,7 +19,7 @@ public:
virtual ~FunctionPrototype() override = default;
virtual ThrowCompletionOr<Value> internal_call(Value this_argument, ReadonlySpan<Value> arguments_list) override;
virtual DeprecatedFlyString const& name() const override { return m_name; }
virtual FlyString const& name() const override { return m_name; }
private:
explicit FunctionPrototype(Realm&);
@ -31,7 +31,7 @@ private:
JS_DECLARE_NATIVE_FUNCTION(symbol_has_instance);
// 20.2.3: The Function prototype object has a "name" property whose value is the empty String.
DeprecatedFlyString m_name;
FlyString m_name;
};
}

View file

@ -41,7 +41,7 @@ ThrowCompletionOr<Value> GlobalEnvironment::get_this_binding(VM&) const
}
// 9.1.1.4.1 HasBinding ( N ), https://tc39.es/ecma262/#sec-global-environment-records-hasbinding-n
ThrowCompletionOr<bool> GlobalEnvironment::has_binding(DeprecatedFlyString const& name, Optional<size_t>*) const
ThrowCompletionOr<bool> GlobalEnvironment::has_binding(FlyString const& name, Optional<size_t>*) const
{
// 1. Let DclRec be envRec.[[DeclarativeRecord]].
// 2. If ! DclRec.HasBinding(N) is true, return true.
@ -54,7 +54,7 @@ ThrowCompletionOr<bool> GlobalEnvironment::has_binding(DeprecatedFlyString const
}
// 9.1.1.4.2 CreateMutableBinding ( N, D ), https://tc39.es/ecma262/#sec-global-environment-records-createmutablebinding-n-d
ThrowCompletionOr<void> GlobalEnvironment::create_mutable_binding(VM& vm, DeprecatedFlyString const& name, bool can_be_deleted)
ThrowCompletionOr<void> GlobalEnvironment::create_mutable_binding(VM& vm, FlyString const& name, bool can_be_deleted)
{
// 1. Let DclRec be envRec.[[DeclarativeRecord]].
// 2. If ! DclRec.HasBinding(N) is true, throw a TypeError exception.
@ -66,7 +66,7 @@ ThrowCompletionOr<void> GlobalEnvironment::create_mutable_binding(VM& vm, Deprec
}
// 9.1.1.4.3 CreateImmutableBinding ( N, S ), https://tc39.es/ecma262/#sec-global-environment-records-createimmutablebinding-n-s
ThrowCompletionOr<void> GlobalEnvironment::create_immutable_binding(VM& vm, DeprecatedFlyString const& name, bool strict)
ThrowCompletionOr<void> GlobalEnvironment::create_immutable_binding(VM& vm, FlyString const& name, bool strict)
{
// 1. Let DclRec be envRec.[[DeclarativeRecord]].
// 2. If ! DclRec.HasBinding(N) is true, throw a TypeError exception.
@ -78,7 +78,7 @@ ThrowCompletionOr<void> GlobalEnvironment::create_immutable_binding(VM& vm, Depr
}
// 9.1.1.4.4 InitializeBinding ( N, V, hint ), https://tc39.es/ecma262/#sec-global-environment-records-initializebinding-n-v
ThrowCompletionOr<void> GlobalEnvironment::initialize_binding(VM& vm, DeprecatedFlyString const& name, Value value, InitializeBindingHint hint)
ThrowCompletionOr<void> GlobalEnvironment::initialize_binding(VM& vm, FlyString const& name, Value value, InitializeBindingHint hint)
{
// 1. Let DclRec be envRec.[[DeclarativeRecord]].
// 2. If ! DclRec.HasBinding(N) is true, then
@ -96,7 +96,7 @@ ThrowCompletionOr<void> GlobalEnvironment::initialize_binding(VM& vm, Deprecated
}
// 9.1.1.4.5 SetMutableBinding ( N, V, S ), https://tc39.es/ecma262/#sec-global-environment-records-setmutablebinding-n-v-s
ThrowCompletionOr<void> GlobalEnvironment::set_mutable_binding(VM& vm, DeprecatedFlyString const& name, Value value, bool strict)
ThrowCompletionOr<void> GlobalEnvironment::set_mutable_binding(VM& vm, FlyString const& name, Value value, bool strict)
{
// 1. Let DclRec be envRec.[[DeclarativeRecord]].
// 2. If ! DclRec.HasBinding(N) is true, then
@ -111,7 +111,7 @@ ThrowCompletionOr<void> GlobalEnvironment::set_mutable_binding(VM& vm, Deprecate
}
// 9.1.1.4.6 GetBindingValue ( N, S ), https://tc39.es/ecma262/#sec-global-environment-records-getbindingvalue-n-s
ThrowCompletionOr<Value> GlobalEnvironment::get_binding_value(VM& vm, DeprecatedFlyString const& name, bool strict)
ThrowCompletionOr<Value> GlobalEnvironment::get_binding_value(VM& vm, FlyString const& name, bool strict)
{
// 1. Let DclRec be envRec.[[DeclarativeRecord]].
// 2. If ! DclRec.HasBinding(N) is true, then
@ -129,7 +129,7 @@ ThrowCompletionOr<Value> GlobalEnvironment::get_binding_value(VM& vm, Deprecated
}
// 9.1.1.4.7 DeleteBinding ( N ), https://tc39.es/ecma262/#sec-global-environment-records-deletebinding-n
ThrowCompletionOr<bool> GlobalEnvironment::delete_binding(VM& vm, DeprecatedFlyString const& name)
ThrowCompletionOr<bool> GlobalEnvironment::delete_binding(VM& vm, FlyString const& name)
{
// 1. Let DclRec be envRec.[[DeclarativeRecord]].
// 2. If ! DclRec.HasBinding(N) is true, then
@ -165,7 +165,7 @@ ThrowCompletionOr<bool> GlobalEnvironment::delete_binding(VM& vm, DeprecatedFlyS
}
// 9.1.1.4.12 HasVarDeclaration ( N ), https://tc39.es/ecma262/#sec-hasvardeclaration
bool GlobalEnvironment::has_var_declaration(DeprecatedFlyString const& name) const
bool GlobalEnvironment::has_var_declaration(FlyString const& name) const
{
// 1. Let varDeclaredNames be envRec.[[VarNames]].
// 2. If varDeclaredNames contains N, return true.
@ -174,7 +174,7 @@ bool GlobalEnvironment::has_var_declaration(DeprecatedFlyString const& name) con
}
// 9.1.1.4.13 HasLexicalDeclaration ( N ), https://tc39.es/ecma262/#sec-haslexicaldeclaration
bool GlobalEnvironment::has_lexical_declaration(DeprecatedFlyString const& name) const
bool GlobalEnvironment::has_lexical_declaration(FlyString const& name) const
{
// 1. Let DclRec be envRec.[[DeclarativeRecord]].
// 2. Return ! DclRec.HasBinding(N).
@ -182,7 +182,7 @@ bool GlobalEnvironment::has_lexical_declaration(DeprecatedFlyString const& name)
}
// 9.1.1.4.14 HasRestrictedGlobalProperty ( N ), https://tc39.es/ecma262/#sec-hasrestrictedglobalproperty
ThrowCompletionOr<bool> GlobalEnvironment::has_restricted_global_property(DeprecatedFlyString const& name) const
ThrowCompletionOr<bool> GlobalEnvironment::has_restricted_global_property(FlyString const& name) const
{
// 1. Let ObjRec be envRec.[[ObjectRecord]].
// 2. Let globalObject be ObjRec.[[BindingObject]].
@ -204,7 +204,7 @@ ThrowCompletionOr<bool> GlobalEnvironment::has_restricted_global_property(Deprec
}
// 9.1.1.4.15 CanDeclareGlobalVar ( N ), https://tc39.es/ecma262/#sec-candeclareglobalvar
ThrowCompletionOr<bool> GlobalEnvironment::can_declare_global_var(DeprecatedFlyString const& name) const
ThrowCompletionOr<bool> GlobalEnvironment::can_declare_global_var(FlyString const& name) const
{
// 1. Let ObjRec be envRec.[[ObjectRecord]].
// 2. Let globalObject be ObjRec.[[BindingObject]].
@ -222,7 +222,7 @@ ThrowCompletionOr<bool> GlobalEnvironment::can_declare_global_var(DeprecatedFlyS
}
// 9.1.1.4.16 CanDeclareGlobalFunction ( N ), https://tc39.es/ecma262/#sec-candeclareglobalfunction
ThrowCompletionOr<bool> GlobalEnvironment::can_declare_global_function(DeprecatedFlyString const& name) const
ThrowCompletionOr<bool> GlobalEnvironment::can_declare_global_function(FlyString const& name) const
{
// 1. Let ObjRec be envRec.[[ObjectRecord]].
// 2. Let globalObject be ObjRec.[[BindingObject]].
@ -248,7 +248,7 @@ ThrowCompletionOr<bool> GlobalEnvironment::can_declare_global_function(Deprecate
}
// 9.1.1.4.17 CreateGlobalVarBinding ( N, D ), https://tc39.es/ecma262/#sec-createglobalvarbinding
ThrowCompletionOr<void> GlobalEnvironment::create_global_var_binding(DeprecatedFlyString const& name, bool can_be_deleted)
ThrowCompletionOr<void> GlobalEnvironment::create_global_var_binding(FlyString const& name, bool can_be_deleted)
{
auto& vm = this->vm();
@ -283,7 +283,7 @@ ThrowCompletionOr<void> GlobalEnvironment::create_global_var_binding(DeprecatedF
}
// 9.1.1.4.18 CreateGlobalFunctionBinding ( N, V, D ), https://tc39.es/ecma262/#sec-createglobalfunctionbinding
ThrowCompletionOr<void> GlobalEnvironment::create_global_function_binding(DeprecatedFlyString const& name, Value value, bool can_be_deleted)
ThrowCompletionOr<void> GlobalEnvironment::create_global_function_binding(FlyString const& name, Value value, bool can_be_deleted)
{
// 1. Let ObjRec be envRec.[[ObjectRecord]].
// 2. Let globalObject be ObjRec.[[BindingObject]].

View file

@ -18,25 +18,25 @@ public:
virtual bool has_this_binding() const final { return true; }
virtual ThrowCompletionOr<Value> get_this_binding(VM&) const final;
virtual ThrowCompletionOr<bool> has_binding(DeprecatedFlyString const& name, Optional<size_t>* = nullptr) const override;
virtual ThrowCompletionOr<void> create_mutable_binding(VM&, DeprecatedFlyString const& name, bool can_be_deleted) override;
virtual ThrowCompletionOr<void> create_immutable_binding(VM&, DeprecatedFlyString const& name, bool strict) override;
virtual ThrowCompletionOr<void> initialize_binding(VM&, DeprecatedFlyString const& name, Value, Environment::InitializeBindingHint) override;
virtual ThrowCompletionOr<void> set_mutable_binding(VM&, DeprecatedFlyString const& name, Value, bool strict) override;
virtual ThrowCompletionOr<Value> get_binding_value(VM&, DeprecatedFlyString const& name, bool strict) override;
virtual ThrowCompletionOr<bool> delete_binding(VM&, DeprecatedFlyString const& name) override;
virtual ThrowCompletionOr<bool> has_binding(FlyString const& name, Optional<size_t>* = nullptr) const override;
virtual ThrowCompletionOr<void> create_mutable_binding(VM&, FlyString const& name, bool can_be_deleted) override;
virtual ThrowCompletionOr<void> create_immutable_binding(VM&, FlyString const& name, bool strict) override;
virtual ThrowCompletionOr<void> initialize_binding(VM&, FlyString const& name, Value, Environment::InitializeBindingHint) override;
virtual ThrowCompletionOr<void> set_mutable_binding(VM&, FlyString const& name, Value, bool strict) override;
virtual ThrowCompletionOr<Value> get_binding_value(VM&, FlyString const& name, bool strict) override;
virtual ThrowCompletionOr<bool> delete_binding(VM&, FlyString const& name) override;
ObjectEnvironment& object_record() { return *m_object_record; }
Object& global_this_value() { return *m_global_this_value; }
DeclarativeEnvironment& declarative_record() { return *m_declarative_record; }
bool has_var_declaration(DeprecatedFlyString const& name) const;
bool has_lexical_declaration(DeprecatedFlyString const& name) const;
ThrowCompletionOr<bool> has_restricted_global_property(DeprecatedFlyString const& name) const;
ThrowCompletionOr<bool> can_declare_global_var(DeprecatedFlyString const& name) const;
ThrowCompletionOr<bool> can_declare_global_function(DeprecatedFlyString const& name) const;
ThrowCompletionOr<void> create_global_var_binding(DeprecatedFlyString const& name, bool can_be_deleted);
ThrowCompletionOr<void> create_global_function_binding(DeprecatedFlyString const& name, Value, bool can_be_deleted);
bool has_var_declaration(FlyString const& name) const;
bool has_lexical_declaration(FlyString const& name) const;
ThrowCompletionOr<bool> has_restricted_global_property(FlyString const& name) const;
ThrowCompletionOr<bool> can_declare_global_var(FlyString const& name) const;
ThrowCompletionOr<bool> can_declare_global_function(FlyString const& name) const;
ThrowCompletionOr<void> create_global_var_binding(FlyString const& name, bool can_be_deleted);
ThrowCompletionOr<void> create_global_function_binding(FlyString const& name, Value, bool can_be_deleted);
private:
GlobalEnvironment(Object&, Object& this_value);
@ -47,7 +47,7 @@ private:
GC::Ptr<ObjectEnvironment> m_object_record; // [[ObjectRecord]]
GC::Ptr<Object> m_global_this_value; // [[GlobalThisValue]]
GC::Ptr<DeclarativeEnvironment> m_declarative_record; // [[DeclarativeRecord]]
Vector<DeprecatedFlyString> m_var_names; // [[VarNames]]
Vector<FlyString> m_var_names; // [[VarNames]]
};
template<>

View file

@ -239,7 +239,7 @@ ThrowCompletionOr<String> JSONObject::serialize_json_object(VM& vm, StringifySta
if (serialized_property_string.has_value()) {
property_strings.append(MUST(String::formatted(
"{}:{}{}",
quote_json_string(MUST(String::from_byte_string(key.to_string()))),
quote_json_string(key.to_string()),
state.gap.is_empty() ? "" : " ",
serialized_property_string)));
}

View file

@ -20,7 +20,7 @@ ModuleEnvironment::ModuleEnvironment(Environment* outer_environment)
}
// 9.1.1.5.1 GetBindingValue ( N, S ), https://tc39.es/ecma262/#sec-module-environment-records-getbindingvalue-n-s
ThrowCompletionOr<Value> ModuleEnvironment::get_binding_value(VM& vm, DeprecatedFlyString const& name, bool strict)
ThrowCompletionOr<Value> ModuleEnvironment::get_binding_value(VM& vm, FlyString const& name, bool strict)
{
// 1. Assert: S is true.
VERIFY(strict);
@ -51,7 +51,7 @@ ThrowCompletionOr<Value> ModuleEnvironment::get_binding_value(VM& vm, Deprecated
}
// 9.1.1.5.2 DeleteBinding ( N ), https://tc39.es/ecma262/#sec-module-environment-records-deletebinding-n
ThrowCompletionOr<bool> ModuleEnvironment::delete_binding(VM&, DeprecatedFlyString const&)
ThrowCompletionOr<bool> ModuleEnvironment::delete_binding(VM&, FlyString const&)
{
// The DeleteBinding concrete method of a module Environment Record is never used within this specification.
VERIFY_NOT_REACHED();
@ -65,7 +65,7 @@ ThrowCompletionOr<Value> ModuleEnvironment::get_this_binding(VM&) const
}
// 9.1.1.5.5 CreateImportBinding ( N, M, N2 ), https://tc39.es/ecma262/#sec-createimportbinding
ThrowCompletionOr<void> ModuleEnvironment::create_import_binding(DeprecatedFlyString name, Module* module, DeprecatedFlyString binding_name)
ThrowCompletionOr<void> ModuleEnvironment::create_import_binding(FlyString name, Module* module, FlyString binding_name)
{
// 1. Assert: envRec does not already have a binding for N.
VERIFY(!get_indirect_binding(name));
@ -82,7 +82,7 @@ ThrowCompletionOr<void> ModuleEnvironment::create_import_binding(DeprecatedFlySt
return {};
}
ModuleEnvironment::IndirectBinding const* ModuleEnvironment::get_indirect_binding(DeprecatedFlyString const& name) const
ModuleEnvironment::IndirectBinding const* ModuleEnvironment::get_indirect_binding(FlyString const& name) const
{
auto binding_or_end = m_indirect_bindings.find_if([&](IndirectBinding const& binding) {
return binding.name == name;
@ -93,7 +93,7 @@ ModuleEnvironment::IndirectBinding const* ModuleEnvironment::get_indirect_bindin
return &(*binding_or_end);
}
Optional<ModuleEnvironment::BindingAndIndex> ModuleEnvironment::find_binding_and_index(DeprecatedFlyString const& name) const
Optional<ModuleEnvironment::BindingAndIndex> ModuleEnvironment::find_binding_and_index(FlyString const& name) const
{
auto* indirect_binding = get_indirect_binding(name);
if (indirect_binding != nullptr) {

View file

@ -22,11 +22,11 @@ public:
// in Table 18 and share the same specifications for all of those methods except for
// GetBindingValue, DeleteBinding, HasThisBinding and GetThisBinding.
// In addition, module Environment Records support the methods listed in Table 24.
virtual ThrowCompletionOr<Value> get_binding_value(VM&, DeprecatedFlyString const& name, bool strict) override;
virtual ThrowCompletionOr<bool> delete_binding(VM&, DeprecatedFlyString const& name) override;
virtual ThrowCompletionOr<Value> get_binding_value(VM&, FlyString const& name, bool strict) override;
virtual ThrowCompletionOr<bool> delete_binding(VM&, FlyString const& name) override;
virtual bool has_this_binding() const final { return true; }
virtual ThrowCompletionOr<Value> get_this_binding(VM&) const final;
ThrowCompletionOr<void> create_import_binding(DeprecatedFlyString name, Module* module, DeprecatedFlyString binding_name);
ThrowCompletionOr<void> create_import_binding(FlyString name, Module* module, FlyString binding_name);
private:
explicit ModuleEnvironment(Environment* outer_environment);
@ -34,13 +34,13 @@ private:
virtual void visit_edges(Visitor&) override;
struct IndirectBinding {
DeprecatedFlyString name;
FlyString name;
GC::Ptr<Module> module;
DeprecatedFlyString binding_name;
FlyString binding_name;
};
IndirectBinding const* get_indirect_binding(DeprecatedFlyString const& name) const;
IndirectBinding const* get_indirect_binding(FlyString const& name) const;
virtual Optional<BindingAndIndex> find_binding_and_index(DeprecatedFlyString const& name) const override;
virtual Optional<BindingAndIndex> find_binding_and_index(FlyString const& name) const override;
// FIXME: Since we always access this via the name this could be a map.
Vector<IndirectBinding> m_indirect_bindings;

View file

@ -13,15 +13,15 @@ namespace JS {
GC_DEFINE_ALLOCATOR(ModuleNamespaceObject);
ModuleNamespaceObject::ModuleNamespaceObject(Realm& realm, Module* module, Vector<DeprecatedFlyString> exports)
ModuleNamespaceObject::ModuleNamespaceObject(Realm& realm, Module* module, Vector<FlyString> exports)
: Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().object_prototype(), MayInterfereWithIndexedPropertyAccess::Yes)
, m_module(module)
, m_exports(move(exports))
{
// Note: We just perform step 6 of 10.4.6.12 ModuleNamespaceCreate ( module, exports ), https://tc39.es/ecma262/#sec-modulenamespacecreate
// 6. Let sortedExports be a List whose elements are the elements of exports ordered as if an Array of the same values had been sorted using %Array.prototype.sort% using undefined as comparefn.
quick_sort(m_exports, [&](DeprecatedFlyString const& lhs, DeprecatedFlyString const& rhs) {
return lhs.view() < rhs.view();
quick_sort(m_exports, [&](FlyString const& lhs, FlyString const& rhs) {
return lhs.bytes_as_string_view() < rhs.bytes_as_string_view();
});
}

View file

@ -33,12 +33,12 @@ public:
virtual void initialize(Realm&) override;
private:
ModuleNamespaceObject(Realm&, Module* module, Vector<DeprecatedFlyString> exports);
ModuleNamespaceObject(Realm&, Module* module, Vector<FlyString> exports);
virtual void visit_edges(Visitor&) override;
GC::Ptr<Module> m_module; // [[Module]]
Vector<DeprecatedFlyString> m_exports; // [[Exports]]
GC::Ptr<Module> m_module; // [[Module]]
Vector<FlyString> m_exports; // [[Exports]]
};
}

View file

@ -7,21 +7,21 @@
#pragma once
#include <AK/DeprecatedFlyString.h>
#include <AK/FlyString.h>
#include <AK/Vector.h>
#include <LibJS/Module.h>
namespace JS {
struct ModuleWithSpecifier {
ByteString specifier; // [[Specifier]]
String specifier; // [[Specifier]]
GC::Ref<Module> module; // [[Module]]
};
// https://tc39.es/proposal-import-attributes/#importattribute-record
struct ImportAttribute {
ByteString key;
ByteString value;
String key;
String value;
bool operator==(ImportAttribute const&) const = default;
};
@ -30,20 +30,20 @@ struct ImportAttribute {
struct ModuleRequest {
ModuleRequest() = default;
explicit ModuleRequest(DeprecatedFlyString specifier)
explicit ModuleRequest(FlyString specifier)
: module_specifier(move(specifier))
{
}
ModuleRequest(DeprecatedFlyString specifier, Vector<ImportAttribute> attributes);
ModuleRequest(FlyString specifier, Vector<ImportAttribute> attributes);
void add_attribute(ByteString key, ByteString value)
void add_attribute(String key, String value)
{
attributes.empend(move(key), move(value));
}
DeprecatedFlyString module_specifier; // [[Specifier]]
Vector<ImportAttribute> attributes; // [[Attributes]]
FlyString module_specifier; // [[Specifier]]
Vector<ImportAttribute> attributes; // [[Attributes]]
bool operator==(ModuleRequest const&) const = default;
};

View file

@ -68,7 +68,7 @@ GC::Ref<NativeFunction> NativeFunction::create(Realm& allocating_realm, Function
return function;
}
GC::Ref<NativeFunction> NativeFunction::create(Realm& realm, DeprecatedFlyString const& name, Function<ThrowCompletionOr<Value>(VM&)> function)
GC::Ref<NativeFunction> NativeFunction::create(Realm& realm, FlyString const& name, Function<ThrowCompletionOr<Value>(VM&)> function)
{
return realm.create<NativeFunction>(name, GC::create_function(realm.heap(), move(function)), realm.intrinsics().function_prototype());
}
@ -90,7 +90,7 @@ NativeFunction::NativeFunction(Object& prototype)
{
}
NativeFunction::NativeFunction(DeprecatedFlyString name, GC::Ptr<GC::Function<ThrowCompletionOr<Value>(VM&)>> native_function, Object& prototype)
NativeFunction::NativeFunction(FlyString name, GC::Ptr<GC::Function<ThrowCompletionOr<Value>(VM&)>> native_function, Object& prototype)
: FunctionObject(prototype)
, m_name(move(name))
, m_native_function(move(native_function))
@ -98,7 +98,7 @@ NativeFunction::NativeFunction(DeprecatedFlyString name, GC::Ptr<GC::Function<Th
{
}
NativeFunction::NativeFunction(DeprecatedFlyString name, Object& prototype)
NativeFunction::NativeFunction(FlyString name, Object& prototype)
: FunctionObject(prototype)
, m_name(move(name))
, m_realm(&prototype.shape().realm())

View file

@ -22,7 +22,7 @@ class NativeFunction : public FunctionObject {
public:
static GC::Ref<NativeFunction> create(Realm&, ESCAPING Function<ThrowCompletionOr<Value>(VM&)> behaviour, i32 length, PropertyKey const& name = FlyString {}, Optional<Realm*> = {}, Optional<Object*> prototype = {}, Optional<StringView> const& prefix = {});
static GC::Ref<NativeFunction> create(Realm&, DeprecatedFlyString const& name, ESCAPING Function<ThrowCompletionOr<Value>(VM&)>);
static GC::Ref<NativeFunction> create(Realm&, FlyString const& name, ESCAPING Function<ThrowCompletionOr<Value>(VM&)>);
virtual ~NativeFunction() override = default;
@ -34,18 +34,18 @@ public:
virtual ThrowCompletionOr<Value> call();
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject& new_target);
virtual DeprecatedFlyString const& name() const override { return m_name; }
virtual FlyString const& name() const override { return m_name; }
virtual bool is_strict_mode() const override;
virtual bool has_constructor() const override { return false; }
virtual Realm* realm() const override { return m_realm; }
Optional<DeprecatedFlyString> const& initial_name() const { return m_initial_name; }
void set_initial_name(Badge<FunctionObject>, DeprecatedFlyString initial_name) { m_initial_name = move(initial_name); }
Optional<FlyString> const& initial_name() const { return m_initial_name; }
void set_initial_name(Badge<FunctionObject>, FlyString initial_name) { m_initial_name = move(initial_name); }
protected:
NativeFunction(DeprecatedFlyString name, Object& prototype);
NativeFunction(FlyString name, Object& prototype);
NativeFunction(GC::Ptr<GC::Function<ThrowCompletionOr<Value>(VM&)>>, Object* prototype, Realm& realm);
NativeFunction(DeprecatedFlyString name, GC::Ptr<GC::Function<ThrowCompletionOr<Value>(VM&)>>, Object& prototype);
NativeFunction(FlyString name, GC::Ptr<GC::Function<ThrowCompletionOr<Value>(VM&)>>, Object& prototype);
explicit NativeFunction(Object& prototype);
virtual void initialize(Realm&) override;
@ -54,9 +54,9 @@ protected:
private:
virtual bool is_native_function() const final { return true; }
DeprecatedFlyString m_name;
FlyString m_name;
GC::Ptr<PrimitiveString> m_name_string;
Optional<DeprecatedFlyString> m_initial_name; // [[InitialName]]
Optional<FlyString> m_initial_name; // [[InitialName]]
GC::Ptr<GC::Function<ThrowCompletionOr<Value>(VM&)>> m_native_function;
GC::Ptr<Realm> m_realm;
};

View file

@ -25,7 +25,7 @@ namespace JS {
GC_DEFINE_ALLOCATOR(Object);
static HashMap<GC::Ptr<Object const>, HashMap<DeprecatedFlyString, Object::IntrinsicAccessor>> s_intrinsics;
static HashMap<GC::Ptr<Object const>, HashMap<FlyString, Object::IntrinsicAccessor>> s_intrinsics;
// 10.1.12 OrdinaryObjectCreate ( proto [ , additionalInternalSlotsList ] ), https://tc39.es/ecma262/#sec-ordinaryobjectcreate
GC::Ref<Object> Object::create(Realm& realm, Object* prototype)
@ -1369,7 +1369,7 @@ Optional<Completion> Object::enumerate_object_properties(Function<Optional<Compl
// * Enumerating the properties of the target object includes enumerating properties of its prototype, and the prototype of the prototype, and so on, recursively.
// * A property of a prototype is not processed if it has the same name as a property that has already been processed.
HashTable<DeprecatedFlyString> visited;
HashTable<FlyString> visited;
auto const* target = this;
while (target) {
@ -1377,7 +1377,7 @@ Optional<Completion> Object::enumerate_object_properties(Function<Optional<Compl
for (auto& key : own_keys) {
if (!key.is_string())
continue;
DeprecatedFlyString property_key = key.as_string().byte_string();
FlyString property_key = key.as_string().utf8_string();
if (visited.contains(property_key))
continue;
auto descriptor = TRY(target->internal_get_own_property(property_key));

View file

@ -27,7 +27,7 @@ void ObjectEnvironment::visit_edges(Cell::Visitor& visitor)
}
// 9.1.1.2.1 HasBinding ( N ), https://tc39.es/ecma262/#sec-object-environment-records-hasbinding-n
ThrowCompletionOr<bool> ObjectEnvironment::has_binding(DeprecatedFlyString const& name, Optional<size_t>*) const
ThrowCompletionOr<bool> ObjectEnvironment::has_binding(FlyString const& name, Optional<size_t>*) const
{
auto& vm = this->vm();
@ -62,7 +62,7 @@ ThrowCompletionOr<bool> ObjectEnvironment::has_binding(DeprecatedFlyString const
}
// 9.1.1.2.2 CreateMutableBinding ( N, D ), https://tc39.es/ecma262/#sec-object-environment-records-createmutablebinding-n-d
ThrowCompletionOr<void> ObjectEnvironment::create_mutable_binding(VM&, DeprecatedFlyString const& name, bool can_be_deleted)
ThrowCompletionOr<void> ObjectEnvironment::create_mutable_binding(VM&, FlyString const& name, bool can_be_deleted)
{
// 1. Let bindingObject be envRec.[[BindingObject]].
// 2. Perform ? DefinePropertyOrThrow(bindingObject, N, PropertyDescriptor { [[Value]]: undefined, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: D }).
@ -73,14 +73,14 @@ ThrowCompletionOr<void> ObjectEnvironment::create_mutable_binding(VM&, Deprecate
}
// 9.1.1.2.3 CreateImmutableBinding ( N, S ), https://tc39.es/ecma262/#sec-object-environment-records-createimmutablebinding-n-s
ThrowCompletionOr<void> ObjectEnvironment::create_immutable_binding(VM&, DeprecatedFlyString const&, bool)
ThrowCompletionOr<void> ObjectEnvironment::create_immutable_binding(VM&, FlyString const&, bool)
{
// "The CreateImmutableBinding concrete method of an object Environment Record is never used within this specification."
VERIFY_NOT_REACHED();
}
// 9.1.1.2.4 InitializeBinding ( N, V ), https://tc39.es/ecma262/#sec-object-environment-records-initializebinding-n-v
ThrowCompletionOr<void> ObjectEnvironment::initialize_binding(VM& vm, DeprecatedFlyString const& name, Value value, Environment::InitializeBindingHint hint)
ThrowCompletionOr<void> ObjectEnvironment::initialize_binding(VM& vm, FlyString const& name, Value value, Environment::InitializeBindingHint hint)
{
// 1. Assert: hint is normal.
VERIFY(hint == Environment::InitializeBindingHint::Normal);
@ -93,7 +93,7 @@ ThrowCompletionOr<void> ObjectEnvironment::initialize_binding(VM& vm, Deprecated
}
// 9.1.1.2.5 SetMutableBinding ( N, V, S ), https://tc39.es/ecma262/#sec-object-environment-records-setmutablebinding-n-v-s
ThrowCompletionOr<void> ObjectEnvironment::set_mutable_binding(VM&, DeprecatedFlyString const& name, Value value, bool strict)
ThrowCompletionOr<void> ObjectEnvironment::set_mutable_binding(VM&, FlyString const& name, Value value, bool strict)
{
auto& vm = this->vm();
@ -135,7 +135,7 @@ ThrowCompletionOr<void> ObjectEnvironment::set_mutable_binding(VM&, DeprecatedFl
}
// 9.1.1.2.6 GetBindingValue ( N, S ), https://tc39.es/ecma262/#sec-object-environment-records-getbindingvalue-n-s
ThrowCompletionOr<Value> ObjectEnvironment::get_binding_value(VM&, DeprecatedFlyString const& name, bool strict)
ThrowCompletionOr<Value> ObjectEnvironment::get_binding_value(VM&, FlyString const& name, bool strict)
{
auto& vm = this->vm();
@ -164,7 +164,7 @@ ThrowCompletionOr<Value> ObjectEnvironment::get_binding_value(VM&, DeprecatedFly
}
// 9.1.1.2.7 DeleteBinding ( N ), https://tc39.es/ecma262/#sec-object-environment-records-deletebinding-n
ThrowCompletionOr<bool> ObjectEnvironment::delete_binding(VM&, DeprecatedFlyString const& name)
ThrowCompletionOr<bool> ObjectEnvironment::delete_binding(VM&, FlyString const& name)
{
// 1. Let bindingObject be envRec.[[BindingObject]].
// 2. Return ? bindingObject.[[Delete]](N).

View file

@ -20,13 +20,13 @@ public:
Yes,
};
virtual ThrowCompletionOr<bool> has_binding(DeprecatedFlyString const& name, Optional<size_t>* = nullptr) const override;
virtual ThrowCompletionOr<void> create_mutable_binding(VM&, DeprecatedFlyString const& name, bool can_be_deleted) override;
virtual ThrowCompletionOr<void> create_immutable_binding(VM&, DeprecatedFlyString const& name, bool strict) override;
virtual ThrowCompletionOr<void> initialize_binding(VM&, DeprecatedFlyString const& name, Value, Environment::InitializeBindingHint) override;
virtual ThrowCompletionOr<void> set_mutable_binding(VM&, DeprecatedFlyString const& name, Value, bool strict) override;
virtual ThrowCompletionOr<Value> get_binding_value(VM&, DeprecatedFlyString const& name, bool strict) override;
virtual ThrowCompletionOr<bool> delete_binding(VM&, DeprecatedFlyString const& name) override;
virtual ThrowCompletionOr<bool> has_binding(FlyString const& name, Optional<size_t>* = nullptr) const override;
virtual ThrowCompletionOr<void> create_mutable_binding(VM&, FlyString const& name, bool can_be_deleted) override;
virtual ThrowCompletionOr<void> create_immutable_binding(VM&, FlyString const& name, bool strict) override;
virtual ThrowCompletionOr<void> initialize_binding(VM&, FlyString const& name, Value, Environment::InitializeBindingHint) override;
virtual ThrowCompletionOr<void> set_mutable_binding(VM&, FlyString const& name, Value, bool strict) override;
virtual ThrowCompletionOr<Value> get_binding_value(VM&, FlyString const& name, bool strict) override;
virtual ThrowCompletionOr<bool> delete_binding(VM&, FlyString const& name) override;
// 9.1.1.2.10 WithBaseObject ( ), https://tc39.es/ecma262/#sec-object-environment-records-withbaseobject
virtual Object* with_base_object() const override

View file

@ -21,7 +21,7 @@ PrivateEnvironment::PrivateEnvironment(PrivateEnvironment* parent)
// Note: we start at one such that 0 can be invalid / default initialized.
u64 PrivateEnvironment::s_next_id = 1u;
PrivateName PrivateEnvironment::resolve_private_identifier(DeprecatedFlyString const& identifier) const
PrivateName PrivateEnvironment::resolve_private_identifier(FlyString const& identifier) const
{
auto name_or_end = find_private_name(identifier);
@ -34,7 +34,7 @@ PrivateName PrivateEnvironment::resolve_private_identifier(DeprecatedFlyString c
return m_outer_environment->resolve_private_identifier(identifier);
}
void PrivateEnvironment::add_private_name(DeprecatedFlyString description)
void PrivateEnvironment::add_private_name(FlyString description)
{
if (!find_private_name(description).is_end())
return;

View file

@ -6,7 +6,7 @@
#pragma once
#include <AK/DeprecatedFlyString.h>
#include <AK/FlyString.h>
#include <AK/StringView.h>
#include <AK/Vector.h>
#include <LibGC/CellAllocator.h>
@ -16,14 +16,14 @@ namespace JS {
struct PrivateName {
PrivateName() = default;
PrivateName(u64 unique_id, DeprecatedFlyString description)
PrivateName(u64 unique_id, FlyString description)
: unique_id(unique_id)
, description(move(description))
{
}
u64 unique_id { 0 };
DeprecatedFlyString description;
FlyString description;
bool operator==(PrivateName const& rhs) const;
};
@ -33,9 +33,9 @@ class PrivateEnvironment : public Cell {
GC_DECLARE_ALLOCATOR(PrivateEnvironment);
public:
PrivateName resolve_private_identifier(DeprecatedFlyString const& identifier) const;
PrivateName resolve_private_identifier(FlyString const& identifier) const;
void add_private_name(DeprecatedFlyString description);
void add_private_name(FlyString description);
PrivateEnvironment* outer_environment() { return m_outer_environment; }
PrivateEnvironment const* outer_environment() const { return m_outer_environment; }
@ -45,7 +45,7 @@ private:
virtual void visit_edges(Visitor&) override;
auto find_private_name(DeprecatedFlyString const& description) const
auto find_private_name(FlyString const& description) const
{
return m_private_names.find_if([&](PrivateName const& private_name) {
return private_name.description == description;

View file

@ -6,7 +6,6 @@
#pragma once
#include <AK/DeprecatedFlyString.h>
#include <AK/FlyString.h>
#include <LibGC/Root.h>
#include <LibJS/Runtime/Completion.h>
@ -31,7 +30,7 @@ public:
return PropertyKey { value.as_symbol() };
if (value.is_integral_number() && value.as_double() >= 0 && value.as_double() < NumericLimits<u32>::max())
return static_cast<u32>(value.as_double());
return TRY(value.to_byte_string(vm));
return TRY(value.to_string(vm));
}
PropertyKey() = delete;
@ -45,24 +44,19 @@ public:
VERIFY(index >= 0);
if constexpr (NumericLimits<T>::max() >= NumericLimits<u32>::max()) {
if (index >= NumericLimits<u32>::max()) {
m_data = DeprecatedFlyString { ByteString::number(index) };
m_data = FlyString { String::number(index) };
return;
}
}
}
PropertyKey(DeprecatedFlyString string, StringMayBeNumber string_may_be_number = StringMayBeNumber::Yes)
PropertyKey(FlyString string, StringMayBeNumber string_may_be_number = StringMayBeNumber::Yes)
: m_data { try_coerce_into_number(move(string), string_may_be_number) }
{
}
PropertyKey(String const& string)
: PropertyKey(DeprecatedFlyString(string.to_byte_string()))
{
}
PropertyKey(FlyString const& string)
: PropertyKey(string.to_deprecated_fly_string())
: PropertyKey(FlyString(string))
{
}
@ -74,26 +68,26 @@ public:
PropertyKey(StringOrSymbol const& string_or_symbol)
: m_data {
string_or_symbol.is_string()
? Variant<DeprecatedFlyString, GC::Root<Symbol>, u32> { string_or_symbol.as_string() }
: Variant<DeprecatedFlyString, GC::Root<Symbol>, u32> { const_cast<Symbol*>(string_or_symbol.as_symbol()) }
? Variant<FlyString, GC::Root<Symbol>, u32> { string_or_symbol.as_string() }
: Variant<FlyString, GC::Root<Symbol>, u32> { const_cast<Symbol*>(string_or_symbol.as_symbol()) }
}
{
}
bool is_number() const { return m_data.has<u32>(); }
bool is_string() const { return m_data.has<DeprecatedFlyString>(); }
bool is_string() const { return m_data.has<FlyString>(); }
bool is_symbol() const { return m_data.has<GC::Root<Symbol>>(); }
u32 as_number() const { return m_data.get<u32>(); }
DeprecatedFlyString const& as_string() const { return m_data.get<DeprecatedFlyString>(); }
FlyString const& as_string() const { return m_data.get<FlyString>(); }
Symbol const* as_symbol() const { return m_data.get<GC::Root<Symbol>>(); }
ByteString to_string() const
String to_string() const
{
VERIFY(!is_symbol());
if (is_string())
return as_string();
return ByteString::number(as_number());
return as_string().to_string();
return String::number(as_number());
}
StringOrSymbol to_string_or_symbol() const
@ -109,21 +103,21 @@ public:
private:
friend Traits<JS::PropertyKey>;
static Variant<DeprecatedFlyString, u32> try_coerce_into_number(DeprecatedFlyString string, StringMayBeNumber string_may_be_number)
static Variant<FlyString, u32> try_coerce_into_number(FlyString string, StringMayBeNumber string_may_be_number)
{
if (string_may_be_number != StringMayBeNumber::Yes)
return string;
if (string.is_empty())
return string;
if (string.starts_with("0"sv) && string.length() != 1)
if (string.bytes_as_string_view().starts_with("0"sv) && string.bytes().size() != 1)
return string;
auto property_index = string.to_number<u32>(TrimWhitespace::No);
auto property_index = string.bytes_as_string_view().to_number<u32>(TrimWhitespace::No);
if (!property_index.has_value() || property_index.value() >= NumericLimits<u32>::max())
return string;
return property_index.release_value();
}
Variant<DeprecatedFlyString, u32, GC::Root<Symbol>> m_data;
Variant<FlyString, u32, GC::Root<Symbol>> m_data;
};
}
@ -135,7 +129,7 @@ struct Traits<JS::PropertyKey> : public DefaultTraits<JS::PropertyKey> {
static unsigned hash(JS::PropertyKey const& name)
{
return name.m_data.visit(
[](DeprecatedFlyString const& string) { return string.hash(); },
[](FlyString const& string) { return string.hash(); },
[](GC::Root<JS::Symbol> const& symbol) { return ptr_hash(symbol.ptr()); },
[](u32 const& number) { return int_hash(number); });
}

View file

@ -899,7 +899,7 @@ void ProxyObject::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_handler);
}
DeprecatedFlyString const& ProxyObject::name() const
FlyString const& ProxyObject::name() const
{
VERIFY(is_function());
return static_cast<FunctionObject&>(*m_target).name();

View file

@ -21,7 +21,7 @@ public:
virtual ~ProxyObject() override = default;
virtual DeprecatedFlyString const& name() const override;
virtual FlyString const& name() const override;
virtual bool has_constructor() const override;
Object const& target() const { return m_target; }

View file

@ -208,7 +208,7 @@ ThrowCompletionOr<void> Reference::initialize_referenced_binding(VM& vm, Value v
}
// 6.2.4.9 MakePrivateReference ( baseValue, privateIdentifier ), https://tc39.es/ecma262/#sec-makeprivatereference
Reference make_private_reference(VM& vm, Value base_value, DeprecatedFlyString const& private_identifier)
Reference make_private_reference(VM& vm, Value base_value, FlyString const& private_identifier)
{
// 1. Let privEnv be the running execution context's PrivateEnvironment.
auto private_environment = vm.running_execution_context().private_environment;

View file

@ -13,7 +13,7 @@
namespace JS {
Reference make_private_reference(VM&, Value base_value, DeprecatedFlyString const& private_identifier);
Reference make_private_reference(VM&, Value base_value, FlyString const& private_identifier);
class Reference {
public:
@ -39,7 +39,7 @@ public:
{
}
Reference(Environment& base, DeprecatedFlyString referenced_name, bool strict = false, Optional<EnvironmentCoordinate> environment_coordinate = {})
Reference(Environment& base, FlyString referenced_name, bool strict = false, Optional<EnvironmentCoordinate> environment_coordinate = {})
: m_base_type(BaseType::Environment)
, m_base_environment(&base)
, m_name(move(referenced_name))

View file

@ -19,7 +19,7 @@ namespace JS {
GC_DEFINE_ALLOCATOR(RegExpObject);
Result<regex::RegexOptions<ECMAScriptFlags>, ByteString> regex_flags_from_string(StringView flags)
Result<regex::RegexOptions<ECMAScriptFlags>, String> regex_flags_from_string(StringView flags)
{
bool d = false, g = false, i = false, m = false, s = false, u = false, y = false, v = false;
auto options = RegExpObject::default_flags;
@ -28,42 +28,42 @@ Result<regex::RegexOptions<ECMAScriptFlags>, ByteString> regex_flags_from_string
switch (ch) {
case 'd':
if (d)
return ByteString::formatted(ErrorType::RegExpObjectRepeatedFlag.message(), ch);
return MUST(String::formatted(ErrorType::RegExpObjectRepeatedFlag.message(), ch));
d = true;
break;
case 'g':
if (g)
return ByteString::formatted(ErrorType::RegExpObjectRepeatedFlag.message(), ch);
return MUST(String::formatted(ErrorType::RegExpObjectRepeatedFlag.message(), ch));
g = true;
options |= regex::ECMAScriptFlags::Global;
break;
case 'i':
if (i)
return ByteString::formatted(ErrorType::RegExpObjectRepeatedFlag.message(), ch);
return MUST(String::formatted(ErrorType::RegExpObjectRepeatedFlag.message(), ch));
i = true;
options |= regex::ECMAScriptFlags::Insensitive;
break;
case 'm':
if (m)
return ByteString::formatted(ErrorType::RegExpObjectRepeatedFlag.message(), ch);
return MUST(String::formatted(ErrorType::RegExpObjectRepeatedFlag.message(), ch));
m = true;
options |= regex::ECMAScriptFlags::Multiline;
break;
case 's':
if (s)
return ByteString::formatted(ErrorType::RegExpObjectRepeatedFlag.message(), ch);
return MUST(String::formatted(ErrorType::RegExpObjectRepeatedFlag.message(), ch));
s = true;
options |= regex::ECMAScriptFlags::SingleLine;
break;
case 'u':
if (u)
return ByteString::formatted(ErrorType::RegExpObjectRepeatedFlag.message(), ch);
return MUST(String::formatted(ErrorType::RegExpObjectRepeatedFlag.message(), ch));
u = true;
options |= regex::ECMAScriptFlags::Unicode;
break;
case 'y':
if (y)
return ByteString::formatted(ErrorType::RegExpObjectRepeatedFlag.message(), ch);
return MUST(String::formatted(ErrorType::RegExpObjectRepeatedFlag.message(), ch));
y = true;
// Now for the more interesting flag, 'sticky' actually unsets 'global', part of which is the default.
options.reset_flag(regex::ECMAScriptFlags::Global);
@ -75,12 +75,12 @@ Result<regex::RegexOptions<ECMAScriptFlags>, ByteString> regex_flags_from_string
break;
case 'v':
if (v)
return ByteString::formatted(ErrorType::RegExpObjectRepeatedFlag.message(), ch);
return MUST(String::formatted(ErrorType::RegExpObjectRepeatedFlag.message(), ch));
v = true;
options |= regex::ECMAScriptFlags::UnicodeSets;
break;
default:
return ByteString::formatted(ErrorType::RegExpObjectBadFlag.message(), ch);
return MUST(String::formatted(ErrorType::RegExpObjectBadFlag.message(), ch));
}
}
@ -88,14 +88,14 @@ Result<regex::RegexOptions<ECMAScriptFlags>, ByteString> regex_flags_from_string
}
// 22.2.3.4 Static Semantics: ParsePattern ( patternText, u, v ), https://tc39.es/ecma262/#sec-parsepattern
ErrorOr<ByteString, ParseRegexPatternError> parse_regex_pattern(StringView pattern, bool unicode, bool unicode_sets)
ErrorOr<String, ParseRegexPatternError> parse_regex_pattern(StringView pattern, bool unicode, bool unicode_sets)
{
if (unicode && unicode_sets)
return ParseRegexPatternError { ByteString::formatted(ErrorType::RegExpObjectIncompatibleFlags.message(), 'u', 'v') };
return ParseRegexPatternError { MUST(String::formatted(ErrorType::RegExpObjectIncompatibleFlags.message(), 'u', 'v')) };
auto utf16_pattern_result = AK::utf8_to_utf16(pattern);
if (utf16_pattern_result.is_error())
return ParseRegexPatternError { "Out of memory"sv };
return ParseRegexPatternError { "Out of memory"_string };
auto utf16_pattern = utf16_pattern_result.release_value();
Utf16View utf16_pattern_view { utf16_pattern };
@ -133,11 +133,11 @@ ErrorOr<ByteString, ParseRegexPatternError> parse_regex_pattern(StringView patte
previous_code_unit_was_backslash = false;
}
return builder.to_byte_string();
return builder.to_string_without_validation();
}
// 22.2.3.4 Static Semantics: ParsePattern ( patternText, u, v ), https://tc39.es/ecma262/#sec-parsepattern
ThrowCompletionOr<ByteString> parse_regex_pattern(VM& vm, StringView pattern, bool unicode, bool unicode_sets)
ThrowCompletionOr<String> parse_regex_pattern(VM& vm, StringView pattern, bool unicode, bool unicode_sets)
{
auto result = parse_regex_pattern(pattern, unicode, unicode_sets);
if (result.is_error())
@ -151,7 +151,7 @@ GC::Ref<RegExpObject> RegExpObject::create(Realm& realm)
return realm.create<RegExpObject>(realm.intrinsics().regexp_prototype());
}
GC::Ref<RegExpObject> RegExpObject::create(Realm& realm, Regex<ECMA262> regex, ByteString pattern, ByteString flags)
GC::Ref<RegExpObject> RegExpObject::create(Realm& realm, Regex<ECMA262> regex, String pattern, String flags)
{
return realm.create<RegExpObject>(move(regex), move(pattern), move(flags), realm.intrinsics().regexp_prototype());
}
@ -179,7 +179,7 @@ static RegExpObject::Flags to_flag_bits(StringView flags)
return flag_bits;
}
RegExpObject::RegExpObject(Regex<ECMA262> regex, ByteString pattern, ByteString flags, Object& prototype)
RegExpObject::RegExpObject(Regex<ECMA262> regex, String pattern, String flags, Object& prototype)
: Object(ConstructWithPrototypeTag::Tag, prototype)
, m_pattern(move(pattern))
, m_flags(move(flags))
@ -203,14 +203,14 @@ ThrowCompletionOr<GC::Ref<RegExpObject>> RegExpObject::regexp_initialize(VM& vm,
// 1. If pattern is undefined, let P be the empty String.
// 2. Else, let P be ? ToString(pattern).
auto pattern = pattern_value.is_undefined()
? ByteString::empty()
: TRY(pattern_value.to_byte_string(vm));
? String {}
: TRY(pattern_value.to_string(vm));
// 3. If flags is undefined, let F be the empty String.
// 4. Else, let F be ? ToString(flags).
auto flags = flags_value.is_undefined()
? ByteString::empty()
: TRY(flags_value.to_byte_string(vm));
? String {}
: TRY(flags_value.to_string(vm));
// 5. If F contains any code unit other than "d", "g", "i", "m", "s", "u", "v", or "y", or if F contains any code unit more than once, throw a SyntaxError exception.
// 6. If F contains "i", let i be true; else let i be false.
@ -223,7 +223,7 @@ ThrowCompletionOr<GC::Ref<RegExpObject>> RegExpObject::regexp_initialize(VM& vm,
return vm.throw_completion<SyntaxError>(parsed_flags_or_error.release_error());
auto parsed_flags = parsed_flags_or_error.release_value();
auto parsed_pattern = ByteString::empty();
auto parsed_pattern = String {};
if (!pattern.is_empty()) {
bool unicode = parsed_flags.has_flag_set(regex::ECMAScriptFlags::Unicode);
bool unicode_sets = parsed_flags.has_flag_set(regex::ECMAScriptFlags::UnicodeSets);
@ -237,7 +237,7 @@ ThrowCompletionOr<GC::Ref<RegExpObject>> RegExpObject::regexp_initialize(VM& vm,
}
// 14. If parseResult is a non-empty List of SyntaxError objects, throw a SyntaxError exception.
Regex<ECMA262> regex(move(parsed_pattern), parsed_flags);
Regex<ECMA262> regex(parsed_pattern.to_byte_string(), parsed_flags);
if (regex.parser_result.error != regex::Error::NoError)
return vm.throw_completion<SyntaxError>(ErrorType::RegExpCompileError, regex.error_string());
@ -265,7 +265,7 @@ ThrowCompletionOr<GC::Ref<RegExpObject>> RegExpObject::regexp_initialize(VM& vm,
}
// 22.2.6.13.1 EscapeRegExpPattern ( P, F ), https://tc39.es/ecma262/#sec-escaperegexppattern
ByteString RegExpObject::escape_regexp_pattern() const
String RegExpObject::escape_regexp_pattern() const
{
// 1. Let S be a String in the form of a Pattern[~UnicodeMode] (Pattern[+UnicodeMode] if F contains "u") equivalent
// to P interpreted as UTF-16 encoded Unicode code points (6.1.4), in which certain code points are escaped as
@ -281,7 +281,7 @@ ByteString RegExpObject::escape_regexp_pattern() const
// specification can be met by letting S be "(?:)".
// 3. Return S.
if (m_pattern.is_empty())
return "(?:)";
return "(?:)"_string;
// FIXME: Check the 'u' and 'v' flags and escape accordingly
StringBuilder builder;
@ -322,7 +322,7 @@ ByteString RegExpObject::escape_regexp_pattern() const
}
}
return builder.to_byte_string();
return builder.to_string_without_validation();
}
void RegExpObject::visit_edges(JS::Cell::Visitor& visitor)

View file

@ -18,12 +18,12 @@ namespace JS {
ThrowCompletionOr<GC::Ref<RegExpObject>> regexp_create(VM&, Value pattern, Value flags);
ThrowCompletionOr<GC::Ref<RegExpObject>> regexp_alloc(VM&, FunctionObject& new_target);
Result<regex::RegexOptions<ECMAScriptFlags>, ByteString> regex_flags_from_string(StringView flags);
Result<regex::RegexOptions<ECMAScriptFlags>, String> regex_flags_from_string(StringView flags);
struct ParseRegexPatternError {
ByteString error;
String error;
};
ErrorOr<ByteString, ParseRegexPatternError> parse_regex_pattern(StringView pattern, bool unicode, bool unicode_sets);
ThrowCompletionOr<ByteString> parse_regex_pattern(VM& vm, StringView pattern, bool unicode, bool unicode_sets);
ErrorOr<String, ParseRegexPatternError> parse_regex_pattern(StringView pattern, bool unicode, bool unicode_sets);
ThrowCompletionOr<String> parse_regex_pattern(VM& vm, StringView pattern, bool unicode, bool unicode_sets);
class RegExpObject : public Object {
JS_OBJECT(RegExpObject, Object);
@ -51,16 +51,16 @@ public:
};
static GC::Ref<RegExpObject> create(Realm&);
static GC::Ref<RegExpObject> create(Realm&, Regex<ECMA262> regex, ByteString pattern, ByteString flags);
static GC::Ref<RegExpObject> create(Realm&, Regex<ECMA262> regex, String pattern, String flags);
ThrowCompletionOr<GC::Ref<RegExpObject>> regexp_initialize(VM&, Value pattern, Value flags);
ByteString escape_regexp_pattern() const;
String escape_regexp_pattern() const;
virtual void initialize(Realm&) override;
virtual ~RegExpObject() override = default;
ByteString const& pattern() const { return m_pattern; }
ByteString const& flags() const { return m_flags; }
String const& pattern() const { return m_pattern; }
String const& flags() const { return m_flags; }
Flags flag_bits() const { return m_flag_bits; }
Regex<ECMA262> const& regex() { return *m_regex; }
Regex<ECMA262> const& regex() const { return *m_regex; }
@ -72,12 +72,12 @@ public:
private:
RegExpObject(Object& prototype);
RegExpObject(Regex<ECMA262> regex, ByteString pattern, ByteString flags, Object& prototype);
RegExpObject(Regex<ECMA262> regex, String pattern, String flags, Object& prototype);
virtual void visit_edges(Visitor&) override;
ByteString m_pattern;
ByteString m_flags;
String m_pattern;
String m_flags;
Flags m_flag_bits { 0 };
bool m_legacy_features_enabled { false }; // [[LegacyFeaturesEnabled]]
// Note: This is initialized in RegExpAlloc, but will be non-null afterwards

View file

@ -99,7 +99,7 @@ static Value get_match_index_par(VM& vm, Utf16View const& string, Match const& m
}
// 22.2.7.8 MakeMatchIndicesIndexPairArray ( S, indices, groupNames, hasGroups ), https://tc39.es/ecma262/#sec-makematchindicesindexpairarray
static Value make_match_indices_index_pair_array(VM& vm, Utf16View const& string, Vector<Optional<Match>> const& indices, HashMap<DeprecatedFlyString, Match> const& group_names, bool has_groups)
static Value make_match_indices_index_pair_array(VM& vm, Utf16View const& string, Vector<Optional<Match>> const& indices, HashMap<FlyString, Match> const& group_names, bool has_groups)
{
// Note: This implementation differs from the spec, but has the same behavior.
//
@ -186,7 +186,7 @@ static ThrowCompletionOr<Value> regexp_builtin_exec(VM& vm, RegExpObject& regexp
// 5. If flags contains "y", let sticky be true; else let sticky be false.
bool sticky = regex.options().has_flag_set(ECMAScriptFlags::Sticky);
// 6. If flags contains "d", let hasIndices be true, else let hasIndices be false.
bool has_indices = regexp_object.flags().find('d').has_value();
bool has_indices = regexp_object.flags().bytes_as_string_view().find('d').has_value();
// 7. If global is false and sticky is false, set lastIndex to 0.
if (!global && !sticky)
@ -273,7 +273,7 @@ static ThrowCompletionOr<Value> regexp_builtin_exec(VM& vm, RegExpObject& regexp
Vector<Utf16String> captured_values;
// 26. Let groupNames be a new empty List.
HashMap<DeprecatedFlyString, Match> group_names;
HashMap<FlyString, Match> group_names;
// 27. Add match as the last element of indices.
indices.append(move(match_indices));

View file

@ -147,7 +147,7 @@ ThrowCompletionOr<Value> perform_shadow_realm_eval(VM& vm, StringView source_tex
// 11. If result.[[Type]] is normal, then
if (!eval_result.is_throw_completion()) {
// a. Set result to the result of evaluating body.
auto maybe_executable = Bytecode::compile(vm, program, FunctionKind::Normal, "ShadowRealmEval"sv);
auto maybe_executable = Bytecode::compile(vm, program, FunctionKind::Normal, "ShadowRealmEval"_fly_string);
if (maybe_executable.is_error()) {
result = maybe_executable.release_error();
} else {
@ -211,7 +211,7 @@ ThrowCompletionOr<Value> shadow_realm_import_value(VM& vm, String specifier_stri
auto referrer = GC::Ref { *eval_context->realm };
// 7. Perform HostLoadImportedModule(referrer, specifierString, empty, innerCapability).
vm.host_load_imported_module(referrer, ModuleRequest { specifier_string.to_byte_string() }, nullptr, inner_capability);
vm.host_load_imported_module(referrer, ModuleRequest { specifier_string }, nullptr, inner_capability);
// 7. Suspend evalContext and remove it from the execution context stack.
// NOTE: We don't support this concept yet.

View file

@ -6,7 +6,7 @@
#pragma once
#include <AK/DeprecatedFlyString.h>
#include <AK/FlyString.h>
#include <LibJS/Runtime/PrimitiveString.h>
#include <LibJS/Runtime/Symbol.h>
#include <LibJS/Runtime/Value.h>
@ -20,7 +20,7 @@ public:
{
}
StringOrSymbol(DeprecatedFlyString const& string)
StringOrSymbol(FlyString const& string)
: m_string(string)
{
}
@ -28,7 +28,7 @@ public:
~StringOrSymbol()
{
if (is_string())
m_string.~DeprecatedFlyString();
m_string.~FlyString();
}
StringOrSymbol(Symbol const* symbol)
@ -40,7 +40,7 @@ public:
StringOrSymbol(StringOrSymbol const& other)
{
if (other.is_string())
new (&m_string) DeprecatedFlyString(other.m_string);
new (&m_string) FlyString(other.m_string);
else
m_bits = other.m_bits;
}
@ -48,7 +48,7 @@ public:
StringOrSymbol(StringOrSymbol&& other)
{
if (other.is_string())
new (&m_string) DeprecatedFlyString(move(other.m_string));
new (&m_string) FlyString(move(other.m_string));
else
m_bits = exchange(other.m_bits, 0);
}
@ -57,7 +57,7 @@ public:
ALWAYS_INLINE bool is_symbol() const { return is_valid() && (m_bits & 2); }
ALWAYS_INLINE bool is_string() const { return is_valid() && !(m_bits & 2); }
ALWAYS_INLINE DeprecatedFlyString as_string() const
ALWAYS_INLINE FlyString as_string() const
{
VERIFY(is_string());
return m_string;
@ -69,12 +69,12 @@ public:
return reinterpret_cast<Symbol const*>(m_bits & ~2ULL);
}
ByteString to_display_string() const
String to_display_string() const
{
if (is_string())
return as_string();
return as_string().to_string();
if (is_symbol())
return as_symbol()->descriptive_string().release_value_but_fixme_should_propagate_errors().to_byte_string();
return MUST(as_symbol()->descriptive_string());
VERIFY_NOT_REACHED();
}
@ -134,7 +134,7 @@ private:
}
union {
DeprecatedFlyString m_string;
FlyString m_string;
Symbol const* m_symbol_with_tag;
uintptr_t m_bits;
};

View file

@ -482,7 +482,7 @@ void TypedArrayBase::visit_edges(Visitor& visitor)
{ \
} \
\
DeprecatedFlyString const& ClassName::element_name() const \
FlyString const& ClassName::element_name() const \
{ \
return vm().names.ClassName.as_string(); \
} \

View file

@ -52,7 +52,7 @@ public:
[[nodiscard]] Kind kind() const { return m_kind; }
u32 element_size() const { return m_element_size; }
virtual DeprecatedFlyString const& element_name() const = 0;
virtual FlyString const& element_name() const = 0;
// 25.1.3.11 IsUnclampedIntegerElementType ( type ), https://tc39.es/ecma262/#sec-isunclampedintegerelementtype
virtual bool is_unclamped_integer_element_type() const = 0;
@ -526,7 +526,7 @@ ThrowCompletionOr<double> compare_typed_array_elements(VM&, Value x, Value y, Fu
static ThrowCompletionOr<GC::Ref<ClassName>> create(Realm&, u32 length, FunctionObject& new_target); \
static ThrowCompletionOr<GC::Ref<ClassName>> create(Realm&, u32 length); \
static GC::Ref<ClassName> create(Realm&, u32 length, ArrayBuffer& buffer); \
virtual DeprecatedFlyString const& element_name() const override; \
virtual FlyString const& element_name() const override; \
\
protected: \
ClassName(Object& prototype, u32 length, ArrayBuffer& array_buffer); \

View file

@ -13,7 +13,7 @@ namespace JS {
GC_DEFINE_ALLOCATOR(TypedArrayConstructor);
TypedArrayConstructor::TypedArrayConstructor(DeprecatedFlyString const& name, Object& prototype)
TypedArrayConstructor::TypedArrayConstructor(FlyString const& name, Object& prototype)
: NativeFunction(name, prototype)
{
}

View file

@ -23,7 +23,7 @@ public:
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject& new_target) override;
protected:
TypedArrayConstructor(DeprecatedFlyString const& name, Object& prototype);
TypedArrayConstructor(FlyString const& name, Object& prototype);
private:
virtual bool has_constructor() const override { return true; }

View file

@ -40,7 +40,7 @@ namespace JS {
ErrorOr<NonnullRefPtr<VM>> VM::create(OwnPtr<CustomData> custom_data)
{
ErrorMessages error_messages {};
error_messages[to_underlying(ErrorMessage::OutOfMemory)] = TRY(String::from_utf8(ErrorType::OutOfMemory.message()));
error_messages[to_underlying(ErrorMessage::OutOfMemory)] = ErrorType::OutOfMemory.message();
auto vm = adopt_ref(*new VM(move(custom_data), move(error_messages)));
@ -121,7 +121,7 @@ VM::VM(OwnPtr<CustomData> custom_data, ErrorMessages error_messages)
};
host_get_supported_import_attributes = [&] {
return Vector<ByteString> { "type" };
return Vector<String> { "type"_string };
};
// 19.2.1.2 HostEnsureCanCompileStrings ( calleeRealm, parameterStrings, bodyString, direct ), https://tc39.es/ecma262/#sec-hostensurecancompilestrings
@ -276,7 +276,7 @@ void VM::gather_roots(HashMap<GC::Cell*, GC::HeapRoot>& roots)
}
// 9.1.2.1 GetIdentifierReference ( env, name, strict ), https://tc39.es/ecma262/#sec-getidentifierreference
ThrowCompletionOr<Reference> VM::get_identifier_reference(Environment* environment, DeprecatedFlyString name, bool strict, size_t hops)
ThrowCompletionOr<Reference> VM::get_identifier_reference(Environment* environment, FlyString name, bool strict, size_t hops)
{
// 1. If env is the value null, then
if (!environment) {
@ -310,7 +310,7 @@ ThrowCompletionOr<Reference> VM::get_identifier_reference(Environment* environme
}
// 9.4.2 ResolveBinding ( name [ , env ] ), https://tc39.es/ecma262/#sec-resolvebinding
ThrowCompletionOr<Reference> VM::resolve_binding(DeprecatedFlyString const& name, Environment* environment)
ThrowCompletionOr<Reference> VM::resolve_binding(FlyString const& name, Environment* environment)
{
// 1. If env is not present or if env is undefined, then
if (!environment) {
@ -522,7 +522,7 @@ ScriptOrModule VM::get_active_script_or_module() const
return m_execution_context_stack[0]->script_or_module;
}
VM::StoredModule* VM::get_stored_module(ImportedModuleReferrer const&, ByteString const& filename, ByteString const&)
VM::StoredModule* VM::get_stored_module(ImportedModuleReferrer const&, ByteString const& filename, String const&)
{
// Note the spec says:
// If this operation is called multiple times with the same (referrer, specifier) pair and it performs
@ -632,7 +632,7 @@ void VM::load_imported_module(ImportedModuleReferrer referrer, ModuleRequest con
return;
}
ByteString module_type;
String module_type;
for (auto& attribute : module_request.attributes) {
if (attribute.key == "type"sv) {
module_type = attribute.value;
@ -659,7 +659,7 @@ void VM::load_imported_module(ImportedModuleReferrer referrer, ModuleRequest con
});
LexicalPath base_path { base_filename };
auto filename = LexicalPath::absolute_path(base_path.dirname(), module_request.module_specifier);
auto filename = LexicalPath::absolute_path(base_path.dirname(), module_request.module_specifier.to_deprecated_fly_string());
dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] base path: '{}'", base_path);
dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] initial filename: '{}'", filename);
@ -735,7 +735,7 @@ void VM::load_imported_module(ImportedModuleReferrer referrer, ModuleRequest con
m_loaded_modules.empend(
referrer,
module->filename(),
ByteString {}, // Null type
String {}, // Null type
make_root<Module>(*module),
true);

View file

@ -9,7 +9,7 @@
#pragma once
#include <AK/DeprecatedFlyString.h>
#include <AK/FlyString.h>
#include <AK/Function.h>
#include <AK/HashMap.h>
#include <AK/RefCounted.h>
@ -197,8 +197,8 @@ public:
u32 execution_generation() const { return m_execution_generation; }
void finish_execution_generation() { ++m_execution_generation; }
ThrowCompletionOr<Reference> resolve_binding(DeprecatedFlyString const&, Environment* = nullptr);
ThrowCompletionOr<Reference> get_identifier_reference(Environment*, DeprecatedFlyString, bool strict, size_t hops = 0);
ThrowCompletionOr<Reference> resolve_binding(FlyString const&, Environment* = nullptr);
ThrowCompletionOr<Reference> get_identifier_reference(Environment*, FlyString, bool strict, size_t hops = 0);
// 5.2.3.2 Throw an Exception, https://tc39.es/ecma262/#sec-throw-an-exception
template<typename T, typename... Args>
@ -274,7 +274,7 @@ public:
Function<HashMap<PropertyKey, Value>(SourceTextModule&)> host_get_import_meta_properties;
Function<void(Object*, SourceTextModule const&)> host_finalize_import_meta;
Function<Vector<ByteString>()> host_get_supported_import_attributes;
Function<Vector<String>()> host_get_supported_import_attributes;
void set_dynamic_imports_allowed(bool value) { m_dynamic_imports_allowed = value; }
@ -335,12 +335,12 @@ private:
struct StoredModule {
ImportedModuleReferrer referrer;
ByteString filename;
ByteString type;
String type;
GC::Root<Module> module;
bool has_once_started_linking { false };
};
StoredModule* get_stored_module(ImportedModuleReferrer const& script_or_module, ByteString const& filename, ByteString const& type);
StoredModule* get_stored_module(ImportedModuleReferrer const& script_or_module, ByteString const& filename, String const& type);
Vector<StoredModule> m_loaded_modules;

View file

@ -912,7 +912,7 @@ ThrowCompletionOr<PropertyKey> Value::to_property_key(VM& vm) const
}
// 3. Return ! ToString(key).
return MUST(key.to_byte_string(vm));
return MUST(key.to_string(vm));
}
// 7.1.6 ToInt32 ( argument ), https://tc39.es/ecma262/#sec-toint32

View file

@ -23,7 +23,7 @@ public:
virtual ThrowCompletionOr<Value> internal_call(Value this_argument, ReadonlySpan<Value> arguments_list) override;
// FIXME: Remove this (and stop inventing random internal slots that shouldn't exist, jeez)
virtual DeprecatedFlyString const& name() const override { return m_wrapped_target_function->name(); }
virtual FlyString const& name() const override { return m_wrapped_target_function->name(); }
virtual Realm* realm() const override { return m_realm; }