1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-08 05:27:14 +09:00

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
parent fc744e3f3f
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

@ -63,7 +63,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;
@ -87,15 +87,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, FlyString given_name) const
{
auto& realm = *vm.current_realm();
if (given_name.is_empty())
given_name = "";
given_name = ""_fly_string;
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);
@ -117,10 +117,10 @@ Value FunctionExpression::instantiate_ordinary_function_expression(VM& vm, Depre
return closure;
}
Optional<ByteString> CallExpression::expression_string() const
Optional<String> CallExpression::expression_string() const
{
if (is<Identifier>(*m_callee))
return static_cast<Identifier const&>(*m_callee).string();
return static_cast<Identifier const&>(*m_callee).string().to_string();
if (is<MemberExpression>(*m_callee))
return static_cast<MemberExpression const&>(*m_callee).to_string_approximation();
@ -159,21 +159,20 @@ ThrowCompletionOr<ClassElement::ClassValue> ClassMethod::class_element_evaluatio
auto set_function_name = [&](ByteString prefix = "") {
auto name = property_key_or_private_name.visit(
[&](PropertyKey const& property_key) -> ByteString {
[&](PropertyKey const& property_key) -> String {
if (property_key.is_symbol()) {
auto description = property_key.as_symbol()->description();
if (!description.has_value() || description->is_empty())
return "";
return ByteString::formatted("[{}]", *description);
} else {
return property_key.to_string();
return ""_string;
return MUST(String::formatted("[{}]", *description));
}
return property_key.to_string();
},
[&](PrivateName const& private_name) -> ByteString {
return private_name.description;
[&](PrivateName const& private_name) -> String {
return private_name.description.to_string();
});
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>()) {
@ -230,11 +229,11 @@ ThrowCompletionOr<ClassElement::ClassValue> ClassField::class_element_evaluation
if (m_initializer) {
auto copy_initializer = m_initializer;
auto name = property_key_or_private_name.visit(
[&](PropertyKey const& property_key) -> ByteString {
[&](PropertyKey const& property_key) -> String {
return property_key.is_number() ? property_key.to_string() : property_key.to_string_or_symbol().to_display_string();
},
[&](PrivateName const& private_name) -> ByteString {
return private_name.description;
[&](PrivateName const& private_name) -> String {
return private_name.description.to_string();
});
// FIXME: A potential optimization is not creating the functions here since these are never directly accessible.
@ -242,7 +241,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"_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);
}
@ -254,19 +253,19 @@ ThrowCompletionOr<ClassElement::ClassValue> ClassField::class_element_evaluation
};
}
static Optional<DeprecatedFlyString> nullopt_or_private_identifier_description(Expression const& expression)
static Optional<FlyString> nullopt_or_private_identifier_description(Expression const& expression)
{
if (is<PrivateIdentifier>(expression))
return static_cast<PrivateIdentifier const&>(expression).string();
return {};
}
Optional<DeprecatedFlyString> ClassField::private_bound_identifier() const
Optional<FlyString> ClassField::private_bound_identifier() const
{
return nullopt_or_private_identifier_description(*m_key);
}
Optional<DeprecatedFlyString> ClassMethod::private_bound_identifier() const
Optional<FlyString> ClassMethod::private_bound_identifier() const
{
return nullopt_or_private_identifier_description(*m_key);
}
@ -289,7 +288,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, ""_string, 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);
@ -298,7 +297,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<FlyString> const& binding_name, FlyString const& class_name) const
{
auto& realm = *vm.current_realm();
@ -1209,16 +1208,16 @@ void MemberExpression::dump(int indent) const
m_property->dump(indent + 1);
}
ByteString MemberExpression::to_string_approximation() const
String MemberExpression::to_string_approximation() const
{
ByteString object_string = "<object>";
String object_string = "<object>"_string;
if (is<Identifier>(*m_object))
object_string = static_cast<Identifier const&>(*m_object).string();
object_string = static_cast<Identifier const&>(*m_object).string().to_string();
if (is_computed())
return ByteString::formatted("{}[<computed>]", object_string);
return MUST(String::formatted("{}[<computed>]", object_string));
if (is<PrivateIdentifier>(*m_property))
return ByteString::formatted("{}.{}", object_string, as<PrivateIdentifier>(*m_property).string());
return ByteString::formatted("{}.{}", object_string, as<Identifier>(*m_property).string());
return MUST(String::formatted("{}.{}", object_string, as<PrivateIdentifier>(*m_property).string()));
return MUST(String::formatted("{}.{}", object_string, as<Identifier>(*m_property).string()));
}
bool MemberExpression::ends_in_private_name() const
@ -1349,7 +1348,7 @@ void CatchClause::dump(int indent) const
{
print_indent(indent);
m_parameter.visit(
[&](DeprecatedFlyString const& parameter) {
[&](FlyString const& parameter) {
if (parameter.is_empty())
outln("CatchClause");
else
@ -1498,7 +1497,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)
{
@ -1516,7 +1515,7 @@ void ExportStatement::dump(int indent) const
print_indent(indent + 1);
outln("(ExportEntries)");
auto string_or_null = [](Optional<DeprecatedFlyString> const& string) -> ByteString {
auto string_or_null = [](Optional<FlyString> const& string) -> ByteString {
if (!string.has_value()) {
return "null";
}
@ -1564,7 +1563,7 @@ void ImportStatement::dump(int indent) const
}
}
bool ExportStatement::has_export(DeprecatedFlyString const& export_name) const
bool ExportStatement::has_export(FlyString const& export_name) const
{
return any_of(m_entries.begin(), m_entries.end(), [&](auto& entry) {
// Make sure that empty exported names does not overlap with anything
@ -1574,7 +1573,7 @@ bool ExportStatement::has_export(DeprecatedFlyString const& export_name) const
});
}
bool ImportStatement::has_bound_name(DeprecatedFlyString const& name) const
bool ImportStatement::has_bound_name(FlyString const& name) const
{
return any_of(m_entries.begin(), m_entries.end(), [&](auto& entry) {
return entry.local_name == name;
@ -1688,7 +1687,7 @@ ThrowCompletionOr<void> Program::global_declaration_instantiation(VM& vm, Global
Vector<FunctionDeclaration const&> functions_to_initialize;
// 7. Let declaredFunctionNames be a new empty List.
HashTable<DeprecatedFlyString> declared_function_names;
HashTable<FlyString> declared_function_names;
// 8. For each element d of varDeclarations, in reverse List order, do
@ -1723,7 +1722,7 @@ ThrowCompletionOr<void> Program::global_declaration_instantiation(VM& vm, Global
}));
// 9. Let declaredVarNames be a new empty List.
HashTable<DeprecatedFlyString> declared_var_names;
HashTable<FlyString> declared_var_names;
// 10. For each element d of varDeclarations, do
TRY(for_each_var_scoped_variable_declaration([&](Declaration const& declaration) {
@ -1853,7 +1852,7 @@ ThrowCompletionOr<void> Program::global_declaration_instantiation(VM& vm, Global
return {};
}
ModuleRequest::ModuleRequest(DeprecatedFlyString module_specifier_, Vector<ImportAttribute> attributes)
ModuleRequest::ModuleRequest(FlyString module_specifier_, Vector<ImportAttribute> attributes)
: module_specifier(move(module_specifier_))
, attributes(move(attributes))
{

View file

@ -9,7 +9,7 @@
#pragma once
#include <AK/ByteString.h>
#include <AK/DeprecatedFlyString.h>
#include <AK/FlyString.h>
#include <AK/OwnPtr.h>
#include <AK/RefPtr.h>
#include <AK/Variant.h>
@ -168,7 +168,7 @@ private:
// 14.13 Labelled Statements, https://tc39.es/ecma262/#sec-labelled-statements
class LabelledStatement final : public Statement {
public:
LabelledStatement(SourceRange source_range, DeprecatedFlyString label, NonnullRefPtr<Statement const> labelled_item)
LabelledStatement(SourceRange source_range, FlyString label, NonnullRefPtr<Statement const> labelled_item)
: Statement(move(source_range))
, m_label(move(label))
, m_labelled_item(move(labelled_item))
@ -177,16 +177,16 @@ public:
virtual void dump(int indent) const override;
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_bytecode(Bytecode::Generator&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const override;
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_labelled_evaluation(Bytecode::Generator&, Vector<DeprecatedFlyString> const&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const;
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_labelled_evaluation(Bytecode::Generator&, Vector<FlyString> const&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const;
DeprecatedFlyString const& label() const { return m_label; }
DeprecatedFlyString& label() { return m_label; }
FlyString const& label() const { return m_label; }
FlyString& label() { return m_label; }
NonnullRefPtr<Statement const> const& labelled_item() const { return m_labelled_item; }
private:
virtual bool is_labelled_statement() const final { return true; }
DeprecatedFlyString m_label;
FlyString m_label;
NonnullRefPtr<Statement const> m_labelled_item;
};
@ -194,18 +194,18 @@ class LabelableStatement : public Statement {
public:
using Statement::Statement;
Vector<DeprecatedFlyString> const& labels() const { return m_labels; }
virtual void add_label(DeprecatedFlyString string) { m_labels.append(move(string)); }
Vector<FlyString> const& labels() const { return m_labels; }
virtual void add_label(FlyString string) { m_labels.append(move(string)); }
protected:
Vector<DeprecatedFlyString> m_labels;
Vector<FlyString> m_labels;
};
class IterationStatement : public Statement {
public:
using Statement::Statement;
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_labelled_evaluation(Bytecode::Generator&, Vector<DeprecatedFlyString> const&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const;
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_labelled_evaluation(Bytecode::Generator&, Vector<FlyString> const&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const;
private:
virtual bool is_iteration_statement() const final { return true; }
@ -325,8 +325,8 @@ public:
ThrowCompletionOr<void> for_each_function_hoistable_with_annexB_extension(ThrowCompletionOrVoidCallback<FunctionDeclaration&>&& callback) const;
Vector<DeprecatedFlyString> const& local_variables_names() const { return m_local_variables_names; }
size_t add_local_variable(DeprecatedFlyString name)
Vector<FlyString> const& local_variables_names() const { return m_local_variables_names; }
size_t add_local_variable(FlyString name)
{
auto index = m_local_variables_names.size();
m_local_variables_names.append(move(name));
@ -348,15 +348,15 @@ private:
Vector<NonnullRefPtr<FunctionDeclaration const>> m_functions_hoistable_with_annexB_extension;
Vector<DeprecatedFlyString> m_local_variables_names;
Vector<FlyString> m_local_variables_names;
};
// ImportEntry Record, https://tc39.es/ecma262/#table-importentry-record-fields
struct ImportEntry {
Optional<DeprecatedFlyString> import_name; // [[ImportName]]: stored string if Optional is not empty, NAMESPACE-OBJECT otherwise
DeprecatedFlyString local_name; // [[LocalName]]
Optional<FlyString> import_name; // [[ImportName]]: stored string if Optional is not empty, NAMESPACE-OBJECT otherwise
FlyString local_name; // [[LocalName]]
ImportEntry(Optional<DeprecatedFlyString> import_name_, DeprecatedFlyString local_name_)
ImportEntry(Optional<FlyString> import_name_, FlyString local_name_)
: import_name(move(import_name_))
, local_name(move(local_name_))
{
@ -390,7 +390,7 @@ public:
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_bytecode(Bytecode::Generator&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const override;
bool has_bound_name(DeprecatedFlyString const& name) const;
bool has_bound_name(FlyString const& name) const;
Vector<ImportEntry> const& entries() const { return m_entries; }
ModuleRequest const& module_request() const { return m_module_request; }
@ -412,10 +412,10 @@ struct ExportEntry {
EmptyNamedExport,
} kind;
Optional<DeprecatedFlyString> export_name; // [[ExportName]]
Optional<DeprecatedFlyString> local_or_import_name; // Either [[ImportName]] or [[LocalName]]
Optional<FlyString> export_name; // [[ExportName]]
Optional<FlyString> local_or_import_name; // Either [[ImportName]] or [[LocalName]]
ExportEntry(Kind export_kind, Optional<DeprecatedFlyString> export_name_, Optional<DeprecatedFlyString> local_or_import_name_)
ExportEntry(Kind export_kind, Optional<FlyString> export_name_, Optional<FlyString> local_or_import_name_)
: kind(export_kind)
, export_name(move(export_name_))
, local_or_import_name(move(local_or_import_name_))
@ -427,7 +427,7 @@ struct ExportEntry {
return m_module_request != nullptr;
}
static ExportEntry indirect_export_entry(ModuleRequest const& module_request, Optional<DeprecatedFlyString> export_name, Optional<DeprecatedFlyString> import_name)
static ExportEntry indirect_export_entry(ModuleRequest const& module_request, Optional<FlyString> export_name, Optional<FlyString> import_name)
{
ExportEntry entry { Kind::NamedExport, move(export_name), move(import_name) };
entry.m_module_request = &module_request;
@ -445,7 +445,7 @@ private:
friend class ExportStatement;
public:
static ExportEntry named_export(DeprecatedFlyString export_name, DeprecatedFlyString local_name)
static ExportEntry named_export(FlyString export_name, FlyString local_name)
{
return ExportEntry { Kind::NamedExport, move(export_name), move(local_name) };
}
@ -455,7 +455,7 @@ public:
return ExportEntry { Kind::ModuleRequestAllButDefault, {}, {} };
}
static ExportEntry all_module_request(DeprecatedFlyString export_name)
static ExportEntry all_module_request(FlyString export_name)
{
return ExportEntry { Kind::ModuleRequestAll, move(export_name), {} };
}
@ -468,7 +468,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))
@ -487,7 +487,7 @@ public:
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_bytecode(Bytecode::Generator&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const override;
bool has_export(DeprecatedFlyString const& export_name) const;
bool has_export(FlyString const& export_name) const;
bool has_statement() const { return m_statement; }
Vector<ExportEntry> const& entries() const { return m_entries; }
@ -654,13 +654,13 @@ struct BindingPattern : RefCounted<BindingPattern> {
class Identifier final : public Expression {
public:
explicit Identifier(SourceRange source_range, DeprecatedFlyString string)
explicit Identifier(SourceRange source_range, FlyString string)
: Expression(move(source_range))
, m_string(move(string))
{
}
DeprecatedFlyString const& string() const { return m_string; }
FlyString const& string() const { return m_string; }
bool is_local() const { return m_local_variable_index.has_value(); }
size_t local_variable_index() const
@ -679,7 +679,7 @@ public:
private:
virtual bool is_identifier() const override { return true; }
DeprecatedFlyString m_string;
FlyString m_string;
Optional<size_t> m_local_variable_index;
bool m_is_global { false };
@ -701,13 +701,13 @@ struct FunctionParsingInsights {
class FunctionNode {
public:
StringView name() const { return m_name ? m_name->string().view() : ""sv; }
FlyString name() const { return m_name ? m_name->string() : ""_fly_string; }
RefPtr<Identifier const> name_identifier() const { return m_name; }
ByteString const& source_text() const { return m_source_text; }
Statement const& body() const { return *m_body; }
Vector<FunctionParameter> const& parameters() const { return m_parameters; }
i32 function_length() const { return m_function_length; }
Vector<DeprecatedFlyString> const& local_variables_names() const { return m_local_variables_names; }
Vector<FlyString> const& local_variables_names() const { return m_local_variables_names; }
bool is_strict_mode() const { return m_is_strict_mode; }
bool might_need_arguments_object() const { return m_parsing_insights.might_need_arguments_object; }
bool contains_direct_call_to_eval() const { return m_parsing_insights.contains_direct_call_to_eval; }
@ -717,12 +717,12 @@ 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&, FlyString given_name) const = 0;
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)
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<FlyString> local_variables_names)
: m_name(move(name))
, m_source_text(move(source_text))
, m_body(move(body))
@ -752,7 +752,7 @@ private:
bool m_is_arrow_function : 1 { false };
FunctionParsingInsights m_parsing_insights;
Vector<DeprecatedFlyString> m_local_variables_names;
Vector<FlyString> m_local_variables_names;
};
class FunctionDeclaration final
@ -761,7 +761,7 @@ class FunctionDeclaration final
public:
static bool must_have_name() { return true; }
FunctionDeclaration(SourceRange source_range, RefPtr<Identifier const> name, ByteString source_text, NonnullRefPtr<Statement const> body, Vector<FunctionParameter> parameters, i32 function_length, FunctionKind kind, bool is_strict_mode, FunctionParsingInsights insights, Vector<DeprecatedFlyString> local_variables_names)
FunctionDeclaration(SourceRange source_range, RefPtr<Identifier const> name, ByteString source_text, NonnullRefPtr<Statement const> body, Vector<FunctionParameter> parameters, i32 function_length, FunctionKind kind, bool is_strict_mode, FunctionParsingInsights insights, Vector<FlyString> local_variables_names)
: Declaration(move(source_range))
, FunctionNode(move(name), move(source_text), move(body), move(parameters), function_length, kind, is_strict_mode, insights, false, move(local_variables_names))
{
@ -777,7 +777,7 @@ 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&, FlyString) const override { VERIFY_NOT_REACHED(); }
virtual ~FunctionDeclaration() { }
@ -791,7 +791,7 @@ class FunctionExpression final
public:
static bool must_have_name() { return false; }
FunctionExpression(SourceRange source_range, RefPtr<Identifier const> name, ByteString source_text, NonnullRefPtr<Statement const> body, Vector<FunctionParameter> parameters, i32 function_length, FunctionKind kind, bool is_strict_mode, FunctionParsingInsights insights, Vector<DeprecatedFlyString> local_variables_names, bool is_arrow_function = false)
FunctionExpression(SourceRange source_range, RefPtr<Identifier const> name, ByteString source_text, NonnullRefPtr<Statement const> body, Vector<FunctionParameter> parameters, i32 function_length, FunctionKind kind, bool is_strict_mode, FunctionParsingInsights insights, Vector<FlyString> local_variables_names, bool is_arrow_function = false)
: Expression(move(source_range))
, FunctionNode(move(name), move(source_text), move(body), move(parameters), function_length, kind, is_strict_mode, insights, is_arrow_function, move(local_variables_names))
{
@ -804,7 +804,7 @@ 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&, FlyString given_name) const override;
virtual ~FunctionExpression() { }
@ -909,7 +909,7 @@ public:
virtual void dump(int indent) const override;
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_bytecode(Bytecode::Generator&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const override;
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_labelled_evaluation(Bytecode::Generator&, Vector<DeprecatedFlyString> const&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const override;
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_labelled_evaluation(Bytecode::Generator&, Vector<FlyString> const&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const override;
private:
NonnullRefPtr<Expression const> m_test;
@ -930,7 +930,7 @@ public:
virtual void dump(int indent) const override;
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_bytecode(Bytecode::Generator&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const override;
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_labelled_evaluation(Bytecode::Generator&, Vector<DeprecatedFlyString> const&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const override;
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_labelled_evaluation(Bytecode::Generator&, Vector<FlyString> const&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const override;
private:
NonnullRefPtr<Expression const> m_test;
@ -975,7 +975,7 @@ public:
virtual void dump(int indent) const override;
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_bytecode(Bytecode::Generator&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const override;
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_labelled_evaluation(Bytecode::Generator&, Vector<DeprecatedFlyString> const&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const override;
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_labelled_evaluation(Bytecode::Generator&, Vector<FlyString> const&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const override;
private:
RefPtr<ASTNode const> m_init;
@ -999,7 +999,7 @@ public:
Statement const& body() const { return *m_body; }
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_bytecode(Bytecode::Generator&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const override;
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_labelled_evaluation(Bytecode::Generator&, Vector<DeprecatedFlyString> const&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const override;
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_labelled_evaluation(Bytecode::Generator&, Vector<FlyString> const&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const override;
virtual void dump(int indent) const override;
private:
@ -1023,7 +1023,7 @@ public:
Statement const& body() const { return *m_body; }
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_bytecode(Bytecode::Generator&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const override;
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_labelled_evaluation(Bytecode::Generator&, Vector<DeprecatedFlyString> const&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const override;
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_labelled_evaluation(Bytecode::Generator&, Vector<FlyString> const&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const override;
virtual void dump(int indent) const override;
private:
@ -1043,7 +1043,7 @@ public:
}
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_bytecode(Bytecode::Generator&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const override;
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_labelled_evaluation(Bytecode::Generator&, Vector<DeprecatedFlyString> const&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const override;
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_labelled_evaluation(Bytecode::Generator&, Vector<FlyString> const&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const override;
virtual void dump(int indent) const override;
private:
@ -1228,7 +1228,7 @@ private:
class StringLiteral final : public Expression {
public:
explicit StringLiteral(SourceRange source_range, ByteString value)
explicit StringLiteral(SourceRange source_range, String value)
: Expression(move(source_range))
, m_value(move(value))
{
@ -1237,12 +1237,12 @@ public:
virtual void dump(int indent) const override;
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_bytecode(Bytecode::Generator&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const override;
ByteString const& value() const { return m_value; }
String const& value() const { return m_value; }
private:
virtual bool is_string_literal() const override { return true; }
ByteString m_value;
String m_value;
};
class NullLiteral final : public PrimitiveLiteral {
@ -1260,7 +1260,7 @@ public:
class RegExpLiteral final : public Expression {
public:
RegExpLiteral(SourceRange source_range, regex::Parser::Result parsed_regex, ByteString parsed_pattern, regex::RegexOptions<ECMAScriptFlags> parsed_flags, ByteString pattern, ByteString flags)
RegExpLiteral(SourceRange source_range, regex::Parser::Result parsed_regex, String parsed_pattern, regex::RegexOptions<ECMAScriptFlags> parsed_flags, String pattern, String flags)
: Expression(move(source_range))
, m_parsed_regex(move(parsed_regex))
, m_parsed_pattern(move(parsed_pattern))
@ -1274,35 +1274,35 @@ public:
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_bytecode(Bytecode::Generator&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const override;
regex::Parser::Result const& parsed_regex() const { return m_parsed_regex; }
ByteString const& parsed_pattern() const { return m_parsed_pattern; }
String const& parsed_pattern() const { return m_parsed_pattern; }
regex::RegexOptions<ECMAScriptFlags> const& parsed_flags() const { return m_parsed_flags; }
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; }
private:
regex::Parser::Result m_parsed_regex;
ByteString m_parsed_pattern;
String m_parsed_pattern;
regex::RegexOptions<ECMAScriptFlags> m_parsed_flags;
ByteString m_pattern;
ByteString m_flags;
String m_pattern;
String m_flags;
};
class PrivateIdentifier final : public Expression {
public:
explicit PrivateIdentifier(SourceRange source_range, DeprecatedFlyString string)
explicit PrivateIdentifier(SourceRange source_range, FlyString string)
: Expression(move(source_range))
, m_string(move(string))
{
}
DeprecatedFlyString const& string() const { return m_string; }
FlyString const& string() const { return m_string; }
virtual void dump(int indent) const override;
virtual bool is_private_identifier() const override { return true; }
private:
DeprecatedFlyString m_string;
FlyString m_string;
};
class ClassElement : public ASTNode {
@ -1326,7 +1326,7 @@ public:
using ClassValue = Variant<ClassFieldDefinition, Completion, PrivateElement>;
virtual ThrowCompletionOr<ClassValue> class_element_evaluation(VM&, Object& home_object, Value) const = 0;
virtual Optional<DeprecatedFlyString> private_bound_identifier() const { return {}; }
virtual Optional<FlyString> private_bound_identifier() const { return {}; }
private:
bool m_is_static { false };
@ -1354,7 +1354,7 @@ public:
virtual void dump(int indent) const override;
virtual ThrowCompletionOr<ClassValue> class_element_evaluation(VM&, Object& home_object, Value property_key) const override;
virtual Optional<DeprecatedFlyString> private_bound_identifier() const override;
virtual Optional<FlyString> private_bound_identifier() const override;
private:
virtual bool is_class_method() const override { return true; }
@ -1381,7 +1381,7 @@ public:
virtual void dump(int indent) const override;
virtual ThrowCompletionOr<ClassValue> class_element_evaluation(VM&, Object& home_object, Value property_key) const override;
virtual Optional<DeprecatedFlyString> private_bound_identifier() const override;
virtual Optional<FlyString> private_bound_identifier() const override;
private:
NonnullRefPtr<Expression const> m_key;
@ -1433,7 +1433,7 @@ public:
{
}
StringView name() const { return m_name ? m_name->string().view() : ""sv; }
FlyString name() const { return m_name ? m_name->string() : ""_fly_string; }
ByteString const& source_text() const { return m_source_text; }
RefPtr<FunctionExpression const> constructor() const { return m_constructor; }
@ -1444,7 +1444,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<FlyString> const& binding_name = {}, FlyString const& class_name = {}) const;
private:
virtual bool is_class_expression() const override { return true; }
@ -1473,7 +1473,7 @@ public:
virtual bool is_lexical_declaration() const override { return true; }
StringView name() const { return m_class_expression->name(); }
FlyString name() const { return m_class_expression->name(); }
private:
virtual bool is_class_declaration() const override { return true; }
@ -1487,7 +1487,7 @@ private:
// 10.2.1.3 Runtime Semantics: EvaluateBody, https://tc39.es/ecma262/#sec-runtime-semantics-evaluatebody
class ClassFieldInitializerStatement final : public Statement {
public:
ClassFieldInitializerStatement(SourceRange source_range, NonnullRefPtr<Expression const> expression, DeprecatedFlyString field_name)
ClassFieldInitializerStatement(SourceRange source_range, NonnullRefPtr<Expression const> expression, FlyString field_name)
: Statement(move(source_range))
, m_expression(move(expression))
, m_class_field_identifier_name(move(field_name))
@ -1499,7 +1499,7 @@ public:
private:
NonnullRefPtr<Expression const> m_expression;
DeprecatedFlyString m_class_field_identifier_name; // [[ClassFieldIdentifierName]]
FlyString m_class_field_identifier_name; // [[ClassFieldIdentifierName]]
};
class SpreadExpression final : public Expression {
@ -1575,7 +1575,7 @@ protected:
virtual bool is_call_expression() const override { return true; }
Optional<ByteString> expression_string() const;
Optional<String> expression_string() const;
NonnullRefPtr<Expression const> m_callee;
};
@ -1924,7 +1924,7 @@ public:
Expression const& object() const { return *m_object; }
Expression const& property() const { return *m_property; }
ByteString to_string_approximation() const;
[[nodiscard]] String to_string_approximation() const;
bool ends_in_private_name() const;
@ -2040,7 +2040,7 @@ private:
class CatchClause final : public ASTNode {
public:
CatchClause(SourceRange source_range, DeprecatedFlyString parameter, NonnullRefPtr<BlockStatement const> body)
CatchClause(SourceRange source_range, FlyString parameter, NonnullRefPtr<BlockStatement const> body)
: ASTNode(move(source_range))
, m_parameter(move(parameter))
, m_body(move(body))
@ -2060,7 +2060,7 @@ public:
virtual void dump(int indent) const override;
private:
Variant<DeprecatedFlyString, NonnullRefPtr<BindingPattern const>> m_parameter;
Variant<FlyString, NonnullRefPtr<BindingPattern const>> m_parameter;
NonnullRefPtr<BlockStatement const> m_body;
};
@ -2130,7 +2130,7 @@ public:
virtual void dump(int indent) const override;
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_bytecode(Bytecode::Generator&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const override;
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_labelled_evaluation(Bytecode::Generator&, Vector<DeprecatedFlyString> const&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const;
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_labelled_evaluation(Bytecode::Generator&, Vector<FlyString> const&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const;
void add_case(NonnullRefPtr<SwitchCase const> switch_case) { m_cases.append(move(switch_case)); }
@ -2141,22 +2141,22 @@ private:
class BreakStatement final : public Statement {
public:
BreakStatement(SourceRange source_range, Optional<DeprecatedFlyString> target_label)
BreakStatement(SourceRange source_range, Optional<FlyString> target_label)
: Statement(move(source_range))
, m_target_label(move(target_label))
{
}
Optional<DeprecatedFlyString> const& target_label() const { return m_target_label; }
Optional<FlyString> const& target_label() const { return m_target_label; }
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_bytecode(Bytecode::Generator&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const override;
private:
Optional<DeprecatedFlyString> m_target_label;
Optional<FlyString> m_target_label;
};
class ContinueStatement final : public Statement {
public:
ContinueStatement(SourceRange source_range, Optional<DeprecatedFlyString> target_label)
ContinueStatement(SourceRange source_range, Optional<FlyString> target_label)
: Statement(move(source_range))
, m_target_label(move(target_label))
{
@ -2164,10 +2164,10 @@ public:
virtual Bytecode::CodeGenerationErrorOr<Optional<Bytecode::ScopedOperand>> generate_bytecode(Bytecode::Generator&, Optional<Bytecode::ScopedOperand> preferred_dst = {}) const override;
Optional<DeprecatedFlyString> const& target_label() const { return m_target_label; }
Optional<FlyString> const& target_label() const { return m_target_label; }
private:
Optional<DeprecatedFlyString> m_target_label;
Optional<FlyString> m_target_label;
};
class DebuggerStatement final : public Statement {

View file

@ -788,7 +788,7 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> LabelledStatement::gene
// 14.13.4 Runtime Semantics: LabelledEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-labelledevaluation
// LabelledStatement : LabelIdentifier : LabelledItem
Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> LabelledStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector<DeprecatedFlyString> const& label_set, [[maybe_unused]] Optional<ScopedOperand> preferred_dst) const
Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> LabelledStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector<FlyString> const& label_set, [[maybe_unused]] Optional<ScopedOperand> preferred_dst) const
{
Bytecode::Generator::SourceLocationScope scope(generator, *this);
// Convert the m_labelled_item NNRP to a reference early so we don't have to do it every single time we want to use it.
@ -836,7 +836,7 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> LabelledStatement::gene
return stmt_result;
}
Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> IterationStatement::generate_labelled_evaluation(Bytecode::Generator&, Vector<DeprecatedFlyString> const&, [[maybe_unused]] Optional<ScopedOperand> preferred_dst) const
Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> IterationStatement::generate_labelled_evaluation(Bytecode::Generator&, Vector<FlyString> const&, [[maybe_unused]] Optional<ScopedOperand> preferred_dst) const
{
return Bytecode::CodeGenerationError {
this,
@ -850,7 +850,7 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> WhileStatement::generat
return generate_labelled_evaluation(generator, {});
}
Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> WhileStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector<DeprecatedFlyString> const& label_set, [[maybe_unused]] Optional<ScopedOperand> preferred_dst) const
Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> WhileStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector<FlyString> const& label_set, [[maybe_unused]] Optional<ScopedOperand> preferred_dst) const
{
Bytecode::Generator::SourceLocationScope scope(generator, *this);
// test
@ -902,7 +902,7 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> DoWhileStatement::gener
return generate_labelled_evaluation(generator, {});
}
Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> DoWhileStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector<DeprecatedFlyString> const& label_set, [[maybe_unused]] Optional<ScopedOperand> preferred_dst) const
Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> DoWhileStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector<FlyString> const& label_set, [[maybe_unused]] Optional<ScopedOperand> preferred_dst) const
{
Bytecode::Generator::SourceLocationScope scope(generator, *this);
// jump always (true) body
@ -960,7 +960,7 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> ForStatement::generate_
return generate_labelled_evaluation(generator, {});
}
Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> ForStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector<DeprecatedFlyString> const& label_set, [[maybe_unused]] Optional<ScopedOperand> preferred_dst) const
Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> ForStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector<FlyString> const& label_set, [[maybe_unused]] Optional<ScopedOperand> preferred_dst) const
{
Bytecode::Generator::SourceLocationScope scope(generator, *this);
// init
@ -1142,17 +1142,17 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> ObjectExpression::gener
if (is<StringLiteral>(property->key())) {
auto& string_literal = static_cast<StringLiteral const&>(property->key());
Bytecode::IdentifierTableIndex key_name = generator.intern_identifier(string_literal.value());
Bytecode::IdentifierTableIndex key_name = generator.intern_identifier(MUST(FlyString::from_utf8(string_literal.value().bytes())));
Optional<ScopedOperand> value;
if (property_kind == Bytecode::Op::PropertyKind::ProtoSetter) {
value = TRY(property->value().generate_bytecode(generator)).value();
} else {
ByteString identifier = string_literal.value();
auto identifier = string_literal.value();
if (property_kind == Bytecode::Op::PropertyKind::Getter)
identifier = ByteString::formatted("get {}", identifier);
identifier = MUST(String::formatted("get {}", identifier));
else if (property_kind == Bytecode::Op::PropertyKind::Setter)
identifier = ByteString::formatted("set {}", identifier);
identifier = MUST(String::formatted("set {}", identifier));
auto name = generator.intern_identifier(identifier);
value = TRY(generator.emit_named_evaluation_if_anonymous_function(property->value(), name)).value();
}
@ -1846,8 +1846,8 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> ReturnStatement::genera
auto received_completion_type = generator.allocate_register();
auto received_completion_value = generator.allocate_register();
auto type_identifier = generator.intern_identifier("type");
auto value_identifier = generator.intern_identifier("value");
auto type_identifier = generator.intern_identifier("type"_fly_string);
auto value_identifier = generator.intern_identifier("value"_fly_string);
return_value = generate_await(generator, *return_value, received_completion, received_completion_type, received_completion_value, type_identifier, value_identifier);
}
@ -1966,8 +1966,8 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> YieldExpression::genera
auto received_completion_type = generator.allocate_register();
auto received_completion_value = generator.allocate_register();
auto type_identifier = generator.intern_identifier("type");
auto value_identifier = generator.intern_identifier("value");
auto type_identifier = generator.intern_identifier("type"_fly_string);
auto value_identifier = generator.intern_identifier("value"_fly_string);
if (m_is_yield_from) {
// 15.5.5 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-generator-function-definitions-runtime-semantics-evaluation
@ -2102,7 +2102,7 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> YieldExpression::genera
// i. Let throw be ? GetMethod(iterator, "throw").
auto throw_method = generator.allocate_register();
generator.emit<Bytecode::Op::GetMethod>(throw_method, iterator, generator.intern_identifier("throw"));
generator.emit<Bytecode::Op::GetMethod>(throw_method, iterator, generator.intern_identifier("throw"_fly_string));
// ii. If throw is not undefined, then
auto& throw_method_is_defined_block = generator.make_block();
@ -2187,7 +2187,7 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> YieldExpression::genera
// ii. Let return be ? GetMethod(iterator, "return").
auto return_method = generator.allocate_register();
generator.emit<Bytecode::Op::GetMethod>(return_method, iterator, generator.intern_identifier("return"));
generator.emit<Bytecode::Op::GetMethod>(return_method, iterator, generator.intern_identifier("return"_fly_string));
// iii. If return is undefined, then
auto& return_is_undefined_block = generator.make_block();
@ -2542,7 +2542,7 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> TaggedTemplateLiteral::
generator.emit_with_extra_operand_slots<Bytecode::Op::NewArray>(raw_string_regs.size(), raw_strings_array, raw_string_regs);
}
generator.emit<Bytecode::Op::PutById>(strings_array, generator.intern_identifier("raw"), raw_strings_array, Bytecode::Op::PropertyKind::KeyValue, generator.next_property_lookup_cache());
generator.emit<Bytecode::Op::PutById>(strings_array, generator.intern_identifier("raw"_fly_string), raw_strings_array, Bytecode::Op::PropertyKind::KeyValue, generator.next_property_lookup_cache());
auto arguments = generator.allocate_register();
if (!argument_regs.is_empty())
@ -2661,7 +2661,7 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> TryStatement::generate_
bool did_create_variable_scope_for_catch_clause = false;
TRY(m_handler->parameter().visit(
[&](DeprecatedFlyString const& parameter) -> Bytecode::CodeGenerationErrorOr<void> {
[&](FlyString const& parameter) -> Bytecode::CodeGenerationErrorOr<void> {
if (!parameter.is_empty()) {
generator.begin_variable_scope();
did_create_variable_scope_for_catch_clause = true;
@ -2762,7 +2762,7 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> SwitchStatement::genera
return generate_labelled_evaluation(generator, {});
}
Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> SwitchStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector<DeprecatedFlyString> const& label_set, [[maybe_unused]] Optional<ScopedOperand> preferred_dst) const
Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> SwitchStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector<FlyString> const& label_set, [[maybe_unused]] Optional<ScopedOperand> preferred_dst) const
{
Bytecode::Generator::SourceLocationScope scope(generator, *this);
@ -2989,8 +2989,8 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> AwaitExpression::genera
generator.emit<Bytecode::Op::Mov>(received_completion, generator.accumulator());
auto type_identifier = generator.intern_identifier("type");
auto value_identifier = generator.intern_identifier("value");
auto type_identifier = generator.intern_identifier("type"_fly_string);
auto value_identifier = generator.intern_identifier("value"_fly_string);
return generate_await(generator, argument, received_completion, received_completion_type, received_completion_value, type_identifier, value_identifier);
}
@ -3144,7 +3144,7 @@ static Bytecode::CodeGenerationErrorOr<ForInOfHeadEvaluationResult> for_in_of_he
}
// 14.7.5.7 ForIn/OfBodyEvaluation ( lhs, stmt, iteratorRecord, iterationKind, lhsKind, labelSet [ , iteratorKind ] ), https://tc39.es/ecma262/#sec-runtime-semantics-forin-div-ofbodyevaluation-lhs-stmt-iterator-lhskind-labelset
static Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> for_in_of_body_evaluation(Bytecode::Generator& generator, ASTNode const& node, Variant<NonnullRefPtr<ASTNode const>, NonnullRefPtr<BindingPattern const>> const& lhs, ASTNode const& body, ForInOfHeadEvaluationResult const& head_result, Vector<DeprecatedFlyString> const& label_set, Bytecode::BasicBlock& loop_end, Bytecode::BasicBlock& loop_update, IteratorHint iterator_kind = IteratorHint::Sync, [[maybe_unused]] Optional<ScopedOperand> preferred_dst = {})
static Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> for_in_of_body_evaluation(Bytecode::Generator& generator, ASTNode const& node, Variant<NonnullRefPtr<ASTNode const>, NonnullRefPtr<BindingPattern const>> const& lhs, ASTNode const& body, ForInOfHeadEvaluationResult const& head_result, Vector<FlyString> const& label_set, Bytecode::BasicBlock& loop_end, Bytecode::BasicBlock& loop_update, IteratorHint iterator_kind = IteratorHint::Sync, [[maybe_unused]] Optional<ScopedOperand> preferred_dst = {})
{
// 1. If iteratorKind is not present, set iteratorKind to sync.
@ -3186,8 +3186,8 @@ static Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> for_in_of_body_e
auto received_completion_type = generator.allocate_register();
auto received_completion_value = generator.allocate_register();
auto type_identifier = generator.intern_identifier("type");
auto value_identifier = generator.intern_identifier("value");
auto type_identifier = generator.intern_identifier("type"_fly_string);
auto value_identifier = generator.intern_identifier("value"_fly_string);
generator.emit<Bytecode::Op::Mov>(received_completion, generator.accumulator());
auto new_result = generate_await(generator, next_result, received_completion, received_completion_type, received_completion_value, type_identifier, value_identifier);
@ -3377,7 +3377,7 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> ForInStatement::generat
}
// 14.7.5.5 Runtime Semantics: ForInOfLoopEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-forinofloopevaluation
Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> ForInStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector<DeprecatedFlyString> const& label_set, [[maybe_unused]] Optional<ScopedOperand> preferred_dst) const
Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> ForInStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector<FlyString> const& label_set, [[maybe_unused]] Optional<ScopedOperand> preferred_dst) const
{
auto& loop_end = generator.make_block();
auto& loop_update = generator.make_block();
@ -3393,7 +3393,7 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> ForOfStatement::generat
return generate_labelled_evaluation(generator, {});
}
Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> ForOfStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector<DeprecatedFlyString> const& label_set, [[maybe_unused]] Optional<ScopedOperand> preferred_dst) const
Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> ForOfStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector<FlyString> const& label_set, [[maybe_unused]] Optional<ScopedOperand> preferred_dst) const
{
auto& loop_end = generator.make_block();
auto& loop_update = generator.make_block();
@ -3409,7 +3409,7 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> ForAwaitOfStatement::ge
return generate_labelled_evaluation(generator, {});
}
Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> ForAwaitOfStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector<DeprecatedFlyString> const& label_set, [[maybe_unused]] Optional<ScopedOperand> preferred_dst) const
Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> ForAwaitOfStatement::generate_labelled_evaluation(Bytecode::Generator& generator, Vector<FlyString> const& label_set, [[maybe_unused]] Optional<ScopedOperand> preferred_dst) const
{
auto& loop_end = generator.make_block();
auto& loop_update = generator.make_block();
@ -3561,7 +3561,7 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> ExportStatement::genera
}
if (is<ClassExpression>(*m_statement)) {
auto value = TRY(generator.emit_named_evaluation_if_anonymous_function(static_cast<ClassExpression const&>(*m_statement), generator.intern_identifier("default"sv))).value();
auto value = TRY(generator.emit_named_evaluation_if_anonymous_function(static_cast<ClassExpression const&>(*m_statement), generator.intern_identifier("default"_fly_string))).value();
if (!static_cast<ClassExpression const&>(*m_statement).has_name()) {
generator.emit<Bytecode::Op::InitializeLexicalBinding>(
@ -3574,7 +3574,7 @@ Bytecode::CodeGenerationErrorOr<Optional<ScopedOperand>> ExportStatement::genera
// ExportDeclaration : export default AssignmentExpression ;
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();
auto value = TRY(generator.emit_named_evaluation_if_anonymous_function(static_cast<Expression const&>(*m_statement), generator.intern_identifier("default"_fly_string))).value();
generator.emit<Bytecode::Op::InitializeLexicalBinding>(
generator.intern_identifier(ExportStatement::local_name_for_default),
value);

View file

@ -6,7 +6,7 @@
#pragma once
#include <AK/DeprecatedFlyString.h>
#include <AK/FlyString.h>
#include <AK/HashMap.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/OwnPtr.h>
@ -60,7 +60,7 @@ public:
virtual ~Executable() override;
DeprecatedFlyString name;
FlyString name;
Vector<u8> bytecode;
Vector<PropertyLookupCache> property_lookup_caches;
Vector<GlobalVariableCache> global_variable_caches;
@ -85,15 +85,15 @@ public:
HashMap<size_t, SourceRecord> source_map;
Vector<DeprecatedFlyString> local_variable_names;
Vector<FlyString> local_variable_names;
size_t local_index_base { 0 };
Optional<IdentifierTableIndex> length_identifier;
ByteString const& get_string(StringTableIndex index) const { return string_table->get(index); }
DeprecatedFlyString const& get_identifier(IdentifierTableIndex index) const { return identifier_table->get(index); }
String const& get_string(StringTableIndex index) const { return string_table->get(index); }
FlyString const& get_identifier(IdentifierTableIndex index) const { return identifier_table->get(index); }
Optional<DeprecatedFlyString const&> get_identifier(Optional<IdentifierTableIndex> const& index) const
Optional<FlyString const&> get_identifier(Optional<IdentifierTableIndex> const& index) const
{
if (!index.has_value())
return {};

View file

@ -56,7 +56,7 @@ CodeGenerationErrorOr<void> Generator::emit_function_declaration_instantiation(E
if (function.m_arguments_object_needed) {
Optional<Operand> dst;
auto local_var_index = function.m_local_variables_names.find_first_index("arguments"sv);
auto local_var_index = function.m_local_variables_names.find_first_index("arguments"_fly_string);
if (local_var_index.has_value())
dst = local(local_var_index.value());
@ -219,7 +219,7 @@ CodeGenerationErrorOr<void> Generator::emit_function_declaration_instantiation(E
return {};
}
CodeGenerationErrorOr<GC::Ref<Executable>> Generator::compile(VM& vm, ASTNode const& node, FunctionKind enclosing_function_kind, GC::Ptr<ECMAScriptFunctionObject const> function, MustPropagateCompletion must_propagate_completion, Vector<DeprecatedFlyString> local_variable_names)
CodeGenerationErrorOr<GC::Ref<Executable>> Generator::compile(VM& vm, ASTNode const& node, FunctionKind enclosing_function_kind, GC::Ptr<ECMAScriptFunctionObject const> function, MustPropagateCompletion must_propagate_completion, Vector<FlyString> local_variable_names)
{
Generator generator(vm, function, must_propagate_completion);
@ -482,7 +482,7 @@ CodeGenerationErrorOr<GC::Ref<Executable>> Generator::compile(VM& vm, ASTNode co
CodeGenerationErrorOr<GC::Ref<Executable>> Generator::generate_from_ast_node(VM& vm, ASTNode const& node, FunctionKind enclosing_function_kind)
{
Vector<DeprecatedFlyString> local_variable_names;
Vector<FlyString> local_variable_names;
if (is<ScopeNode>(node))
local_variable_names = static_cast<ScopeNode const&>(node).local_variables_names();
return compile(vm, node, enclosing_function_kind, {}, MustPropagateCompletion::Yes, move(local_variable_names));
@ -588,7 +588,7 @@ void Generator::end_variable_scope()
}
}
void Generator::begin_continuable_scope(Label continue_target, Vector<DeprecatedFlyString> const& language_label_set)
void Generator::begin_continuable_scope(Label continue_target, Vector<FlyString> const& language_label_set)
{
m_continuable_scopes.append({ continue_target, language_label_set });
start_boundary(BlockBoundaryType::Continue);
@ -605,7 +605,7 @@ Label Generator::nearest_breakable_scope() const
return m_breakable_scopes.last().bytecode_target;
}
void Generator::begin_breakable_scope(Label breakable_target, Vector<DeprecatedFlyString> const& language_label_set)
void Generator::begin_breakable_scope(Label breakable_target, Vector<FlyString> const& language_label_set)
{
m_breakable_scopes.append({ breakable_target, language_label_set });
start_boundary(BlockBoundaryType::Break);
@ -902,21 +902,21 @@ void Generator::emit_set_variable(JS::Identifier const& identifier, ScopedOperan
}
}
static Optional<ByteString> expression_identifier(Expression const& expression)
static Optional<String> expression_identifier(Expression const& expression)
{
if (expression.is_identifier()) {
auto const& identifier = static_cast<Identifier const&>(expression);
return identifier.string();
return identifier.string().to_string();
}
if (expression.is_numeric_literal()) {
auto const& literal = static_cast<NumericLiteral const&>(expression);
return literal.value().to_string_without_side_effects().to_byte_string();
return literal.value().to_string_without_side_effects();
}
if (expression.is_string_literal()) {
auto const& literal = static_cast<StringLiteral const&>(expression);
return ByteString::formatted("'{}'", literal.value());
return MUST(String::formatted("'{}'", literal.value()));
}
if (expression.is_member_expression()) {
@ -933,7 +933,7 @@ static Optional<ByteString> expression_identifier(Expression const& expression)
builder.appendff(".{}", *identifer);
}
return builder.to_byte_string();
return builder.to_string_without_validation();
}
return {};
@ -996,7 +996,7 @@ void Generator::generate_scoped_jump(JumpType type)
VERIFY_NOT_REACHED();
}
void Generator::generate_labelled_jump(JumpType type, DeprecatedFlyString const& label)
void Generator::generate_labelled_jump(JumpType type, FlyString const& label)
{
TemporaryChange temp { m_current_unwind_context, m_current_unwind_context };
size_t current_boundary = m_boundaries.size();
@ -1047,7 +1047,7 @@ void Generator::generate_break()
generate_scoped_jump(JumpType::Break);
}
void Generator::generate_break(DeprecatedFlyString const& break_label)
void Generator::generate_break(FlyString const& break_label)
{
generate_labelled_jump(JumpType::Break, break_label);
}
@ -1057,7 +1057,7 @@ void Generator::generate_continue()
generate_scoped_jump(JumpType::Continue);
}
void Generator::generate_continue(DeprecatedFlyString const& continue_label)
void Generator::generate_continue(FlyString const& continue_label)
{
generate_labelled_jump(JumpType::Continue, continue_label);
}
@ -1121,12 +1121,12 @@ void Generator::emit_get_by_id_with_this(ScopedOperand dst, ScopedOperand base,
void Generator::emit_iterator_value(ScopedOperand dst, ScopedOperand result)
{
emit_get_by_id(dst, result, intern_identifier("value"sv));
emit_get_by_id(dst, result, intern_identifier("value"_fly_string));
}
void Generator::emit_iterator_complete(ScopedOperand dst, ScopedOperand result)
{
emit_get_by_id(dst, result, intern_identifier("done"sv));
emit_get_by_id(dst, result, intern_identifier("done"_fly_string));
}
bool Generator::is_local_initialized(u32 local_index) const

View file

@ -153,9 +153,9 @@ public:
CodeGenerationErrorOr<Optional<ScopedOperand>> emit_named_evaluation_if_anonymous_function(Expression const&, Optional<IdentifierTableIndex> lhs_name, Optional<ScopedOperand> preferred_dst = {});
void begin_continuable_scope(Label continue_target, Vector<DeprecatedFlyString> const& language_label_set);
void begin_continuable_scope(Label continue_target, Vector<FlyString> const& language_label_set);
void end_continuable_scope();
void begin_breakable_scope(Label breakable_target, Vector<DeprecatedFlyString> const& language_label_set);
void begin_breakable_scope(Label breakable_target, Vector<FlyString> const& language_label_set);
void end_breakable_scope();
[[nodiscard]] Label nearest_continuable_scope() const;
@ -188,7 +188,7 @@ public:
return m_current_basic_block->is_terminated();
}
StringTableIndex intern_string(ByteString string)
StringTableIndex intern_string(String string)
{
return m_string_table->insert(move(string));
}
@ -198,7 +198,7 @@ public:
return m_regex_table->insert(move(regex));
}
IdentifierTableIndex intern_identifier(DeprecatedFlyString string)
IdentifierTableIndex intern_identifier(FlyString string)
{
return m_identifier_table->insert(move(string));
}
@ -265,10 +265,10 @@ public:
bool must_enter_finalizer() const { return m_boundaries.contains_slow(BlockBoundaryType::ReturnToFinally); }
void generate_break();
void generate_break(DeprecatedFlyString const& break_label);
void generate_break(FlyString const& break_label);
void generate_continue();
void generate_continue(DeprecatedFlyString const& continue_label);
void generate_continue(FlyString const& continue_label);
template<typename OpType>
void emit_return(ScopedOperand value)
@ -343,14 +343,14 @@ public:
private:
VM& m_vm;
static CodeGenerationErrorOr<GC::Ref<Executable>> compile(VM&, ASTNode const&, FunctionKind, GC::Ptr<ECMAScriptFunctionObject const>, MustPropagateCompletion, Vector<DeprecatedFlyString> local_variable_names);
static CodeGenerationErrorOr<GC::Ref<Executable>> compile(VM&, ASTNode const&, FunctionKind, GC::Ptr<ECMAScriptFunctionObject const>, MustPropagateCompletion, Vector<FlyString> local_variable_names);
enum class JumpType {
Continue,
Break,
};
void generate_scoped_jump(JumpType);
void generate_labelled_jump(JumpType, DeprecatedFlyString const& label);
void generate_labelled_jump(JumpType, FlyString const& label);
Generator(VM&, GC::Ptr<ECMAScriptFunctionObject const>, MustPropagateCompletion);
~Generator() = default;
@ -362,7 +362,7 @@ private:
struct LabelableScope {
Label bytecode_target;
Vector<DeprecatedFlyString> language_label_set;
Vector<FlyString> language_label_set;
};
BasicBlock* m_current_basic_block { nullptr };

View file

@ -8,14 +8,14 @@
namespace JS::Bytecode {
IdentifierTableIndex IdentifierTable::insert(DeprecatedFlyString string)
IdentifierTableIndex IdentifierTable::insert(FlyString string)
{
m_identifiers.append(move(string));
VERIFY(m_identifiers.size() <= NumericLimits<u32>::max());
return { static_cast<u32>(m_identifiers.size() - 1) };
}
DeprecatedFlyString const& IdentifierTable::get(IdentifierTableIndex index) const
FlyString const& IdentifierTable::get(IdentifierTableIndex index) const
{
return m_identifiers[index.value];
}

View file

@ -6,8 +6,8 @@
#pragma once
#include <AK/DeprecatedFlyString.h>
#include <AK/DistinctNumeric.h>
#include <AK/FlyString.h>
#include <AK/Vector.h>
namespace JS::Bytecode {
@ -24,13 +24,13 @@ class IdentifierTable {
public:
IdentifierTable() = default;
IdentifierTableIndex insert(DeprecatedFlyString);
DeprecatedFlyString const& get(IdentifierTableIndex) const;
IdentifierTableIndex insert(FlyString);
FlyString const& get(IdentifierTableIndex) const;
void dump() const;
bool is_empty() const { return m_identifiers.is_empty(); }
private:
Vector<DeprecatedFlyString> m_identifiers;
Vector<FlyString> m_identifiers;
};
}

View file

@ -833,7 +833,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())
@ -1199,7 +1199,7 @@ inline ThrowCompletionOr<Value> get_global(Interpreter& interpreter, IdentifierT
return vm.throw_completion<ReferenceError>(ErrorType::UnknownIdentifier, identifier);
}
inline ThrowCompletionOr<void> put_by_property_key(VM& vm, Value base, Value this_value, Value value, Optional<DeprecatedFlyString const&> const& base_identifier, PropertyKey name, Op::PropertyKind kind, PropertyLookupCache* cache = nullptr)
inline ThrowCompletionOr<void> put_by_property_key(VM& vm, Value base, Value this_value, Value value, Optional<FlyString const&> const& base_identifier, PropertyKey name, Op::PropertyKind kind, PropertyLookupCache* cache = nullptr)
{
// Better error message than to_object would give
if (vm.in_strict_mode() && base.is_nullish())
@ -1219,14 +1219,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;
}
@ -1306,7 +1306,7 @@ inline Value new_function(VM& vm, FunctionNode const& function_node, Optional<Id
Value value;
if (!function_node.has_name()) {
DeprecatedFlyString name = {};
FlyString name;
if (lhs_name.has_value())
name = vm.bytecode_interpreter().current_executable().get_identifier(lhs_name.value());
value = function_node.instantiate_ordinary_function_expression(vm, name);
@ -1323,7 +1323,7 @@ inline Value new_function(VM& vm, FunctionNode const& function_node, Optional<Id
return value;
}
inline ThrowCompletionOr<void> put_by_value(VM& vm, Value base, Optional<DeprecatedFlyString const&> const& base_identifier, Value property_key_value, Value value, Op::PropertyKind kind)
inline ThrowCompletionOr<void> put_by_value(VM& vm, Value base, Optional<FlyString const&> const& base_identifier, Value property_key_value, Value value, Op::PropertyKind kind)
{
// OPTIMIZATION: Fast path for simple Int32 indexes in array-like objects.
if ((kind == Op::PropertyKind::KeyValue || kind == Op::PropertyKind::DirectKeyValue)
@ -1426,7 +1426,7 @@ struct CalleeAndThis {
Value this_value;
};
inline ThrowCompletionOr<CalleeAndThis> get_callee_and_this_from_environment(Bytecode::Interpreter& interpreter, DeprecatedFlyString const& name, EnvironmentCoordinate& cache)
inline ThrowCompletionOr<CalleeAndThis> get_callee_and_this_from_environment(Bytecode::Interpreter& interpreter, FlyString const& name, EnvironmentCoordinate& cache)
{
auto& vm = interpreter.vm();
@ -1472,14 +1472,14 @@ inline ThrowCompletionOr<CalleeAndThis> get_callee_and_this_from_environment(Byt
}
// 13.2.7.3 Runtime Semantics: Evaluation, https://tc39.es/ecma262/#sec-regular-expression-literals-runtime-semantics-evaluation
inline Value new_regexp(VM& vm, ParsedRegex const& parsed_regex, ByteString const& pattern, ByteString const& flags)
inline Value new_regexp(VM& vm, ParsedRegex const& parsed_regex, String const& pattern, String const& flags)
{
// 1. Let pattern be CodePointsToString(BodyText of RegularExpressionLiteral).
// 2. Let flags be CodePointsToString(FlagText of RegularExpressionLiteral).
// 3. Return ! RegExpCreate(pattern, flags).
auto& realm = *vm.current_realm();
Regex<ECMA262> regex(parsed_regex.regex, parsed_regex.pattern, parsed_regex.flags);
Regex<ECMA262> regex(parsed_regex.regex, parsed_regex.pattern.to_byte_string(), parsed_regex.flags);
// NOTE: We bypass RegExpCreate and subsequently RegExpAlloc as an optimization to use the already parsed values.
auto regexp_object = RegExpObject::create(realm, move(regex), pattern, flags);
// RegExpAlloc has these two steps from the 'Legacy RegExp features' proposal.
@ -1514,7 +1514,7 @@ inline GC::RootVector<Value> argument_list_evaluation(VM& vm, Value arguments)
return argument_values;
}
inline ThrowCompletionOr<void> create_variable(VM& vm, DeprecatedFlyString const& name, Op::EnvironmentMode mode, bool is_global, bool is_immutable, bool is_strict)
inline ThrowCompletionOr<void> create_variable(VM& vm, FlyString const& name, Op::EnvironmentMode mode, bool is_global, bool is_immutable, bool is_strict)
{
if (mode == Op::EnvironmentMode::Lexical) {
VERIFY(!is_global);
@ -1549,13 +1549,13 @@ inline ThrowCompletionOr<ECMAScriptFunctionObject*> new_class(VM& vm, Value supe
auto* class_environment = vm.lexical_environment();
vm.running_execution_context().lexical_environment = vm.running_execution_context().saved_lexical_environments.take_last();
Optional<DeprecatedFlyString> binding_name;
DeprecatedFlyString class_name;
Optional<FlyString> binding_name;
FlyString class_name;
if (!class_expression.has_name() && lhs_name.has_value()) {
class_name = interpreter.current_executable().get_identifier(lhs_name.value());
} else {
binding_name = name;
class_name = name.is_null() ? ""sv : name;
class_name = 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

@ -6,8 +6,8 @@
#pragma once
#include <AK/ByteString.h>
#include <AK/DistinctNumeric.h>
#include <AK/String.h>
#include <AK/Vector.h>
#include <LibRegex/RegexParser.h>
@ -17,7 +17,7 @@ AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL(size_t, RegexTableIndex, Comparison);
struct ParsedRegex {
regex::Parser::Result regex;
ByteString pattern;
String pattern;
regex::RegexOptions<ECMAScriptFlags> flags;
};

View file

@ -8,13 +8,13 @@
namespace JS::Bytecode {
StringTableIndex StringTable::insert(ByteString string)
StringTableIndex StringTable::insert(String string)
{
m_strings.append(move(string));
return m_strings.size() - 1;
}
ByteString const& StringTable::get(StringTableIndex index) const
String const& StringTable::get(StringTableIndex index) const
{
return m_strings[index.value()];
}

View file

@ -6,8 +6,8 @@
#pragma once
#include <AK/ByteString.h>
#include <AK/DistinctNumeric.h>
#include <AK/String.h>
#include <AK/Vector.h>
namespace JS::Bytecode {
@ -21,13 +21,13 @@ class StringTable {
public:
StringTable() = default;
StringTableIndex insert(ByteString);
ByteString const& get(StringTableIndex) const;
StringTableIndex insert(String);
String const& get(StringTableIndex) const;
void dump() const;
bool is_empty() const { return m_strings.is_empty(); }
private:
Vector<ByteString> m_strings;
Vector<String> m_strings;
};
}

View file

@ -172,7 +172,7 @@ static ThrowCompletionOr<GC::Ref<Object>> create_table_row(Realm& realm, Value r
// 2. Set `row["(index)"]` to `rowIndex`
{
auto key = PropertyKey { "(index)", PropertyKey::StringMayBeNumber::No };
auto key = PropertyKey { "(index)"_fly_string, PropertyKey::StringMayBeNumber::No };
TRY(row->set(key, row_index, Object::ShouldThrowExceptions::No));
add_column(key);

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

@ -16,7 +16,7 @@
namespace JS {
HashMap<DeprecatedFlyString, TokenType> Lexer::s_keywords;
HashMap<FlyString, TokenType> Lexer::s_keywords;
static constexpr TokenType parse_two_char_token(StringView view)
{
@ -231,46 +231,46 @@ Lexer::Lexer(StringView source, StringView filename, size_t line_number, size_t
, m_parsed_identifiers(adopt_ref(*new ParsedIdentifiers))
{
if (s_keywords.is_empty()) {
s_keywords.set("async", TokenType::Async);
s_keywords.set("await", TokenType::Await);
s_keywords.set("break", TokenType::Break);
s_keywords.set("case", TokenType::Case);
s_keywords.set("catch", TokenType::Catch);
s_keywords.set("class", TokenType::Class);
s_keywords.set("const", TokenType::Const);
s_keywords.set("continue", TokenType::Continue);
s_keywords.set("debugger", TokenType::Debugger);
s_keywords.set("default", TokenType::Default);
s_keywords.set("delete", TokenType::Delete);
s_keywords.set("do", TokenType::Do);
s_keywords.set("else", TokenType::Else);
s_keywords.set("enum", TokenType::Enum);
s_keywords.set("export", TokenType::Export);
s_keywords.set("extends", TokenType::Extends);
s_keywords.set("false", TokenType::BoolLiteral);
s_keywords.set("finally", TokenType::Finally);
s_keywords.set("for", TokenType::For);
s_keywords.set("function", TokenType::Function);
s_keywords.set("if", TokenType::If);
s_keywords.set("import", TokenType::Import);
s_keywords.set("in", TokenType::In);
s_keywords.set("instanceof", TokenType::Instanceof);
s_keywords.set("let", TokenType::Let);
s_keywords.set("new", TokenType::New);
s_keywords.set("null", TokenType::NullLiteral);
s_keywords.set("return", TokenType::Return);
s_keywords.set("super", TokenType::Super);
s_keywords.set("switch", TokenType::Switch);
s_keywords.set("this", TokenType::This);
s_keywords.set("throw", TokenType::Throw);
s_keywords.set("true", TokenType::BoolLiteral);
s_keywords.set("try", TokenType::Try);
s_keywords.set("typeof", TokenType::Typeof);
s_keywords.set("var", TokenType::Var);
s_keywords.set("void", TokenType::Void);
s_keywords.set("while", TokenType::While);
s_keywords.set("with", TokenType::With);
s_keywords.set("yield", TokenType::Yield);
s_keywords.set("async"_fly_string, TokenType::Async);
s_keywords.set("await"_fly_string, TokenType::Await);
s_keywords.set("break"_fly_string, TokenType::Break);
s_keywords.set("case"_fly_string, TokenType::Case);
s_keywords.set("catch"_fly_string, TokenType::Catch);
s_keywords.set("class"_fly_string, TokenType::Class);
s_keywords.set("const"_fly_string, TokenType::Const);
s_keywords.set("continue"_fly_string, TokenType::Continue);
s_keywords.set("debugger"_fly_string, TokenType::Debugger);
s_keywords.set("default"_fly_string, TokenType::Default);
s_keywords.set("delete"_fly_string, TokenType::Delete);
s_keywords.set("do"_fly_string, TokenType::Do);
s_keywords.set("else"_fly_string, TokenType::Else);
s_keywords.set("enum"_fly_string, TokenType::Enum);
s_keywords.set("export"_fly_string, TokenType::Export);
s_keywords.set("extends"_fly_string, TokenType::Extends);
s_keywords.set("false"_fly_string, TokenType::BoolLiteral);
s_keywords.set("finally"_fly_string, TokenType::Finally);
s_keywords.set("for"_fly_string, TokenType::For);
s_keywords.set("function"_fly_string, TokenType::Function);
s_keywords.set("if"_fly_string, TokenType::If);
s_keywords.set("import"_fly_string, TokenType::Import);
s_keywords.set("in"_fly_string, TokenType::In);
s_keywords.set("instanceof"_fly_string, TokenType::Instanceof);
s_keywords.set("let"_fly_string, TokenType::Let);
s_keywords.set("new"_fly_string, TokenType::New);
s_keywords.set("null"_fly_string, TokenType::NullLiteral);
s_keywords.set("return"_fly_string, TokenType::Return);
s_keywords.set("super"_fly_string, TokenType::Super);
s_keywords.set("switch"_fly_string, TokenType::Switch);
s_keywords.set("this"_fly_string, TokenType::This);
s_keywords.set("throw"_fly_string, TokenType::Throw);
s_keywords.set("true"_fly_string, TokenType::BoolLiteral);
s_keywords.set("try"_fly_string, TokenType::Try);
s_keywords.set("typeof"_fly_string, TokenType::Typeof);
s_keywords.set("var"_fly_string, TokenType::Var);
s_keywords.set("void"_fly_string, TokenType::Void);
s_keywords.set("while"_fly_string, TokenType::While);
s_keywords.set("with"_fly_string, TokenType::With);
s_keywords.set("yield"_fly_string, TokenType::Yield);
}
consume();
@ -699,7 +699,7 @@ Token Lexer::next()
// bunch of Invalid* tokens (bad numeric literals, unterminated comments etc.)
StringView token_message;
Optional<DeprecatedFlyString> identifier;
Optional<FlyString> identifier;
size_t identifier_length = 0;
if (m_current_token.type() == TokenType::RegexLiteral && !is_eof() && is_ascii_alpha(m_current_char) && !did_consume_whitespace_or_comments) {
@ -767,7 +767,7 @@ Token Lexer::next()
code_point = is_identifier_middle(identifier_length);
} while (code_point.has_value());
identifier = builder.string_view();
identifier = builder.to_string_without_validation();
token_type = TokenType::PrivateIdentifier;
m_parsed_identifiers->identifiers.set(*identifier);
@ -789,7 +789,7 @@ Token Lexer::next()
code_point = is_identifier_middle(identifier_length);
} while (code_point.has_value());
identifier = builder.string_view();
identifier = builder.to_string_without_validation();
m_parsed_identifiers->identifiers.set(*identifier);
auto it = s_keywords.find(identifier->hash(), [&](auto& entry) { return entry.key == identifier; });

View file

@ -80,12 +80,12 @@ private:
Optional<size_t> m_hit_invalid_unicode;
static HashMap<DeprecatedFlyString, TokenType> s_keywords;
static HashMap<FlyString, TokenType> s_keywords;
struct ParsedIdentifiers : public RefCounted<ParsedIdentifiers> {
// Resolved identifiers must be kept alive for the duration of the parsing stage, otherwise
// the only references to these strings are deleted by the Token destructor.
HashTable<DeprecatedFlyString> identifiers;
HashTable<FlyString> identifiers;
};
RefPtr<ParsedIdentifiers> m_parsed_identifiers;

View file

@ -101,7 +101,7 @@ void finish_loading_imported_module(ImportedModuleReferrer referrer, ModuleReque
// i. Append the Record { [[Specifier]]: specifier, [[Module]]: result.[[Value]] } to referrer.[[LoadedModules]].
loaded_modules.append(ModuleWithSpecifier {
.specifier = module_request.module_specifier,
.specifier = module_request.module_specifier.to_string(),
.module = GC::Ref<Module>(*module) });
}
}
@ -136,7 +136,7 @@ ThrowCompletionOr<Object*> Module::get_module_namespace(VM& vm)
auto exported_names = TRY(get_exported_names(vm));
// b. Let unambiguousNames be a new empty List.
Vector<DeprecatedFlyString> unambiguous_names;
Vector<FlyString> unambiguous_names;
// c. For each element name of exportedNames, do
for (auto& name : exported_names) {
@ -159,7 +159,7 @@ ThrowCompletionOr<Object*> Module::get_module_namespace(VM& vm)
}
// 10.4.6.12 ModuleNamespaceCreate ( module, exports ), https://tc39.es/ecma262/#sec-modulenamespacecreate
Object* Module::module_namespace_create(Vector<DeprecatedFlyString> unambiguous_names)
Object* Module::module_namespace_create(Vector<FlyString> unambiguous_names)
{
auto& realm = this->realm();

View file

@ -7,7 +7,7 @@
#pragma once
#include <AK/DeprecatedFlyString.h>
#include <AK/FlyString.h>
#include <LibGC/Ptr.h>
#include <LibJS/ModuleLoading.h>
#include <LibJS/Runtime/Environment.h>
@ -38,7 +38,7 @@ struct ResolvedBinding {
Type type { Null };
GC::Ptr<Module> module;
DeprecatedFlyString export_name;
FlyString export_name;
bool is_valid() const
{
@ -109,8 +109,8 @@ public:
virtual ThrowCompletionOr<void> link(VM& vm) = 0;
virtual ThrowCompletionOr<Promise*> evaluate(VM& vm) = 0;
virtual ThrowCompletionOr<Vector<DeprecatedFlyString>> get_exported_names(VM& vm, Vector<Module*> export_star_set = {}) = 0;
virtual ThrowCompletionOr<ResolvedBinding> resolve_export(VM& vm, DeprecatedFlyString const& export_name, Vector<ResolvedBinding> resolve_set = {}) = 0;
virtual ThrowCompletionOr<Vector<FlyString>> get_exported_names(VM& vm, Vector<Module*> export_star_set = {}) = 0;
virtual ThrowCompletionOr<ResolvedBinding> resolve_export(VM& vm, FlyString const& export_name, Vector<ResolvedBinding> resolve_set = {}) = 0;
virtual ThrowCompletionOr<u32> inner_module_linking(VM& vm, Vector<Module*>& stack, u32 index);
virtual ThrowCompletionOr<u32> inner_module_evaluation(VM& vm, Vector<Module*>& stack, u32 index);
@ -128,7 +128,7 @@ protected:
}
private:
Object* module_namespace_create(Vector<DeprecatedFlyString> unambiguous_names);
Object* module_namespace_create(Vector<FlyString> unambiguous_names);
// These handles are only safe as long as the VM they live in is valid.
// But evaluated modules SHOULD be stored in the VM so unless you intentionally

File diff suppressed because it is too large Load diff

View file

@ -243,7 +243,7 @@ private:
bool match(TokenType type) const;
bool done() const;
void expected(char const* what);
void syntax_error(ByteString const& message, Optional<Position> = {});
void syntax_error(String const& message, Optional<Position> = {});
Token consume();
Token consume_and_allow_division();
Token consume_identifier();
@ -260,7 +260,7 @@ private:
Token next_token(size_t steps = 1) const;
void check_identifier_name_for_assignment_validity(DeprecatedFlyString const&, bool force_strict = false);
void check_identifier_name_for_assignment_validity(FlyString const&, bool force_strict = false);
bool try_parse_arrow_function_expression_failed_at_position(Position const&) const;
void set_try_parse_arrow_function_expression_failed_at_position(Position const&, bool);
@ -270,7 +270,7 @@ private:
bool parse_directive(ScopeNode& body);
void parse_statement_list(ScopeNode& output_node, AllowLabelledFunction allow_labelled_functions = AllowLabelledFunction::No);
DeprecatedFlyString consume_string_value();
FlyString consume_string_value();
ModuleRequest parse_module_request();
struct RulePosition {
@ -308,9 +308,9 @@ private:
Vector<ParserError> errors;
ScopePusher* current_scope_pusher { nullptr };
HashMap<StringView, Optional<Position>> labels_in_scope;
HashMap<FlyString, Optional<Position>> labels_in_scope;
HashMap<size_t, Position> invalid_property_range_in_object_expression;
HashTable<StringView>* referenced_private_names { nullptr };
HashTable<FlyString>* referenced_private_names { nullptr };
bool strict_mode { false };
bool allow_super_property_lookup { false };
@ -333,7 +333,7 @@ private:
ParserState(Lexer, Program::Type);
};
[[nodiscard]] NonnullRefPtr<Identifier const> create_identifier_and_register_in_current_scope(SourceRange range, DeprecatedFlyString string, Optional<DeclarationKind> = {});
[[nodiscard]] NonnullRefPtr<Identifier const> create_identifier_and_register_in_current_scope(SourceRange range, FlyString string, Optional<DeclarationKind> = {});
NonnullRefPtr<SourceCode const> m_source_code;
Vector<Position> m_rule_starts;

View file

@ -15,14 +15,14 @@ namespace JS {
String ParserError::to_string() const
{
if (!position.has_value())
return MUST(String::from_byte_string(message));
return message;
return MUST(String::formatted("{} (line: {}, column: {})", message, position.value().line, position.value().column));
}
ByteString ParserError::to_byte_string() const
{
if (!position.has_value())
return message;
return message.to_byte_string();
return ByteString::formatted("{} (line: {}, column: {})", message, position.value().line, position.value().column);
}

View file

@ -16,7 +16,7 @@
namespace JS {
struct ParserError {
ByteString message;
String message;
Optional<Position> position;
String to_string() const;

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

View file

@ -261,7 +261,7 @@ Result<GC::Ref<SourceTextModule>, Vector<ParserError>> SourceTextModule::parse(S
}
// 16.2.1.6.2 GetExportedNames ( [ exportStarSet ] ), https://tc39.es/ecma262/#sec-getexportednames
ThrowCompletionOr<Vector<DeprecatedFlyString>> SourceTextModule::get_exported_names(VM& vm, Vector<Module*> export_star_set)
ThrowCompletionOr<Vector<FlyString>> SourceTextModule::get_exported_names(VM& vm, Vector<Module*> export_star_set)
{
dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] get_export_names of {}", filename());
// 1. Assert: module.[[Status]] is not new.
@ -276,14 +276,14 @@ ThrowCompletionOr<Vector<DeprecatedFlyString>> SourceTextModule::get_exported_na
// FIXME: How do we check that?
// b. Return a new empty List.
return Vector<DeprecatedFlyString> {};
return Vector<FlyString> {};
}
// 4. Append module to exportStarSet.
export_star_set.append(this);
// 5. Let exportedNames be a new empty List.
Vector<DeprecatedFlyString> exported_names;
Vector<FlyString> exported_names;
// 6. For each ExportEntry Record e of module.[[LocalExportEntries]], do
for (auto& entry : m_local_export_entries) {
@ -443,7 +443,7 @@ ThrowCompletionOr<void> SourceTextModule::initialize_environment(VM& vm)
// Note: We just loop through them in step 21.
// 20. Let declaredVarNames be a new empty List.
Vector<DeprecatedFlyString> declared_var_names;
Vector<FlyString> declared_var_names;
// 21. For each element d of varDeclarations, do
// a. For each element dn of the BoundNames of d, do
@ -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 = 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());
@ -537,7 +537,7 @@ ThrowCompletionOr<void> SourceTextModule::initialize_environment(VM& vm)
}
// 16.2.1.6.3 ResolveExport ( exportName [ , resolveSet ] ), https://tc39.es/ecma262/#sec-resolveexport
ThrowCompletionOr<ResolvedBinding> SourceTextModule::resolve_export(VM& vm, DeprecatedFlyString const& export_name, Vector<ResolvedBinding> resolve_set)
ThrowCompletionOr<ResolvedBinding> SourceTextModule::resolve_export(VM& vm, FlyString const& export_name, Vector<ResolvedBinding> resolve_set)
{
// 1. Assert: module.[[Status]] is not new.
VERIFY(m_status != ModuleStatus::New);
@ -716,7 +716,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 {
@ -769,7 +769,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

@ -25,8 +25,8 @@ public:
Program const& parse_node() const { return *m_ecmascript_code; }
virtual ThrowCompletionOr<Vector<DeprecatedFlyString>> get_exported_names(VM& vm, Vector<Module*> export_star_set) override;
virtual ThrowCompletionOr<ResolvedBinding> resolve_export(VM& vm, DeprecatedFlyString const& export_name, Vector<ResolvedBinding> resolve_set = {}) override;
virtual ThrowCompletionOr<Vector<FlyString>> get_exported_names(VM& vm, Vector<Module*> export_star_set) override;
virtual ThrowCompletionOr<ResolvedBinding> resolve_export(VM& vm, FlyString const& export_name, Vector<ResolvedBinding> resolve_set = {}) override;
Object* import_meta() { return m_import_meta; }
void set_import_meta(Badge<VM>, Object* import_meta) { m_import_meta = import_meta; }

View file

@ -18,7 +18,7 @@ namespace JS {
GC_DEFINE_ALLOCATOR(SyntheticModule);
// 1.2.1 CreateSyntheticModule ( exportNames, evaluationSteps, realm, hostDefined ), https://tc39.es/proposal-json-modules/#sec-createsyntheticmodule
SyntheticModule::SyntheticModule(Vector<DeprecatedFlyString> export_names, SyntheticModule::EvaluationFunction evaluation_steps, Realm& realm, StringView filename)
SyntheticModule::SyntheticModule(Vector<FlyString> export_names, SyntheticModule::EvaluationFunction evaluation_steps, Realm& realm, StringView filename)
: Module(realm, filename)
, m_export_names(move(export_names))
, m_evaluation_steps(move(evaluation_steps))
@ -27,14 +27,14 @@ SyntheticModule::SyntheticModule(Vector<DeprecatedFlyString> export_names, Synth
}
// 1.2.3.1 GetExportedNames( exportStarSet ), https://tc39.es/proposal-json-modules/#sec-smr-getexportednames
ThrowCompletionOr<Vector<DeprecatedFlyString>> SyntheticModule::get_exported_names(VM&, Vector<Module*>)
ThrowCompletionOr<Vector<FlyString>> SyntheticModule::get_exported_names(VM&, Vector<Module*>)
{
// 1. Return module.[[ExportNames]].
return m_export_names;
}
// 1.2.3.2 ResolveExport( exportName, resolveSet ), https://tc39.es/proposal-json-modules/#sec-smr-resolveexport
ThrowCompletionOr<ResolvedBinding> SyntheticModule::resolve_export(VM&, DeprecatedFlyString const& export_name, Vector<ResolvedBinding>)
ThrowCompletionOr<ResolvedBinding> SyntheticModule::resolve_export(VM&, FlyString const& export_name, Vector<ResolvedBinding>)
{
// 1. If module.[[ExportNames]] does not contain exportName, return null.
if (!m_export_names.contains_slow(export_name))
@ -123,7 +123,7 @@ ThrowCompletionOr<Promise*> SyntheticModule::evaluate(VM& vm)
}
// 1.2.2 SetSyntheticModuleExport ( module, exportName, exportValue ), https://tc39.es/proposal-json-modules/#sec-setsyntheticmoduleexport
ThrowCompletionOr<void> SyntheticModule::set_synthetic_module_export(DeprecatedFlyString const& export_name, Value export_value)
ThrowCompletionOr<void> SyntheticModule::set_synthetic_module_export(FlyString const& export_name, Value export_value)
{
auto& vm = this->realm().vm();
@ -139,11 +139,11 @@ GC::Ref<SyntheticModule> SyntheticModule::create_default_export_synthetic_module
// 1. Let closure be the a Abstract Closure with parameters (module) that captures defaultExport and performs the following steps when called:
auto closure = [default_export = make_root(default_export)](SyntheticModule& module) -> ThrowCompletionOr<void> {
// a. Return ? module.SetSyntheticExport("default", defaultExport).
return module.set_synthetic_module_export("default", default_export.value());
return module.set_synthetic_module_export("default"_fly_string, default_export.value());
};
// 2. Return CreateSyntheticModule("default", closure, realm)
return realm.heap().allocate<SyntheticModule>(Vector<DeprecatedFlyString> { "default" }, move(closure), realm, filename);
return realm.heap().allocate<SyntheticModule>(Vector<FlyString> { "default"_fly_string }, move(closure), realm, filename);
}
// 1.4 ParseJSONModule ( source ), https://tc39.es/proposal-json-modules/#sec-parse-json-module

View file

@ -20,19 +20,19 @@ public:
static GC::Ref<SyntheticModule> create_default_export_synthetic_module(Value default_export, Realm& realm, StringView filename);
ThrowCompletionOr<void> set_synthetic_module_export(DeprecatedFlyString const& export_name, Value export_value);
ThrowCompletionOr<void> set_synthetic_module_export(FlyString const& export_name, Value export_value);
virtual ThrowCompletionOr<void> link(VM& vm) override;
virtual ThrowCompletionOr<Promise*> evaluate(VM& vm) override;
virtual ThrowCompletionOr<Vector<DeprecatedFlyString>> get_exported_names(VM& vm, Vector<Module*> export_star_set) override;
virtual ThrowCompletionOr<ResolvedBinding> resolve_export(VM& vm, DeprecatedFlyString const& export_name, Vector<ResolvedBinding> resolve_set) override;
virtual ThrowCompletionOr<Vector<FlyString>> get_exported_names(VM& vm, Vector<Module*> export_star_set) override;
virtual ThrowCompletionOr<ResolvedBinding> resolve_export(VM& vm, FlyString const& export_name, Vector<ResolvedBinding> resolve_set) override;
virtual PromiseCapability& load_requested_modules(GC::Ptr<GraphLoadingState::HostDefined>) override;
private:
SyntheticModule(Vector<DeprecatedFlyString> export_names, EvaluationFunction evaluation_steps, Realm& realm, StringView filename);
SyntheticModule(Vector<FlyString> export_names, EvaluationFunction evaluation_steps, Realm& realm, StringView filename);
Vector<DeprecatedFlyString> m_export_names; // [[ExportNames]]
EvaluationFunction m_evaluation_steps; // [[EvaluationSteps]]
Vector<FlyString> m_export_names; // [[ExportNames]]
EvaluationFunction m_evaluation_steps; // [[EvaluationSteps]]
};
ThrowCompletionOr<GC::Ref<Module>> parse_json_module(StringView source_text, Realm& realm, StringView filename);

View file

@ -6,7 +6,7 @@
#pragma once
#include <AK/DeprecatedFlyString.h>
#include <AK/FlyString.h>
#include <AK/String.h>
#include <AK/StringView.h>
#include <AK/Variant.h>
@ -208,16 +208,16 @@ public:
{
return m_value.visit(
[](StringView view) { return view; },
[](DeprecatedFlyString const& identifier) { return identifier.view(); },
[](FlyString const& identifier) { return identifier.bytes_as_string_view(); },
[](Empty) -> StringView { VERIFY_NOT_REACHED(); });
}
DeprecatedFlyString DeprecatedFlyString_value() const
FlyString fly_string_value() const
{
return m_value.visit(
[](StringView view) -> DeprecatedFlyString { return view; },
[](DeprecatedFlyString const& identifier) -> DeprecatedFlyString { return identifier; },
[](Empty) -> DeprecatedFlyString { VERIFY_NOT_REACHED(); });
[](StringView view) -> FlyString { return MUST(FlyString::from_utf8(view)); },
[](FlyString const& identifier) -> FlyString { return identifier; },
[](Empty) -> FlyString { VERIFY_NOT_REACHED(); });
}
size_t line_number() const { return m_line_number; }
@ -236,7 +236,7 @@ public:
ByteString string_value(StringValueStatus& status) const;
ByteString raw_template_value() const;
void set_identifier_value(DeprecatedFlyString value)
void set_identifier_value(FlyString value)
{
m_value = move(value);
}
@ -249,7 +249,7 @@ private:
StringView m_message;
StringView m_trivia;
StringView m_original_value;
Variant<Empty, StringView, DeprecatedFlyString> m_value {};
Variant<Empty, StringView, FlyString> m_value {};
size_t m_line_number { 0 };
size_t m_line_column { 0 };
size_t m_offset { 0 };

View file

@ -12,7 +12,7 @@
#include <AK/ByteString.h>
#include <AK/COWVector.h>
#include <AK/DeprecatedFlyString.h>
#include <AK/FlyString.h>
#include <AK/MemMem.h>
#include <AK/RedBlackTree.h>
#include <AK/StringBuilder.h>
@ -476,7 +476,7 @@ private:
class Match final {
private:
Optional<DeprecatedFlyString> string;
Optional<FlyString> string;
public:
Match() = default;
@ -491,9 +491,9 @@ public:
{
}
Match(ByteString string_, size_t const line_, size_t const column_, size_t const global_offset_)
Match(String string_, size_t const line_, size_t const column_, size_t const global_offset_)
: string(move(string_))
, view(string.value().view())
, view(string.value().bytes_as_string_view())
, line(line_)
, column(column_)
, global_offset(global_offset_)
@ -502,7 +502,7 @@ public:
Match(RegexStringView const view_, StringView capture_group_name_, size_t const line_, size_t const column_, size_t const global_offset_)
: view(view_)
, capture_group_name(capture_group_name_)
, capture_group_name(MUST(FlyString::from_utf8(capture_group_name_)))
, line(line_)
, column(column_)
, global_offset(global_offset_)
@ -521,7 +521,7 @@ public:
}
RegexStringView view {};
Optional<DeprecatedFlyString> capture_group_name {};
Optional<FlyString> capture_group_name {};
size_t line { 0 };
size_t column { 0 };
size_t global_offset { 0 };

View file

@ -11,6 +11,7 @@
#include <AK/ByteString.h>
#include <AK/CharacterTypes.h>
#include <AK/Debug.h>
#include <AK/DeprecatedFlyString.h>
#include <AK/GenericLexer.h>
#include <AK/ScopeGuard.h>
#include <AK/StringBuilder.h>

View file

@ -11,6 +11,7 @@
#include "RegexLexer.h"
#include "RegexOptions.h"
#include <AK/DeprecatedFlyString.h>
#include <AK/Forward.h>
#include <AK/HashMap.h>
#include <AK/Types.h>

View file

@ -185,7 +185,7 @@ static WebIDL::ExceptionOr<KeyframeType<AL>> process_a_keyframe_like_object(JS::
// 1. Let raw value be the result of calling the [[Get]] internal method on keyframe input, with property name
// as the property key and keyframe input as the receiver.
// 2. Check the completion record of raw value.
JS::PropertyKey key { property_name.to_byte_string(), JS::PropertyKey::StringMayBeNumber::No };
JS::PropertyKey key { property_name, JS::PropertyKey::StringMayBeNumber::No };
auto raw_value = TRY(keyframe_object.has_property(key)) ? TRY(keyframe_object.get(key)) : *all_value;
using PropertyValuesType = Conditional<AL == AllowLists::Yes, Vector<String>, String>;
@ -827,7 +827,7 @@ WebIDL::ExceptionOr<GC::RootVector<JS::Object*>> KeyframeEffect::get_keyframes()
for (auto const& [id, value] : keyframe.parsed_properties()) {
auto value_string = JS::PrimitiveString::create(vm, value->to_string(CSS::CSSStyleValue::SerializationMode::Normal));
TRY(object->set(JS::PropertyKey { DeprecatedFlyString(CSS::camel_case_string_from_property_id(id)), JS::PropertyKey::StringMayBeNumber::No }, value_string, ShouldThrowExceptions::Yes));
TRY(object->set(JS::PropertyKey { CSS::camel_case_string_from_property_id(id), JS::PropertyKey::StringMayBeNumber::No }, value_string, ShouldThrowExceptions::Yes));
}
m_keyframe_objects.append(object);

View file

@ -369,7 +369,7 @@ ErrorOr<void> initialize_main_thread_vm(HTML::EventLoop::Type type)
// 2. Let url be the result of resolving a module specifier given moduleScript and specifier.
auto url = TRY(Bindings::throw_dom_exception_if_needed(vm, [&] {
return HTML::resolve_module_specifier(*module_script, specifier_string.to_byte_string());
return HTML::resolve_module_specifier(*module_script, specifier_string);
}));
// 3. Return the serialization of url.
@ -388,9 +388,9 @@ ErrorOr<void> initialize_main_thread_vm(HTML::EventLoop::Type type)
};
// 8.1.6.7.2 HostGetSupportedImportAttributes(), https://html.spec.whatwg.org/multipage/webappapis.html#hostgetsupportedimportassertions
s_main_thread_vm->host_get_supported_import_attributes = []() -> Vector<ByteString> {
s_main_thread_vm->host_get_supported_import_attributes = []() -> Vector<String> {
// 1. Return « "type" ».
return { "type"sv };
return { "type"_string };
};
// 8.1.6.7.3 HostLoadImportedModule(referrer, moduleRequest, loadState, payload), https://html.spec.whatwg.org/multipage/webappapis.html#hostloadimportedmodule
@ -460,7 +460,7 @@ ErrorOr<void> initialize_main_thread_vm(HTML::EventLoop::Type type)
// 2. Resolve a module specifier given referencingScript and moduleRequest.[[Specifier]], catching any
// exceptions. If they throw an exception, let resolutionError be the thrown exception.
auto maybe_exception = HTML::resolve_module_specifier(referencing_script, module_request.module_specifier);
auto maybe_exception = HTML::resolve_module_specifier(referencing_script, module_request.module_specifier.to_string());
// 3. If the previous step threw an exception, then:
if (maybe_exception.is_exception()) {
@ -500,7 +500,7 @@ ErrorOr<void> initialize_main_thread_vm(HTML::EventLoop::Type type)
// 8. Let url be the result of resolving a module specifier given referencingScript and moduleRequest.[[Specifier]],
// catching any exceptions. If they throw an exception, let resolutionError be the thrown exception.
auto url = HTML::resolve_module_specifier(referencing_script, module_request.module_specifier);
auto url = HTML::resolve_module_specifier(referencing_script, module_request.module_specifier.to_string());
// 9. If the previous step threw an exception, then:
if (url.is_exception()) {

View file

@ -41,7 +41,7 @@ JS::ThrowCompletionOr<bool> PlatformObject::is_named_property_exposed_on_object(
// 1. If P is not a supported property name of O, then return false.
// NOTE: This is in it's own variable to enforce the type.
if (!is_supported_property_name(MUST(String::from_byte_string(property_key.to_string()))))
if (!is_supported_property_name(property_key.to_string()))
return false;
// 2. If O has an own property named P, then return false.
@ -118,7 +118,7 @@ JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> PlatformObject::legacy_p
// 1. If the result of running the named property visibility algorithm with property name P and object O is true, then:
if (TRY(is_named_property_exposed_on_object(property_name))) {
// FIXME: It's unfortunate that this is done twice, once in is_named_property_exposed_on_object and here.
auto property_name_string = MUST(FlyString::from_deprecated_fly_string(property_name.to_string()));
auto property_name_string = property_name.to_string();
// 1. Let operation be the operation used to declare the named property getter.
// 2. Let value be an uninitialized variable.
@ -236,7 +236,7 @@ JS::ThrowCompletionOr<bool> PlatformObject::internal_set(JS::PropertyKey const&
// 2. If O implements an interface with a named property setter and P is a String, then:
if (m_legacy_platform_object_flags->has_named_property_setter && property_name.is_string()) {
// 1. Invoke the named property setter on O with P and V.
TRY(throw_dom_exception_if_needed(vm, [&] { return invoke_named_property_setter(MUST(String::from_byte_string(property_name.as_string())), value); }));
TRY(throw_dom_exception_if_needed(vm, [&] { return invoke_named_property_setter(property_name.as_string(), value); }));
// 2. Return true.
return true;
@ -282,7 +282,7 @@ JS::ThrowCompletionOr<bool> PlatformObject::internal_define_own_property(JS::Pro
// 2. If O supports named properties, O does not implement an interface with the [Global] extended attribute, P is a String, and P is not an unforgeable property name of O, then:
// FIXME: Check if P is not an unforgeable property name of O
if (m_legacy_platform_object_flags->supports_named_properties && !m_legacy_platform_object_flags->has_global_interface_extended_attribute && property_name.is_string()) {
auto const property_name_as_string = MUST(FlyString::from_deprecated_fly_string(property_name.as_string()));
auto const property_name_as_string = property_name.as_string();
// 1. Let creating be true if P is not a supported property name, and false otherwise.
bool creating = !is_supported_property_name(property_name_as_string);
@ -360,7 +360,7 @@ JS::ThrowCompletionOr<bool> PlatformObject::internal_delete(JS::PropertyKey cons
// 4. Otherwise, operation was defined with an identifier:
// 1. Perform method steps of operation with O as this and « P » as the argument values.
// 2. If operation was declared with a return type of boolean and the steps returned false, then return false.
auto did_deletion_fail = TRY(throw_dom_exception_if_needed(vm, [&] { return delete_value(MUST(String::from_byte_string(property_name_string))); }));
auto did_deletion_fail = TRY(throw_dom_exception_if_needed(vm, [&] { return delete_value(property_name_string); }));
if (!m_legacy_platform_object_flags->named_property_deleter_has_identifier)
VERIFY(did_deletion_fail != DidDeletionFail::NotRelevant);
@ -423,7 +423,7 @@ JS::ThrowCompletionOr<GC::RootVector<JS::Value>> PlatformObject::internal_own_pr
// 3. If O supports named properties, then for each P of Os supported property names that is visible according to the named property visibility algorithm, append P to keys.
if (m_legacy_platform_object_flags->supports_named_properties) {
for (auto& named_property : supported_property_names()) {
if (TRY(is_named_property_exposed_on_object(named_property.to_deprecated_fly_string())))
if (TRY(is_named_property_exposed_on_object(named_property)))
keys.append(JS::PrimitiveString::create(vm, named_property));
}
}

View file

@ -4737,7 +4737,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 = as<JS::Array>(vm.argument(0).as_object());
auto entries_length = MUST(MUST(entries.get(vm.names.length)).to_length(vm));

View file

@ -513,7 +513,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

@ -59,8 +59,8 @@ Vector<CrossOriginProperty> cross_origin_properties(Variant<HTML::Location const
bool is_cross_origin_accessible_window_property_name(JS::PropertyKey const& property_key)
{
// A JavaScript property name P is a cross-origin accessible window property name if it is "window", "self", "location", "close", "closed", "focus", "blur", "frames", "length", "top", "opener", "parent", "postMessage", or an array index property name.
static Array<DeprecatedFlyString, 13> property_names {
"window"sv, "self"sv, "location"sv, "close"sv, "closed"sv, "focus"sv, "blur"sv, "frames"sv, "length"sv, "top"sv, "opener"sv, "parent"sv, "postMessage"sv
static Array<FlyString, 13> property_names {
"window"_fly_string, "self"_fly_string, "location"_fly_string, "close"_fly_string, "closed"_fly_string, "focus"_fly_string, "blur"_fly_string, "frames"_fly_string, "length"_fly_string, "top"_fly_string, "opener"_fly_string, "parent"_fly_string, "postMessage"_fly_string
};
return (property_key.is_string() && any_of(property_names, [&](auto const& name) { return property_key.as_string() == name; })) || property_key.is_number();
}
@ -108,7 +108,7 @@ Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<HT
if (!property_key.is_string()) {
return {};
}
auto const& property_key_string = MUST(FlyString::from_deprecated_fly_string(property_key.as_string()));
auto const& property_key_string = property_key.as_string();
// 2. For each e of CrossOriginProperties(O):
for (auto const& entry : cross_origin_properties(object_const_variant)) {

View file

@ -208,7 +208,7 @@ JS::ThrowCompletionOr<void> CustomElementRegistry::define(String const& name, We
// 4. For each callbackName of the keys of lifecycleCallbacks:
for (auto const& callback_name : { CustomElementReactionNames::connectedCallback, CustomElementReactionNames::disconnectedCallback, CustomElementReactionNames::adoptedCallback, CustomElementReactionNames::attributeChangedCallback }) {
// 1. Let callbackValue be ? Get(prototype, callbackName).
auto callback_value = TRY(prototype.get(callback_name.to_deprecated_fly_string()));
auto callback_value = TRY(prototype.get(callback_name));
// 2. If callbackValue is not undefined, then set the value of the entry in lifecycleCallbacks with key callbackName to the result of
// converting callbackValue to the Web IDL Function callback type.
@ -259,7 +259,7 @@ JS::ThrowCompletionOr<void> CustomElementRegistry::define(String const& name, We
if (form_associated) {
for (auto const& callback_name : { CustomElementReactionNames::formAssociatedCallback, CustomElementReactionNames::formResetCallback, CustomElementReactionNames::formDisabledCallback, CustomElementReactionNames::formStateRestoreCallback }) {
// 1. Let callbackValue be ? Get(prototype, callbackName).
auto callback_value = TRY(prototype.get(callback_name.to_deprecated_fly_string()));
auto callback_value = TRY(prototype.get(callback_name));
// 2. If callbackValue is not undefined, then set lifecycleCallbacks[callbackName] to the result of converting callbackValue
// to the Web IDL Function callback type.

View file

@ -118,7 +118,7 @@ Variant<GC::Ref<DOM::HTMLCollection>, GC::Ref<DOM::Element>, Empty> HTMLAllColle
return Empty {};
// 2. Return the result of getting the "all"-indexed or named element(s) from this, given nameOrIndex.
return get_the_all_indexed_or_named_elements(name_or_index.value().to_deprecated_fly_string());
return get_the_all_indexed_or_named_elements(name_or_index.value());
}
// https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#dom-htmlallcollection-nameditem
@ -211,7 +211,7 @@ Variant<GC::Ref<DOM::HTMLCollection>, GC::Ref<DOM::Element>, Empty> HTMLAllColle
}
// 2. Return the result of getting the "all"-named element(s) from collection given nameOrIndex.
return get_the_all_named_elements(MUST(FlyString::from_deprecated_fly_string(name_or_index.as_string())));
return get_the_all_named_elements(name_or_index.as_string());
}
Optional<JS::Value> HTMLAllCollection::item_value(size_t index) const

View file

@ -61,19 +61,19 @@ ScriptFetchOptions default_script_fetch_options()
}
// https://html.spec.whatwg.org/multipage/webappapis.html#module-type-from-module-request
ByteString module_type_from_module_request(JS::ModuleRequest const& module_request)
String module_type_from_module_request(JS::ModuleRequest const& module_request)
{
// 1. Let moduleType be "javascript".
ByteString module_type = "javascript"sv;
String module_type = "javascript"_string;
// 2. If moduleRequest.[[Attributes]] has a Record entry such that entry.[[Key]] is "type", then:
for (auto const& entry : module_request.attributes) {
if (entry.key != "type"sv)
if (entry.key != "type"_string)
continue;
// 1. If entry.[[Value]] is "javascript", then set moduleType to null.
if (entry.value == "javascript"sv)
module_type = nullptr;
if (entry.value == "javascript"_string)
module_type = ""_string; // FIXME: This should be null!
// 2. Otherwise, set moduleType to entry.[[Value]].
else
module_type = entry.value;
@ -85,7 +85,7 @@ ByteString module_type_from_module_request(JS::ModuleRequest const& module_reque
// https://html.spec.whatwg.org/multipage/webappapis.html#resolve-a-module-specifier
// https://whatpr.org/html/9893/webappapis.html#resolve-a-module-specifier
WebIDL::ExceptionOr<URL::URL> resolve_module_specifier(Optional<Script&> referring_script, ByteString const& specifier)
WebIDL::ExceptionOr<URL::URL> resolve_module_specifier(Optional<Script&> referring_script, String const& specifier)
{
auto& vm = Bindings::main_thread_vm();
@ -124,10 +124,10 @@ WebIDL::ExceptionOr<URL::URL> resolve_module_specifier(Optional<Script&> referri
auto serialized_base_url = base_url->serialize();
// 7. Let asURL be the result of resolving a URL-like module specifier given specifier and baseURL.
auto as_url = resolve_url_like_module_specifier(specifier, *base_url);
auto as_url = resolve_url_like_module_specifier(specifier.to_byte_string(), *base_url);
// 8. Let normalizedSpecifier be the serialization of asURL, if asURL is non-null; otherwise, specifier.
auto normalized_specifier = as_url.has_value() ? as_url->serialize().to_byte_string() : specifier;
auto normalized_specifier = as_url.has_value() ? as_url->serialize() : specifier;
// 9. Let result be a URL-or-null, initially null.
Optional<URL::URL> result;
@ -142,7 +142,7 @@ WebIDL::ExceptionOr<URL::URL> resolve_module_specifier(Optional<Script&> referri
// 1. If scopePrefix is serializedBaseURL, or if scopePrefix ends with U+002F (/) and scopePrefix is a code unit prefix of serializedBaseURL, then:
if (scope_prefix == serialized_base_url || (scope_prefix.ends_with('/') && Infra::is_code_unit_prefix(scope_prefix, serialized_base_url))) {
// 1. Let scopeImportsMatch be the result of resolving an imports match given normalizedSpecifier, asURL, and scopeImports.
auto scope_imports_match = TRY(resolve_imports_match(normalized_specifier, as_url, scope_imports));
auto scope_imports_match = TRY(resolve_imports_match(normalized_specifier.to_byte_string(), as_url, scope_imports));
// 2. If scopeImportsMatch is not null, then set result to scopeImportsMatch, and break.
if (scope_imports_match.has_value()) {
@ -154,7 +154,7 @@ WebIDL::ExceptionOr<URL::URL> resolve_module_specifier(Optional<Script&> referri
// 11. If result is null, set result be the result of resolving an imports match given normalizedSpecifier, asURL, and importMap's imports.
if (!result.has_value())
result = TRY(resolve_imports_match(normalized_specifier, as_url, import_map.imports()));
result = TRY(resolve_imports_match(normalized_specifier.to_byte_string(), as_url, import_map.imports()));
// 12. If result is null, set it to asURL.
// Spec-Note: By this point, if result was null, specifier wasn't remapped to anything by importMap, but it might have been able to be turned into a URL.
@ -164,7 +164,7 @@ WebIDL::ExceptionOr<URL::URL> resolve_module_specifier(Optional<Script&> referri
// 13. If result is not null, then:
if (result.has_value()) {
// 1. Add module to resolved module set given realm, serializedBaseURL, normalizedSpecifier, and asURL.
add_module_to_resolved_module_set(*realm, serialized_base_url, MUST(String::from_byte_string(normalized_specifier)), as_url);
add_module_to_resolved_module_set(*realm, serialized_base_url, normalized_specifier, as_url);
// 2. Return result.
return result.release_value();
@ -180,7 +180,7 @@ WebIDL::ExceptionOr<Optional<URL::URL>> resolve_imports_match(ByteString const&
// 1. For each specifierKey → resolutionResult of specifierMap:
for (auto const& [specifier_key, resolution_result] : specifier_map) {
// 1. If specifierKey is normalizedSpecifier, then:
if (specifier_key == normalized_specifier) {
if (specifier_key.bytes_as_string_view() == normalized_specifier) {
// 1. If resolutionResult is null, then throw a TypeError indicating that resolution of specifierKey was blocked by a null entry.
if (!resolution_result.has_value())
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, String::formatted("Import resolution of '{}' was blocked by a null entry.", specifier_key).release_value_but_fixme_should_propagate_errors() };
@ -193,7 +193,7 @@ WebIDL::ExceptionOr<Optional<URL::URL>> resolve_imports_match(ByteString const&
// 2. If all of the following are true:
if (
// - specifierKey ends with U+002F (/);
specifier_key.ends_with("/"sv) &&
specifier_key.bytes_as_string_view().ends_with("/"sv) &&
// - specifierKey is a code unit prefix of normalizedSpecifier; and
Infra::is_code_unit_prefix(specifier_key, normalized_specifier) &&
// - either asURL is null, or asURL is special,
@ -207,7 +207,7 @@ WebIDL::ExceptionOr<Optional<URL::URL>> resolve_imports_match(ByteString const&
// 2. Assert: resolutionResult is a URL.
// 3. Let afterPrefix be the portion of normalizedSpecifier after the initial specifierKey prefix.
// FIXME: Clarify if this is meant by the portion after the initial specifierKey prefix.
auto after_prefix = normalized_specifier.substring(specifier_key.length());
auto after_prefix = normalized_specifier.substring(specifier_key.bytes_as_string_view().length());
// 4. Assert: resolutionResult, serialized, ends with U+002F (/), as enforced during parsing.
VERIFY(resolution_result->serialize().ends_with('/'));
@ -321,7 +321,7 @@ String resolve_a_module_integrity_metadata(const URL::URL& url, EnvironmentSetti
// 2. If map's integrity[url] does not exist, then return the empty string.
// 3. Return map's integrity[url].
return MUST(String::from_byte_string(map.integrity().get(url).value_or("")));
return map.integrity().get(url).value_or(""_string);
}
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-classic-script
@ -623,7 +623,7 @@ void fetch_single_module_script(JS::Realm& realm,
OnFetchScriptComplete on_complete)
{
// 1. Let moduleType be "javascript".
ByteString module_type = "javascript"sv;
String module_type = "javascript"_string;
// 2. If moduleRequest was given, then set moduleType to the result of running the module type from module request steps given moduleRequest.
if (module_request.has_value())
@ -639,8 +639,8 @@ void fetch_single_module_script(JS::Realm& realm,
// 5. If moduleMap[(url, moduleType)] is "fetching", wait in parallel until that entry's value changes,
// then queue a task on the networking task source to proceed with running the following steps.
if (module_map.is_fetching(url, module_type)) {
module_map.wait_for_change(realm.heap(), url, module_type, [on_complete, &realm](auto entry) -> void {
if (module_map.is_fetching(url, module_type.to_byte_string())) {
module_map.wait_for_change(realm.heap(), url, module_type.to_byte_string(), [on_complete, &realm](auto entry) -> void {
HTML::queue_global_task(HTML::Task::Source::Networking, realm.global_object(), GC::create_function(realm.heap(), [on_complete, entry] {
// FIXME: This should run other steps, for now we just assume the script loaded.
VERIFY(entry.type == ModuleMap::EntryType::ModuleScript || entry.type == ModuleMap::EntryType::Failed);
@ -653,14 +653,14 @@ void fetch_single_module_script(JS::Realm& realm,
}
// 6. If moduleMap[(url, moduleType)] exists, run onComplete given moduleMap[(url, moduleType)], and return.
auto entry = module_map.get(url, module_type);
auto entry = module_map.get(url, module_type.to_byte_string());
if (entry.has_value() && entry->type == ModuleMap::EntryType::ModuleScript) {
on_complete->function()(entry->module_script);
return;
}
// 7. Set moduleMap[(url, moduleType)] to "fetching".
module_map.set(url, module_type, { ModuleMap::EntryType::Fetching, nullptr });
module_map.set(url, module_type.to_byte_string(), { ModuleMap::EntryType::Fetching, nullptr });
// 8. Let request be a new request whose URL is url, mode is "cors", referrer is referrer, and client is fetchClient.
auto request = Fetch::Infrastructure::Request::create(realm.vm());
@ -670,7 +670,7 @@ void fetch_single_module_script(JS::Realm& realm,
request->set_client(&fetch_client);
// 9. Set request's destination to the result of running the fetch destination from module type steps given destination and moduleType.
request->set_destination(fetch_destination_from_module_type(destination, module_type));
request->set_destination(fetch_destination_from_module_type(destination, module_type.to_byte_string()));
// 10. If destination is "worker", "sharedworker", or "serviceworker", and isTopLevel is true, then set request's mode to "same-origin".
if ((destination == Fetch::Infrastructure::Request::Destination::Worker || destination == Fetch::Infrastructure::Request::Destination::SharedWorker || destination == Fetch::Infrastructure::Request::Destination::ServiceWorker) && is_top_level == TopLevelModule::Yes)
@ -691,7 +691,7 @@ void fetch_single_module_script(JS::Realm& realm,
// - response's status is not an ok status,
if (body_bytes.has<Empty>() || body_bytes.has<Fetch::Infrastructure::FetchAlgorithms::ConsumeBodyFailureTag>() || !Fetch::Infrastructure::is_ok_status(response->status())) {
// then set moduleMap[(url, moduleType)] to null, run onComplete given null, and abort these steps.
module_map.set(url, module_type, { ModuleMap::EntryType::Failed, nullptr });
module_map.set(url, module_type.to_byte_string(), { ModuleMap::EntryType::Failed, nullptr });
on_complete->function()(nullptr);
return;
}
@ -719,7 +719,7 @@ void fetch_single_module_script(JS::Realm& realm,
// FIXME: 9. If mimeType is a JSON MIME type and moduleType is "json", then set moduleScript to the result of creating a JSON module script given sourceText and settingsObject.
// 10. Set moduleMap[(url, moduleType)] to moduleScript, and run onComplete given moduleScript.
module_map.set(url, module_type, { ModuleMap::EntryType::ModuleScript, module_script });
module_map.set(url, module_type.to_byte_string(), { ModuleMap::EntryType::ModuleScript, module_script });
on_complete->function()(module_script);
};

View file

@ -82,8 +82,8 @@ private:
}
};
ByteString module_type_from_module_request(JS::ModuleRequest const&);
WebIDL::ExceptionOr<URL::URL> resolve_module_specifier(Optional<Script&> referring_script, ByteString const& specifier);
String module_type_from_module_request(JS::ModuleRequest const&);
WebIDL::ExceptionOr<URL::URL> resolve_module_specifier(Optional<Script&> referring_script, String const& specifier);
WebIDL::ExceptionOr<Optional<URL::URL>> resolve_imports_match(ByteString const& normalized_specifier, Optional<URL::URL> as_url, ModuleSpecifierMap const&);
Optional<URL::URL> resolve_url_like_module_specifier(ByteString const& specifier, URL::URL const& base_url);
ScriptFetchOptions get_descendant_script_fetch_options(ScriptFetchOptions const& original_options, URL::URL const& url, EnvironmentSettingsObject& settings_object);

View file

@ -31,7 +31,7 @@ WebIDL::ExceptionOr<ImportMap> parse_import_map_string(JS::Realm& realm, ByteStr
auto& parsed_object = parsed.as_object();
// 3. Let sortedAndNormalizedImports be an empty ordered map.
ModuleSpecifierMap sorted_and_normalised_imports;
ModuleSpecifierMap sorted_and_normalized_imports;
// 4. If parsed["imports"] exists, then:
if (TRY(parsed_object.has_property("imports"_fly_string))) {
@ -42,11 +42,11 @@ WebIDL::ExceptionOr<ImportMap> parse_import_map_string(JS::Realm& realm, ByteStr
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "The 'imports' top-level value of an importmap needs to be a JSON object."_string };
// Set sortedAndNormalizedImports to the result of sorting and normalizing a module specifier map given parsed["imports"] and baseURL.
sorted_and_normalised_imports = TRY(sort_and_normalise_module_specifier_map(realm, imports.as_object(), base_url));
sorted_and_normalized_imports = TRY(sort_and_normalise_module_specifier_map(realm, imports.as_object(), base_url));
}
// 5. Let sortedAndNormalizedScopes be an empty ordered map.
HashMap<URL::URL, ModuleSpecifierMap> sorted_and_normalised_scopes;
HashMap<URL::URL, ModuleSpecifierMap> sorted_and_normalized_scopes;
// 6. If parsed["scopes"] exists, then:
if (TRY(parsed_object.has_property("scopes"_fly_string))) {
@ -57,11 +57,11 @@ WebIDL::ExceptionOr<ImportMap> parse_import_map_string(JS::Realm& realm, ByteStr
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "The 'scopes' top-level value of an importmap needs to be a JSON object."_string };
// Set sortedAndNormalizedScopes to the result of sorting and normalizing scopes given parsed["scopes"] and baseURL.
sorted_and_normalised_scopes = TRY(sort_and_normalise_scopes(realm, scopes.as_object(), base_url));
sorted_and_normalized_scopes = TRY(sort_and_normalise_scopes(realm, scopes.as_object(), base_url));
}
// 7. Let normalizedIntegrity be an empty ordered map.
ModuleIntegrityMap normalised_integrity;
ModuleIntegrityMap normalized_integrity;
// 8. If parsed["integrity"] exists, then:
if (TRY(parsed_object.has_property("integrity"_fly_string))) {
@ -72,7 +72,7 @@ WebIDL::ExceptionOr<ImportMap> parse_import_map_string(JS::Realm& realm, ByteStr
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "The 'integrity' top-level value of an importmap needs to be a JSON object."_string };
// 2. Set normalizedIntegrity to the result of normalizing a module integrity map given parsed["integrity"] and baseURL.
normalised_integrity = TRY(normalize_module_integrity_map(realm, integrity.as_object(), base_url));
normalized_integrity = TRY(normalize_module_integrity_map(realm, integrity.as_object(), base_url));
}
// 9. If parsed's keys contains any items besides "imports", "scopes", or "integrity", then the user agent should report a warning to the console indicating that an invalid top-level key was present in the import map.
@ -86,14 +86,14 @@ WebIDL::ExceptionOr<ImportMap> parse_import_map_string(JS::Realm& realm, ByteStr
// 10. Return an import map whose imports are sortedAndNormalizedImports, whose scopes are sortedAndNormalizedScopes, and whose integrity are normalizedIntegrity.
ImportMap import_map;
import_map.set_imports(sorted_and_normalised_imports);
import_map.set_scopes(sorted_and_normalised_scopes);
import_map.set_integrity(normalised_integrity);
import_map.set_imports(sorted_and_normalized_imports);
import_map.set_scopes(sorted_and_normalized_scopes);
import_map.set_integrity(normalized_integrity);
return import_map;
}
// https://html.spec.whatwg.org/multipage/webappapis.html#normalizing-a-specifier-key
Optional<DeprecatedFlyString> normalise_specifier_key(JS::Realm& realm, DeprecatedFlyString specifier_key, URL::URL base_url)
Optional<FlyString> normalize_specifier_key(JS::Realm& realm, FlyString specifier_key, URL::URL base_url)
{
// 1. If specifierKey is the empty string, then:
if (specifier_key.is_empty()) {
@ -102,15 +102,15 @@ Optional<DeprecatedFlyString> normalise_specifier_key(JS::Realm& realm, Deprecat
console.output_debug_message(JS::Console::LogLevel::Warn, "Specifier keys may not be empty"sv);
// 2. Return null.
return Optional<DeprecatedFlyString> {};
return Optional<FlyString> {};
}
// 2. Let url be the result of resolving a URL-like module specifier, given specifierKey and baseURL.
auto url = resolve_url_like_module_specifier(specifier_key, base_url);
auto url = resolve_url_like_module_specifier(specifier_key.to_string().to_byte_string(), base_url);
// 3. If url is not null, then return the serialization of url.
if (url.has_value())
return url->serialize().to_byte_string();
return url->serialize();
// 4. Return specifierKey.
return specifier_key;
@ -120,17 +120,17 @@ Optional<DeprecatedFlyString> normalise_specifier_key(JS::Realm& realm, Deprecat
WebIDL::ExceptionOr<ModuleSpecifierMap> sort_and_normalise_module_specifier_map(JS::Realm& realm, JS::Object& original_map, URL::URL base_url)
{
// 1. Let normalized be an empty ordered map.
ModuleSpecifierMap normalised;
ModuleSpecifierMap normalized;
// 2. For each specifierKey → value of originalMap:
for (auto& specifier_key : original_map.shape().property_table().keys()) {
auto value = TRY(original_map.get(specifier_key.as_string()));
// 1. Let normalizedSpecifierKey be the result of normalizing a specifier key given specifierKey and baseURL.
auto normalised_specifier_key = normalise_specifier_key(realm, specifier_key.as_string(), base_url);
auto normalized_specifier_key = normalize_specifier_key(realm, specifier_key.as_string(), base_url);
// 2. If normalizedSpecifierKey is null, then continue.
if (!normalised_specifier_key.has_value())
if (!normalized_specifier_key.has_value())
continue;
// 3. If value is not a string, then:
@ -140,7 +140,7 @@ WebIDL::ExceptionOr<ModuleSpecifierMap> sort_and_normalise_module_specifier_map(
console.output_debug_message(JS::Console::LogLevel::Warn, "Addresses need to be strings"sv);
// 2. Set normalized[normalizedSpecifierKey] to null.
normalised.set(normalised_specifier_key.value(), {});
normalized.set(normalized_specifier_key.value().to_string(), {});
// 3. Continue.
continue;
@ -156,39 +156,39 @@ WebIDL::ExceptionOr<ModuleSpecifierMap> sort_and_normalise_module_specifier_map(
console.output_debug_message(JS::Console::LogLevel::Warn, "Address was invalid"sv);
// 2. Set normalized[normalizedSpecifierKey] to null.
normalised.set(normalised_specifier_key.value(), {});
normalized.set(normalized_specifier_key.value().to_string(), {});
// 3. Continue.
continue;
}
// 6. If specifierKey ends with U+002F (/), and the serialization of addressURL does not end with U+002F (/), then:
if (specifier_key.as_string().ends_with("/"sv) && !address_url->serialize().ends_with('/')) {
if (specifier_key.as_string().bytes_as_string_view().ends_with("/"sv) && !address_url->serialize().ends_with('/')) {
// 1. The user agent may report a warning to the console indicating that an invalid address was given for the specifier key specifierKey; since specifierKey ends with a slash, the address needs to as well.
auto& console = realm.intrinsics().console_object()->console();
console.output_debug_message(JS::Console::LogLevel::Warn,
MUST(String::formatted("An invalid address was given for the specifier key ({}); since specifierKey ends with a slash, the address needs to as well", specifier_key.as_string())));
// 2. Set normalized[normalizedSpecifierKey] to null.
normalised.set(normalised_specifier_key.value(), {});
normalized.set(normalized_specifier_key.value().to_string(), {});
// 3. Continue.
continue;
}
// 7. Set normalized[normalizedSpecifierKey] to addressURL.
normalised.set(normalised_specifier_key.value(), address_url.value());
normalized.set(normalized_specifier_key.value().to_string(), address_url.value());
}
// 3. Return the result of sorting in descending order normalized, with an entry a being less than an entry b if a's key is code unit less than b's key.
return normalised;
return normalized;
}
// https://html.spec.whatwg.org/multipage/webappapis.html#sorting-and-normalizing-scopes
WebIDL::ExceptionOr<HashMap<URL::URL, ModuleSpecifierMap>> sort_and_normalise_scopes(JS::Realm& realm, JS::Object& original_map, URL::URL base_url)
{
// 1. Let normalized be an empty ordered map.
HashMap<URL::URL, ModuleSpecifierMap> normalised;
HashMap<URL::URL, ModuleSpecifierMap> normalized;
// 2. For each scopePrefix → potentialSpecifierMap of originalMap:
for (auto& scope_prefix : original_map.shape().property_table().keys()) {
@ -214,25 +214,25 @@ WebIDL::ExceptionOr<HashMap<URL::URL, ModuleSpecifierMap>> sort_and_normalise_sc
// 4. Let normalizedScopePrefix be the serialization of scopePrefixURL.
// 5. Set normalized[normalizedScopePrefix] to the result of sorting and normalizing a module specifier map given potentialSpecifierMap and baseURL.
normalised.set(scope_prefix_url.value(), TRY(sort_and_normalise_module_specifier_map(realm, potential_specifier_map.as_object(), base_url)));
normalized.set(scope_prefix_url.value(), TRY(sort_and_normalise_module_specifier_map(realm, potential_specifier_map.as_object(), base_url)));
}
// 3. Return the result of sorting in descending order normalized, with an entry a being less than an entry b if a's key is code unit less than b's key.
return normalised;
return normalized;
}
// https://html.spec.whatwg.org/multipage/webappapis.html#normalizing-a-module-integrity-map
WebIDL::ExceptionOr<ModuleIntegrityMap> normalize_module_integrity_map(JS::Realm& realm, JS::Object& original_map, URL::URL base_url)
{
// 1. Let normalized be an empty ordered map.
ModuleIntegrityMap normalised;
ModuleIntegrityMap normalized;
// 2. For each key → value of originalMap:
for (auto& key : original_map.shape().property_table().keys()) {
auto value = TRY(original_map.get(key.as_string()));
// 1. Let resolvedURL be the result of resolving a URL-like module specifier given key and baseURL.
auto resolved_url = resolve_url_like_module_specifier(key.as_string(), base_url);
auto resolved_url = resolve_url_like_module_specifier(key.as_string().to_string().to_byte_string(), base_url);
// 2. If resolvedURL is null, then:
if (!resolved_url.has_value()) {
@ -257,11 +257,11 @@ WebIDL::ExceptionOr<ModuleIntegrityMap> normalize_module_integrity_map(JS::Realm
}
// 4. Set normalized[resolvedURL] to value.
normalised.set(resolved_url.release_value(), value.as_string().byte_string());
normalized.set(resolved_url.release_value(), value.as_string().utf8_string());
}
// 3. Return normalized.
return normalised;
return normalized;
}
// https://html.spec.whatwg.org/multipage/webappapis.html#merge-module-specifier-maps
@ -316,13 +316,13 @@ void merge_existing_and_new_import_maps(Window& global, ImportMap& new_import_ma
// 1. If scopePrefix is record's serialized base URL, or if scopePrefix ends with U+002F (/) and scopePrefix is a code unit prefix of record's serialized base URL, then:
if (scope_prefix.to_string() == record.serialized_base_url || (scope_prefix.to_string().ends_with('/') && record.serialized_base_url.has_value() && Infra::is_code_unit_prefix(scope_prefix.to_string(), *record.serialized_base_url))) {
// 1. For each specifierKey → resolutionResult of scopeImports:
scope_imports.remove_all_matching([&](ByteString const& specifier_key, Optional<URL::URL> const&) {
scope_imports.remove_all_matching([&](String const& specifier_key, Optional<URL::URL> const&) {
// 1. If specifierKey is record's specifier, or if all of the following conditions are true:
// * specifierKey ends with U+002F (/);
// * specifierKey is a code unit prefix of record's specifier;
// * either record's specifier as a URL is null or is special,
// then:
if (specifier_key.view() == record.specifier
if (specifier_key.bytes_as_string_view() == record.specifier
|| (specifier_key.ends_with('/')
&& Infra::is_code_unit_prefix(specifier_key, record.specifier)
&& record.specifier_is_null_or_url_like_that_is_special)) {
@ -373,9 +373,9 @@ void merge_existing_and_new_import_maps(Window& global, ImportMap& new_import_ma
// 6. For each record of global's resolved module set:
for (auto const& record : global.resolved_module_set()) {
// 1. For each specifier → url of newImportMapImports:
new_import_map_imports.remove_all_matching([&](ByteString const& specifier, Optional<URL::URL> const&) {
new_import_map_imports.remove_all_matching([&](String const& specifier, Optional<URL::URL> const&) {
// 1. If specifier starts with record's specifier, then:
if (specifier.starts_with(record.specifier)) {
if (specifier.bytes_as_string_view().starts_with(record.specifier)) {
// 1. The user agent may report a warning to the console indicating the ignored rule. They may choose to
// avoid reporting if the rule is identical to an existing one.
auto& console = realm.intrinsics().console_object()->console();

View file

@ -13,8 +13,8 @@
namespace Web::HTML {
using ModuleSpecifierMap = HashMap<ByteString, Optional<URL::URL>>;
using ModuleIntegrityMap = HashMap<URL::URL, ByteString>;
using ModuleSpecifierMap = HashMap<String, Optional<URL::URL>>;
using ModuleIntegrityMap = HashMap<URL::URL, String>;
// https://html.spec.whatwg.org/multipage/webappapis.html#import-map
class ImportMap {
@ -40,7 +40,7 @@ private:
};
WebIDL::ExceptionOr<ImportMap> parse_import_map_string(JS::Realm& realm, ByteString const& input, URL::URL base_url);
Optional<DeprecatedFlyString> normalise_specifier_key(JS::Realm& realm, DeprecatedFlyString specifier_key, URL::URL base_url);
Optional<FlyString> normalize_specifier_key(JS::Realm& realm, FlyString specifier_key, URL::URL base_url);
WebIDL::ExceptionOr<ModuleSpecifierMap> sort_and_normalise_module_specifier_map(JS::Realm& realm, JS::Object& original_map, URL::URL base_url);
WebIDL::ExceptionOr<HashMap<URL::URL, ModuleSpecifierMap>> sort_and_normalise_scopes(JS::Realm& realm, JS::Object& original_map, URL::URL base_url);
WebIDL::ExceptionOr<ModuleIntegrityMap> normalize_module_integrity_map(JS::Realm& realm, JS::Object& original_map, URL::URL base_url);

View file

@ -521,8 +521,8 @@ WebIDL::ExceptionOr<void> serialize_reg_exp_object(JS::VM& vm, SerializationReco
// Note: A Regex<ECMA262> object is perfectly happy to be reconstructed with just the source+flags
// In the future, we could optimize the work being done on the deserialize step by serializing
// more of the internal state (the [[RegExpMatcher]] internal slot)
TRY(serialize_string(vm, serialized, TRY_OR_THROW_OOM(vm, String::from_byte_string(regexp_object.pattern()))));
TRY(serialize_string(vm, serialized, TRY_OR_THROW_OOM(vm, String::from_byte_string(regexp_object.flags()))));
TRY(serialize_string(vm, serialized, regexp_object.pattern()));
TRY(serialize_string(vm, serialized, regexp_object.flags()));
return {};
}
@ -684,8 +684,8 @@ WebIDL::ExceptionOr<void> serialize_viewed_array_buffer(JS::VM& vm, Vector<u32>&
// [[ArrayBufferSerialized]]: bufferSerialized, [[ByteLength]]: value.[[ByteLength]],
// [[ByteOffset]]: value.[[ByteOffset]], [[ArrayLength]]: value.[[ArrayLength]] }.
serialize_enum(vector, ValueTag::ArrayBufferView);
vector.extend(move(buffer_serialized)); // [[ArrayBufferSerialized]]
TRY(serialize_string(vm, vector, view.element_name())); // [[Constructor]]
vector.extend(move(buffer_serialized)); // [[ArrayBufferSerialized]]
TRY(serialize_string(vm, vector, view.element_name().to_string())); // [[Constructor]]
serialize_primitive_type(vector, JS::typed_array_byte_length(view_record));
serialize_primitive_type(vector, view.byte_offset());
serialize_primitive_type(vector, JS::typed_array_length(view_record));

View file

@ -740,9 +740,9 @@ WebIDL::ExceptionOr<void> Window::initialize_web_interfaces(Badge<WindowEnvironm
auto const& path = url.paths().first();
if (path == "processes"sv)
define_direct_property("processes", realm.create<Internals::Processes>(realm), JS::default_attributes);
define_direct_property("processes"_fly_string, realm.create<Internals::Processes>(realm), JS::default_attributes);
else if (path == "settings"sv)
define_direct_property("settings", realm.create<Internals::Settings>(realm), JS::default_attributes);
define_direct_property("settings"_fly_string, realm.create<Internals::Settings>(realm), JS::default_attributes);
}
return {};

View file

@ -119,7 +119,7 @@ JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> WindowProxy::internal_ge
auto navigable_property_set = m_window->document_tree_child_navigable_target_name_property_set();
auto property_key_string = property_key.to_string();
if (auto navigable = navigable_property_set.get(property_key_string.view()); navigable.has_value()) {
if (auto navigable = navigable_property_set.get(property_key_string); navigable.has_value()) {
// 1. Let value be the active WindowProxy of the named object of W with the name P.
auto value = navigable.value()->active_window_proxy();

View file

@ -137,7 +137,7 @@ WebIDL::ExceptionOr<ByteBuffer> serialize_javascript_value_to_json_bytes(JS::VM&
auto map_value_js_value = convert_an_infra_value_to_a_json_compatible_javascript_value(realm, map_entry.value);
// 3. Perform ! CreateDataPropertyOrThrow(jsValue, mapKey, mapValueJSValue).
MUST(js_value->create_data_property_or_throw(map_entry.key.to_byte_string(), map_value_js_value));
MUST(js_value->create_data_property_or_throw(map_entry.key, map_value_js_value));
}
// 6. Return jsValue.

View file

@ -54,7 +54,7 @@ void Instance::initialize(JS::Realm& realm)
[&](Wasm::FunctionAddress const& address) {
Optional<GC::Ptr<JS::FunctionObject>> object = m_function_instances.get(address);
if (!object.has_value()) {
object = Detail::create_native_function(vm, address, export_.name(), this);
object = Detail::create_native_function(vm, address, MUST(String::from_byte_string(export_.name())), this);
m_function_instances.set(address, *object);
}

View file

@ -372,7 +372,7 @@ JS::ThrowCompletionOr<NonnullRefPtr<CompiledWebAssemblyModule>> compile_a_webass
GC_DEFINE_ALLOCATOR(ExportedWasmFunction);
GC::Ref<ExportedWasmFunction> ExportedWasmFunction::create(JS::Realm& realm, DeprecatedFlyString const& name, Function<JS::ThrowCompletionOr<JS::Value>(JS::VM&)> behavior, Wasm::FunctionAddress exported_address)
GC::Ref<ExportedWasmFunction> ExportedWasmFunction::create(JS::Realm& realm, FlyString const& name, Function<JS::ThrowCompletionOr<JS::Value>(JS::VM&)> behavior, Wasm::FunctionAddress exported_address)
{
auto& vm = realm.vm();
auto prototype = realm.intrinsics().function_prototype();
@ -383,13 +383,13 @@ GC::Ref<ExportedWasmFunction> ExportedWasmFunction::create(JS::Realm& realm, Dep
prototype);
}
ExportedWasmFunction::ExportedWasmFunction(DeprecatedFlyString name, GC::Ptr<GC::Function<JS::ThrowCompletionOr<JS::Value>(JS::VM&)>> behavior, Wasm::FunctionAddress exported_address, JS::Object& prototype)
ExportedWasmFunction::ExportedWasmFunction(FlyString name, GC::Ptr<GC::Function<JS::ThrowCompletionOr<JS::Value>(JS::VM&)>> behavior, Wasm::FunctionAddress exported_address, JS::Object& prototype)
: NativeFunction(move(name), move(behavior), prototype)
, m_exported_address(exported_address)
{
}
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, String const& name, Instance* instance)
{
auto& realm = *vm.current_realm();
Optional<Wasm::FunctionType> type;
@ -545,7 +545,7 @@ JS::Value to_js_value(JS::VM& vm, Wasm::Value& wasm_value, Wasm::ValueType type)
[](Wasm::HostFunction& host_function) {
return host_function.name();
});
return create_native_function(vm, address, name);
return create_native_function(vm, address, MUST(String::from_byte_string(name)));
}
case Wasm::ValueType::ExternReference: {
auto ref_ = wasm_value.to<Wasm::Reference>();

View file

@ -71,13 +71,13 @@ class ExportedWasmFunction final : public JS::NativeFunction {
GC_DECLARE_ALLOCATOR(ExportedWasmFunction);
public:
static GC::Ref<ExportedWasmFunction> create(JS::Realm&, DeprecatedFlyString const& name, ESCAPING Function<JS::ThrowCompletionOr<JS::Value>(JS::VM&)>, Wasm::FunctionAddress);
static GC::Ref<ExportedWasmFunction> create(JS::Realm&, FlyString const& name, ESCAPING Function<JS::ThrowCompletionOr<JS::Value>(JS::VM&)>, Wasm::FunctionAddress);
virtual ~ExportedWasmFunction() override = default;
Wasm::FunctionAddress exported_address() const { return m_exported_address; }
protected:
ExportedWasmFunction(DeprecatedFlyString name, GC::Ptr<GC::Function<JS::ThrowCompletionOr<JS::Value>(JS::VM&)>>, Wasm::FunctionAddress, Object& prototype);
ExportedWasmFunction(FlyString name, GC::Ptr<GC::Function<JS::ThrowCompletionOr<JS::Value>(JS::VM&)>>, Wasm::FunctionAddress, Object& prototype);
private:
Wasm::FunctionAddress m_exported_address;
@ -87,7 +87,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, String 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);

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