1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:57:45 +00:00

LibJS: Implement console.assert()

This commit is contained in:
Linus Groh 2021-04-18 17:08:14 +02:00
parent e37421bddc
commit 8d490aba76
12 changed files with 89 additions and 9 deletions

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 2020, Emanuele Torre <torreemanuele6@gmail.com>
* Copyright (c) 2020, Linus Groh <mail@linusgroh.de>
* Copyright (c) 2020-2021, Linus Groh <mail@linusgroh.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -118,6 +118,13 @@ Value Console::count_reset()
return js_undefined();
}
Value Console::assert_()
{
if (m_client)
return m_client->assert_();
return js_undefined();
}
unsigned Console::counter_increment(String label)
{
auto value = m_counters.get(label);

View file

@ -57,13 +57,11 @@ public:
Value info();
Value log();
Value warn();
Value clear();
Value trace();
Value count();
Value count_reset();
Value assert_();
unsigned counter_increment(String label);
bool counter_reset(String label);
@ -77,7 +75,7 @@ private:
class ConsoleClient {
public:
ConsoleClient(Console& console)
explicit ConsoleClient(Console& console)
: m_console(console)
{
}
@ -91,6 +89,7 @@ public:
virtual Value trace() = 0;
virtual Value count() = 0;
virtual Value count_reset() = 0;
virtual Value assert_() = 0;
protected:
virtual ~ConsoleClient() = default;

View file

@ -71,6 +71,7 @@ namespace JS {
P(asUintN) \
P(asin) \
P(asinh) \
P(assert) \
P(at) \
P(atan) \
P(atan2) \

View file

@ -1,6 +1,6 @@
/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2020, Linus Groh <mail@linusgroh.de>
* Copyright (c) 2020-2021, Linus Groh <mail@linusgroh.de>
* Copyright (c) 2020, Emanuele Torre <torreemanuele6@gmail.com>
* All rights reserved.
*
@ -50,6 +50,7 @@ void ConsoleObject::initialize(GlobalObject& global_object)
define_native_function(vm.names.count, count);
define_native_function(vm.names.countReset, count_reset);
define_native_function(vm.names.clear, clear);
define_native_function(vm.names.assert, assert_);
}
ConsoleObject::~ConsoleObject()
@ -101,4 +102,9 @@ JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::clear)
return global_object.console().clear();
}
JS_DEFINE_NATIVE_FUNCTION(ConsoleObject::assert_)
{
return global_object.console().assert_();
}
}

View file

@ -48,6 +48,7 @@ private:
JS_DECLARE_NATIVE_FUNCTION(count);
JS_DECLARE_NATIVE_FUNCTION(count_reset);
JS_DECLARE_NATIVE_FUNCTION(clear);
JS_DECLARE_NATIVE_FUNCTION(assert_);
};
}

View file

@ -321,10 +321,10 @@ void VM::throw_exception(Exception& exception)
unwind(ScopeType::Try);
}
String VM::join_arguments() const
String VM::join_arguments(size_t start_index) const
{
StringBuilder joined_arguments;
for (size_t i = 0; i < argument_count(); ++i) {
for (size_t i = start_index; i < argument_count(); ++i) {
joined_arguments.append(argument(i).to_string_without_side_effects().characters());
if (i != argument_count() - 1)
joined_arguments.append(' ');

View file

@ -222,7 +222,7 @@ public:
Value construct(Function&, Function& new_target, Optional<MarkedValueList> arguments, GlobalObject&);
String join_arguments() const;
String join_arguments(size_t start_index = 0) const;
Value resolve_this_binding(GlobalObject&) const;
const ScopeObject* find_this_scope() const;