mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:27:35 +00:00
js/LibJS: Move test functions to pure javascript.
The addition of assert functions to Userland/js was done before we had load(..) implemented. Now that it exists, it seems like the right move the test helper functions to pure javascript instead of poluting js with random global functions.
This commit is contained in:
parent
9477efe970
commit
d74ad81402
91 changed files with 193 additions and 19 deletions
|
@ -372,28 +372,9 @@ void repl(JS::Interpreter& interpreter)
|
|||
}
|
||||
}
|
||||
|
||||
JS::Value assert_impl(JS::Interpreter& interpreter)
|
||||
{
|
||||
if (!interpreter.argument_count())
|
||||
return interpreter.throw_exception<JS::TypeError>("No arguments specified");
|
||||
|
||||
auto assertion_value = interpreter.argument(0).to_boolean();
|
||||
if (!assertion_value)
|
||||
return interpreter.throw_exception<JS::Error>("AssertionError", "The assertion failed!");
|
||||
|
||||
return JS::Value(assertion_value);
|
||||
}
|
||||
|
||||
JS::Value assert_not_reached(JS::Interpreter& interpreter)
|
||||
{
|
||||
return interpreter.throw_exception<JS::Error>("AssertionError", "assertNotReached() was reached!");
|
||||
}
|
||||
|
||||
void enable_test_mode(JS::Interpreter& interpreter)
|
||||
{
|
||||
interpreter.global_object().put_native_function("load", ReplObject::load_file);
|
||||
interpreter.global_object().put_native_function("assert", assert_impl);
|
||||
interpreter.global_object().put_native_function("assertNotReached", assert_not_reached);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue