1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:38:12 +00:00

LibJS: Add argument(i) and argument_count() to Interpreter

Add some convenience accessors for retrieving arguments from the
current call frame.
This commit is contained in:
Andreas Kling 2020-04-01 22:38:59 +02:00
parent 1549c5c48b
commit cd1d369cdd
9 changed files with 49 additions and 34 deletions

View file

@ -211,9 +211,9 @@ ReplObject::~ReplObject()
JS::Value ReplObject::exit_interpreter(JS::Interpreter& interpreter)
{
if (interpreter.call_frame().arguments.is_empty())
if (!interpreter.argument_count())
exit(0);
int exit_code = interpreter.call_frame().arguments[0].to_number().as_double();
int exit_code = interpreter.argument(0).to_number().as_double();
exit(exit_code);
return JS::js_undefined();
}
@ -230,10 +230,10 @@ JS::Value ReplObject::repl_help(JS::Interpreter& interpreter)
JS::Value ReplObject::load_file(JS::Interpreter& interpreter)
{
if (interpreter.call_frame().arguments.is_empty())
if (!interpreter.argument_count())
return JS::Value(false);
Vector<JS::Value> files = interpreter.call_frame().arguments;
for (JS::Value file : files) {
for (auto& file : interpreter.call_frame().arguments) {
String file_name = file.as_string()->string();
auto js_file = Core::File::construct(file_name);
if (!js_file->open(Core::IODevice::ReadOnly)) {