LibJS: Remove a bunch of gratuitous JS namespace qualifiers

This commit is contained in:
Linus Groh 2022-04-03 15:19:33 +01:00
parent f2c02077ba
commit 5b48912d35
Notes: sideshowbarker 2024-07-17 14:33:00 +09:00
17 changed files with 66 additions and 65 deletions

View File

@ -3023,7 +3023,7 @@ Completion ObjectExpression::execute(Interpreter& interpreter, GlobalObject& glo
object->define_direct_accessor(property_key, nullptr, &value.as_function(), Attribute::Configurable | Attribute::Enumerable);
break;
case ObjectProperty::Type::KeyValue:
object->define_direct_property(property_key, value, JS::default_attributes);
object->define_direct_property(property_key, value, default_attributes);
break;
case ObjectProperty::Type::Spread:
default:
@ -3104,7 +3104,7 @@ void OptionalChain::dump(int indent) const
}
}
ThrowCompletionOr<OptionalChain::ReferenceAndValue> OptionalChain::to_reference_and_value(JS::Interpreter& interpreter, JS::GlobalObject& global_object) const
ThrowCompletionOr<OptionalChain::ReferenceAndValue> OptionalChain::to_reference_and_value(Interpreter& interpreter, GlobalObject& global_object) const
{
auto base_reference = TRY(m_base->to_reference(interpreter, global_object));
auto base = base_reference.is_unresolvable()

View File

@ -113,7 +113,7 @@ ThrowCompletionOr<Value> Console::trace()
}
// 3. Perform Printer("trace", « trace »).
return m_client->printer(JS::Console::LogLevel::Trace, trace);
return m_client->printer(Console::LogLevel::Trace, trace);
}
// 1.2.1. count(label), https://console.spec.whatwg.org/#count
@ -183,7 +183,7 @@ ThrowCompletionOr<Value> Console::assert_()
auto message = js_string(vm(), "Assertion failed");
// NOTE: Assemble `data` from the function arguments.
Vector<JS::Value> data;
Vector<Value> data;
if (vm().argument_count() > 1) {
data.ensure_capacity(vm().argument_count() - 1);
for (size_t i = 1; i < vm().argument_count(); ++i) {
@ -407,19 +407,19 @@ void Console::output_debug_message([[maybe_unused]] LogLevel log_level, [[maybe_
{
#ifdef __serenity__
switch (log_level) {
case JS::Console::LogLevel::Debug:
case Console::LogLevel::Debug:
dbgln("\033[32;1m(js debug)\033[0m {}", output);
break;
case JS::Console::LogLevel::Error:
case Console::LogLevel::Error:
dbgln("\033[32;1m(js error)\033[0m {}", output);
break;
case JS::Console::LogLevel::Info:
case Console::LogLevel::Info:
dbgln("\033[32;1m(js info)\033[0m {}", output);
break;
case JS::Console::LogLevel::Log:
case Console::LogLevel::Log:
dbgln("\033[32;1m(js log)\033[0m {}", output);
break;
case JS::Console::LogLevel::Warn:
case Console::LogLevel::Warn:
dbgln("\033[32;1m(js warn)\033[0m {}", output);
break;
default:

View File

@ -142,16 +142,16 @@ void MarkupGenerator::function_to_html(Object const& function, StringBuilder& ht
void MarkupGenerator::date_to_html(Object const& date, StringBuilder& html_output, HashTable<Object*>&)
{
html_output.appendff("Date {}", JS::to_date_string(static_cast<JS::Date const&>(date).date_value()));
html_output.appendff("Date {}", to_date_string(static_cast<Date const&>(date).date_value()));
}
void MarkupGenerator::error_to_html(Object const& object, StringBuilder& html_output, HashTable<Object*>&)
{
auto& vm = object.vm();
auto name = object.get_without_side_effects(vm.names.name).value_or(JS::js_undefined());
auto message = object.get_without_side_effects(vm.names.message).value_or(JS::js_undefined());
auto name = object.get_without_side_effects(vm.names.name).value_or(js_undefined());
auto message = object.get_without_side_effects(vm.names.message).value_or(js_undefined());
if (name.is_accessor() || message.is_accessor()) {
html_output.append(wrap_string_in_style(JS::Value(&object).to_string_without_side_effects(), StyleType::Invalid));
html_output.append(wrap_string_in_style(Value(&object).to_string_without_side_effects(), StyleType::Invalid));
} else {
auto name_string = name.to_string_without_side_effects();
auto message_string = message.to_string_without_side_effects();

View File

@ -580,13 +580,13 @@ ThrowCompletionOr<Value> perform_eval(Value x, GlobalObject& caller_realm, Calle
Optional<Value> eval_result;
if (auto* bytecode_interpreter = Bytecode::Interpreter::current()) {
auto executable_result = JS::Bytecode::Generator::generate(program);
auto executable_result = Bytecode::Generator::generate(program);
if (executable_result.is_error())
return vm.throw_completion<InternalError>(bytecode_interpreter->global_object(), ErrorType::NotImplemented, executable_result.error().to_string());
auto executable = executable_result.release_value();
executable->name = "eval"sv;
if (JS::Bytecode::g_dump_bytecode)
if (Bytecode::g_dump_bytecode)
executable->dump();
eval_result = TRY(bytecode_interpreter->run(*executable));
// Turn potentially empty JS::Value from the bytecode interpreter into an empty Optional
@ -1009,7 +1009,7 @@ Object* create_mapped_arguments_object(GlobalObject& global_object, FunctionObje
// 3. Perform map.[[DefineOwnProperty]](! ToString(𝔽(index)), PropertyDescriptor { [[Set]]: p, [[Get]]: g, [[Enumerable]]: false, [[Configurable]]: true }).
object->parameter_map().define_native_accessor(
PropertyKey { index },
[&environment, name](VM&, GlobalObject& global_object_getter) -> JS::ThrowCompletionOr<Value> {
[&environment, name](VM&, GlobalObject& global_object_getter) -> ThrowCompletionOr<Value> {
return MUST(environment.get_binding_value(global_object_getter, name, false));
},
[&environment, name](VM& vm, GlobalObject& global_object_setter) {

View File

@ -777,19 +777,19 @@ Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body()
if (bytecode_interpreter) {
if (!m_bytecode_executable) {
auto compile = [&](auto& node, auto kind, auto name) -> ThrowCompletionOr<NonnullOwnPtr<Bytecode::Executable>> {
auto executable_result = JS::Bytecode::Generator::generate(node, kind);
auto executable_result = Bytecode::Generator::generate(node, kind);
if (executable_result.is_error())
return vm.throw_completion<InternalError>(bytecode_interpreter->global_object(), ErrorType::NotImplemented, executable_result.error().to_string());
auto bytecode_executable = executable_result.release_value();
bytecode_executable->name = name;
auto& passes = JS::Bytecode::Interpreter::optimization_pipeline();
auto& passes = Bytecode::Interpreter::optimization_pipeline();
passes.perform(*bytecode_executable);
if constexpr (JS_BYTECODE_DEBUG) {
dbgln("Optimisation passes took {}us", passes.elapsed());
dbgln("Compiled Bytecode::Block for function '{}':", m_name);
}
if (JS::Bytecode::g_dump_bytecode)
if (Bytecode::g_dump_bytecode)
bytecode_executable->dump();
return bytecode_executable;

View File

@ -9,10 +9,10 @@
namespace JS {
FinalizationRegistry::FinalizationRegistry(Realm& realm, JS::JobCallback cleanup_callback, Object& prototype)
FinalizationRegistry::FinalizationRegistry(Realm& realm, JobCallback cleanup_callback, Object& prototype)
: Object(prototype)
, WeakContainer(heap())
, m_realm(JS::make_handle(realm))
, m_realm(make_handle(realm))
, m_cleanup_callback(move(cleanup_callback))
{
}

View File

@ -22,7 +22,7 @@ class FinalizationRegistry final
JS_OBJECT(FinalizationRegistry, Object);
public:
explicit FinalizationRegistry(Realm&, JS::JobCallback, Object& prototype);
explicit FinalizationRegistry(Realm&, JobCallback, Object& prototype);
virtual ~FinalizationRegistry() override = default;
void add_finalization_record(Cell& target, Value held_value, Object* unregister_token);
@ -41,7 +41,7 @@ private:
virtual void visit_edges(Visitor& visitor) override;
Handle<Realm> m_realm;
JS::JobCallback m_cleanup_callback;
JobCallback m_cleanup_callback;
struct FinalizationRecord {
Cell* target { nullptr };

View File

@ -72,10 +72,10 @@ ThrowCompletionOr<Value> GeneratorObject::next_impl(VM& vm, GlobalObject& global
auto previous_generated_value = TRY(generated_value(m_previous_value));
auto result = Object::create(global_object, global_object.object_prototype());
result->define_direct_property("value", previous_generated_value, JS::default_attributes);
result->define_direct_property("value", previous_generated_value, default_attributes);
if (m_done) {
result->define_direct_property("done", Value(true), JS::default_attributes);
result->define_direct_property("done", Value(true), default_attributes);
return result;
}
@ -85,7 +85,7 @@ ThrowCompletionOr<Value> GeneratorObject::next_impl(VM& vm, GlobalObject& global
if (!next_block) {
// The generator has terminated, now we can simply return done=true.
m_done = true;
result->define_direct_property("done", Value(true), JS::default_attributes);
result->define_direct_property("done", Value(true), default_attributes);
return result;
}
@ -116,8 +116,8 @@ ThrowCompletionOr<Value> GeneratorObject::next_impl(VM& vm, GlobalObject& global
m_previous_value = TRY(next_result);
result->define_direct_property("value", TRY(generated_value(m_previous_value)), JS::default_attributes);
result->define_direct_property("done", Value(m_done), JS::default_attributes);
result->define_direct_property("value", TRY(generated_value(m_previous_value)), default_attributes);
result->define_direct_property("done", Value(m_done), default_attributes);
return result;
}

View File

@ -488,7 +488,7 @@ JS_DEFINE_NATIVE_FUNCTION(GlobalObject::eval)
}
// 19.2.6.1.1 Encode ( string, unescapedSet ), https://tc39.es/ecma262/#sec-encode
static ThrowCompletionOr<String> encode([[maybe_unused]] JS::GlobalObject& global_object, String const& string, StringView unescaped_set)
static ThrowCompletionOr<String> encode(GlobalObject& global_object, String const& string, StringView unescaped_set)
{
auto& vm = global_object.vm();
auto utf16_string = Utf16String(string);
@ -544,7 +544,7 @@ static ThrowCompletionOr<String> encode([[maybe_unused]] JS::GlobalObject& globa
}
// 19.2.6.1.2 Decode ( string, reservedSet ), https://tc39.es/ecma262/#sec-decode
static ThrowCompletionOr<String> decode(JS::GlobalObject& global_object, String const& string, StringView reserved_set)
static ThrowCompletionOr<String> decode(GlobalObject& global_object, String const& string, StringView reserved_set)
{
StringBuilder decoded_builder;
auto code_point_start_offset = 0u;

View File

@ -117,7 +117,7 @@ ThrowCompletionOr<Value> canonical_code_for_display_names(GlobalObject& global_o
return vm.throw_completion<RangeError>(global_object, ErrorType::IntlInvalidLanguageTag, code);
// c. Return ! CanonicalizeUnicodeLocaleId(code).
auto canonicalized_tag = JS::Intl::canonicalize_unicode_locale_id(*locale_id);
auto canonicalized_tag = Intl::canonicalize_unicode_locale_id(*locale_id);
return js_string(vm, move(canonicalized_tag));
}

View File

@ -69,7 +69,7 @@ static ThrowCompletionOr<String> apply_options_to_tag(GlobalObject& global_objec
auto region = TRY(get_string_option(global_object, options, vm.names.region, Unicode::is_unicode_region_subtag));
// 10. Set tag to ! CanonicalizeUnicodeLocaleId(tag).
auto canonicalized_tag = JS::Intl::canonicalize_unicode_locale_id(*locale_id);
auto canonicalized_tag = Intl::canonicalize_unicode_locale_id(*locale_id);
// 11. Assert: tag matches the unicode_locale_id production.
locale_id = Unicode::parse_unicode_locale_id(canonicalized_tag);

View File

@ -431,7 +431,7 @@ Object* JSONObject::parse_json_object(GlobalObject& global_object, JsonObject co
{
auto* object = Object::create(global_object, global_object.object_prototype());
json_object.for_each_member([&](auto& key, auto& value) {
object->define_direct_property(key, parse_json_value(global_object, value), JS::default_attributes);
object->define_direct_property(key, parse_json_value(global_object, value), default_attributes);
});
return object;
}
@ -441,7 +441,7 @@ Array* JSONObject::parse_json_array(GlobalObject& global_object, JsonArray const
auto* array = MUST(Array::create(global_object, 0));
size_t index = 0;
json_array.for_each([&](auto& value) {
array->define_direct_property(index++, parse_json_value(global_object, value), JS::default_attributes);
array->define_direct_property(index++, parse_json_value(global_object, value), default_attributes);
});
return array;
}

View File

@ -77,14 +77,14 @@ static ThrowCompletionOr<Value> run_reaction_job(GlobalObject& global_object, Pr
// i. Let status be Call(promiseCapability.[[Reject]], undefined, « handlerResult.[[Value]] »).
auto* reject_function = promise_capability.value().reject;
dbgln_if(PROMISE_DEBUG, "run_reaction_job: Calling PromiseCapability's reject function @ {}", reject_function);
return JS::call(global_object, *reject_function, js_undefined(), *handler_result.value());
return call(global_object, *reject_function, js_undefined(), *handler_result.value());
}
// i. Else,
else {
// i. Let status be Call(promiseCapability.[[Resolve]], undefined, « handlerResult.[[Value]] »).
auto* resolve_function = promise_capability.value().resolve;
dbgln_if(PROMISE_DEBUG, "[PromiseReactionJob]: Calling PromiseCapability's resolve function @ {}", resolve_function);
return JS::call(global_object, *resolve_function, js_undefined(), *handler_result.value());
return call(global_object, *resolve_function, js_undefined(), *handler_result.value());
}
// j. Return Completion(status).
@ -95,7 +95,7 @@ PromiseJob create_promise_reaction_job(GlobalObject& global_object, PromiseReact
{
// 1. Let job be a new Job Abstract Closure with no parameters that captures reaction and argument and performs the following steps when called:
// See run_reaction_job for "the following steps".
auto job = [global_object = JS::make_handle(&global_object), reaction = JS::make_handle(&reaction), argument = JS::make_handle(argument)]() mutable {
auto job = [global_object = make_handle(&global_object), reaction = make_handle(&reaction), argument = make_handle(argument)]() mutable {
return run_reaction_job(*global_object.cell(), *reaction.cell(), argument.value());
};
@ -142,7 +142,7 @@ static ThrowCompletionOr<Value> run_resolve_thenable_job(GlobalObject& global_ob
if (then_call_result.is_error()) {
// i. Let status be Call(resolvingFunctions.[[Reject]], undefined, « thenCallResult.[[Value]] »).
dbgln_if(PROMISE_DEBUG, "run_resolve_thenable_job: then_call_result is an abrupt completion, calling reject function with value {}", *then_call_result.throw_completion().value());
auto status = JS::call(global_object, &reject_function, js_undefined(), *then_call_result.throw_completion().value());
auto status = call(global_object, &reject_function, js_undefined(), *then_call_result.throw_completion().value());
// ii. Return Completion(status).
return status;
@ -174,7 +174,7 @@ PromiseJob create_promise_resolve_thenable_job(GlobalObject& global_object, Prom
// 1. Let job be a new Job Abstract Closure with no parameters that captures promiseToResolve, thenable, and then and performs the following steps when called:
// See PromiseResolveThenableJob::call() for "the following steps".
// NOTE: This is done out of order, since `then` is moved into the lambda and `then` would be invalid if it was done at the start.
auto job = [global_object = JS::make_handle(&global_object), promise_to_resolve = JS::make_handle(&promise_to_resolve), thenable = JS::make_handle(thenable), then = move(then)]() mutable {
auto job = [global_object = make_handle(&global_object), promise_to_resolve = make_handle(&promise_to_resolve), thenable = make_handle(thenable), then = move(then)]() mutable {
return run_resolve_thenable_job(*global_object.cell(), *promise_to_resolve.cell(), thenable.value(), then);
};

View File

@ -109,7 +109,7 @@ ThrowCompletionOr<Value> perform_shadow_realm_eval(GlobalObject& global_object,
// b. If script is a List of errors, throw a SyntaxError exception.
if (parser.has_errors()) {
auto& error = parser.errors()[0];
return vm.throw_completion<JS::SyntaxError>(global_object, error.to_string());
return vm.throw_completion<SyntaxError>(global_object, error.to_string());
}
// c. If script Contains ScriptBody is false, return undefined.

View File

@ -1598,7 +1598,7 @@ ThrowCompletionOr<TriState> is_less_than(GlobalObject& global_object, bool left_
}
// 7.3.21 Invoke ( V, P [ , argumentsList ] ), https://tc39.es/ecma262/#sec-invoke
ThrowCompletionOr<Value> Value::invoke_internal(GlobalObject& global_object, JS::PropertyKey const& property_key, Optional<MarkedVector<Value>> arguments)
ThrowCompletionOr<Value> Value::invoke_internal(GlobalObject& global_object, PropertyKey const& property_key, Optional<MarkedVector<Value>> arguments)
{
auto& vm = global_object.vm();
auto property = TRY(get(global_object, property_key));

View File

@ -12,24 +12,24 @@
namespace JS {
static Syntax::TextStyle style_for_token_type(Gfx::Palette const& palette, JS::TokenType type)
static Syntax::TextStyle style_for_token_type(Gfx::Palette const& palette, TokenType type)
{
switch (JS::Token::category(type)) {
case JS::TokenCategory::Invalid:
switch (Token::category(type)) {
case TokenCategory::Invalid:
return { palette.syntax_comment() };
case JS::TokenCategory::Number:
case TokenCategory::Number:
return { palette.syntax_number() };
case JS::TokenCategory::String:
case TokenCategory::String:
return { palette.syntax_string() };
case JS::TokenCategory::Punctuation:
case TokenCategory::Punctuation:
return { palette.syntax_punctuation() };
case JS::TokenCategory::Operator:
case TokenCategory::Operator:
return { palette.syntax_operator() };
case JS::TokenCategory::Keyword:
case TokenCategory::Keyword:
return { palette.syntax_keyword(), true };
case JS::TokenCategory::ControlKeyword:
case TokenCategory::ControlKeyword:
return { palette.syntax_control_keyword(), true };
case JS::TokenCategory::Identifier:
case TokenCategory::Identifier:
return { palette.syntax_identifier() };
default:
return { palette.base_text() };
@ -38,8 +38,8 @@ static Syntax::TextStyle style_for_token_type(Gfx::Palette const& palette, JS::T
bool SyntaxHighlighter::is_identifier(u64 token) const
{
auto js_token = static_cast<JS::TokenType>(static_cast<size_t>(token));
return js_token == JS::TokenType::Identifier;
auto js_token = static_cast<TokenType>(static_cast<size_t>(token));
return js_token == TokenType::Identifier;
}
bool SyntaxHighlighter::is_navigatable([[maybe_unused]] u64 token) const
@ -51,7 +51,7 @@ void SyntaxHighlighter::rehighlight(Palette const& palette)
{
auto text = m_client->get_text();
JS::Lexer lexer(text);
Lexer lexer(text);
Vector<GUI::TextDocumentSpan> spans;
GUI::TextPosition position { 0, 0 };
@ -65,7 +65,7 @@ void SyntaxHighlighter::rehighlight(Palette const& palette)
position.set_column(position.column() + 1);
};
auto append_token = [&](StringView str, const JS::Token& token, bool is_trivia) {
auto append_token = [&](StringView str, Token const& token, bool is_trivia) {
if (str.is_empty())
return;
@ -76,7 +76,7 @@ void SyntaxHighlighter::rehighlight(Palette const& palette)
GUI::TextDocumentSpan span;
span.range.set_start(start);
span.range.set_end({ position.line(), position.column() });
auto type = is_trivia ? JS::TokenType::Invalid : token.type();
auto type = is_trivia ? TokenType::Invalid : token.type();
auto style = style_for_token_type(palette, type);
span.attributes.color = style.color;
span.attributes.bold = style.bold;
@ -97,7 +97,7 @@ void SyntaxHighlighter::rehighlight(Palette const& palette)
append_token(token.trivia(), token, true);
append_token(token.value(), token, false);
if (token.type() == JS::TokenType::Eof)
if (token.type() == TokenType::Eof)
was_eof = true;
}
@ -113,15 +113,16 @@ Vector<Syntax::Highlighter::MatchingTokenPair> SyntaxHighlighter::matching_token
{
static Vector<Syntax::Highlighter::MatchingTokenPair> pairs;
if (pairs.is_empty()) {
pairs.append({ static_cast<u64>(JS::TokenType::CurlyOpen), static_cast<u64>(JS::TokenType::CurlyClose) });
pairs.append({ static_cast<u64>(JS::TokenType::ParenOpen), static_cast<u64>(JS::TokenType::ParenClose) });
pairs.append({ static_cast<u64>(JS::TokenType::BracketOpen), static_cast<u64>(JS::TokenType::BracketClose) });
pairs.append({ static_cast<u64>(TokenType::CurlyOpen), static_cast<u64>(TokenType::CurlyClose) });
pairs.append({ static_cast<u64>(TokenType::ParenOpen), static_cast<u64>(TokenType::ParenClose) });
pairs.append({ static_cast<u64>(TokenType::BracketOpen), static_cast<u64>(TokenType::BracketClose) });
}
return pairs;
}
bool SyntaxHighlighter::token_types_equal(u64 token1, u64 token2) const
{
return static_cast<JS::TokenType>(token1) == static_cast<JS::TokenType>(token2);
return static_cast<TokenType>(token1) == static_cast<TokenType>(token2);
}
}

View File

@ -23,14 +23,14 @@ SyntheticModule::SyntheticModule(Vector<FlyString> export_names, SyntheticModule
}
// 1.2.3.1 GetExportedNames( exportStarSet ), https://tc39.es/proposal-json-modules/#sec-smr-getexportednames
ThrowCompletionOr<Vector<FlyString>> JS::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> JS::SyntheticModule::resolve_export(VM&, FlyString 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))
@ -41,7 +41,7 @@ ThrowCompletionOr<ResolvedBinding> JS::SyntheticModule::resolve_export(VM&, FlyS
}
// 1.2.3.3 Link ( ), https://tc39.es/proposal-json-modules/#sec-smr-instantiate
ThrowCompletionOr<void> JS::SyntheticModule::link(VM& vm)
ThrowCompletionOr<void> SyntheticModule::link(VM& vm)
{
// Note: Has some changes from PR: https://github.com/tc39/proposal-json-modules/pull/13.
// Which includes renaming it from Instantiate ( ) to Link ( ).
@ -73,7 +73,7 @@ ThrowCompletionOr<void> JS::SyntheticModule::link(VM& vm)
}
// 1.2.3.4 Evaluate ( ), https://tc39.es/proposal-json-modules/#sec-smr-Evaluate
ThrowCompletionOr<Promise*> JS::SyntheticModule::evaluate(VM& vm)
ThrowCompletionOr<Promise*> SyntheticModule::evaluate(VM& vm)
{
// Note: Has some changes from PR: https://github.com/tc39/proposal-json-modules/pull/13.
// 1. Suspend the currently running execution context.