mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-23 02:42:10 +00:00
js: Coerce assert() argument to boolean
It's JavaScript after all :^)
This commit is contained in:
parent
62d0fa5af8
commit
6d5d668585
Notes:
sideshowbarker
2024-07-19 07:39:48 +09:00
Author: https://github.com/linusg
Commit: 6d5d668585
Pull-request: https://github.com/SerenityOS/serenity/pull/1769
1 changed files with 4 additions and 7 deletions
|
@ -360,16 +360,13 @@ void repl(JS::Interpreter& interpreter)
|
||||||
JS::Value assert_impl(JS::Interpreter& interpreter)
|
JS::Value assert_impl(JS::Interpreter& interpreter)
|
||||||
{
|
{
|
||||||
if (!interpreter.argument_count())
|
if (!interpreter.argument_count())
|
||||||
return interpreter.throw_exception<JS::Error>("TypeError", "No arguments specified");
|
return interpreter.throw_exception<JS::TypeError>("No arguments specified");
|
||||||
|
|
||||||
auto assertion_value = interpreter.argument(0);
|
auto assertion_value = interpreter.argument(0).to_boolean();
|
||||||
if (!assertion_value.is_boolean())
|
if (!assertion_value)
|
||||||
return interpreter.throw_exception<JS::Error>("TypeError", "The first argument is not a boolean");
|
|
||||||
|
|
||||||
if (!assertion_value.to_boolean())
|
|
||||||
return interpreter.throw_exception<JS::Error>("AssertionError", "The assertion failed!");
|
return interpreter.throw_exception<JS::Error>("AssertionError", "The assertion failed!");
|
||||||
|
|
||||||
return assertion_value;
|
return JS::Value(assertion_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue