LibJS+LibWeb: Remove various DeprecatedFlyStrings

Things of note:

 * `PropertyKey`s/`StringOrSymbol`s are converted from `DeprecatedFlyString`
   to `FlyString` when used as function names. This is inefficient.
 * Various name fields have been moved to `FlyString` rather than
   relying on the implicit conversion from `DeprecatedFlyString` to
   `ByteString`. `FlyString` is probably more appropriate anyway.
This commit is contained in:
Jonne Ransijn 2024-11-21 22:40:56 +01:00
parent 6dc61f895d
commit 78c16390b0
No known key found for this signature in database
GPG key ID: 49DC70026D2C578C
84 changed files with 205 additions and 178 deletions

View file

@ -44,7 +44,7 @@ public:
}
static Error from_string_view(StringView string_literal) { return Error(string_literal); }
template<OneOf<ByteString, DeprecatedFlyString, String, FlyString> T>
template<OneOf<ByteString, String, FlyString> T>
static Error from_string_view(T)
{
// `Error::from_string_view(ByteString::formatted(...))` is a somewhat common mistake, which leads to a UAF situation.

View file

@ -60,7 +60,7 @@ public:
[[nodiscard]] static String from_utf8_with_replacement_character(StringView, WithBOMHandling = WithBOMHandling::Yes);
template<typename T>
requires(IsOneOf<RemoveCVReference<T>, ByteString, DeprecatedFlyString, FlyString, String>)
requires(IsOneOf<RemoveCVReference<T>, ByteString, FlyString, String>)
static ErrorOr<String> from_utf8(T&&) = delete;
[[nodiscard]] static String from_utf8_without_validation(ReadonlyBytes);

View file

@ -64,7 +64,7 @@ static void print_indent(int indent)
out("{}", ByteString::repeated(' ', indent * 2));
}
static void update_function_name(Value value, DeprecatedFlyString const& name)
static void update_function_name(Value value, FlyString const& name)
{
if (!value.is_function())
return;
@ -88,15 +88,15 @@ void LabelledStatement::dump(int indent) const
}
// 15.2.5 Runtime Semantics: InstantiateOrdinaryFunctionExpression, https://tc39.es/ecma262/#sec-runtime-semantics-instantiateordinaryfunctionexpression
Value FunctionExpression::instantiate_ordinary_function_expression(VM& vm, DeprecatedFlyString given_name) const
Value FunctionExpression::instantiate_ordinary_function_expression(VM& vm, StringView given_name) const
{
auto& realm = *vm.current_realm();
if (given_name.is_empty())
given_name = "";
given_name = ""sv;
auto has_own_name = !name().is_empty();
auto const used_name = has_own_name ? name() : given_name.view();
auto const used_name = has_own_name ? name() : given_name;
auto environment = GC::Ref { *vm.running_execution_context().lexical_environment };
if (has_own_name) {
VERIFY(environment);
@ -106,7 +106,7 @@ Value FunctionExpression::instantiate_ordinary_function_expression(VM& vm, Depre
auto private_environment = vm.running_execution_context().private_environment;
auto closure = ECMAScriptFunctionObject::create(realm, used_name, source_text(), body(), parameters(), function_length(), local_variables_names(), environment, private_environment, kind(), is_strict_mode(),
auto closure = ECMAScriptFunctionObject::create(realm, MUST(FlyString::from_utf8(used_name)), source_text(), body(), parameters(), function_length(), local_variables_names(), environment, private_environment, kind(), is_strict_mode(),
parsing_insights(), is_arrow_function());
// FIXME: 6. Perform SetFunctionName(closure, name).
@ -152,7 +152,7 @@ ThrowCompletionOr<ClassElement::ClassValue> ClassMethod::class_element_evaluatio
{
auto property_key_or_private_name = TRY(class_key_to_property_name(vm, *m_key, property_key));
auto& method_function = *ECMAScriptFunctionObject::create(*vm.current_realm(), m_function->name(), m_function->source_text(), m_function->body(), m_function->parameters(), m_function->function_length(), m_function->local_variables_names(), vm.lexical_environment(), vm.running_execution_context().private_environment, m_function->kind(), m_function->is_strict_mode(),
auto& method_function = *ECMAScriptFunctionObject::create(*vm.current_realm(), MUST(FlyString::from_utf8(m_function->name())), m_function->source_text(), m_function->body(), m_function->parameters(), m_function->function_length(), m_function->local_variables_names(), vm.lexical_environment(), vm.running_execution_context().private_environment, m_function->kind(), m_function->is_strict_mode(),
m_function->parsing_insights(), m_function->is_arrow_function());
auto method_value = Value(&method_function);
@ -174,7 +174,7 @@ ThrowCompletionOr<ClassElement::ClassValue> ClassMethod::class_element_evaluatio
return private_name.description;
});
update_function_name(method_value, ByteString::formatted("{}{}{}", prefix, prefix.is_empty() ? "" : " ", name));
update_function_name(method_value, MUST(String::formatted("{}{}{}", prefix, prefix.is_empty() ? "" : " ", name)));
};
if (property_key_or_private_name.has<PropertyKey>()) {
@ -243,7 +243,7 @@ ThrowCompletionOr<ClassElement::ClassValue> ClassField::class_element_evaluation
FunctionParsingInsights parsing_insights;
parsing_insights.uses_this_from_environment = true;
parsing_insights.uses_this = true;
initializer = ECMAScriptFunctionObject::create(realm, "field", ByteString::empty(), *function_code, {}, 0, {}, vm.lexical_environment(), vm.running_execution_context().private_environment, FunctionKind::Normal, true, parsing_insights, false, property_key_or_private_name);
initializer = ECMAScriptFunctionObject::create(realm, "field"_fly_string, ByteString::empty(), *function_code, {}, 0, {}, vm.lexical_environment(), vm.running_execution_context().private_environment, FunctionKind::Normal, true, parsing_insights, false, property_key_or_private_name);
initializer->make_method(target);
}
@ -290,7 +290,7 @@ ThrowCompletionOr<ClassElement::ClassValue> StaticInitializer::class_element_eva
FunctionParsingInsights parsing_insights;
parsing_insights.uses_this_from_environment = true;
parsing_insights.uses_this = true;
auto body_function = ECMAScriptFunctionObject::create(realm, ByteString::empty(), ByteString::empty(), *m_function_body, {}, 0, m_function_body->local_variables_names(), lexical_environment, private_environment, FunctionKind::Normal, true, parsing_insights, false);
auto body_function = ECMAScriptFunctionObject::create(realm, FlyString {}, ByteString::empty(), *m_function_body, {}, 0, m_function_body->local_variables_names(), lexical_environment, private_environment, FunctionKind::Normal, true, parsing_insights, false);
// 6. Perform MakeMethod(bodyFunction, homeObject).
body_function->make_method(home_object);
@ -299,7 +299,7 @@ ThrowCompletionOr<ClassElement::ClassValue> StaticInitializer::class_element_eva
return ClassValue { normal_completion(body_function) };
}
ThrowCompletionOr<ECMAScriptFunctionObject*> ClassExpression::create_class_constructor(VM& vm, Environment* class_environment, Environment* environment, Value super_class, ReadonlySpan<Value> element_keys, Optional<DeprecatedFlyString> const& binding_name, DeprecatedFlyString const& class_name) const
ThrowCompletionOr<ECMAScriptFunctionObject*> ClassExpression::create_class_constructor(VM& vm, Environment* class_environment, Environment* environment, Value super_class, ReadonlySpan<Value> element_keys, Optional<DeprecatedFlyString> const& binding_name, FlyString const& class_name) const
{
auto& realm = *vm.current_realm();
@ -342,7 +342,7 @@ ThrowCompletionOr<ECMAScriptFunctionObject*> ClassExpression::create_class_const
parsing_insights.uses_this = true;
auto class_constructor = ECMAScriptFunctionObject::create(
realm,
constructor.name(),
MUST(FlyString::from_utf8(constructor.name())),
constructor.source_text(),
constructor.body(),
constructor.parameters(),
@ -1499,7 +1499,7 @@ void ScopeNode::add_hoisted_function(NonnullRefPtr<FunctionDeclaration const> de
m_functions_hoistable_with_annexB_extension.append(move(declaration));
}
DeprecatedFlyString ExportStatement::local_name_for_default = "*default*";
FlyString ExportStatement::local_name_for_default = "*default*"_fly_string;
static void dump_assert_clauses(ModuleRequest const& request)
{
@ -1629,7 +1629,18 @@ void ScopeNode::block_declaration_instantiation(VM& vm, Environment* environment
auto& function_declaration = static_cast<FunctionDeclaration const&>(declaration);
// ii. Let fo be InstantiateFunctionObject of d with arguments env and privateEnv.
auto function = ECMAScriptFunctionObject::create(realm, function_declaration.name(), function_declaration.source_text(), function_declaration.body(), function_declaration.parameters(), function_declaration.function_length(), function_declaration.local_variables_names(), environment, private_environment, function_declaration.kind(), function_declaration.is_strict_mode(),
auto function = ECMAScriptFunctionObject::create(
realm,
MUST(FlyString::from_utf8(function_declaration.name())),
function_declaration.source_text(),
function_declaration.body(),
function_declaration.parameters(),
function_declaration.function_length(),
function_declaration.local_variables_names(),
environment,
private_environment,
function_declaration.kind(),
function_declaration.is_strict_mode(),
function_declaration.parsing_insights());
// iii. Perform ! env.InitializeBinding(fn, fo). NOTE: This step is replaced in section B.3.2.6.
@ -1837,7 +1848,7 @@ ThrowCompletionOr<void> Program::global_declaration_instantiation(VM& vm, Global
for (auto& declaration : functions_to_initialize.in_reverse()) {
// a. Let fn be the sole element of the BoundNames of f.
// b. Let fo be InstantiateFunctionObject of f with arguments env and privateEnv.
auto function = ECMAScriptFunctionObject::create(realm, declaration.name(), declaration.source_text(), declaration.body(), declaration.parameters(), declaration.function_length(), declaration.local_variables_names(), &global_environment, private_environment, declaration.kind(), declaration.is_strict_mode(),
auto function = ECMAScriptFunctionObject::create(realm, MUST(FlyString::from_utf8(declaration.name())), declaration.source_text(), declaration.body(), declaration.parameters(), declaration.function_length(), declaration.local_variables_names(), &global_environment, private_environment, declaration.kind(), declaration.is_strict_mode(),
declaration.parsing_insights());
// c. Perform ? env.CreateGlobalFunctionBinding(fn, fo, false).

View file

@ -469,7 +469,7 @@ public:
class ExportStatement final : public Statement {
public:
static DeprecatedFlyString local_name_for_default;
static FlyString local_name_for_default;
ExportStatement(SourceRange source_range, RefPtr<ASTNode const> statement, Vector<ExportEntry> entries, bool is_default_export, Optional<ModuleRequest> module_request)
: Statement(move(source_range))
@ -718,9 +718,9 @@ public:
bool uses_this_from_environment() const { return m_parsing_insights.uses_this_from_environment; }
virtual bool has_name() const = 0;
virtual Value instantiate_ordinary_function_expression(VM&, DeprecatedFlyString given_name) const = 0;
virtual Value instantiate_ordinary_function_expression(VM&, StringView given_name) const = 0;
virtual ~FunctionNode() {};
virtual ~FunctionNode() { }
protected:
FunctionNode(RefPtr<Identifier const> name, ByteString source_text, NonnullRefPtr<Statement const> body, Vector<FunctionParameter> parameters, i32 function_length, FunctionKind kind, bool is_strict_mode, FunctionParsingInsights parsing_insights, bool is_arrow_function, Vector<DeprecatedFlyString> local_variables_names)
@ -778,9 +778,9 @@ public:
void set_should_do_additional_annexB_steps() { m_is_hoisted = true; }
bool has_name() const override { return true; }
Value instantiate_ordinary_function_expression(VM&, DeprecatedFlyString) const override { VERIFY_NOT_REACHED(); }
Value instantiate_ordinary_function_expression(VM&, StringView) const override { VERIFY_NOT_REACHED(); }
virtual ~FunctionDeclaration() {};
virtual ~FunctionDeclaration() { }
private:
bool m_is_hoisted { false };
@ -805,9 +805,9 @@ public:
bool has_name() const override { return !name().is_empty(); }
Value instantiate_ordinary_function_expression(VM&, DeprecatedFlyString given_name) const override;
Value instantiate_ordinary_function_expression(VM&, StringView given_name) const override;
virtual ~FunctionExpression() {};
virtual ~FunctionExpression() { }
private:
virtual bool is_function_expression() const override { return true; }
@ -1445,7 +1445,7 @@ public:
bool has_name() const { return m_name; }
ThrowCompletionOr<ECMAScriptFunctionObject*> create_class_constructor(VM&, Environment* class_environment, Environment* environment, Value super_class, ReadonlySpan<Value> element_keys, Optional<DeprecatedFlyString> const& binding_name = {}, DeprecatedFlyString const& class_name = {}) const;
ThrowCompletionOr<ECMAScriptFunctionObject*> create_class_constructor(VM&, Environment* class_environment, Environment* environment, Value super_class, ReadonlySpan<Value> element_keys, Optional<DeprecatedFlyString> const& binding_name = {}, FlyString const& class_name = {}) const;
private:
virtual bool is_class_expression() const override { return true; }

View file

@ -3553,7 +3553,7 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> ExportStatement::genera
if (!static_cast<ClassExpression const&>(*m_statement).has_name()) {
generator.emit<Bytecode::Op::InitializeLexicalBinding>(
generator.intern_identifier(ExportStatement::local_name_for_default),
generator.intern_identifier(ExportStatement::local_name_for_default.to_deprecated_fly_string()),
value);
}
@ -3564,7 +3564,7 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> ExportStatement::genera
VERIFY(is<Expression>(*m_statement));
auto value = TRY(generator.emit_named_evaluation_if_anonymous_function(static_cast<Expression const&>(*m_statement), generator.intern_identifier("default"sv))).value();
generator.emit<Bytecode::Op::InitializeLexicalBinding>(
generator.intern_identifier(ExportStatement::local_name_for_default),
generator.intern_identifier(ExportStatement::local_name_for_default.to_deprecated_fly_string()),
value);
return value;
}

View file

@ -7,6 +7,7 @@
#pragma once
#include <AK/DeprecatedFlyString.h>
#include <AK/FlyString.h>
#include <AK/HashMap.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/OwnPtr.h>
@ -58,7 +59,7 @@ public:
virtual ~Executable() override;
DeprecatedFlyString name;
FlyString name;
Vector<u8> bytecode;
Vector<PropertyLookupCache> property_lookup_caches;
Vector<GlobalVariableCache> global_variable_caches;

View file

@ -813,7 +813,7 @@ void Interpreter::enter_object_environment(Object& object)
running_execution_context().lexical_environment = new_object_environment(object, true, old_environment);
}
ThrowCompletionOr<GC::Ref<Bytecode::Executable>> compile(VM& vm, ASTNode const& node, FunctionKind kind, DeprecatedFlyString const& name)
ThrowCompletionOr<GC::Ref<Bytecode::Executable>> compile(VM& vm, ASTNode const& node, FunctionKind kind, FlyString const& name)
{
auto executable_result = Bytecode::Generator::generate_from_ast_node(vm, node, kind);
if (executable_result.is_error())
@ -1186,14 +1186,14 @@ inline ThrowCompletionOr<void> put_by_property_key(VM& vm, Value base, Value thi
case Op::PropertyKind::Getter: {
auto& function = value.as_function();
if (function.name().is_empty() && is<ECMAScriptFunctionObject>(function))
static_cast<ECMAScriptFunctionObject*>(&function)->set_name(ByteString::formatted("get {}", name));
static_cast<ECMAScriptFunctionObject*>(&function)->set_name(MUST(String::formatted("get {}", name)));
object->define_direct_accessor(name, &function, nullptr, Attribute::Configurable | Attribute::Enumerable);
break;
}
case Op::PropertyKind::Setter: {
auto& function = value.as_function();
if (function.name().is_empty() && is<ECMAScriptFunctionObject>(function))
static_cast<ECMAScriptFunctionObject*>(&function)->set_name(ByteString::formatted("set {}", name));
static_cast<ECMAScriptFunctionObject*>(&function)->set_name(MUST(String::formatted("set {}", name)));
object->define_direct_accessor(name, nullptr, &function, Attribute::Configurable | Attribute::Enumerable);
break;
}
@ -1278,7 +1278,7 @@ inline Value new_function(VM& vm, FunctionNode const& function_node, Optional<Id
name = vm.bytecode_interpreter().current_executable().get_identifier(lhs_name.value());
value = function_node.instantiate_ordinary_function_expression(vm, name);
} else {
value = ECMAScriptFunctionObject::create(*vm.current_realm(), function_node.name(), function_node.source_text(), function_node.body(), function_node.parameters(), function_node.function_length(), function_node.local_variables_names(), vm.lexical_environment(), vm.running_execution_context().private_environment, function_node.kind(), function_node.is_strict_mode(),
value = ECMAScriptFunctionObject::create(*vm.current_realm(), MUST(FlyString::from_utf8(function_node.name())), function_node.source_text(), function_node.body(), function_node.parameters(), function_node.function_length(), function_node.local_variables_names(), vm.lexical_environment(), vm.running_execution_context().private_environment, function_node.kind(), function_node.is_strict_mode(),
function_node.parsing_insights(), function_node.is_arrow_function());
}
@ -1517,12 +1517,12 @@ inline ThrowCompletionOr<ECMAScriptFunctionObject*> new_class(VM& vm, Value supe
vm.running_execution_context().lexical_environment = vm.running_execution_context().saved_lexical_environments.take_last();
Optional<DeprecatedFlyString> binding_name;
DeprecatedFlyString class_name;
FlyString class_name;
if (!class_expression.has_name() && lhs_name.has_value()) {
class_name = interpreter.current_executable().get_identifier(lhs_name.value());
class_name = MUST(FlyString::from_deprecated_fly_string(interpreter.current_executable().get_identifier(lhs_name.value())));
} else {
binding_name = name;
class_name = name.is_null() ? ""sv : name;
class_name = name.is_null() ? FlyString {} : MUST(FlyString::from_utf8(name));
}
return TRY(class_expression.create_class_constructor(vm, class_environment, vm.lexical_environment(), super_class, element_keys, binding_name, class_name));

View file

@ -109,7 +109,7 @@ private:
extern bool g_dump_bytecode;
ThrowCompletionOr<GC::Ref<Bytecode::Executable>> compile(VM&, ASTNode const&, JS::FunctionKind kind, DeprecatedFlyString const& name);
ThrowCompletionOr<GC::Ref<Bytecode::Executable>> compile(VM&, ASTNode const&, JS::FunctionKind kind, FlyString const& name);
ThrowCompletionOr<GC::Ref<Bytecode::Executable>> compile(VM&, ECMAScriptFunctionObject const&);
}

View file

@ -13,7 +13,7 @@ GC_DEFINE_ALLOCATOR(IsHTMLDDA);
IsHTMLDDA::IsHTMLDDA(Realm& realm)
// NativeFunction without prototype is currently not possible (only due to the lack of a ctor that supports it)
: NativeFunction("IsHTMLDDA", realm.intrinsics().function_prototype())
: NativeFunction("IsHTMLDDA"_fly_string, realm.intrinsics().function_prototype())
{
}

View file

@ -2919,7 +2919,7 @@ NonnullRefPtr<FunctionNodeType> Parser::parse_function_node(u16 parse_options, O
if (parse_options & FunctionNodeParseOptions::HasDefaultExportName) {
name = create_identifier_and_register_in_current_scope(
{ m_source_code, rule_start.position(), position() },
ExportStatement::local_name_for_default);
ExportStatement::local_name_for_default.to_deprecated_fly_string());
} else if (FunctionNodeType::must_have_name() || match_identifier()) {
name = create_identifier_and_register_in_current_scope(
{ m_source_code, rule_start.position(), position() },
@ -4891,7 +4891,7 @@ NonnullRefPtr<ExportStatement const> Parser::parse_export_statement(Program& pro
m_state.current_scope_pusher->add_declaration(function_declaration);
if (matches_function == MatchesFunctionDeclaration::WithoutName)
local_name = ExportStatement::local_name_for_default;
local_name = ExportStatement::local_name_for_default.to_deprecated_fly_string();
else
local_name = function_declaration->name();
@ -4927,7 +4927,7 @@ NonnullRefPtr<ExportStatement const> Parser::parse_export_statement(Program& pro
}
if (!local_name.has_value())
local_name = ExportStatement::local_name_for_default;
local_name = ExportStatement::local_name_for_default.to_deprecated_fly_string();
entries_with_location.append({ ExportEntry::named_export(default_string_value, local_name.release_value()), default_position });
} else {

View file

@ -688,7 +688,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, {});
@ -970,7 +970,7 @@ ThrowCompletionOr<void> eval_declaration_instantiation(VM& vm, Program const& pr
for (auto& declaration : functions_to_initialize.in_reverse()) {
// a. Let fn be the sole element of the BoundNames of f.
// b. Let fo be InstantiateFunctionObject of f with arguments lexEnv and privateEnv.
auto function = ECMAScriptFunctionObject::create(realm, declaration.name(), declaration.source_text(), declaration.body(), declaration.parameters(), declaration.function_length(), declaration.local_variables_names(), lexical_environment, private_environment, declaration.kind(), declaration.is_strict_mode(),
auto function = ECMAScriptFunctionObject::create(realm, MUST(FlyString::from_utf8(declaration.name())), declaration.source_text(), declaration.body(), declaration.parameters(), declaration.function_length(), declaration.local_variables_names(), lexical_environment, private_environment, declaration.kind(), declaration.is_strict_mode(),
declaration.parsing_insights());
// c. If varEnv is a global Environment Record, then

View file

@ -17,7 +17,7 @@ namespace JS {
GC_DEFINE_ALLOCATOR(ArrayBufferConstructor);
ArrayBufferConstructor::ArrayBufferConstructor(Realm& realm)
: NativeFunction(realm.vm().names.ArrayBuffer.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.ArrayBuffer.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -25,7 +25,7 @@ namespace JS {
GC_DEFINE_ALLOCATOR(ArrayConstructor);
ArrayConstructor::ArrayConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Array.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.Array.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -15,7 +15,7 @@ namespace JS {
GC_DEFINE_ALLOCATOR(AsyncFunctionConstructor);
AsyncFunctionConstructor::AsyncFunctionConstructor(Realm& realm)
: NativeFunction(realm.vm().names.AsyncFunction.as_string(), realm.intrinsics().function_constructor())
: NativeFunction(realm.vm().names.AsyncFunction.as_fly_string(), realm.intrinsics().function_constructor())
{
}

View file

@ -15,7 +15,7 @@ namespace JS {
GC_DEFINE_ALLOCATOR(AsyncGeneratorFunctionConstructor);
AsyncGeneratorFunctionConstructor::AsyncGeneratorFunctionConstructor(Realm& realm)
: NativeFunction(realm.vm().names.AsyncGeneratorFunction.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.AsyncGeneratorFunction.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -20,7 +20,7 @@ GC_DEFINE_ALLOCATOR(BigIntConstructor);
static Crypto::SignedBigInteger const BIGINT_ONE { 1 };
BigIntConstructor::BigIntConstructor(Realm& realm)
: NativeFunction(realm.vm().names.BigInt.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.BigInt.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -16,7 +16,7 @@ namespace JS {
GC_DEFINE_ALLOCATOR(BooleanConstructor);
BooleanConstructor::BooleanConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Boolean.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.Boolean.as_fly_string(), realm.intrinsics().function_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

@ -17,7 +17,7 @@ namespace JS {
GC_DEFINE_ALLOCATOR(DataViewConstructor);
DataViewConstructor::DataViewConstructor(Realm& realm)
: NativeFunction(realm.vm().names.DataView.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.DataView.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -206,7 +206,7 @@ static double parse_date_string(VM& vm, ByteString const& date_string)
}
DateConstructor::DateConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Date.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.Date.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -13,7 +13,7 @@ namespace JS {
GC_DEFINE_ALLOCATOR(DisposableStackConstructor);
DisposableStackConstructor::DisposableStackConstructor(Realm& realm)
: NativeFunction(realm.vm().names.DisposableStack.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.DisposableStack.as_fly_string(), realm.intrinsics().function_prototype())
{
}

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<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)
{
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<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)
{
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<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)
: FunctionObject(prototype)
, m_name(move(name))
, m_function_length(function_length)
@ -731,14 +731,14 @@ void async_block_start(VM& vm, T const& async_body, PromiseCapability const& pro
auto& running_context = vm.running_execution_context();
// 3. Set the code evaluation state of asyncContext such that when evaluation is resumed for that execution context the following steps will be performed:
auto execution_steps = NativeFunction::create(realm, "", [&async_body, &promise_capability, &async_context](auto& vm) -> ThrowCompletionOr<Value> {
auto execution_steps = NativeFunction::create(realm, ""_fly_string, [&async_body, &promise_capability, &async_context](auto& vm) -> ThrowCompletionOr<Value> {
Completion result;
// a. If asyncBody is a Parse Node, then
if constexpr (!IsSame<T, GC::Function<Completion()>>) {
// a. Let result be the result of evaluating asyncBody.
// FIXME: Cache this executable somewhere.
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
@ -861,7 +861,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<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, 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 = {});
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; }
@ -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<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);
virtual bool is_ecmascript_function_object() const override { return true; }
virtual void visit_edges(Visitor&) override;
@ -117,7 +117,7 @@ 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;

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() : ""_fly_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.bytes_as_string_view());
}
};

View file

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

View file

@ -14,7 +14,7 @@ namespace JS {
GC_DEFINE_ALLOCATOR(ErrorConstructor);
ErrorConstructor::ErrorConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Error.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.Error.as_fly_string(), realm.intrinsics().function_prototype())
{
}
@ -69,7 +69,7 @@ ThrowCompletionOr<GC::Ref<Object>> ErrorConstructor::construct(FunctionObject& n
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
GC_DEFINE_ALLOCATOR(ConstructorName); \
ConstructorName::ConstructorName(Realm& realm) \
: NativeFunction(realm.vm().names.ClassName.as_string(), realm.intrinsics().error_constructor()) \
: NativeFunction(realm.vm().names.ClassName.as_fly_string(), realm.intrinsics().error_constructor()) \
{ \
} \
\
@ -101,7 +101,7 @@ ThrowCompletionOr<GC::Ref<Object>> ErrorConstructor::construct(FunctionObject& n
auto message = vm.argument(0); \
auto options = vm.argument(1); \
\
/* 2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%NativeError.prototype%", « [[ErrorData]] »). */ \
/* 2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%NativeError.prototype%", « [[ErrorData]] »). */ \
auto error = TRY(ordinary_create_from_constructor<ClassName>(vm, new_target, &Intrinsics::snake_name##_prototype)); \
\
/* 3. If message is not undefined, then */ \

View file

@ -8,7 +8,6 @@
#pragma once
#include <AK/DeprecatedFlyString.h>
#include <AK/WeakPtr.h>
#include <LibJS/Bytecode/BasicBlock.h>
#include <LibJS/Forward.h>

View file

@ -16,7 +16,7 @@ namespace JS {
GC_DEFINE_ALLOCATOR(FinalizationRegistryConstructor);
FinalizationRegistryConstructor::FinalizationRegistryConstructor(Realm& realm)
: NativeFunction(realm.vm().names.FinalizationRegistry.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.FinalizationRegistry.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -21,7 +21,7 @@ namespace JS {
GC_DEFINE_ALLOCATOR(FunctionConstructor);
FunctionConstructor::FunctionConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Function.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.Function.as_fly_string(), realm.intrinsics().function_prototype())
{
}
@ -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

@ -59,7 +59,7 @@ void FunctionObject::set_function_name(Variant<PropertyKey, PrivateName> const&
// 4. If F has an [[InitialName]] internal slot, then
if (is<NativeFunction>(this)) {
// a. Set F.[[InitialName]] to name.
static_cast<NativeFunction&>(*this).set_initial_name({}, name);
static_cast<NativeFunction&>(*this).set_initial_name({}, MUST(FlyString::from_deprecated_fly_string(name)));
}
// 5. If prefix is present, then
@ -70,7 +70,7 @@ void FunctionObject::set_function_name(Variant<PropertyKey, PrivateName> const&
// b. If F has an [[InitialName]] internal slot, then
if (is<NativeFunction>(this)) {
// i. Optionally, set F.[[InitialName]] to name.
static_cast<NativeFunction&>(*this).set_initial_name({}, name);
static_cast<NativeFunction&>(*this).set_initial_name({}, MUST(FlyString::from_deprecated_fly_string(name)));
}
}

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);

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&);
@ -32,7 +32,7 @@ private:
// Totally unnecessary, but sadly still necessary.
// TODO: Get rid of the pointless name() method.
DeprecatedFlyString m_name { "FunctionPrototype" };
FlyString m_name { "FunctionPrototype"_fly_string };
};
}

View file

@ -18,7 +18,7 @@ GC_DEFINE_ALLOCATOR(CollatorConstructor);
// 10.1 The Intl.Collator Constructor, https://tc39.es/ecma402/#sec-the-intl-collator-constructor
CollatorConstructor::CollatorConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Collator.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.Collator.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -20,7 +20,7 @@ GC_DEFINE_ALLOCATOR(DateTimeFormatConstructor);
// 11.1 The Intl.DateTimeFormat Constructor, https://tc39.es/ecma402/#sec-intl-datetimeformat-constructor
DateTimeFormatConstructor::DateTimeFormatConstructor(Realm& realm)
: NativeFunction(realm.vm().names.DateTimeFormat.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.DateTimeFormat.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -19,7 +19,7 @@ GC_DEFINE_ALLOCATOR(DisplayNamesConstructor);
// 12.1 The Intl.DisplayNames Constructor, https://tc39.es/ecma402/#sec-intl-displaynames-constructor
DisplayNamesConstructor::DisplayNamesConstructor(Realm& realm)
: NativeFunction(realm.vm().names.DisplayNames.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.DisplayNames.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -19,7 +19,7 @@ GC_DEFINE_ALLOCATOR(DurationFormatConstructor);
// 1.2 The Intl.DurationFormat Constructor, https://tc39.es/proposal-intl-duration-format/#sec-intl-durationformat-constructor
DurationFormatConstructor::DurationFormatConstructor(Realm& realm)
: NativeFunction(realm.vm().names.DurationFormat.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.DurationFormat.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -18,7 +18,7 @@ GC_DEFINE_ALLOCATOR(ListFormatConstructor);
// 13.1 The Intl.ListFormat Constructor, https://tc39.es/ecma402/#sec-intl-listformat-constructor
ListFormatConstructor::ListFormatConstructor(Realm& realm)
: NativeFunction(realm.vm().names.ListFormat.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.ListFormat.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -220,7 +220,7 @@ static LocaleAndKeys apply_unicode_extension_to_tag(StringView tag, LocaleAndKey
// 14.1 The Intl.Locale Constructor, https://tc39.es/ecma402/#sec-intl-locale-constructor
LocaleConstructor::LocaleConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Locale.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.Locale.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -17,7 +17,7 @@ GC_DEFINE_ALLOCATOR(NumberFormatConstructor);
// 15.1 The Intl.NumberFormat Constructor, https://tc39.es/ecma402/#sec-intl-numberformat-constructor
NumberFormatConstructor::NumberFormatConstructor(Realm& realm)
: NativeFunction(realm.vm().names.NumberFormat.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.NumberFormat.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -19,7 +19,7 @@ GC_DEFINE_ALLOCATOR(PluralRulesConstructor);
// 16.1 The Intl.PluralRules Constructor, https://tc39.es/ecma402/#sec-intl-pluralrules-constructor
PluralRulesConstructor::PluralRulesConstructor(Realm& realm)
: NativeFunction(realm.vm().names.PluralRules.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.PluralRules.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -18,7 +18,7 @@ GC_DEFINE_ALLOCATOR(RelativeTimeFormatConstructor);
// 17.1 The Intl.RelativeTimeFormat Constructor, https://tc39.es/ecma402/#sec-intl-relativetimeformat-constructor
RelativeTimeFormatConstructor::RelativeTimeFormatConstructor(Realm& realm)
: NativeFunction(realm.vm().names.RelativeTimeFormat.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.RelativeTimeFormat.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -19,7 +19,7 @@ GC_DEFINE_ALLOCATOR(SegmenterConstructor);
// 18.1 The Intl.Segmenter Constructor, https://tc39.es/ecma402/#sec-intl-segmenter-constructor
SegmenterConstructor::SegmenterConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Segmenter.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.Segmenter.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -18,7 +18,7 @@ GC_DEFINE_ALLOCATOR(IteratorConstructor);
// 27.1.3.1 The Iterator Constructor, https://tc39.es/ecma262/#sec-iterator-constructor
IteratorConstructor::IteratorConstructor(Realm& realm)
: Base(realm.vm().names.Iterator.as_string(), realm.intrinsics().function_prototype())
: Base(realm.vm().names.Iterator.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -17,7 +17,7 @@ namespace JS {
GC_DEFINE_ALLOCATOR(MapConstructor);
MapConstructor::MapConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Map.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.Map.as_fly_string(), realm.intrinsics().function_prototype())
{
}

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, 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

@ -28,7 +28,7 @@ namespace JS {
GC_DEFINE_ALLOCATOR(NumberConstructor);
NumberConstructor::NumberConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Number.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.Number.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -20,7 +20,7 @@ namespace JS {
GC_DEFINE_ALLOCATOR(ObjectConstructor);
ObjectConstructor::ObjectConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Object.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.Object.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -219,7 +219,7 @@ static ThrowCompletionOr<Value> perform_promise_race(VM& vm, IteratorRecord& ite
}
PromiseConstructor::PromiseConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Promise.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.Promise.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -161,6 +161,11 @@ public:
return m_string;
}
FlyString as_fly_string() const
{
return MUST(FlyString::from_deprecated_fly_string(as_string()));
}
Symbol const* as_symbol() const
{
VERIFY(is_symbol());

View file

@ -41,7 +41,7 @@ static ThrowCompletionOr<ProxyObject*> proxy_create(VM& vm, Value target, Value
}
ProxyConstructor::ProxyConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Proxy.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.Proxy.as_fly_string(), realm.intrinsics().function_prototype())
{
}

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

@ -15,7 +15,7 @@ namespace JS {
GC_DEFINE_ALLOCATOR(RegExpConstructor);
RegExpConstructor::RegExpConstructor(Realm& realm)
: NativeFunction(realm.vm().names.RegExp.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.RegExp.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -16,7 +16,7 @@ namespace JS {
GC_DEFINE_ALLOCATOR(SetConstructor);
SetConstructor::SetConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Set.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.Set.as_fly_string(), realm.intrinsics().function_prototype())
{
}

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 {

View file

@ -15,7 +15,7 @@ GC_DEFINE_ALLOCATOR(ShadowRealmConstructor);
// 3.2 The ShadowRealm Constructor, https://tc39.es/proposal-shadowrealm/#sec-shadowrealm-constructor
ShadowRealmConstructor::ShadowRealmConstructor(Realm& realm)
: NativeFunction(realm.vm().names.ShadowRealm.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.ShadowRealm.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -17,7 +17,7 @@ namespace JS {
GC_DEFINE_ALLOCATOR(SharedArrayBufferConstructor);
SharedArrayBufferConstructor::SharedArrayBufferConstructor(Realm& realm)
: NativeFunction(realm.vm().names.SharedArrayBuffer.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.SharedArrayBuffer.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -21,7 +21,7 @@ namespace JS {
GC_DEFINE_ALLOCATOR(StringConstructor);
StringConstructor::StringConstructor(Realm& realm)
: NativeFunction(realm.vm().names.String.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.String.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -7,6 +7,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>
@ -73,6 +74,11 @@ public:
return m_string;
}
ALWAYS_INLINE FlyString as_fly_string() const
{
return MUST(FlyString::from_deprecated_fly_string(as_string()));
}
ALWAYS_INLINE Symbol const* as_symbol() const
{
VERIFY(is_symbol());

View file

@ -14,7 +14,7 @@ namespace JS {
GC_DEFINE_ALLOCATOR(SymbolConstructor);
SymbolConstructor::SymbolConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Symbol.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.Symbol.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -16,7 +16,7 @@ GC_DEFINE_ALLOCATOR(DurationConstructor);
// 7.1 The Temporal.Duration Constructor, https://tc39.es/proposal-temporal/#sec-temporal-duration-constructor
DurationConstructor::DurationConstructor(Realm& realm)
: NativeFunction(realm.vm().names.Duration.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.Duration.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -507,7 +507,7 @@ void TypedArrayBase::visit_edges(Visitor& visitor)
} \
\
ConstructorName::ConstructorName(Realm& realm, Object& prototype) \
: NativeFunction(realm.vm().names.ClassName.as_string(), prototype) \
: NativeFunction(realm.vm().names.ClassName.as_fly_string(), prototype) \
{ \
} \
\

View file

@ -13,13 +13,13 @@ namespace JS {
GC_DEFINE_ALLOCATOR(TypedArrayConstructor);
TypedArrayConstructor::TypedArrayConstructor(DeprecatedFlyString const& name, Object& prototype)
TypedArrayConstructor::TypedArrayConstructor(FlyString const& name, Object& prototype)
: NativeFunction(name, prototype)
{
}
TypedArrayConstructor::TypedArrayConstructor(Realm& realm)
: NativeFunction(realm.vm().names.TypedArray.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.TypedArray.as_fly_string(), realm.intrinsics().function_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

@ -16,7 +16,7 @@ namespace JS {
GC_DEFINE_ALLOCATOR(WeakMapConstructor);
WeakMapConstructor::WeakMapConstructor(Realm& realm)
: NativeFunction(realm.vm().names.WeakMap.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.WeakMap.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -15,7 +15,7 @@ namespace JS {
GC_DEFINE_ALLOCATOR(WeakRefConstructor);
WeakRefConstructor::WeakRefConstructor(Realm& realm)
: NativeFunction(realm.vm().names.WeakRef.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.WeakRef.as_fly_string(), realm.intrinsics().function_prototype())
{
}

View file

@ -16,7 +16,7 @@ namespace JS {
GC_DEFINE_ALLOCATOR(WeakSetConstructor);
WeakSetConstructor::WeakSetConstructor(Realm& realm)
: NativeFunction(realm.vm().names.WeakSet.as_string(), realm.intrinsics().function_prototype())
: NativeFunction(realm.vm().names.WeakSet.as_fly_string(), realm.intrinsics().function_prototype())
{
}

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; }

View file

@ -176,7 +176,7 @@ Result<GC::Ref<SourceTextModule>, Vector<ParserError>> SourceTextModule::parse(S
[&](ImportEntry const& import_entry) {
return import_entry.local_name == entry.local_or_import_name;
})
.is_end());
.is_end());
default_export = export_statement;
}
@ -497,9 +497,9 @@ ThrowCompletionOr<void> SourceTextModule::initialize_environment(VM& vm)
// 1. Let fo be InstantiateFunctionObject of d with arguments env and privateEnv.
// NOTE: Special case if the function is a default export of an anonymous function
// it has name "*default*" but internally should have name "default".
DeprecatedFlyString function_name = function_declaration.name();
FlyString function_name = MUST(FlyString::from_utf8(function_declaration.name()));
if (function_name == ExportStatement::local_name_for_default)
function_name = "default"sv;
function_name = "default"_fly_string;
auto function = ECMAScriptFunctionObject::create(realm(), function_name, function_declaration.source_text(), function_declaration.body(), function_declaration.parameters(), function_declaration.function_length(), function_declaration.local_variables_names(), environment, private_environment, function_declaration.kind(), function_declaration.is_strict_mode(),
function_declaration.parsing_insights());
@ -714,7 +714,7 @@ ThrowCompletionOr<void> SourceTextModule::execute_module(VM& vm, GC::Ptr<Promise
// c. Let result be the result of evaluating module.[[ECMAScriptCode]].
Completion result;
auto maybe_executable = Bytecode::compile(vm, m_ecmascript_code, FunctionKind::Normal, "ShadowRealmEval"sv);
auto maybe_executable = Bytecode::compile(vm, m_ecmascript_code, FunctionKind::Normal, "ShadowRealmEval"_fly_string);
if (maybe_executable.is_error())
result = maybe_executable.release_error();
else {
@ -768,7 +768,7 @@ ThrowCompletionOr<void> SourceTextModule::execute_module(VM& vm, GC::Ptr<Promise
parsing_insights.uses_this_from_environment = true;
parsing_insights.uses_this = true;
auto module_wrapper_function = ECMAScriptFunctionObject::create(
realm(), "module code with top-level await", StringView {}, this->m_ecmascript_code,
realm(), "module code with top-level await"_fly_string, StringView {}, this->m_ecmascript_code,
{}, 0, {}, environment(), nullptr, FunctionKind::Async, true, parsing_insights);
module_wrapper_function->set_is_module_wrapper(true);

View file

@ -6,6 +6,7 @@
#pragma once
#include <AK/FlyString.h>
#include <AK/Function.h>
#include <AK/HashMap.h>
#include <AK/HashTable.h>
@ -29,7 +30,7 @@ struct LinkError {
enum OtherErrors {
InvalidImportedModule,
};
Vector<ByteString> missing_imports;
Vector<FlyString> missing_imports;
Vector<OtherErrors> other_errors;
};
@ -276,7 +277,7 @@ using ExternValue = Variant<FunctionAddress, TableAddress, MemoryAddress, Global
class ExportInstance {
public:
explicit ExportInstance(ByteString name, ExternValue value)
explicit ExportInstance(FlyString name, ExternValue value)
: m_name(move(name))
, m_value(move(value))
{
@ -286,7 +287,7 @@ public:
auto& value() const { return m_value; }
private:
ByteString m_name;
FlyString m_name;
ExternValue m_value;
};
@ -361,7 +362,7 @@ private:
class HostFunction {
public:
explicit HostFunction(AK::Function<Result(Configuration&, Vector<Value>&)> function, FunctionType const& type, ByteString name)
explicit HostFunction(AK::Function<Result(Configuration&, Vector<Value>&)> function, FunctionType const& type, FlyString name)
: m_function(move(function))
, m_type(type)
, m_name(move(name))
@ -375,7 +376,7 @@ public:
private:
AK::Function<Result(Configuration&, Vector<Value>&)> m_function;
FunctionType m_type;
ByteString m_name;
FlyString m_name;
};
using FunctionInstance = Variant<WasmFunction, HostFunction>;
@ -654,8 +655,8 @@ private:
class Linker {
public:
struct Name {
ByteString module;
ByteString name;
FlyString module;
FlyString name;
ImportSection::Import::ImportDesc type;
};

View file

@ -88,14 +88,17 @@ static auto parse_vector(Stream& stream)
}
}
static ParseResult<ByteString> parse_name(Stream& stream)
static ParseResult<String> parse_name(Stream& stream)
{
ScopeLogger<WASM_BINPARSER_DEBUG> logger;
auto data = TRY(parse_vector<u8>(stream));
auto string = ByteString::copy(data);
auto string = StringView { data.span() };
if (!Utf8View(string).validate(Utf8View::AllowSurrogates::No))
return ParseError::InvalidUtf8;
return string;
auto string_or_error = String::from_utf8(string);
if (string_or_error.is_error())
return ParseError::OutOfMemory;
return string_or_error.value();
}
ParseResult<ValueType> ValueType::parse(Stream& stream)

View file

@ -9,6 +9,7 @@
#include <AK/Badge.h>
#include <AK/ByteString.h>
#include <AK/DistinctNumeric.h>
#include <AK/FlyString.h>
#include <AK/LEB128.h>
#include <AK/Result.h>
#include <AK/String.h>
@ -534,7 +535,7 @@ private:
class CustomSection {
public:
CustomSection(ByteString name, ByteBuffer contents)
CustomSection(FlyString name, ByteBuffer contents)
: m_name(move(name))
, m_contents(move(contents))
{
@ -546,7 +547,7 @@ public:
static ParseResult<CustomSection> parse(Stream& stream);
private:
ByteString m_name;
FlyString m_name;
ByteBuffer m_contents;
};
@ -572,7 +573,7 @@ public:
class Import {
public:
using ImportDesc = Variant<TypeIndex, TableType, MemoryType, GlobalType, FunctionType>;
Import(ByteString module, ByteString name, ImportDesc description)
Import(FlyString module, FlyString name, ImportDesc description)
: m_module(move(module))
, m_name(move(name))
, m_description(move(description))
@ -593,8 +594,8 @@ public:
return Import { module, name, result };
}
ByteString m_module;
ByteString m_name;
FlyString m_module;
FlyString m_name;
ImportDesc m_description;
};
@ -755,7 +756,7 @@ private:
public:
class Export {
public:
explicit Export(ByteString name, ExportDesc description)
explicit Export(FlyString name, ExportDesc description)
: m_name(move(name))
, m_description(move(description))
{
@ -767,7 +768,7 @@ public:
static ParseResult<Export> parse(Stream& stream);
private:
ByteString m_name;
FlyString m_name;
ExportDesc m_description;
};

View file

@ -939,7 +939,7 @@ ErrorOr<HostFunction> Implementation::function_by_name(StringView name)
#define IMPL(x) \
if (name_for_comparison == names.x) \
return invocation_of<&Implementation::impl$##x>(#x##sv);
return invocation_of<&Implementation::impl$##x>(#x##_fly_string);
ENUMERATE_FUNCTION_NAMES(IMPL)
@ -980,7 +980,7 @@ auto CompatibleValueType = IsOneOf<HostType<T>, char, i8, i16, i32, u8, u16>
template<typename RV, typename... Args, ErrorOr<RV> (Implementation::*impl)(Configuration&, Args...)>
struct InvocationOf<impl> {
HostFunction operator()(Implementation& self, StringView function_name)
HostFunction operator()(Implementation& self, FlyString const& function_name)
{
using R = typename decltype([] {
if constexpr (IsSame<RV, Result<void>>)

View file

@ -29,7 +29,7 @@ namespace Wasm::Wasi::ABI {
template<auto impl>
struct InvocationOf {
HostFunction operator()(Implementation&, StringView name);
HostFunction operator()(Implementation&, FlyString const& name);
};
template<typename T, size_t N>
@ -847,7 +847,7 @@ struct Implementation {
private:
template<auto impl>
HostFunction invocation_of(StringView name) { return ABI::InvocationOf<impl> {}(*this, name); }
HostFunction invocation_of(FlyString const& name) { return ABI::InvocationOf<impl> {}(*this, name); }
ErrorOr<Result<void>> impl$args_get(Configuration&, Pointer<Pointer<u8>> argv, Pointer<u8> argv_buf);
ErrorOr<Result<ArgsSizes>> impl$args_sizes_get(Configuration&);

View file

@ -4155,7 +4155,7 @@ void Document::start_intersection_observing_a_lazy_loading_element(Element& elem
// 2. If doc's lazy load intersection observer is null, set it to a new IntersectionObserver instance, initialized as follows:
if (!m_lazy_load_intersection_observer) {
// - The callback is these steps, with arguments entries and observer:
auto callback = JS::NativeFunction::create(realm, "", [this](JS::VM& vm) -> JS::ThrowCompletionOr<JS::Value> {
auto callback = JS::NativeFunction::create(realm, ""_fly_string, [this](JS::VM& vm) -> JS::ThrowCompletionOr<JS::Value> {
// For each entry in entries using a method of iteration which does not trigger developer-modifiable array accessors or iteration hooks:
auto& entries = verify_cast<JS::Array>(vm.argument(0).as_object());
auto entries_length = MUST(MUST(entries.get(vm.names.length)).to_length(vm));

View file

@ -481,7 +481,7 @@ WebIDL::CallbackType* EventTarget::get_current_value_of_event_handler(FlyString
// 6. Return scope. (NOTE: Not necessary)
auto function = JS::ECMAScriptFunctionObject::create(realm, name.to_deprecated_fly_string(), builder.to_byte_string(), program->body(), program->parameters(), program->function_length(), program->local_variables_names(), scope, nullptr, JS::FunctionKind::Normal, program->is_strict_mode(),
auto function = JS::ECMAScriptFunctionObject::create(realm, name, builder.to_byte_string(), program->body(), program->parameters(), program->function_length(), program->local_variables_names(), scope, nullptr, JS::FunctionKind::Normal, program->is_strict_mode(),
program->parsing_insights(), is_arrow_function);
// 10. Remove settings object's realm execution context from the JavaScript execution context stack.

View file

@ -222,7 +222,7 @@ JS::ThrowCompletionOr<NonnullOwnPtr<Wasm::ModuleInstance>> instantiate_module(JS
return Wasm::Result { move(wasm_values) };
},
type,
ByteString::formatted("func{}", resolved_imports.size()),
MUST(String::formatted("func{}", resolved_imports.size())),
};
auto address = cache.abstract_machine().store().allocate(move(host_function));
dbgln_if(LIBWEB_WASM_DEBUG, "Resolved to {}", address->value());
@ -323,7 +323,7 @@ JS::ThrowCompletionOr<NonnullRefPtr<CompiledWebAssemblyModule>> compile_a_webass
return compiled_module;
}
JS::NativeFunction* create_native_function(JS::VM& vm, Wasm::FunctionAddress address, ByteString const& name, Instance* instance)
JS::NativeFunction* create_native_function(JS::VM& vm, Wasm::FunctionAddress address, FlyString const& name, Instance* instance)
{
auto& realm = *vm.current_realm();
Optional<Wasm::FunctionType> type;
@ -471,9 +471,9 @@ JS::Value to_js_value(JS::VM& vm, Wasm::Value& wasm_value, Wasm::ValueType type)
auto& cache = get_cache(realm);
auto* function = cache.abstract_machine().store().get(address);
auto name = function->visit(
[&](Wasm::WasmFunction& wasm_function) {
[&](Wasm::WasmFunction& wasm_function) -> FlyString {
auto index = *wasm_function.module().functions().find_first_index(address);
return ByteString::formatted("func{}", index);
return MUST(String::formatted("func{}", index));
},
[](Wasm::HostFunction& host_function) {
return host_function.name();

View file

@ -66,7 +66,7 @@ WebAssemblyCache& get_cache(JS::Realm&);
JS::ThrowCompletionOr<NonnullOwnPtr<Wasm::ModuleInstance>> instantiate_module(JS::VM&, Wasm::Module const&, GC::Ptr<JS::Object> import_object);
JS::ThrowCompletionOr<NonnullRefPtr<CompiledWebAssemblyModule>> compile_a_webassembly_module(JS::VM&, ByteBuffer);
JS::NativeFunction* create_native_function(JS::VM&, Wasm::FunctionAddress address, ByteString const& name, Instance* instance = nullptr);
JS::NativeFunction* create_native_function(JS::VM&, Wasm::FunctionAddress address, FlyString const& name, Instance* instance = nullptr);
JS::ThrowCompletionOr<Wasm::Value> to_webassembly_value(JS::VM&, JS::Value value, Wasm::ValueType const& type);
Wasm::Value default_webassembly_value(JS::VM&, Wasm::ValueType type);
JS::Value to_js_value(JS::VM&, Wasm::Value& wasm_value, Wasm::ValueType type);

View file

@ -67,7 +67,7 @@ static JS::ThrowCompletionOr<JS::Value> execute_a_function_body(HTML::BrowsingCo
// The result of parsing global scope above.
// strict
// The result of parsing strict above.
auto function = JS::ECMAScriptFunctionObject::create(realm, "", move(source_text), function_expression->body(), function_expression->parameters(), function_expression->function_length(), function_expression->local_variables_names(), &global_scope, nullptr, function_expression->kind(), function_expression->is_strict_mode(), function_expression->parsing_insights());
auto function = JS::ECMAScriptFunctionObject::create(realm, ""_fly_string, move(source_text), function_expression->body(), function_expression->parameters(), function_expression->function_length(), function_expression->local_variables_names(), &global_scope, nullptr, function_expression->kind(), function_expression->is_strict_mode(), function_expression->parsing_insights());
// 9. Let completion be Function.[[Call]](window, parameters) with function as the this value.
// NOTE: This is not entirely clear, but I don't think they mean actually passing `function` as

View file

@ -4558,7 +4558,7 @@ namespace Web::Bindings {
GC_DEFINE_ALLOCATOR(@constructor_class@);
@constructor_class@::@constructor_class@(JS::Realm& realm)
: NativeFunction("@name@"sv, realm.intrinsics().function_prototype())
: NativeFunction("@name@"_fly_string, realm.intrinsics().function_prototype())
{
}

View file

@ -82,55 +82,55 @@ private:
{
Wasm::FunctionType print_type { {}, {} };
auto address_print = alloc_noop_function(print_type);
s_spec_test_namespace.set({ "spectest", "print", print_type }, Wasm::ExternValue { *address_print });
s_spec_test_namespace.set({ "spectest"_fly_string, "print"_fly_string, print_type }, Wasm::ExternValue { *address_print });
Wasm::FunctionType print_i32_type { { Wasm::ValueType(Wasm::ValueType::I32) }, {} };
auto address_i32 = alloc_noop_function(print_i32_type);
s_spec_test_namespace.set({ "spectest", "print_i32", print_i32_type }, Wasm::ExternValue { *address_i32 });
s_spec_test_namespace.set({ "spectest"_fly_string, "print_i32"_fly_string, print_i32_type }, Wasm::ExternValue { *address_i32 });
Wasm::FunctionType print_i64_type { { Wasm::ValueType(Wasm::ValueType::I64) }, {} };
auto address_i64 = alloc_noop_function(print_i64_type);
s_spec_test_namespace.set({ "spectest", "print_i64", print_i64_type }, Wasm::ExternValue { *address_i64 });
s_spec_test_namespace.set({ "spectest"_fly_string, "print_i64"_fly_string, print_i64_type }, Wasm::ExternValue { *address_i64 });
Wasm::FunctionType print_f32_type { { Wasm::ValueType(Wasm::ValueType::F32) }, {} };
auto address_f32 = alloc_noop_function(print_f32_type);
s_spec_test_namespace.set({ "spectest", "print_f32", print_f32_type }, Wasm::ExternValue { *address_f32 });
s_spec_test_namespace.set({ "spectest"_fly_string, "print_f32"_fly_string, print_f32_type }, Wasm::ExternValue { *address_f32 });
Wasm::FunctionType print_f64_type { { Wasm::ValueType(Wasm::ValueType::F64) }, {} };
auto address_f64 = alloc_noop_function(print_f64_type);
s_spec_test_namespace.set({ "spectest", "print_f64", print_f64_type }, Wasm::ExternValue { *address_f64 });
s_spec_test_namespace.set({ "spectest"_fly_string, "print_f64"_fly_string, print_f64_type }, Wasm::ExternValue { *address_f64 });
Wasm::FunctionType print_i32_f32_type { { Wasm::ValueType(Wasm::ValueType::I32), Wasm::ValueType(Wasm::ValueType::F32) }, {} };
auto address_i32_f32 = alloc_noop_function(print_i32_f32_type);
s_spec_test_namespace.set({ "spectest", "print_i32_f32", print_i32_f32_type }, Wasm::ExternValue { *address_i32_f32 });
s_spec_test_namespace.set({ "spectest"_fly_string, "print_i32_f32"_fly_string, print_i32_f32_type }, Wasm::ExternValue { *address_i32_f32 });
Wasm::FunctionType print_f64_f64_type { { Wasm::ValueType(Wasm::ValueType::F64), Wasm::ValueType(Wasm::ValueType::F64) }, {} };
auto address_f64_f64 = alloc_noop_function(print_f64_f64_type);
s_spec_test_namespace.set({ "spectest", "print_f64_f64", print_f64_f64_type }, Wasm::ExternValue { *address_f64_f64 });
s_spec_test_namespace.set({ "spectest"_fly_string, "print_f64_f64"_fly_string, print_f64_f64_type }, Wasm::ExternValue { *address_f64_f64 });
Wasm::TableType table_type { Wasm::ValueType(Wasm::ValueType::FunctionReference), Wasm::Limits(10, 20) };
auto table_address = m_machine.store().allocate(table_type);
s_spec_test_namespace.set({ "spectest", "table", table_type }, Wasm::ExternValue { *table_address });
s_spec_test_namespace.set({ "spectest"_fly_string, "table"_fly_string, table_type }, Wasm::ExternValue { *table_address });
Wasm::MemoryType memory_type { Wasm::Limits(1, 2) };
auto memory_address = m_machine.store().allocate(memory_type);
s_spec_test_namespace.set({ "spectest", "memory", memory_type }, Wasm::ExternValue { *memory_address });
s_spec_test_namespace.set({ "spectest"_fly_string, "memory"_fly_string, memory_type }, Wasm::ExternValue { *memory_address });
Wasm::GlobalType global_i32 { Wasm::ValueType(Wasm::ValueType::I32), false };
auto global_i32_address = m_machine.store().allocate(global_i32, Wasm::Value(666));
s_spec_test_namespace.set({ "spectest", "global_i32", global_i32 }, Wasm::ExternValue { *global_i32_address });
s_spec_test_namespace.set({ "spectest"_fly_string, "global_i32"_fly_string, global_i32 }, Wasm::ExternValue { *global_i32_address });
Wasm::GlobalType global_i64 { Wasm::ValueType(Wasm::ValueType::I64), false };
auto global_i64_address = m_machine.store().allocate(global_i64, Wasm::Value((i64)666));
s_spec_test_namespace.set({ "spectest", "global_i64", global_i64 }, Wasm::ExternValue { *global_i64_address });
s_spec_test_namespace.set({ "spectest"_fly_string, "global_i64"_fly_string, global_i64 }, Wasm::ExternValue { *global_i64_address });
Wasm::GlobalType global_f32 { Wasm::ValueType(Wasm::ValueType::F32), false };
auto global_f32_address = m_machine.store().allocate(global_f32, Wasm::Value(666.6f));
s_spec_test_namespace.set({ "spectest", "global_f32", global_f32 }, Wasm::ExternValue { *global_f32_address });
s_spec_test_namespace.set({ "spectest"_fly_string, "global_f32"_fly_string, global_f32 }, Wasm::ExternValue { *global_f32_address });
Wasm::GlobalType global_f64 { Wasm::ValueType(Wasm::ValueType::F64), false };
auto global_f64_address = m_machine.store().allocate(global_f64, Wasm::Value(666.6));
s_spec_test_namespace.set({ "spectest", "global_f64", global_f64 }, Wasm::ExternValue { *global_f64_address });
s_spec_test_namespace.set({ "spectest"_fly_string, "global_f64"_fly_string, global_f64 }, Wasm::ExternValue { *global_f64_address });
return s_spec_test_namespace;
}
@ -143,7 +143,7 @@ private:
return Wasm::Result { Vector<Wasm::Value> {} };
},
type,
"__TEST" });
"__TEST"_fly_string });
}
static HashMap<Wasm::Linker::Name, Wasm::ExternValue> s_spec_test_namespace;
@ -178,7 +178,7 @@ TESTJS_GLOBAL_FUNCTION(parse_webassembly_module, parseWebAssemblyModule)
auto& module_object = static_cast<WebAssemblyModule&>(value.as_object());
for (auto& entry : module_object.module_instance().exports()) {
// FIXME: Don't pretend that everything is a function
imports.set({ property.key.as_string(), entry.name(), Wasm::TypeIndex(0) }, entry.value());
imports.set({ property.key.as_fly_string(), entry.name(), Wasm::TypeIndex(0) }, entry.value());
}
}
}
@ -283,7 +283,7 @@ void WebAssemblyModule::initialize(JS::Realm& realm)
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyModule::get_export)
{
auto name = TRY(vm.argument(0).to_byte_string(vm));
auto name = TRY(vm.argument(0).to_string(vm));
auto this_value = vm.this_value();
auto object = TRY(this_value.to_object(vm));
if (!is<WebAssemblyModule>(*object))

View file

@ -523,7 +523,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
bool export_all_imports = false;
bool shell_mode = false;
bool wasi = false;
ByteString exported_function_to_execute;
String exported_function_to_execute;
Vector<ParsedValue> values_to_push;
Vector<ByteString> modules_to_link_in;
Vector<StringView> args_if_wasi;